【问题标题】:TOR as HTTP proxy instead SOCKSTOR 作为 HTTP 代理而不是 SOCKS
【发布时间】:2015-02-14 20:34:52
【问题描述】:

我想尝试使用 TOR 作为 HTTP 代理,而不是 SOCKS 代理。
我有问题,目标阻止 SOCKS,我想尝试使用 HTTP 代理检查它。

我没有找到任何将 tor 作为 HTTP 代理运行的解决方案。

谢谢。

【问题讨论】:

    标签: proxy tor


    【解决方案1】:

    最简单的方法是在您的/etc/tor/torrc 文件中添加HTTPTunnelPort 9080 行。

    之后您将打开localhost:9080 套接字,您可以设置http_proxy=http://localhost:9080 环境变量来告诉应用程序使用它。

    【讨论】:

    • 这只是一个 HTTP CONNECT 隧道。它不适用于隐藏服务,也不适用于不使用 HTTP CONNECT 的应用程序...
    【解决方案2】:

    你可以试试 Polipo。

    安装:

    apt-get install polipo
    

    然后配置代理链接到 Tor 的 SOCKS 代理,修改 /etc/polipo/config:

    allowedClients = 127.0.0.1, 192.168.1.0/24 # Expose your network (modify accordingly)
    socksParentProxy = "localhost:9050"
    socksProxyType = socks5
    proxyAddress = "0.0.0.0"    # IPv4 only
    

    或者按照这个教程 https://www.marcus-povey.co.uk/2016/03/24/using-tor-as-a-http-proxy/

    Polipo 可在:https://github.com/jech/polipo

    我试过了,效果很好。然而,性能不如预期,因为 polipo 是单线程的。 ;)

    【讨论】:

    • 请注意,polipo 已不再维护(repos 也已存档)。
    【解决方案3】:

    我正在做一个实验来解决这个问题。这只是一个替代答案。此 Python 脚本将充当代理,将 HTTP/HTTPS 请求转发到 Tor-Proxy。

    import sys
    
    major_version = sys.version_info.major
    if major_version == 2:
        import SocketServer
        import SimpleHTTPServer
    elif major_version == 3:
        import http.server as SimpleHTTPServer
        import socketserver as SocketServer
    
    import requests
    
    PROX_LPORT = 1232 # the proxy port you need to use
    
    def get_tor_session():
        session = requests.session()
        # Tor uses the 9050 port as the default socks port
        session.proxies = {'http':  'socks5://127.0.0.1:9050', 'https': 'socks5://127.0.0.1:9050'}
        return session
    
    class LocalProxy(SimpleHTTPServer.SimpleHTTPRequestHandler):
        def do_GET(self):
            # Make a request through the Tor connection
            session = get_tor_session()
            self.wfile.write(session.get(self.path).text.encode())
    
    httpd = SocketServer.ForkingTCPServer(('', PROX_LPORT), LocalProxy)
    print("serving at port", PROX_LPORT)
    httpd.serve_forever()
    

    它在 Firefox 上运行流畅。它还兼容 Python 2 和 3。

    【讨论】:

    • 上面写着127.0.0.1 - - [26/Dec/2021 17:16:52] code 501, message Unsupported method ('CONNECT')
    • 有什么方法可以调整它以使其适用于 HTTPS 连接?
    【解决方案4】:

    有一个 Node 包可以做到这一点。 https://github.com/oyyd/http-proxy-to-socks

    Nodejs 版本 >4 是必需的。

    安装它并从命令行运行:

    hpts -s 127.0.0.1:9050 -p 8080
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-13
      • 1970-01-01
      • 1970-01-01
      • 2010-12-30
      • 1970-01-01
      相关资源
      最近更新 更多