示例#1
0
class HTTPClient(Exploit):
    """ HTTP Client provides methods to handle communication with HTTP server """
    target_protocol = Protocol.HTTP
    verbosity = BoolOption(True, "Enable verbose output? (true/false): ")
    ssl = BoolOption(False, "Enable ssl connection? (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_code:
            print_error(error_code, verbose=self.verbosity)
        except socket.error as error_code:
            print_error(error_code, 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
        else:
            return False
示例#2
0
class FTPClient(BaseFTPClient):
    """ FTP Client exploit """
    target_protocol = Protocol.FTP
    ssl = BoolOption(False, "SSL Enabled/Disabled? (true/false): ")
    verbosity = BoolOption(True, "Enable verbose output? (true/false): ")

    def ftp_create(self,
                   target: str = None,
                   port: int = None) -> BaseFTPClient:
        """ Create FTP client
        :param str target: target FTP server ip address
        :param int port: target FTP server port
        :return BaseFTPClient: FTP client object
        """
        ftp_target = target if target else self.target
        ftp_port = port if port else self.port
        ftp_client = BaseFTPClient(ftp_target,
                                   ftp_port,
                                   ssl=self.ssl,
                                   verbosity=self.verbosity)
        return ftp_client
示例#3
0
class SSHClient(Exploit):
    """ SSH Client exploit """
    target_protocol = Protocol.SSH
    verbosity = BoolOption(True, "Enable verbose output? (true/false): ")

    def ssh_create(self,
                   target: str = None,
                   port: int = None) -> BaseSSHClient:
        """ Create SSH client
        :param str target: target SSH server ip address
        :param int port: target SSH server port
        :return SSHClient: SSH client object
        """
        ssh_target = target if target else self.target
        ssh_port = port if port else self.port
        ssh_client = BaseSSHClient(ssh_target,
                                   ssh_port,
                                   verbosity=self.verbosity)
        return ssh_client
示例#4
0
class TCPClient(Exploit):
    """ TCP Client exploit """
    target_protocol = Protocol.TCP
    verbosity = BoolOption(True, "Enable verbose output? (true/false)")

    def tcp_create(self,
                   target: str = None,
                   port: int = None) -> BaseTCPClient:
        """ Creates TCP client
        :param str target: target TCP server ip address
        :param int port: target TCP server port
        :return BaseTCPClient: TCP client object
        """
        tcp_target = target if target else self.target
        tcp_port = port if port else self.port
        tcp_client = BaseTCPClient(tcp_target,
                                   tcp_port,
                                   verbosity=self.verbosity)
        return tcp_client
示例#5
0
class SNMPClient(BaseSNMPClient):
    """ Create SNMP Exploit """
    target_protocol = Protocol.SNMP
    verbosity = BoolOption(True, "Enable verbose output? (true/false): ")

    def snmp_create(self,
                    target: str = None,
                    port: int = None) -> BaseSNMPClient:
        """ 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 = BaseSNMPClient(snmp_target,
                                     snmp_port,
                                     verbosity=self.verbosity)
        return snmp_client
示例#6
0
class UDPClient(Exploit):
    """ UDP Client exploit """
    target_protocol = Protocol.UDP
    verbosity = BoolOption(True, "Enable verbose output: true/false")

    def udp_create(self,
                   target: str = None,
                   port: int = None) -> BaseUDPClient:
        """ 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 = BaseUDPClient(udp_target,
                                   udp_port,
                                   verbosity=self.verbosity)
        return udp_client
示例#7
0
class TelnetClient(Exploit):
    """ Telnet Client exploit """
    target_protocol = Protocol.TELNET
    verbosity = BoolOption(True, "Enable verbose output: true/false")

    def telnet_create(self,
                      target: str = None,
                      port: int = None) -> BaseTelnetClient:
        """ 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 = BaseTelnetClient(telnet_target,
                                         telnet_port,
                                         verbosity=self.verbosity)
        return telnet_client