Exemple #1
0
def do_unwrap_socks(sock, host, port, client_address, req, left_buf=""):
    if not g.x_tunnel:
        return

    try:
        remote_sock = socks.create_connection((host, port),
                                              proxy_type="socks5h",
                                              proxy_addr="127.0.0.1",
                                              proxy_port=g.x_tunnel_socks_port,
                                              timeout=15)
    except Exception as e:
        xlog.warn("do_unwrap_socks connect to x-tunnel for %s:%d proxy fail.",
                  host, port)
        return

    if isinstance(req.connection, ssl.SSLSocket):
        try:
            # TODO: send SNI
            remote_ssl_sock = ssl.wrap_socket(remote_sock)
        except:
            xlog.warn("do_unwrap_socks ssl_wrap for %s:%d proxy fail.", host,
                      port)
            return
    else:
        remote_ssl_sock = remote_sock

    # avoid close by req.__del__
    req.rfile._close = False
    req.wfile._close = False
    req.connection = None

    if not isinstance(sock, SocketWrap):
        sock = SocketWrap(sock, client_address[0], client_address[1])

    xlog.info("host:%s:%d do_unwrap_socks", host, port)

    remote_ssl_sock.send(left_buf)
    sw = SocketWrap(remote_ssl_sock, "x-tunnel", port, host)
    sock.recved_times = 3
    g.pipe_socks.add_socks(sock, sw)
Exemple #2
0
def do_unwrap_socks(sock, host, port, client_address, req, left_buf=""):
    if not g.x_tunnel:
        return

    try:
        remote_sock = socks.create_connection(
            (host, port),
            proxy_type="socks5h", proxy_addr="127.0.0.1", proxy_port=1080, timeout=15
        )
    except Exception as e:
        xlog.warn("do_unwrap_socks connect to x-tunnel for %s:%d proxy fail.", host, port)
        return

    if isinstance(req.connection, ssl.SSLSocket):
        try:
            # TODO: send SNI
            remote_ssl_sock = ssl.wrap_socket(remote_sock)
        except:
            xlog.warn("do_unwrap_socks ssl_wrap for %s:%d proxy fail.", host, port)
            return
    else:
        remote_ssl_sock = remote_sock

    # avoid close by req.__del__
    req.rfile._close = False
    req.wfile._close = False
    req.connection = None

    if not isinstance(sock, SocketWrap):
        sock = SocketWrap(sock, client_address[0], client_address[1])

    xlog.info("host:%s:%d do_unwrap_socks", host, port)

    remote_ssl_sock.send(left_buf)
    sw = SocketWrap(remote_ssl_sock, "x-tunnel", port, host)
    sock.recved_times = 3
    g.pipe_socks.add_socks(sock, sw)
Exemple #3
0
def do_unwrap_socks(sock, host, port, client_address, req, left_buf=""):
    # TODO: bug exist

    sock.close()
    return

    if not g.x_tunnel:
        return

    try:
        remote_sock = socks.create_connection(
            (host, port),
            proxy_type="socks5", proxy_addr="127.0.0.1", proxy_port=1080, timeout=15
        )
    except Exception as e:
        xlog.warn("do_unwrap_socks connect to x-tunnel for %s:%d proxy fail.", host, port)
        return

    if req.path.startswith("https"):
        try:
            ssl_sock = ssl.wrap_socket(remote_sock)
        except:
            xlog.warn("do_unwrap_socks ssl_wrap for %s:%d proxy fail.", host, port)
            return
    else:
        ssl_sock = remote_sock

    if not isinstance(sock, SocketWrap):
        sock = SocketWrap(sock, "x-tunnel", port, host)

    xlog.info("host:%s:%d do_unwrap_socks", host, port)

    ssl_sock.send(left_buf)
    sw = SocketWrap(ssl_sock, client_address[0], client_address[1])
    sock.recved_times = 3
    g.pipe_socks.add_socks(sock, sw)