예제 #1
0
파일: h2.py 프로젝트: nstudach/pathspider
 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_http(self.source, job, self.args.timeout)
     else:
         raise RuntimeError("Unknown connection mode specified")
예제 #2
0
파일: h2.py 프로젝트: nstudach/pathspider
 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")
예제 #3
0
def connect_tor_http(controller,
                     circuit_path,
                     job,
                     conn_timeout,
                     curlopts=None,
                     curlinfos=None):
    """
    This helper function will perform an HTTP request over Tor. It will not
    perform any special action in the event that this is the experimental flow,
    but can be customised on a per-call basis through the curlopts argument.
    """

    if curlopts is None:
        curlopts = {}

    curlopts[pycurl.PROXY] = "localhost"
    curlopts[pycurl.PROXYPORT] = 9050
    curlopts[pycurl.PROXYTYPE] = pycurl.PROXYTYPE_SOCKS5_HOSTNAME

    attach_error = []

    try:
        if circuit_path is not None:
            circuit_path = circuit_path.split(",")
        circuit_id = controller.new_circuit(circuit_path, await_build=True)
    except stem.CircuitExtensionFailed:
        return {"spdr_state": CONN_DISCARD}

    def attach_stream(stream):
        try:
            if stream.status == 'NEW':
                if (stream.target_address == job['dip']
                        and stream.target_port == job['dp']):
                    controller.attach_stream(stream.id, circuit_id)
        except stem.OperationFailed:
            attach_error.append(None)

    controller.add_event_listener(attach_stream, stem.control.EventType.STREAM)  # pylint: disable=no-member
    result = connect_http(None, job, conn_timeout, curlopts, curlinfos)
    controller.remove_event_listener(attach_stream)

    if len(attach_error) > 0:
        return {"spdr_state": CONN_DISCARD}

    return result
예제 #4
0
파일: sync.py 프로젝트: nstudach/pathspider
    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
예제 #5
0
파일: tfo.py 프로젝트: nstudach/pathspider
 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")