Unverified Commit 121f875a by Marcin Bury Committed by GitHub

Fix telnet timeout (#439)

* Adding verbosity level to prints

* Checking if telnet connection was successful
parent a4e0390f
......@@ -34,9 +34,9 @@ class FTPClient(Exploit):
try:
ftp_client.connect(self.target, self.port, timeout=FTP_TIMEOUT)
except (socket.error, socket.timeout):
print_error("Connection error")
print_error("Connection error", verbose=self.verbosity)
except Exception as err:
print_error(err)
print_error(err, verbose=self.verbosity)
else:
return ftp_client
......
......@@ -85,12 +85,12 @@ class SSHClient(Exploit):
return True
except socket.error:
print_error("Connection error")
print_error("Connection error", verbose=self.verbosity)
ssh_client.close()
return False
except Exception as err:
print_error("Err: {}".format(err))
print_error("Err: {}".format(err), verbose=self.verbosity)
ssh_client.close()
return False
......@@ -182,7 +182,7 @@ class SSHClient(Exploit):
chan.send(d)
except Exception as err:
print_error("Err: {}".format(err))
print_error("Err: {}".format(err), verbose=self.verbosity)
def ssh_close(self, ssh_client):
if ssh_client:
......
......@@ -2,6 +2,7 @@ import socket
from routersploit.core.exploit.exploit import Exploit
from routersploit.core.exploit.exploit import Protocol
from routersploit.core.exploit.option import OptBool
from routersploit.core.exploit.printer import print_status
from routersploit.core.exploit.printer import print_error
from routersploit.core.exploit.utils import is_ipv4
......@@ -16,13 +17,15 @@ class TCPClient(Exploit):
target_protocol = Protocol.TCP
verbosity = OptBool("true", "Enable verbose output: true/false")
def tcp_create(self):
if is_ipv4(self.target):
tcp_client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
elif is_ipv6(self.target):
tcp_client = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
else:
print_error("Target address is not valid IPv4 nor IPv6 address")
print_error("Target address is not valid IPv4 nor IPv6 address", verbose=self.verbosity)
return None
tcp_client.settimeout(TCP_SOCKET_TIMEOUT)
......@@ -33,12 +36,12 @@ class TCPClient(Exploit):
tcp_client = self.tcp_create()
tcp_client.connect((self.target, self.port))
print_status("Connection established")
print_status("Connection established", verbose=self.verbosity)
return tcp_client
except Exception as err:
print_error("Could not connect")
print_error(err)
print_error("Could not connect", verbose=self.verbosity)
print_error(err, verbose=self.verbosity)
return None
......@@ -47,7 +50,7 @@ class TCPClient(Exploit):
if type(data) is bytes:
return tcp_client.send(data)
else:
print_error("Data to send is not type of bytes")
print_error("Data to send is not type of bytes", verbose=self.verbosity)
return None
......@@ -67,9 +70,9 @@ class TCPClient(Exploit):
return response
except socket.timeout:
print_error("Socket did timeout")
print_error("Socket did timeout", verbose=self.verbosity)
except socket.error:
print_error("Socket error")
print_error("Socket error", verbose=self.verbosity)
return None
......
......@@ -40,6 +40,9 @@ class TelnetClient(Exploit):
for _ in range(retries):
try:
telnet_client = self.telnet_connect(target=target, port=port)
if not telnet_client:
continue
telnet_client.expect([b"Login: ", b"login: ", b"Username: ", b"username: "], 5)
telnet_client.write(bytes(username, "utf-8") + b"\r\n")
telnet_client.expect([b"Password: ", b"password: "], 5)
......@@ -55,9 +58,9 @@ class TelnetClient(Exploit):
print_error("Telnet Authentication Failed - Username: '{}' Password: '{}'".format(username, password), verbose=self.verbosity)
break
except EOFError:
print_error("Telnet connection error")
print_error("Telnet connection error", verbose=self.verbosity)
except Exception as err:
print_error(err)
print_error(err, verbose=self.verbosity)
return None
......
......@@ -2,6 +2,7 @@ import socket
from routersploit.core.exploit.exploit import Exploit
from routersploit.core.exploit.exploit import Protocol
from routersploit.core.exploit.option import OptBool
from routersploit.core.exploit.printer import print_error
from routersploit.core.exploit.utils import is_ipv4
from routersploit.core.exploit.utils import is_ipv6
......@@ -15,13 +16,15 @@ class UDPClient(Exploit):
target_protocol = Protocol.UDP
verbosity = OptBool("true", "Enable verbose output: true/false")
def udp_create(self):
if is_ipv4(self.target):
udp_client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
elif is_ipv6(self.target):
udp_client = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
else:
print_error("Target address is not valid IPv4 nor IPv6 address")
print_error("Target address is not valid IPv4 nor IPv6 address", verbose=self.verbosity)
return None
udp_client.settimeout(UDP_SOCKET_TIMEOUT)
......@@ -34,7 +37,7 @@ class UDPClient(Exploit):
elif type(data) is str:
return udp_client.sendto(bytes(data, "utf-8"), (self.target, self.port))
else:
print_error("Data to send is not type of bytes or string")
print_error("Data to send is not type of bytes or string", verbose=self.verbosity)
return None
......@@ -44,9 +47,9 @@ class UDPClient(Exploit):
response = udp_client.recv(num)
return str(response, "utf-8")
except socket.timeout:
print_error("Socket did timeout")
print_error("Socket did timeout", verbose=self.verbosity)
except socket.error:
print_error("Socket err")
print_error("Socket err", verbose=self.verbosity)
return None
......
#!/usr/bin/env python3
from __future__ import print_function
import logging.handlers
import sys
if sys.version_info.major < 3:
print("RouterSploit supports only Python3. Rerun application in Python3 environment.")
exit(0)
import logging.handlers
from routersploit.interpreter import RoutersploitInterpreter
log_handler = logging.handlers.RotatingFileHandler(filename="routersploit.log", maxBytes=500000)
......
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