TOR as HTTP proxy instead SOCKS
Asked Answered
P

4

12

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.

Postiche answered 14/2, 2015 at 20:34 Comment(0)
S
18

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.

Shetler answered 18/5, 2020 at 9:8 Comment(5)
this is only a HTTP CONNECT tunnel. It will not work with hidden services and also not with applications not using HTTP CONNECT...Wallacewallach
@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?Shophar
@Shophar 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/torplexWallacewallach
@K.Frank I got Aria to work with Tor using http-proxy. Not complicated at all. Just add a few lines to torrc.Shophar
@Shophar 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...Wallacewallach
U
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. ;)

Unavoidable answered 21/3, 2018 at 15:49 Comment(1)
Notice that polipo is no longer maintained (also the repos is archived).Plagio
C
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
Canoewood answered 16/2, 2022 at 22:2 Comment(1)
thanks, it worked perfectly! privoxy seems unmaintained and buggy sourceforge.net/p/ijbswa/bugs/938Versieversification
T
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.

Takashi answered 12/9, 2019 at 3:38 Comment(2)
It says 127.0.0.1 - - [26/Dec/2021 17:16:52] code 501, message Unsupported method ('CONNECT')Plagio
Any way to adapt this to make it work with HTTPS connections?Plagio

© 2022 - 2024 — McMap. All rights reserved.