Skip to content

Commit

Permalink
Adding multiple tests (threat9#545)
Browse files Browse the repository at this point in the history
* Adding multiple tests

* Fixing code style
  • Loading branch information
lucyoa authored Nov 3, 2018
1 parent a03e81d commit 58a2eda
Show file tree
Hide file tree
Showing 54 changed files with 649 additions and 54 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
DIRECTORY=.
EXCLUDED=.git,rsf.py
RSF_IMAGE=routersploit
FLAKE8_IGNORED_RULES=E501,F405,F403
FLAKE8_IGNORED_RULES=E501,F405,F403,W504

build:
docker build -t $(RSF_IMAGE) .
Expand Down
2 changes: 1 addition & 1 deletion routersploit/core/exploit/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class RoutersploitException(Exception):
def __init__(self, msg: str=""):
def __init__(self, msg: str = ""):
super(RoutersploitException, self).__init__(msg)


Expand Down
12 changes: 6 additions & 6 deletions routersploit/core/exploit/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
WORDLISTS_DIR = wordlists.__path__[0]


def random_text(length: int, alph: str=string.ascii_letters + string.digits) -> str:
def random_text(length: int, alph: str = string.ascii_letters + string.digits) -> str:
""" Generates random string text
:param int length: length of text to generate
Expand Down Expand Up @@ -79,7 +79,7 @@ def convert_port(port: int) -> bytes:
return bytes.fromhex(res)


def index_modules(modules_directory: str=MODULES_DIR) -> list:
def index_modules(modules_directory: str = MODULES_DIR) -> list:
""" Returns list of all exploits modules
:param str modules_directory: path to modules directory
Expand Down Expand Up @@ -123,7 +123,7 @@ def import_exploit(path: str):
)


def iter_modules(modules_directory: str=MODULES_DIR) -> list:
def iter_modules(modules_directory: str = MODULES_DIR) -> list:
""" Iterates over valid modules
:param str modules_directory: path to modules directory
Expand Down Expand Up @@ -285,8 +285,8 @@ def _compare_versions(version1, version2):
if version1 > version2 then 1
"""

arr1 = re.sub("\D", ".", str(version1)).split(".")
arr2 = re.sub("\D", ".", str(version2)).split(".")
arr1 = re.sub(r"\D", ".", str(version1)).split(".")
arr2 = re.sub(r"\D", ".", str(version2)).split(".")

i = 0

Expand All @@ -302,7 +302,7 @@ def _compare_versions(version1, version2):
return 0


