Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support upstream SOCKS proxy #211

Open
tyll opened this issue Feb 9, 2014 · 26 comments
Open

Support upstream SOCKS proxy #211

tyll opened this issue Feb 9, 2014 · 26 comments
Labels
kind/feature New features / enhancements

Comments

@tyll
Copy link

tyll commented Feb 9, 2014

Implement support for SOCKS upstream proxy with DNS resolution via SOCKS, so mitmproxy can be easily tunnelled through "ssh -D".

@mhils
Copy link
Member

mhils commented Feb 9, 2014

I don't have the time do work on this at the moment, but if someone is interested, wrapping proxy.ServerConnection should do the job.

@kourosh3000
Copy link

Thank you

@niaoniaozz
Copy link

Hello, I am wondering if this feature is implemented in the current version or not.

@mhils
Copy link
Member

mhils commented Dec 23, 2014

Not yet, sorry.

@JeremyRand
Copy link

Hi, so I'm looking at the code for upstream HTTP(S) proxy support and it looks like it's mutually exclusive with running mitmproxy as a SOCKS proxy. I'm potentially interested in looking at adding upstream SOCKS support, but I'd prefer not to have that limitation. Is there an implementation reason for that exclusivity? Is there a good way to implement upstream SOCKS support such that that isn't a problem?

@absane
Copy link

absane commented Mar 14, 2016

Just commenting hoping to bump interest some. I've been trying to use Tor as an upstream proxy and it seems that Tor only supports Socks.

@samos123
Copy link

Would also like to have this feature.

@n0rz
Copy link

n0rz commented Aug 12, 2016

++

@malwarefun
Copy link

You can hook the makesocket call in tcp.py.
Install and import pysocks, then connect to your socks proxy (eg. set_proxy(socks.SOCKS5, "localhost", 9050))

@TonyStark
Copy link

@zhangyoufu i tried but i think its not working
@malwarefun can yo give script example...

@malwarefun
Copy link

Hi @TonyStark ,
Its been a while since I looked at this.. I think I did something like,

import socks
...
def makesocket(self):
    s = socks.socksocket()
    s.set_proxy(socks.SOCKS5, "localhost", 9050)
    return s

@TonyStark
Copy link

@malwarefun
i tried your code but it seems not working.
i also tried this code

import socks
s = socks.socksocket() # Same API as socket.socket in the standard lib
s.set_proxy(socks.SOCKS5, "localhost", 37760)
# Can be treated identical to a regular socket object
s.connect(("127.0.0.1", 8080))
s.sendall("GET / HTTP/1.1 ...")
print s.recv(4096)

but not working too

@ghost
Copy link

ghost commented Jan 20, 2019

Hi there.
I am new to mitmproxy and i was wondering if i modify upstream proxy to support SOCKS, is mitmproxy a good choice for applying load balancing on multiple tor clients? is it suitable for this purpose?
thanks in advance.

@eliyastein
Copy link

Hi, sorry to bump an old thread, but has anyone gotten this to work? I'm looking to use Socks5 proxy as upstream.

@baptx
Copy link

baptx commented Feb 4, 2020

@eliyastein I did it with proxychains
Related: #830

@eliyastein
Copy link

Thanks @baptx - I was actually able to do it using gost:

https://github.com/ginuerzh/gost

@q2dg
Copy link

q2dg commented Apr 10, 2021

Another option is #2813 (comment)

@scruel
Copy link

scruel commented Aug 15, 2021

What a long time unsolved issue, hope support socks5 connect when use upstream mode and us socks5 proxy as its forward proxy.

@scruel
Copy link

scruel commented Aug 15, 2021

Thanks @baptx - I was actually able to do it using gost:

https://github.com/ginuerzh/gost

socks.go:950: [socks5] 127.0.0.1:12915 -> 127.0.0.1:1089 : EOF
2021/08/15 23:12:56 socks.go:950: [socks5] 127.0.0.1:12805 -> 127.0.0.1:1089 : read tcp 127.0.0.1:12806->127.0.0.1:62323: i/o timeout

@bardic
Copy link

bardic commented Dec 17, 2021

@eliyastein would be be able to explain your gost setup? I keep getting port is already in use errors.

@eliyastein
Copy link

@eliyastein would be be able to explain your gost setup? I keep getting port is already in use errors.

@bardic - it has been a while... but I'm looking at the script I wrote to make this work and it looks like it's something like this:

gost -L=localhost:LOCAL_PORT -F=socks5://localhost:PROXY_PORT

Then when I invoke mitm I pass along --mode upstream:localhost:LOCAL_PORT

So basically gost is forwarding the local port that you specify to the socks proxy. I imagine in your case the argument you pass to gost -F will be remote and not local like it was in my case. Of course if everything is local, make sure it's all running on different ports.

@bratao
Copy link

bratao commented May 24, 2022

@mhils Hey, I need to tackle this task for my work, and I want to contribute back upstream.

Can you offer me any advice before I start? I´m planning to use https://github.com/romis2012/python-socks
What would be the right place/class to implement this feature? Before digging it, looks like a candidate would be ProxyConnectionHandler.

@mhils
Copy link
Member

mhils commented May 24, 2022

@bratao: A good first step would be to simply rewrite the existing HTTP Upstream Proxy Implementation with a SOCKSv5 one. Our proxy core is sans-io, which means that python-socks may not be an ideal fit. We already have a SOCKSv5 server Implementation, it'd make more sense to reuse the primitives there.

@nathe97
Copy link

nathe97 commented Nov 17, 2022

Some news for this socks5 in upstream feature?

@gastonmorixe
Copy link

+1

@karser
Copy link

karser commented Dec 11, 2023

it's indeed a missing feature

Update: I found a workaround by using tinyproxy with the following configuration:

Port 8080
upstream socks5 localhost:8000
Allow 0.0.0.0/0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature New features / enhancements
Projects
None yet
Development

No branches or pull requests