krlvm / PowerTunnel-Android

Powerful and extensible proxy server with anti-censorship functionality for Android
GNU General Public License v3.0
1.55k stars 116 forks source link

Bug - failed to start and crashed #146

Open xxjoe2 opened 1 year ago

xxjoe2 commented 1 year ago

hi

installed powertunnel v2.6.3 on my phone but it failed to start powertunnel

after readling the log, the possible cause could be: I/o.l.p.i.ProxyUtils(9429): Could not lookup localhost

so far i have tried:

  1. since my phone dont have /etc/hosts, so i added it

    • dig resolved localhost successfully but powertunnel failed to start with same error
  2. added hosts-cache.txt according to the sources

    • log showed I/HostsPlugin(7772): Loaded 1 hosts, no luck
  3. added a url to fetch a default hosts file, failed too

    • from log: I/HostsPlugin(9429): Loaded 2 hosts I/LittleProxyServer(9429): Starting LittleProxy Server... I/PlatformDependent(9429): Your platform does not provide complete low-level API for accessing direct buffers reliably. Unless explicitly requested, heap buffer will always be preferred to avoid potential system instability. D/EnterpriseController(4412): netId is 0 E/Netd(4412): getNetworkForDns: getNetId from enterpriseCtrl is netid 0 D/DnsProxyListener(4412): DNSDBG::dns addrinfo af 2 - 10330 I/o.l.p.i.ProxyUtils(9429): Could not lookup localhost

full exceptions: E/TunnelingVpnService(7772): Failed to establish VPN Service: Cannot set address E/TunnelingVpnService(7772): java.lang.IllegalStateException: Cannot set address E/TunnelingVpnService(7772): at android.os.Parcel.createException(Parcel.java:2096) E/TunnelingVpnService(7772): at android.os.Parcel.readException(Parcel.java:2056) E/TunnelingVpnService(7772): at android.os.Parcel.readException(Parcel.java:2004) E/TunnelingVpnService(7772): at android.net.IConnectivityManager$Stub$Proxy.establishVpn(IConnectivityManager.java:4048) E/TunnelingVpnService(7772): at android.net.VpnService$Builder.establish(VpnService.java:1133) E/TunnelingVpnService(7772): at io.github.krlvm.powertunnel.android.services.TunnelingVpnService.connect(TunnelingVpnService.java:155) E/TunnelingVpnService(7772): at io.github.krlvm.powertunnel.android.services.TunnelingVpnService.lambda$onStartCommand$0$io-github-krlvm-powertunnel-android-services-TunnelingVpnService(TunnelingVpnService.java:105) E/TunnelingVpnService(7772): at io.github.krlvm.powertunnel.android.services.TunnelingVpnService$$ExternalSyntheticLambda0.accept(Unknown Source:4) E/TunnelingVpnService(7772): at io.github.krlvm.powertunnel.android.managers.ProxyManager.lambda$start$0$io-github-krlvm-powertunnel-android-managers-ProxyManager(ProxyManager.java:128) E/TunnelingVpnService(7772): at io.github.krlvm.powertunnel.android.managers.ProxyManager$$ExternalSyntheticLambda0.run(Unknown Source:2) E/TunnelingVpnService(7772): at java.lang.Thread.run(Thread.java:919) E/TunnelingVpnService(7772): Caused by: android.os.RemoteException: Remote stack trace: E/TunnelingVpnService(7772): at com.android.server.connectivity.Vpn.jniSetAddresses(Native Method) E/TunnelingVpnService(7772): at com.android.server.connectivity.Vpn.establish(Vpn.java:1303) E/TunnelingVpnService(7772): at com.android.server.ConnectivityService.establishVpn(ConnectivityService.java:5644) E/TunnelingVpnService(7772): at android.net.IConnectivityManager$Stub.onTransact(IConnectivityManager.java:1730) E/TunnelingVpnService(7772): at android.os.Binder.execTransactInternal(Binder.java:1056) W/TunnelingVpnService(7772): VPN Service is still not established, stopping... I/ProxyManager(7772): Stopping server... I/LittleProxyServer(7772): Stopping LittleProxy Server... I/DefaultHttpProxyServer(7772): Shutting down proxy server gracefully I/DefaultHttpProxyServer(7772): Closing all channels (graceful) I/o.l.p.i.ServerGroup(7772): Shutting down server group event loops (graceful)

