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

Feature: Proxy support #27

Closed
JonnyShuali opened this issue Apr 22, 2017 · 19 comments
Closed

Feature: Proxy support #27

JonnyShuali opened this issue Apr 22, 2017 · 19 comments

Comments

@JonnyShuali
Copy link
Contributor

I think the best next feature should be socks proxy support or http proxy support. What do you think? How complex it would to add this?
Do you have any idea where the proxy should be placed? I could try to do it myself if you don't have the time...

@rom1v
Copy link
Collaborator

rom1v commented Apr 22, 2017

I think the best next feature should be socks proxy support or http proxy support. What do you think?

HTTP proxy

About HTTP proxy support, I understand your request as a feature that would transparently (i.e. without the Android-side being aware of) proxy HTTP streams. My position is that this is a bad idea.

The main reason is that it does not operate at the same level: gnirehtet redirects TCP connections, not HTTP streams. To force them to use a proxy, it would have to analyze and tamper TCP payloads containing HTTP streams (this would be dirty IMO), which may not work for HTTPS streams (since it would not be able to tamper HTTP headers).

The right way to handle HTTP proxy IMO is to make the client forge proxified HTTP(S) requests. In that case, gnirehtet is considered as a tool that only provides internet access to the Internet to Android devices, as if they were connected via wifi or ethernet: they should explicitly define the proxy, locally (in the web browser or application settings) or globally (on Android, even if this is limited, you can define such a proxy, cf #4 (comment)).

SOCKS proxy

Of course, I could make the same argument for SOCKS proxy: you can just configure it in your device web browser (but there is no global SOCKS proxy settings for Android AFAIK).

Still, the difference is that contrary to HTTP, SOCKS operates at the right level (at least for TCP connections), so in theory, it could be set almost transparently. The main problem is for DNS requests (if you want domain names to be resolved remotely), because the client must behave differently when there is a proxy (it must explicitly pass the domain name in the SOCKS protocol instead of resolving it locally). This implies that the proxy may not be transparent easily.

My first idea to forward connections in gnirehtet was to use SOCKS instead of a custom relay server. See this article, some arguments also apply for using a SOCKS proxy over the current implementation of gnirehtet.

Nevertheless, in theory, it would be possible to wrap the relay server so that all connections are SOCKSified, thanks to tsocks or proxychains. Unfortunately, this actually does not work for the relay server, because java and async I/O if I understood correctly.

Neither:

tsocks java -jar relay.jar
proxychains java -jar relay.jar

Nor:

java -DsocksProxyHost=127.0.0.1 -DsocksProxyPort=1080 -jar relay.jar

actually makes the relay server use the SOCKS proxy (while this works for other applications like pidgin).

See:
http://stackoverflow.com/questions/29076590/tsocks-not-working-with-java
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=576301

@rom1v
Copy link
Collaborator

rom1v commented Oct 16, 2017

Unfortunately, this actually does not work for the relay server, because java and async I/O if I understood correctly.

This may work with the Rust version.

@Biswa96
Copy link

Biswa96 commented Oct 16, 2017

I have a SOCKS proxy (dispatch-proxy) in my PC. Can I use the relay server in PC with that proxy?

@rom1v
Copy link
Collaborator

rom1v commented Oct 16, 2017

Probably with:

tsocks ./gnirehtet relay

or:

proxychains ./gnirehtet relay

(on Linux at least).

@Warpten
Copy link

Warpten commented Mar 20, 2019

Android Q adds VpnService.Builder.setHttpProxy, might be worth looking into in a couple months from now. It's not perfect (it acts as a recommendation and an app is free to ignore it), but it could help.

https://developer.android.com/reference/android/net/VpnService.Builder.html#setHttpProxy(android.net.ProxyInfo)

@sankred9527
Copy link

sankred9527 commented Feb 12, 2021

tsocks / proxychain can work ,but can't work well .

Because gnirehtet use non-blocking connect() , and tsocks/proxychain will change connect() to block, so one blocked connect() will hang up the main loop of gnirehtet .

proxychain must change connect() to block socket :
https://github.com/rofl0r/proxychains-ng/blob/6c029fdf471262e92ebc9a69329a0c45814e2c2c/src/libproxychains.c#L625

I am writing a socks5 proxy (nonblocking ) patch for gnirehtet

@sankred9527
Copy link

I fork gnirehtet and added socks5 proxy support : https://github.com/sankhwang/gnirehtet

@sankred9527
Copy link

sankred9527 commented Jan 5, 2022 via email

@sankred9527
Copy link

sankred9527 commented Jan 11, 2022 via email

@zombob
Copy link

zombob commented Feb 16, 2022

please read : relay-rust/proxy.toml.example <sankhwang@8e6567d#diff-ae635c6bcd903762bebcc3560e927e5adff3fa36f74be6f4831d0d820fa447c6> relay-rust/src/relay/socks5_protocol.rs <sankhwang@8e6567d#diff-64343c43bbdc7eb2cf8ef120c2489e4f181f21cf524f8f38996b830704235f6f> in my fork I commit many codes in : sankhwang@8e6567d cmdszh @.> 于2022年1月10日周一 21:41写道:

I fork gnirehtet and added socks5 proxy support : https://github.com/sankhwang/gnirehtet dhffb @. > 于2022年1月3日周一 22:41写道: … <#m_8551391940203118728_> 请问socks5代理补丁进度如何了,我尝试用proxychains4-ng 效果不是很好 — Reply to this email directly, view it on GitHub <#27 (comment) <#27 (comment)>>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AH5NRTTYQEU7OF2KJMPIKODUUGYQTANCNFSM4DIU2TVQ https://github.com/notifications/unsubscribe-auth/AH5NRTTYQEU7OF2KJMPIKODUUGYQTANCNFSM4DIU2TVQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub. You are receiving this because you commented.Message ID: @.> nothing implemented in your code....?? — Reply to this email directly, view it on GitHub <#27 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AH5NRTSVHW72DDZH2A6F7ZLUVLOYBANCNFSM4DIU2TVQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub. You are receiving this because you commented.Message ID: @.
>

Can you publish a runnable program for test?

@sankred9527
Copy link

sankred9527 commented Feb 16, 2022 via email

@dhffb
Copy link

dhffb commented Apr 15, 2022

你可以拉我的fork自己编译,很简单!

On Wed, Feb 16, 2022 at 10:29 AM zombob @.> wrote: please read : relay-rust/proxy.toml.example < @.#diff-ae635c6bcd903762bebcc3560e927e5adff3fa36f74be6f4831d0d820fa447c6 <sankhwang@8e6567d#diff-ae635c6bcd903762bebcc3560e927e5adff3fa36f74be6f4831d0d820fa447c6>> relay-rust/src/relay/socks5_protocol.rs < @.#diff-64343c43bbdc7eb2cf8ef120c2489e4f181f21cf524f8f38996b830704235f6f <sankhwang@8e6567d#diff-64343c43bbdc7eb2cf8ef120c2489e4f181f21cf524f8f38996b830704235f6f>> in my fork I commit many codes in : @. <sankhwang@8e6567d> cmdszh @. > 于2022年1月10日周一 21:41写道: … <#m_-2079108935672582638_> I fork gnirehtet and added socks5 proxy support : https://github.com/sankhwang/gnirehtet https://github.com/sankhwang/gnirehtet dhffb @. > 于2022年1月3日周一 22:41写道: … <#m_8551391940203118728_> 请问socks5代理补丁进度如何了,我尝试用proxychains4-ng 效果不是很好 — Reply to this email directly, view it on GitHub <#27 <#27> (comment) <#27 (comment) <#27 (comment)>>>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AH5NRTTYQEU7OF2KJMPIKODUUGYQTANCNFSM4DIU2TVQ https://github.com/notifications/unsubscribe-auth/AH5NRTTYQEU7OF2KJMPIKODUUGYQTANCNFSM4DIU2TVQ https://github.com/notifications/unsubscribe-auth/AH5NRTTYQEU7OF2KJMPIKODUUGYQTANCNFSM4DIU2TVQ https://github.com/notifications/unsubscribe-auth/AH5NRTTYQEU7OF2KJMPIKODUUGYQTANCNFSM4DIU2TVQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub. You are receiving this because you commented.Message ID: @.> nothing implemented in your code....?? — Reply to this email directly, view it on GitHub <#27 (comment) <#27 (comment)>>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AH5NRTSVHW72DDZH2A6F7ZLUVLOYBANCNFSM4DIU2TVQ https://github.com/notifications/unsubscribe-auth/AH5NRTSVHW72DDZH2A6F7ZLUVLOYBANCNFSM4DIU2TVQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub. You are receiving this because you commented.Message ID: @.> Can you publish a runnable program for test? — Reply to this email directly, view it on GitHub <#27 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AH5NRTUXW7J5R7IT5ONV7EDU3MDY3ANCNFSM4DIU2TVQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub. You are receiving this because you commented.Message ID: @.***>

不支持UDP?UDP包丢弃导致 网站域名无法解析

@sankred9527
Copy link

sankred9527 commented Apr 20, 2022 via email

@hacker1024
Copy link

Probably with:

tsocks ./gnirehtet relay

or:

proxychains ./gnirehtet relay

(on Linux at least).

This is not working for me on macOS - traffic does not go through the proxy. Did something change to break this?

@hacker1024
Copy link

Android Q adds VpnService.Builder.setHttpProxy, might be worth looking into in a couple months from now. It's not perfect (it acts as a recommendation and an app is free to ignore it), but it could help.

https://developer.android.com/reference/android/net/VpnService.Builder.html#setHttpProxy(android.net.ProxyInfo)

Can this be implemented? It looks fairly easy to add - just pass the VPN service the specified host and port, and then call this method.

@sankred9527
Copy link

Probably with:

tsocks ./gnirehtet relay

or:

proxychains ./gnirehtet relay

(on Linux at least).

This is not working for me on macOS - traffic does not go through the proxy. Did something change to break this?

proxychains / tsocks can work with gnirehtet, but can NOT work well.
because proxychains use a blocked "connect()" function , but gnirehtet use non-blocking connect . If andriod app connect to www.foo.com and blocked in proxychains , all the connections of gnirehtet will be blocked too .

so I fork and patch a non-blocking socks5 proxy fork of gnirehtet .

@sankred9527
Copy link

useless

This proxy is only a recommendation and it is possible that some apps will ignore it.

Android Q adds VpnService.Builder.setHttpProxy, might be worth looking into in a couple months from now. It's not perfect (it acts as a recommendation and an app is free to ignore it), but it could help.
https://developer.android.com/reference/android/net/VpnService.Builder.html#setHttpProxy(android.net.ProxyInfo)

Can this be implemented? It looks fairly easy to add - just pass the VPN service the specified host and port, and then call this method.

@liujinlong123
Copy link

you can pull my fork and compile it yourself , very simple !

How to compile in ubuntu ? I'm a new in rust

@liujinlong123
Copy link

cargo build can make the target. but when I run './gnirehtet run', it had an error

2023-06-07 17:35:38.893 INFO Main: Checking gnirehtet client...
2023-06-07 17:35:38.894 DEBUG Main: Execute: "adb" ["shell", "dumpsys", "package", "com.genymobile.gnirehtet"]
2023-06-07 17:35:38.893 INFO Main: Starting relay server on port 31416 with conf file ...
thread 'main' panicked at 'invalid conf file, -c args is none', src/relay/proxy_config.rs:58:21
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace

can u give us a tutorial ? @sankred9527

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants