Lord of SQL injection – nightmare
Level 18
Source Code
<?php include "../config.php"; login_chk(); dbconnect(); if(preg_match('/prob|_|\.|\(\)|#|-/i', $_GET[pw])) exit("No Hack ~_~"); if(strlen($_GET[pw])>6) exit("No Hack ~_~"); $query = "select id from prob_nightmare where pw=('{$_GET[pw]}') and id!='admin'"; echo "<hr>query : <strong>{$query}</strong><hr><br>"; $result = @mysql_fetch_array(mysql_query($query)); if($result['id']) solve("nightmare"); highlight_file(__FILE__); ?>
Analyse
http://los.sandbox.cash/nightmare-~~.php?pw=123
이라고 입력하게 되면
select id from prob_nightmare where pw=('123') and id!='admin'
과 같이 MySQL 쿼리문이 입력된다.
6번째 줄을 보면 pw의 길이가 6이 넘어가면 "No Hack ~_~"을 출력되며 #, -- 등의 주석을 모두 필터링 하였다.
가 설정 되어있으면 nightmare문제가 풀린다.
그리고 10번째 줄을 보면 &result['id']
Frist Hint is next page