10

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.

4 Answers 4

17

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.

5
  • 6
    this is only a HTTP CONNECT tunnel. It will not work with hidden services and also not with applications not using HTTP CONNECT...
    – K. Frank
    Nov 4, 2020 at 16:11
  • @K.Frank What applications are typically using/not using HTTP CONNECT? I want to use aria2c with Tor to download html-pages using http(s) but aria2c doesn't support SOCKS. Will this work?
    – d-b
    Jul 26, 2023 at 16:48
  • @d-b I don't recall which software I was working with three years ago that didn't support HTTP CONNECT. But regarding the other part, if you want to download stuff using aria2c and tor, then you'll need a bit more, esp. if the files are big. See: github.com/agowa/torplex
    – K. Frank
    Aug 3, 2023 at 10:08
  • @K.Frank I got Aria to work with Tor using http-proxy. Not complicated at all. Just add a few lines to torrc.
    – d-b
    Aug 3, 2023 at 10:57
  • @d-b yea, for small files it is about that easy, but for bigger files (multiple gigabytes or even hundreds of gigabytes), it's another story and you'll need something like in my link and also the patch from that repository to work around some (intentional) limitations of aria2c...
    – K. Frank
    Aug 3, 2023 at 11:34
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. ;)

1
  • 1
    Notice that polipo is no longer maintained (also the repos is archived). Dec 26, 2021 at 16:02
2

There is a Node package that can do this. https://github.com/oyyd/http-proxy-to-socks

Nodejs version >4 is required.

Install it and run from the command line:

hpts -s 127.0.0.1:9050 -p 8080
1
0

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.

2
  • It says 127.0.0.1 - - [26/Dec/2021 17:16:52] code 501, message Unsupported method ('CONNECT') Dec 26, 2021 at 16:17
  • Any way to adapt this to make it work with HTTPS connections? Dec 26, 2021 at 16:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.