write-up/LOS write-up

LOS (Lord of SQL injection) 문제 17번 zombie_assassin write-up

정보보호학과 새내기 2021. 7. 10. 12:04
반응형
SMALL

문제 17번 - zombie_assassin

 

query : select id from prob_zombie_assassin where id='' and pw=''

<?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__); 
?>

일단 다른 문제들과 같이 php 코드가 주어져있다.

 

먼저 필터링 함수를 확인하면 addslashes랑 strrev 함수가 있는 것을 확인할 수 있다.

addslashes함수는 \를 추가해주는 함수인데 우리가 표현할 때 문자형이라는 것을 알리기 위해 \를 사용하듯이 저절로 필요한 문자들(\, ' , " , NULL) 앞에 추가해준다. (즉 우리가 임의로 넣은 \을 문자로 인식하게 만들어버린다.)

strrev함수는 문자열을 거꾸로 뒤집는 함수이다.

추가로 id와 pw를 받는 변수가 prob와 _ , . , ( , )을 필터링하고 대소문자를 구별하지 않는 것을 확인할 수 있다.

<?php 
  $_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 ~_~"); 
?>

 

clear 조건을 확인하기 위해 조건문 코드를 확인해보니 쿼리문이 참이 되면 된다는 것을 알 수 있다.

<?php 
  $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__); 
?>

 

일단 strrev를 우회하기 위해서는 문자열을 통째로 거꾸로 집어넣으면 되고, addslashes함수 때문에 \를 못 넣는 것은 %00을 넣어 대신할 수 있다.

 

따라서 id=%00&&pw=%231=1%20ro을 입력하면 된다. (해석하면 --->id=\&&pw='or 1=1%23)

 

solve

https://los.rubiya.kr/chall/zombie_assassin_eac7521e07fe5f298301a44b61ffeec0.php?id=%00&&pw=%231=1%20ro

클리어 화면

반응형
LIST