[Level 13]Lord of SQL injection – bugbear

Lord of SQL injection – bugbear

Level 13


Source Code

<?php 
  include "../config.php"; 
  login_chk(); 
  dbconnect(); 
  if(preg_match('/prob|_|\.|\(\)/i', $_GET[no])) exit("No Hack ~_~"); 
  if(preg_match('/\'/i', $_GET[pw])) exit("HeHe"); 
  if(preg_match('/\'|substr|ascii|=|or|and| |like|0x/i', $_GET[no])) exit("HeHe"); 
  $query = "select id from prob_bugbear where id='guest' and pw='{$_GET[pw]}' and no={$_GET[no]}"; 
  echo "<hr>query : <strong>{$query}</strong><hr><br>"; 
  $result = @mysql_fetch_array(mysql_query($query)); 
  if($result['id']) echo "<h2>Hello {$result[id]}</h2>"; 
   
  $_GET[pw] = addslashes($_GET[pw]); 
  $query = "select pw from prob_bugbear where id='admin' and pw='{$_GET[pw]}'"; 
  $result = @mysql_fetch_array(mysql_query($query)); 
  if(($result['pw']) && ($result['pw'] == $_GET['pw'])) solve("bugbear"); 
  highlight_file(__FILE__); 
?>

Analyse

http://los.sandbox.cash/bugbear-~~.php?pw=123&no=12 이라고 입력하게 되면
select id from prob_bugbear where id='guest' and pw='123' no=12과 같이 MySQL 쿼리문이 입력된다.
그리고 5번째 줄에서 ‘or’, ‘and’, ‘substr’, ‘=’, ‘ascii’, ‘ ‘, ‘like’, ‘0x’, 싱글쿼터가 필터링 되어있다.
 15번째 줄을 보면 &result['pw']에 admin의 pw가 들어가야만 bugbear문제가 풀린다.

이전 문제처럼 ‘를 사용할 수 도 없고 hex값으로 우회하자니 0x가 필터링 되어있다. 어떻게 해야할까?

Frist Hint is next page

카테고리LOS

글의 문제가 있다면 댓글을 달아 주세요.

이 사이트는 스팸을 줄이는 아키스밋을 사용합니다. 댓글이 어떻게 처리되는지 알아보십시오.