Exemple #1
0
    def send_handshake(self):
        cfgs = self.dispatcher.https_configs
        url = cfgs["url"]
        self.__http_auth_id = cfgs["auth_id"]

        # 伪装成websocket握手
        kv_pairs = [("Connection", "Upgrade"), ("Upgrade", "websocket",), (
            "User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:69.0) Gecko/20100101 Firefox/69.0",),
                    ("Accept-Language", "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2"),
                    ("Sec-WebSocket-Version", 13,), ("Sec-WebSocket-Key", self.rand_string(),),
                    ("Sec-WebSocket-Protocol", "chat")]

        if int(self.__server_address[1]) == 443:
            host = ("Host", self.__server_address[0],)
            origin = ("Origin", "https://%s" % self.__server_address[0])
        else:
            host = ("Host", "%s:%s" % self.__server_address,)
            origin = ("Origin", "https://%s:%s" % self.__server_address,)

        kv_pairs.append(host)
        kv_pairs.append(origin)

        s = httputils.build_http1x_req_header("GET", url, kv_pairs)

        self.writer.write(s.encode("iso-8859-1"))
        self.add_evt_write(self.fileno)
Exemple #2
0
    def send_handshake_request(self):
        """发送握手请求
        :param user:
        :param passwd:
        :return:
        """
        uri = "%s?user=%s&passwd=%s" % (self.__path, self.__user, self.__passwd)

        kv_pairs = [("Connection", "Upgrade"), ("Upgrade", "websocket",), (
            "User-Agent", "LANd_pass",),
                    ("Accept-Language", "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2"),
                    ("Sec-WebSocket-Version", 13,), ("Sec-WebSocket-Key", self.rand_string(),),
                    ("Sec-WebSocket-Protocol", "Socks2Https")]

        if int(self.__address[1]) == 443:
            host = ("Host", self.__address[0],)
            origin = ("Origin", "https://%s" % self.__address[0])
        else:
            host = ("Host", "%s:%s" % self.__address,)
            origin = ("Origin", "https://%s:%s" % self.__address,)

        kv_pairs.append(host)
        kv_pairs.append(origin)

        s = httputils.build_http1x_req_header("GET", uri, kv_pairs)

        self.writer.write(s.encode("iso-8859-1"))
        self.add_evt_write(self.fileno)
Exemple #3
0
    def wrap_header(self, method, host, path, qs_seq, user_agent, headers):
        method = method.upper()

        if not qs_seq:
            uri = path
        else:
            uri = "%s?%s" % (path, httputils.build_qs(qs_seq))

        headers.append(("Host", host))
        headers.append(("User-Agent", user_agent))
        sts = httputils.build_http1x_req_header(method, uri, headers)

        return sts.encode("iso-8859-1")
Exemple #4
0
    def wrap_header(self, method, host, path, qs_seq, user_agent, headers):
        method = method.upper()

        if not qs_seq:
            uri = path
        else:
            uri = "%s?%s" % (path, httputils.build_qs(qs_seq))

        headers.append(("Host", host))
        headers.append(("User-Agent", user_agent))
        sts = httputils.build_http1x_req_header(method, uri, headers)

        return sts.encode("iso-8859-1")
 def http_conn_ok(self):
     if self.__is_http_tunnel_mode:
         self.send_http_response("200 Connection Established")
         return
     # 重新构建http请求头部
     s = httputils.build_http1x_req_header(self.__http_request_info[0],
                                           self.__http_uri,
                                           self.__http_request_kv_pairs)
     if not self.__is_sent_to_convert_client:
         self.send_message_to_handler(self.fileno, self.__raw_client_fd,
                                      s.encode("iso-8859-1"))
     else:
         self.dispatcher.send_tcp_data(self.__packet_id,
                                       s.encode("iso-8859-1"))
Exemple #6
0
    def __handle_http_no_tunnel_proxy(self, request, mapv, body_data):
        rs = _parse_http_uri_no_tunnel_mode(request[1])

        if not rs:
            self.delete_handler(self.fileno)
            return

        host, port, uri = rs
        seq = []

        if self.__debug: print("%s:%s" % (host, port,))

        has_close = False
        # 去除代理信息
        for k, v in mapv:
            if k.lower() == "proxy-connection": continue
            seq.append((k, v,))

        # 重新构建HTTP请求头部
        header_data = httputils.build_http1x_req_header(request[0], uri, seq)
        req_data = b"".join([header_data.encode("iso-8859-1"), body_data])

        is_match, flags = self.__host_match.match(host)
        self.__http_transparent = _http_transparent_proxy_resp()

        if is_match and flags:
            self.__use_tunnel = True
            atyp = self.__get_atyp(host)
            self.__tunnel_proxy_reqconn(atyp, host, port)
            self.__tunnel_proxy_send_tcpdata(req_data)
            return

        self.__fileno = self.create_handler(
            self.fileno, _tcp_client, (host, port,), is_ipv6=self.__is_ipv6
        )
        self.send_message_to_handler(self.fileno, self.__fileno, req_data)
        self.__step = 2