Lord of SQL injection – umaru
Level 25
Source Code
<?php include "../config.php"; login_chk(); dbconnect(); function reset_flag(){ $new_flag = substr(md5(rand(10000000,99999999)."qwer".rand(10000000,99999999)."asdf".rand(10000000,99999999)),8,16); $chk = @mysql_fetch_array(mysql_query("select id from prob_umaru where id='{$_SESSION[los_id]}'")); if(!$chk[id]) mysql_query("insert into prob_umaru values('{$_SESSION[los_id]}','{$new_flag}')"); else mysql_query("update prob_umaru set flag='{$new_flag}' where id='{$_SESSION[los_id]}'"); echo "reset ok"; highlight_file(__FILE__); exit(); } if(!$_GET[flag]){ highlight_file(__FILE__); exit; } if(preg_match('/prob|_|\./i', $_GET[flag])) exit("No Hack ~_~"); if(preg_match('/id|where|order|limit|,/i', $_GET[flag])) exit("HeHe"); if(strlen($_GET[flag])>100) exit("HeHe"); $realflag = @mysql_fetch_array(mysql_query("select flag from prob_umaru where id='{$_SESSION[los_id]}'")); @mysql_query("create temporary table prob_umaru_temp as select * from prob_umaru where id='{$_SESSION[los_id]}'"); @mysql_query("update prob_umaru_temp set flag={$_GET[flag]}"); $tempflag = @mysql_fetch_array(mysql_query("select flag from prob_umaru_temp")); if((!$realflag[flag]) || ($realflag[flag] != $tempflag[flag])) reset_flag(); if($realflag[flag] === $_GET[flag]) solve("umaru"); ?>
Analyse
http://los.sandbox.cash/umaru-~~.php?flag=123
이라고 입력하게 되면
update prob_umaru_temp set flag=123
과 같이 MySQL 쿼리문이 입력된다.
다만 매번 flag가 reset_flag에 의해서 초기화 된다.
그리고
&result[flag]
가 입력한 flag와 일치해야 umaru문제가 풀린다.
즉, 일반적인 Blind SQLi를 하게되면 한글자 확인하면 초기화되고 다시 한글자 확인하면 초기화 된다.
Frist Hint is next page