Lord of SQL injection – dark_eyes
Level 22
Source Code
<?php include "../config.php"; login_chk(); dbconnect(); if(preg_match('/prob|_|\.|\(\)/i', $_GET[pw])) exit("No Hack ~_~"); if(preg_match('/col|if|case|when|sleep|benchmark/i', $_GET[pw])) exit("HeHe"); $query = "select id from prob_dark_eyes where id='admin' and pw='{$_GET[pw]}'"; $result = @mysql_fetch_array(mysql_query($query)); if(mysql_error()) exit(); echo "<hr>query : <strong>{$query}</strong><hr><br>"; $_GET[pw] = addslashes($_GET[pw]); $query = "select pw from prob_dark_eyes where id='admin' and pw='{$_GET[pw]}'"; $result = @mysql_fetch_array(mysql_query($query)); if(($result['pw']) && ($result['pw'] == $_GET['pw'])) solve("dark_eyes"); highlight_file(__FILE__); ?>
Analyse
http://los.sandbox.cash/dark_eyes-~~.php?pw=123
이라고 입력하게 되면
select id from prob_dark_eyes where id='admin' pw='123'
과 같이 MySQL 쿼리문이 입력된다.
6번째 줄에서 'if', 'case', 'when', 'sleep'등를 필터링 하고 있다.
이를 이용해
게다가 10번째 줄을 보면 SQL문장이 오류가 일어날 경우에도 오류를 출력하지 않는다.
&result['pw']
가 입력한 pw와 일치시켜야 dark_eyes문제가 풀린다.
Frist Hint is next page