Exemple #1
0
 def conn_no_h2(self, job, config):  # pylint: disable=unused-argument
     if self.args.connect == "http":
         return connect_http(self.source, job, self.args.timeout)
     if self.args.connect == "https":
         return connect_https(self.source, job, self.args.timeout)
     else:
         raise RuntimeError("Unknown connection mode specified")
Exemple #2
0
 def conn_h2(self, job, config): # pylint: disable=unused-argument
     curlopts = {pycurl.HTTP_VERSION: pycurl.CURL_HTTP_VERSION_2_0}
     curlinfos = {pycurl.INFO_HTTP_VERSION}
     if self.args.connect == "http":
         return connect_http(self.source, job, self.args.timeout, curlopts, curlinfos)
     if self.args.connect == "https":
         return connect_https(self.source, job, self.args.timeout, curlopts, curlinfos)
     else:
         raise RuntimeError("Unknown connection mode specified")
Exemple #3
0
    def connect(self, job, config):  # pylint: disable=unused-argument
        """
        Performs the requested connection.
        """

        if self.args.connect == "tcp":
            rec = connect_tcp(self.source, job, self.args.timeout)
        elif self.args.connect == "http":
            rec = connect_http(self.source, job, self.args.timeout)
        elif self.args.connect == "https":
            rec = connect_https(self.source, job, self.args.timeout)
        elif self.args.connect == "dnstcp":
            rec = connect_dns_tcp(self.source, job, self.args.timeout)
        elif self.args.connect == "dnsudp":
            rec = connect_dns_udp(self.source, job, self.args.timeout)
        else:
            raise RuntimeError("Unknown connection type requested!")

        return rec
Exemple #4
0
 def conn_tfo(self, job, config):  # pylint: disable=unused-argument
     if self.args.connect == "http":
         curlopts = {CURLOPT_TCP_FASTOPEN: 1}
         return connect_http(self.source, job, self.args.timeout, curlopts)
     elif self.args.connect == "https":
         curlopts = {CURLOPT_TCP_FASTOPEN: 1}
         return connect_https(self.source, job, self.args.timeout, curlopts)
     elif self.args.connect == "dnstcp":
         try:
             q = PSDNSRecord(q=DNSQuestion(job['domain'], QTYPE.A))
             data = q.pack()
             data = struct.pack("!H", len(data)) + data
             if ':' in job['dip']:
                 sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
                 sock.bind((self.source[1], 0))
             else:
                 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                 sock.bind((self.source[0], 0))
             # TODO: In non-blocking mode, this will always raise an EINPROGRESS
             # Should perform a blocking select afterwards, if it doesn't become available for
             # read then should fail it
             #sock.settimeout(self.args.timeout)
             sock.sendto(data, socket.MSG_FASTOPEN, (job['dip'], job['dp']))  # pylint: disable=no-member
             sp = sock.getsockname()[1]
             sock.close()
             return {'sp': sp, 'spdr_state': CONN_OK}
         except TimeoutError:
             return {
                 'sp': sock.getsockname()[1],
                 'spdr_state': CONN_TIMEOUT
             }
         except TypeError:  # Caused by not having a v4/v6 address when trying to bind
             return {'sp': 0, 'spdr_state': CONN_FAILED}
         except OSError:
             return {'sp': 0, 'spdr_state': CONN_FAILED}
     else:
         raise RuntimeError("Unknown connection mode specified")