Lord of SQL injection – ALL-Clear
Level ALL-Clear
Source Code
go deep
blog of SilNex
Lord of Sql injection
Level ALL-Clear
go deep
Level 25
<?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"); ?>
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
Level 24
LEVEL BROKEN
(2016/09/09 ~ )
Level 23
LEVEL BROKEN
(2016/09/09 ~ )
Level 22
<?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__); ?>
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
Level 21
<?php include "../config.php"; login_chk(); dbconnect(); if(preg_match('/prob|_|\.|\(\)/i', $_GET[pw])) exit("No Hack ~_~"); if(preg_match('/sleep|benchmark/i', $_GET[pw])) exit("HeHe"); $query = "select id from prob_iron_golem where id='admin' and pw='{$_GET[pw]}'"; $result = @mysql_fetch_array(mysql_query($query)); if(mysql_error()) exit(mysql_error()); echo "<hr>query : <strong>{$query}</strong><hr><br>"; $_GET[pw] = addslashes($_GET[pw]); $query = "select pw from prob_iron_golem where id='admin' and pw='{$_GET[pw]}'"; $result = @mysql_fetch_array(mysql_query($query)); if(($result['pw']) && ($result['pw'] == $_GET['pw'])) solve("iron_golem"); highlight_file(__FILE__); ?>
http://los.sandbox.cash/iron_golem-~~.php?pw=123
이라고 입력하게 되면
select id from prob_iron_golem where id='admin' pw='123'
과 같이 MySQL 쿼리문이 입력된다.
6번째 줄에서 sleep과 benchmark를 필터링 하고 있다.
이를 이용해
다만 10번째 줄을 보면 SQL문장이 오류가 일어날 경우 그 오류를 출력 하는 함수가 존재한다.
&result['pw']
가 입력한 pw와 일치시켜야 iron_golem문제가 풀린다.
Frist Hint is next page
Level 20
<?php include "../config.php"; login_chk(); dbconnect(); if(preg_match('/prob|_|\.|\(\)/i', $_GET[pw])) exit("No Hack ~_~"); $query = "select id from prob_dragon where id='guest'# 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>"; if($result['id'] == 'admin') solve("dragon"); highlight_file(__FILE__); ?>
http://los.sandbox.cash/dragon-~~.php?pw=123
이라고 입력하게 되면
select id from prob_dragon where id='guest'# pw='123'
과 같이 MySQL 쿼리문이 입력된다.
보다시피 id뒤에 주석 처리가 되어있는데 이를 그대로 실행하면 "Hello guest"가 나오게 된다.
가 admin이어야지 dragon문제가 풀린다.
하지만 &result['id']
Frist Hint is next page
Level 19
<?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__); ?>
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