예제 #1
0
class FTPClient(Exploit):
    """ FTP Client exploit """

    target_protocol = Protocol.FTP

    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:
        """ Create FTP client

        :param str target: target FTP server ip address
        :param int port: target FTP server port
        :return FTPCli: FTP client object
        """

        ftp_target = target if target else self.target
        ftp_port = port if port else self.port

        ftp_client = FTPCli(ftp_target,
                            ftp_port,
                            ssl=self.ssl,
                            verbosity=self.verbosity)
        return ftp_client
예제 #2
0
class SSHClient(Exploit):
    """ SSH Client exploit """

    target_protocol = Protocol.SSH

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

    def ssh_create(self, target: str = None, port: int = None) -> SSHCli:
        """ Create SSH client

        :param str target: target SSH server ip address
        :param int port: target SSH server port
        :return SSHCli: SSH client object
        """

        ssh_target = target if target else self.target
        ssh_port = port if port else self.port

        ssh_client = SSHCli(ssh_target, ssh_port, verbosity=self.verbosity)
        return ssh_client
예제 #3
0
class UDPClient(Exploit):
    """ UDP Client exploit """

    target_protocol = Protocol.UDP

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

    def udp_create(self, target: str = None, port: int = None) -> UDPCli:
        """ Create UDP client

        :param str target: target UDP server ip address
        :param int port: target UDP server port
        :return UDPCli: UDP client object
        """

        udp_target = target if target else self.target
        udp_port = port if port else self.port

        udp_client = UDPCli(udp_target, udp_port, verbosity=self.verbosity)
        return udp_client
예제 #4
0
class TCPClient(Exploit):
    """ TCP Client exploit """

    target_protocol = Protocol.TCP

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

    def tcp_create(self, target: str = None, port: int = None) -> TCPCli:
        """ Creates TCP client

        :param str target: target TCP server ip address
        :param int port: target TCP server port
        :return TCPCli: TCP client object
        """

        tcp_target = target if target else self.target
        tcp_port = port if port else self.port

        tcp_client = TCPCli(tcp_target, tcp_port, verbosity=self.verbosity)
        return tcp_client
예제 #5
0
class SNMPClient(Exploit):
    """ SNMP Client exploit """

    target_protocol = Protocol.SNMP

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

    def snmp_create(self, target: str = None, port: int = None) -> SNMPCli:
        """ Create SNMP client

        :param str target: target SNMP server ip address
        :param int port: target SNMP server port
        :return SNMPCli: SNMP client object
        """

        snmp_target = target if target else self.target
        snmp_port = port if port else self.port

        snmp_client = SNMPCli(snmp_target, snmp_port, verbosity=self.verbosity)
        return snmp_client
예제 #6
0
class TelnetClient(Exploit):
    """ Telnet Client exploit """

    target_protocol = Protocol.TELNET

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

    def telnet_create(self, target: str = None, port: int = None) -> TelnetCli:
        """ Create Telnet client

        :param str target: target Telnet ip address
        :param int port: target Telnet port
        :return TelnetCli: Telnet client object
        """

        telnet_target = target if target else self.target
        telnet_port = port if port else self.port

        telnet_client = TelnetCli(telnet_target,
                                  telnet_port,
                                  verbosity=self.verbosity)
        return telnet_client
예제 #7
0
class HTTPClient(Exploit):
    """ HTTP Client provides methods to handle communication with HTTP server """

    target_protocol = Protocol.HTTP

    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:
        """ Requests HTTP resource

        :param str method: method that should be issued e.g. GET, POST
        :param str path: path to the resource that should be requested
        :param requests session: session manager that should be used
        :param kwargs: kwargs passed to request method
        :return Response: Response object
        """

        if self.ssl:
            url = "https://"
        else:
            url = "http://"

        url += "{}:{}{}".format(self.target, self.port, path)

        kwargs.setdefault("timeout", HTTP_TIMEOUT)
        kwargs.setdefault("verify", False)
        kwargs.setdefault("allow_redirects", False)

        try:
            return getattr(session, method.lower())(url, **kwargs)
        except (requests.exceptions.MissingSchema, requests.exceptions.InvalidSchema):
            print_error("Invalid URL format: {}".format(url), verbose=self.verbosity)
        except requests.exceptions.ConnectionError:
            print_error("Connection error: {}".format(url), verbose=self.verbosity)
        except requests.RequestException as error:
            print_error(error, verbose=self.verbosity)
        except socket.error as err:
            print_error(err, verbose=self.verbosity)
        except KeyboardInterrupt:
            print_error("Module has been stopped", verbose=self.verbosity)

        return None

    def get_target_url(self, path: str = "") -> str:
        """ Get target URL

        :param str path: path to http server resource
        :return str: full target url with correct schema
        """

        if self.ssl:
            url = "https://"
        else:
            url = "http://"

        url += "{}:{}{}".format(self.target, self.port, path)

        return url

    def http_test_connect(self) -> bool:
        """ Test connection to HTTP server

        :return bool: True if test connection was successful, False otherwise
        """

        response = self.http_request(
            method="GET",
            path="/"
        )

        if response:
            return True

        return False