在 Android 手机上的使用 stunnel (不需要 root )

☆ Android stunnel

https://github.com/comp500/SSLSocks.git 这个项目可以使用 android 版本的 stunnel, 其实就是调用 https://www.stunnel.org/downloads/stunnel-5.57-android.zip

具体配置和使用命令行差距不大,参考:
https://github.com/comp500/SSLSocks/blob/master/README.md
https://hamy.io/post/0011/how-to-run-stunnel-on-your-android-device/

☆ 设置全局代理

  1. 在 wifi 连接的情况

打开wifi 列表 -> 长按连接的 wifi -> 点击修改 -> 高级选项 -> 填写代理相关信息

  1. 使用 adb shell 执行命令
1
adb shell settings put global http_proxy 192.168.xx.xxx:8888
  1. Android Proxy Toggle

https://github.com/theappbusiness/android-proxy-toggle.git

要正常使用 app 需要用 adb shell 连接上设置相应的权限:

1
adb shell pm grant com.kinandcarta.create.proxytoggle android.permission.WRITE_SECURE_SETTINGS

OnePlus 7T 升级到 Android 12 后,执行上面的命令将出错:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
OnePlus7T:/ $ pm grant com.kinandcarta.create.proxytoggle android.permission.WRITE_SECURE_SETTINGS

Exception occurred while executing 'grant':
java.lang.SecurityException: grantRuntimePermission: Neither user 2000 nor current process has android.permission.GRANT_RUNTIME_PERMISSIONS.
at android.app.ContextImpl.enforce(ContextImpl.java:2187)
at android.app.ContextImpl.enforceCallingOrSelfPermission(ContextImpl.java:2215)
at com.android.server.pm.permission.PermissionManagerService.grantRuntimePermissionInternal(PermissionManagerService.java:1477)
at com.android.server.pm.permission.PermissionManagerService.grantRuntimePermission(PermissionManagerService.java:1459)
at android.permission.PermissionManager.grantRuntimePermission(PermissionManager.java:378)
at com.android.server.pm.PackageManagerShellCommand.runGrantRevokePermission(PackageManagerShellCommand.java:2419)
at com.android.server.pm.PackageManagerShellCommand.onCommand(PackageManagerShellCommand.java:260)
at com.android.modules.utils.BasicShellCommandHandler.exec(BasicShellCommandHandler.java:97)
at android.os.ShellCommand.exec(ShellCommand.java:38)
at com.android.server.pm.PackageManagerService.onShellCommand(PackageManagerService.java:25948)
at android.os.Binder.shellCommand(Binder.java:970)
at android.os.Binder.onTransact(Binder.java:854)
at android.content.pm.IPackageManager$Stub.onTransact(IPackageManager.java:4818)
at com.android.server.pm.PackageManagerService.onTransact(PackageManagerService.java:8987)
at android.os.Binder.execTransactInternal(Binder.java:1226)
at android.os.Binder.execTransact(Binder.java:1163)

少数派的文章 在 ColorOS 上免 root 玩机,请先打开这个开关 中指出需要在开发者选项中
开启 禁止权限监控

开启后可以正常执行 pm grant 命令,执行成功后可以使用 dumpsys package <package name> 列出所有的权限。

1
2
3
4
5
6
7
dumpsys package com.kinandcarta.create.proxytoggle | grep permission

requested permissions:
android.permission.WRITE_SECURE_SETTINGS
android.permission.WRITE_SETTINGS
install permissions:
android.permission.WRITE_SECURE_SETTINGS: granted=true

恢复无代理

如果遇上一些异常情况,比如错误卸载了 Android Proxy Toggle, 可以使用下面命令去掉 Android 全局代理。

1
2
3
adb shell settings delete global http_proxy
adb shell settings delete global global_http_proxy_host
adb shell settings delete global global_http_proxy_port

在 Android 手机上的使用 stunnel (不需要 root )
http://usmacd.com/cn/android_stunnel/
Author
henices
Posted on
February 24, 2021
Licensed under