def detect_file_content(content: str, f: str="/etc/passwd") -> bool:
def detect_file_content(content: str, f: str = "/etc/passwd") -> bool:
""" Detect specific file content in content
:param str content: file content that should be analyzed
Expand Down
8 changes: 4 additions & 4 deletions routersploit/core/ftp/ftp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class FTPCli(object):
""" FTP Client provides methods to handle communication with FTP server """

def __init__(self, ftp_target: str, ftp_port: int, ssl: bool=False, verbosity: bool=False) -> None:
def __init__(self, ftp_target: str, ftp_port: int, ssl: bool = False, verbosity: bool = False) -> None:
""" FTP client constructor
:param str ftp_target: target FTP server ip address
Expand All @@ -35,7 +35,7 @@ def __init__(self, ftp_target: str, ftp_port: int, ssl: bool=False, verbosity: b
else:
self.ftp_client = ftplib.FTP()

def connect(self, retries: int=1) -> bool:
def connect(self, retries: int = 1) -> bool:
""" Connect to FTP server
:param int retries: number of retry attempts
Expand Down Expand Up @@ -65,7 +65,7 @@ def login(self, username: str, password: str) -> bool:
self.ftp_client.login(username, password)
print_success(self.peer, "FTP Authentication Successful - Username: '{}' Password: '{}'".format(username, password), verbose=self.verbosity)
return True
except Exception as err:
except Exception:
print_error(self.peer, "FTP Authentication Failed - Username: '{}' Password: '{}'".format(username, password), verbose=self.verbosity)

self.ftp_client.close()
Expand Down Expand Up @@ -122,7 +122,7 @@ class FTPClient(Exploit):
ssl = OptBool(False, "SSL enabled: true/false")
verbosity = OptBool(True, "Enable verbose output: true/false")

def ftp_create(self, target: str=None, port: int=None) -> FTPCli:
def ftp_create(self, target: str = None, port: int = None) -> FTPCli:
""" Create FTP client
:param str target: target FTP server ip address
Expand Down
4 changes: 2 additions & 2 deletions routersploit/core/http/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class HTTPClient(Exploit):
verbosity = OptBool(True, "Verbosity enabled: true/false")
ssl = OptBool(False, "SSL enabled: true/false")

def http_request(self, method: str, path: str, session: requests=requests, **kwargs) -> requests.Response:
def http_request(self, method: str, path: str, session: requests = requests, **kwargs) -> requests.Response:
""" Requests HTTP resource
:param str method: method that should be issued e.g. GET, POST
Expand Down Expand Up @@ -57,7 +57,7 @@ def http_request(self, method: str, path: str, session: requests=requests, **kwa

return None

def get_target_url(self, path: str="") -> str:
def get_target_url(self, path: str = "") -> str:
""" Get target URL
:param str path: path to http server resource
Expand Down
6 changes: 3 additions & 3 deletions routersploit/core/snmp/snmp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class SNMPCli(object):
""" SNMP Client provides methods to handle communication with SNMP server """

def __init__(self, snmp_target: str, snmp_port: int, verbosity: bool=False) -> None:
def __init__(self, snmp_target: str, snmp_port: int, verbosity: bool = False) -> None:
""" SNMP client constructor
:param str snmp_target: target SNMP server ip address
Expand All @@ -28,7 +28,7 @@ def __init__(self, snmp_target: str, snmp_port: int, verbosity: bool=False) -> N

self.peer = "{}:{}".format(self.snmp_target, snmp_port)

def get(self, community_string: str, oid: str, version: int=1, retries: int=0) -> bytes:
def get(self, community_string: str, oid: str, version: int = 1, retries: int = 0) -> bytes:
""" Get OID from SNMP server
:param str community_string: SNMP server communit string
Expand Down Expand Up @@ -66,7 +66,7 @@ class SNMPClient(Exploit):

verbosity = OptBool(True, "Enable verbose output: true/false")

def snmp_create(self, target: str=None, port: int=None) -> SNMPCli:
def snmp_create(self, target: str = None, port: int = None) -> SNMPCli:
""" Create SNMP client
:param str target: target SNMP server ip address
Expand Down
10 changes: 5 additions & 5 deletions routersploit/core/ssh/ssh_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
class SSHCli(object):
""" SSH Client provides methods to handle communication with SSH server """

def __init__(self, ssh_target: str, ssh_port: int, verbosity=False) -> None:
def __init__(self, ssh_target: str, ssh_port: int, verbosity: bool = False) -> None:
""" SSH client constructor
:param str ssh_target: SSH target ip address
Expand All @@ -38,7 +38,7 @@ def __init__(self, ssh_target: str, ssh_port: int, verbosity=False) -> None:
self.ssh_client = paramiko.SSHClient()
self.ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())

def login(self, username: str, password: str, retries: int=1) -> bool:
def login(self, username: str, password: str, retries: int = 1) -> bool:
""" Login to SSH server
:param str username: SSH account username
Expand All @@ -64,7 +64,7 @@ def login(self, username: str, password: str, retries: int=1) -> bool:

return False

def login_pkey(self, username: str, priv_key: str, retries: int=1) -> bool:
def login_pkey(self, username: str, priv_key: str, retries: int = 1) -> bool:
""" Login to SSH server with private key
:param str username: SSH account username
Expand Down Expand Up @@ -289,7 +289,7 @@ def close(self) -> bool:
self.ssh_client.close()
return True
except Exception as err:
print_error(self.peer, "SSH Error while closing connection", verbose=self.verbosity)
print_error(self.peer, "SSH Error while closing connection", err, verbose=self.verbosity)

return False

Expand All @@ -301,7 +301,7 @@ class SSHClient(Exploit):

verbosity = OptBool(True, "Enable verbose output: true/false")

