Lord of SQL injection – xavis
Level 19
Source Code
<?php include "../config.php"; login_chk(); dbconnect(); if(preg_match('/prob|_|\.|\(\)/i', $_GET[pw])) exit("No Hack ~_~"); if(preg_match('/regex|like/i', $_GET[pw])) exit("HeHe"); $query = "select id from prob_xavis where id='admin' and pw='{$_GET[pw]}'"; 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_xavis where id='admin' and pw='{$_GET[pw]}'"; $result = @mysql_fetch_array(mysql_query($query)); if(($result['pw']) && ($result['pw'] == $_GET['pw'])) solve("xavis"); highlight_file(__FILE__); ?>
Analyse
http://los.sandbox.cash/xavis-~~.php?pw=123
이라고 입력하게 되면
select id from prob_xavis where id='admin' pw='123'
과 같이 MySQL 쿼리문이 입력된다.
그리고 6번째 줄을 보면 'regex', 'like'를 필터링해 정규식으로 풀 수 없게 해놓았고,
가 admin으로의 pw와 일치하면 xavis문제가 풀린다.
10번째 줄에서 SQL 쿼리로 가져온 id를 "Hello (id)"형식으로 출력한다.
또한 12번째 줄에서 addslashes함수를 통해 '나 "등에 \(역 슬레시)를 붙여 처리한 뒤
admin의 pw를 가져온다. 그 후 &result['pw']
Frist Hint is next page