TOR as HTTP proxy instead SOCKS

13,835

Solution 1

The easiest way is to add HTTPTunnelPort 9080 line in your /etc/tor/torrc file.

After that you'll have localhost:9080 socket open and you can set http_proxy=http://localhost:9080 environment variable to tell applications to use it.

Solution 2

you could try Polipo.

Install:

apt-get install polipo

Then configure the proxy to chain to Tor’s SOCKS proxy, modify /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

Or follow this tutorial https://www.marcus-povey.co.uk/2016/03/24/using-tor-as-a-http-proxy/

Polipo is available at: https://github.com/jech/polipo

I tried and it works. However, the performance is not good as expected, since polipo is single-threaded. ;)

Solution 3

I was doing an experiment to fix the problem. This is just an alternative answer. This Python script will act as a proxy that forwards HTTP/HTTPS requests to the 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()

It works smoothly on Firefox. It's also compatible in both Python 2 and 3.

Share:
13,835
gabi
Author by

gabi

Updated on June 11, 2022

Comments

  • gabi
    gabi almost 2 years

    I want to try and use TOR as HTTP proxy, and not SOCKS proxy.
    I have issues, where the destination blocks SOCKS and I want to try to check it with HTTP proxy instead.

    I did not find any solution for running tor as HTTP proxy.

    Thanks.

  • K. Frank
    K. Frank over 3 years
    this is only a HTTP CONNECT tunnel. It will not work with hidden services and also not with applications not using HTTP CONNECT...
  • robertspierre
    robertspierre over 2 years
    Notice that polipo is no longer maintained (also the repos is archived).
  • robertspierre
    robertspierre over 2 years
    It says 127.0.0.1 - - [26/Dec/2021 17:16:52] code 501, message Unsupported method ('CONNECT')
  • robertspierre
    robertspierre over 2 years
    Any way to adapt this to make it work with HTTPS connections?