def ssh_create(self, target: str=None, port: int=None) -> SSHCli:
def ssh_create(self, target: str = None, port: int = None) -> SSHCli:
""" Create SSH client
:param str target: target SSH server ip address
Expand Down
4 changes: 2 additions & 2 deletions routersploit/core/tcp/tcp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class TCPCli(object):
""" TCP Client provides methods to handle communication with TCP server """

def __init__(self, tcp_target: str, tcp_port: int, verbosity: bool=False) -> None:
def __init__(self, tcp_target: str, tcp_port: int, verbosity: bool = False) -> None:
""" TCP client constructor
:param str tcp_target: target TCP server ip address
Expand Down Expand Up @@ -131,7 +131,7 @@ class TCPClient(Exploit):

verbosity = OptBool(True, "Enable verbose output: true/false")

def tcp_create(self, target: str=None, port: int=None) -> TCPCli:
def tcp_create(self, target: str = None, port: int = None) -> TCPCli:
""" Creates TCP client
:param str target: target TCP server ip address
Expand Down
6 changes: 3 additions & 3 deletions routersploit/core/telnet/telnet_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class TelnetCli(object):
""" Telnet Client provides methods to handle communication with Telnet server """

def __init__(self, telnet_target: str, telnet_port: int, verbosity=False) -> None:
def __init__(self, telnet_target: str, telnet_port: int, verbosity: bool = False) -> None:
""" Telnet client constructor
:param str telnet_target: target Telnet server ip address
Expand Down Expand Up @@ -44,7 +44,7 @@ def connect(self) -> bool:

return False

def login(self, username: str, password: str, retries: int=1) -> bool:
def login(self, username: str, password: str, retries: int = 1) -> bool:
""" Login to Telnet server
:param str username: Telnet account username
Expand Down Expand Up @@ -154,7 +154,7 @@ class TelnetClient(Exploit):

verbosity = OptBool(True, "Enable verbose output: true/false")

def telnet_create(self, target: str=None, port: int=None) -> TelnetCli:
def telnet_create(self, target: str = None, port: int = None) -> TelnetCli:
""" Create Telnet client
:param str target: target Telnet ip address
Expand Down
4 changes: 2 additions & 2 deletions routersploit/core/udp/udp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class UDPCli(object):
""" UDP Client provides methods to handle communication with UDP server """

def __init__(self, udp_target: str, udp_port: int, verbosity: bool=False) -> None:
def __init__(self, udp_target: str, udp_port: int, verbosity: bool = False) -> None:
""" UDP client constructor
:param str udp_target: target UDP server ip address
Expand Down Expand Up @@ -91,7 +91,7 @@ class UDPClient(Exploit):

verbosity = OptBool(True, "Enable verbose output: true/false")

def udp_create(self, target: str=None, port: int=None) -> UDPCli:
def udp_create(self, target: str = None, port: int = None) -> UDPCli:
""" Create UDP client
:param str target: target UDP server ip address
Expand Down
10 changes: 5 additions & 5 deletions routersploit/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,11 @@ def __init__(self):
self.__parse_prompt()

self.banner = """ ______ _ _____ _ _ _
| ___ \ | | / ___| | | (_) |
| |_/ /___ _ _| |_ ___ _ __\ `--. _ __ | | ___ _| |_
| // _ \| | | | __/ _ \ '__|`--. \ '_ \| |/ _ \| | __|
| |\ \ (_) | |_| | || __/ | /\__/ / |_) | | (_) | | |_
\_| \_\___/ \__,_|\__\___|_| \____/| .__/|_|\___/|_|\__|
| ___ \\ | | / ___| | | (_) |
| |_/ /___ _ _| |_ ___ _ __\\ `--. _ __ | | ___ _| |_
| // _ \\| | | | __/ _ \\ '__|`--. \\ '_ \\| |/ _ \\| | __|
| |\\ \\ (_) | |_| | || __/ | /\\__/ / |_) | | (_) | | |_
\\_| \\_\\___/ \\__,_|\\__\\___|_| \\____/| .__/|_|\\___/|_|\\__|
| |
Exploitation Framework for |_| by Threat9
Embedded Devices
Expand Down
Empty file.
24 changes: 24 additions & 0 deletions routersploit/modules/creds/routers/2wire/ftp_default_creds.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from routersploit.core.exploit import *

# hack to import from directory/filename starting with a number
FTPDefault = utils.import_exploit("routersploit.modules.creds.generic.ftp_default")


class Exploit(FTPDefault):
__info__ = {
"name": "2Wire Router Default FTP Creds",
"description": "Module performs dictionary attack against 2Wire Router FTP service. "
"If valid credentials are found, they are displayed to the user.",
"authors": (
"Marcin Bury <marcin[at]threat9.com>", # routersploit module
),
"devices": (
"2Wire Router",
),
}

target = OptIP("", "Target IPv4, IPv6 address or file with ip:port (file://)")
port = OptPort(21, "Target FTP port")

threads = OptInteger(1, "Number of threads")
defaults = OptWordlist("admin:admin", "User:Pass or file with default credentials (file://)")
24 changes: 24 additions & 0 deletions routersploit/modules/creds/routers/2wire/ssh_default_creds.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from routersploit.core.exploit import *

# hack to import from directory/filename starting with a number
SSHDefault = utils.import_exploit("routersploit.modules.creds.generic.ssh_default")


class Exploit(SSHDefault):
__info__ = {
"name": "2Wire Router Default SSH Creds",
"description": "Module performs dictionary attack against 2Wire Router SSH service. "
"If valid credentials are found, they are displayed to the user.",
"authors": (
"Marcin Bury <marcin[at]threat9.com>", # routersploit module
),
"devices": (
"2Wire Router",
),
}

target = OptIP("", "Target IPv4, IPv6 address or file with ip:port (file://)")
port = OptPort(22, "Target SSH port")

threads = OptInteger(1, "Number of threads")
defaults = OptWordlist("admin:admin", "User:Pass or file with default credentials (file://)")
24 changes: 24 additions & 0 deletions routersploit/modules/creds/routers/2wire/telnet_default_creds.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from routersploit.core.exploit import *

# hack to import from directory/filename starting with a number
TelnetDefault = utils.import_exploit("routersploit.modules.creds.generic.telnet_default")


class Exploit(TelnetDefault):
__info__ = {
"name": "2Wire Router Default Telnet Creds",
"description": "Module performs dictionary attack against Asmax Router Telnet service. "
"If valid credentials are found, they are displayed to the user.",
"authors": (
"Marcin Bury <marcin[at]threat9.com>", # routersploit module
),
"devices": (
"2Wire Router",
),
}

target = OptIP("", "Target IPv4, IPv6 address or file with ip:port (file://)")
port = OptPort(23, "Target SSH port")

threads = OptInteger(1, "Number of threads")
defaults = OptWordlist("admin:admin", "User:Pass or file with default credentials (file://)")
Empty file.
24 changes: 24 additions & 0 deletions routersploit/modules/creds/routers/3com/ftp_default_creds.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from routersploit.core.exploit import *

# hack to import from directory/filename starting with a number
FTPDefault = utils.import_exploit("routersploit.modules.creds.generic.ftp_default")


class Exploit(FTPDefault):
__info__ = {
"name": "3Com Router Default FTP Creds",
"description": "Module performs dictionary attack against 3Com Router FTP service. "
"If valid credentials are found, they are displayed to the user.",
"authors": (
"Marcin Bury <marcin[at]threat9.com>", # routersploit module
),
"devices": (
"3Com Router",
),
}

target = OptIP("", "Target IPv4, IPv6 address or file with ip:port (file://)")
port = OptPort(21, "Target FTP port")

threads = OptInteger(1, "Number of threads")
defaults = OptWordlist("admin:admin", "User:Pass or file with default credentials (file://)")
24 changes: 24 additions & 0 deletions routersploit/modules/creds/routers/3com/ssh_default_creds.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from routersploit.core.exploit import *

# hack to import from directory/filename starting with a number
SSHDefault = utils.import_exploit("routersploit.modules.creds.generic.ssh_default")


class Exploit(SSHDefault):
__info__ = {
"name": "3Com Router Default SSH Creds",
"description": "Module performs dictionary attack against 3Com Router SSH service. "
"If valid credentials are found, they are displayed to the user.",
"authors": (
"Marcin Bury <marcin[at]threat9.com>", # routersploit module
),
"devices": (
"3Com Router",
),
}

target = OptIP("", "Target IPv4, IPv6 address or file with ip:port (file://)")
port = OptPort(22, "Target SSH port")

threads = OptInteger(1, "Number of threads")
defaults = OptWordlist("admin:admin", "User:Pass or file with default credentials (file://)")
Loading

0 comments on commit 58a2eda

Please sign in to comment.