note: i have not enabled any plugin yet, and i have tried v1.9.1 as suggested mine is running android 10 and other vpns like orbot can be started without problem

any idea?

thanks

krlvm commented 1 year ago

I think you've set your proxy server address as local server address, that's why it can't bind to it.

xxjoe2 commented 1 year ago

I think you've set your proxy server address as local server address, that's why it can't bind to it.

yes i have a proxy server running. but how come? they are in the same address but with different ports

i have proxy and dns server running on the phone so i created an alias 10.255.255.1 and set the proxy to listen to this ip. however, powertunnel still failed to start then, i have stopped those servers and pointing to another upstream proxy server, didnt work. tried to start without upstream proxy, still no luck

any idea to solve this?

krlvm commented 1 year ago

I mean that PowerTunnel also runs a proxy server locally on your device (port 8085 by default), and you changed its IP address from local (0.0.0.0, 127.0.0.1 or any other accessible interface) so something else, where the proxy can't bind port.

You can try clearing the application data.

xxjoe2 commented 1 year ago

I mean that PowerTunnel also runs a proxy server locally on your device (port 8085 by default), and you changed its IP address from local (0.0.0.0, 127.0.0.1 or any other accessible interface) so something else, where the proxy can't bind port.

You can try clearing the application data.

i have tried to set powertunnel to listen on 192.168 10.1 but it still didint start

and it should not cause any problem even they are listening to the same ip (different ports). i installed powertunnel on another non-root device with orbot installed and both of them are listening to 127.0.0.1 without problem

it's weird

been uninstalled and reinstalled a few times, so not caching or data problem

krlvm commented 1 year ago

Are you using a custom ROM?

xxjoe2 commented 1 year ago

yes, rooted samsung, android Q

krlvm commented 1 year ago

Seems like an issue with ROM, and the logs don't shed enough light on this, I can hardly do anything about it

xxjoe2 commented 1 year ago

that was an excerpt which contains critial logs

here you are the full log, after successfully resolved localhost https://paste.c-net.org/ParishPuppet

krlvm commented 1 year ago

The error is, in fact, on the system side.

15388 27727 I TunnelingVpnService: Establishing VPN Service...
15388 27727 E TunnelingVpnService: Failed to establish VPN Service: Cannot set address
15388 27727 E TunnelingVpnService: java.lang.IllegalStateException: Cannot set address
15388 27727 E TunnelingVpnService:  at android.os.Parcel.createException(Parcel.java:2096)
15388 27727 E TunnelingVpnService:  at android.os.Parcel.readException(Parcel.java:2056)
15388 27727 E TunnelingVpnService:  at android.os.Parcel.readException(Parcel.java:2004)
15388 27727 E TunnelingVpnService:  at android.net.IConnectivityManager$Stub$Proxy.establishVpn(IConnectivityManager.java:4048)
15388 27727 E TunnelingVpnService:  at android.net.VpnService$Builder.establish(VpnService.java:1133)
15388 27727 E TunnelingVpnService:  at io.github.krlvm.powertunnel.android.services.TunnelingVpnService.connect(TunnelingVpnService.java:155)
15388 27727 E TunnelingVpnService:  at io.github.krlvm.powertunnel.android.services.TunnelingVpnService.lambda$onStartCommand$0$io-github-krlvm-powertunnel-android-services-TunnelingVpnService(TunnelingVpnService.java:105)
15388 27727 E TunnelingVpnService:  at io.github.krlvm.powertunnel.android.services.TunnelingVpnService$$ExternalSyntheticLambda0.accept(Unknown Source:4)
15388 27727 E TunnelingVpnService:  at io.github.krlvm.powertunnel.android.managers.ProxyManager.lambda$start$0$io-github-krlvm-powertunnel-android-managers-ProxyManager(ProxyManager.java:128)
15388 27727 E TunnelingVpnService:  at io.github.krlvm.powertunnel.android.managers.ProxyManager$$ExternalSyntheticLambda0.run(Unknown Source:2)
15388 27727 E TunnelingVpnService:  at java.lang.Thread.run(Thread.java:919)
15388 27727 E TunnelingVpnService: Caused by: android.os.RemoteException: Remote stack trace:
15388 27727 E TunnelingVpnService:  at com.android.server.connectivity.Vpn.jniSetAddresses(Native Method)
15388 27727 E TunnelingVpnService:  at com.android.server.connectivity.Vpn.establish(Vpn.java:1303)
15388 27727 E TunnelingVpnService:  at com.android.server.ConnectivityService.establishVpn(ConnectivityService.java:5644)
15388 27727 E TunnelingVpnService:  at android.net.IConnectivityManager$Stub.onTransact(IConnectivityManager.java:1730)
15388 27727 E TunnelingVpnService:  at android.os.Binder.execTransactInternal(Binder.java:1056)
15388 27727 E TunnelingVpnService: 
15388 27727 W TunnelingVpnService: VPN Service is still not established, stopping...

Other parts of this log are irrelevant.

If you have root access, you can run PowerTunnel in proxy mode and set 127.0.0.1:8085 as a global system proxy.

xxjoe2 commented 1 year ago

yeah i agreed after reading the log and some source codes however i have no problem when using other vpn like orbot and some real vpn apps. so maybe different implementation? or android q is not supported by powertunnel?

i have another socks proxy server running on the phone. i don need to run it as proxy mode and forward it to my another local upstream proxy. what i want is to run it as vpn mode to make it possible to dirvert other apps/traffic

krlvm commented 1 year ago

Other VPNs work fine because they are VPNs indeed, while PowerTunnel's VPN is just a local packet interceptor

xxjoe2 commented 1 year ago

i see

so it's could be due to hardware like the check for samsung model starts with sm- in the sources (mine isnt sm series) or ROM issue

any idea which particular area(s) in the rom? vpn connection? the protocol used/encryption etc, or what? may be i can port it to my phone

edit i have read VPNService.java and learned that it will throw an illegalStateException if the parama are invalid. and in the establish function, there are 2 params:

mConfig.addresses = mAddresses;

 mConfig.routes = mRoutes;

according to the doc either one can cause an error. so how can i know if it is the address or routes, or both, causing the problem?

edit 2 i just found this https://www.sonicwall.com/support/knowledge-base/mobile-connect-fails-to-establish-sslvpn-connection-with-error-cannot-create-interface/170505292313010/ which shows the same problem but it's for android 4 ice cream.

but still, i am unable to locate the problem area

krlvm commented 1 year ago

If you reinstall the application, do you see something like this?

image

xxjoe2 commented 1 year ago

vpndialog, yes

rn i am looking for similar forks to see if they can get connected

xxjoe2 commented 1 year ago

found this, a fork of raise-isayan's TunProxy https://github.com/yehgdotnet/mobileptrepo/blob/master/android/tunproxy.apk

failed to start too with same errors. so it must be within TunProxy

xxjoe2 commented 1 year ago

sigh..... i got it....

from one of the forks, i found this in the log Cannot add address: fd00:1:fd00:1:fd00:1:fd00:1/128: Permission denied

so, i know what's wrong, coz i disabled ipv6 by default and after i re-enabled ipv6, powertunnel started successfully

so, 1/. can you please make ipv6 optional? 2/. more description about the settings will be great (perhaps most devs hate docs like me), eg

most of them are quite technical, may be you assumed most us are advanced users. but for instance, i understand what transparent mode and strict dns mode are, but i am not very sure what "allow requests to origin server" means. do you mean cross-origin server? just wild guess :D

anyway, thanks a lot for your time and help

looking forward to see more features

krlvm commented 1 year ago

I'll make IPv6 an optional feature.

When "Allow requests to origin server" is disabled, LittleProxy rejects HTTP requests if they are direct requests to proxy, i.e. if they treat the proxy server as the origin server - such requests does not have the HTTP scheme in the URI.

xxjoe2 commented 1 year ago

I'll make IPv6 an optional feature.

When "Allow requests to origin server" is disabled, LittleProxy rejects HTTP requests if they are direct requests to proxy, i.e. if they treat the proxy server as the origin server - such requests does not have the HTTP scheme in the URI.

that's great, thanks!

ok, so it is X-Forwarded-For i believe, which does not affect socks proxies