CHIZI-0618 / box4magisk

Use sing-box, clash, v2ray, xray tunnel proxy on Android devices.
GNU General Public License v3.0
920 stars 104 forks source link

Won't be able to connect with sing-box #41

Closed scruel closed 1 month ago

scruel commented 1 month ago

按如下配置后无法联网

box config

#!/system/bin/sh

bin_name="sing-box"
redir_port="7891"
tproxy_port="9898"
clash_dns_port="1053"
clash_dns_listen="0.0.0.0:${clash_dns_port}"
fake_ip_range_v4="198.18.0.0/15"
fake_ip_range_v6="fc00::/18"
tun_device="tun0"
box_user_group="root:net_admin"
# If you want to change the user or group, you must make the Box core in the /system/bin directory, otherwise the changes will not take effect.
# If you are using Magisk, you can copy the Box core files (sing-box, clash, etc.) to /data/adb/modules/bin_files/system/bin/ and reboot the phone
bin_name_list=("sing-box" "clash" "mihomo" "xray" "v2ray")
box_path="/data/adb/box"
bin_path="${box_path}/bin/${bin_name}"
run_path="${box_path}/run"
pid_file="${run_path}/${bin_name}.pid"
intranet=(0.0.0.0/8 10.0.0.0/8 100.0.0.0/8 127.0.0.0/8 169.254.0.0/16 192.0.0.0/24 192.0.2.0/24 192.88.99.0/24 192.168.0.0/16 198.51.100.0/24 203.0.113.0/24 224.0.0.0/4 240.0.0.0/4 255.255.255.255/32)
# The use of 100.0.0.0/8 instead of 100.64.0.0/10 is purely due to a mistake by China Telecom's service provider, and you can change it back.
intranet6=(::/128 ::1/128 ::ffff:0:0/96 100::/64 64:ff9b::/96 2001::/32 2001:10::/28 2001:20::/28 2001:db8::/32 2002::/16 fe80::/10 ff00::/8)
ipv6="disable"
proxy_method="TPROXY"
# REDIRECT: TCP only / TPROXY: TCP + UDP / MIXED: REDIRECT TCP + TUN UDP
proxy_mode="blacklist"
# blacklist / whitelist / core
user_packages_list=()
# Android User:Package Name, For example:
# user_packages_list=("0:com.android.captiveportallogin" "10:com.tencent.mm")
gid_list=()
# The gid in the list will be bypassed or proxied according to the proxy_mode configuration, and the gid can be arbitrarily specified by the busybox setuidgid command
ap_list=("wlan+" "ap+" "rndis+")
ignore_out_list=()

sing-box config:

sing-box/config.json
{
  "log": {
    "level": "trace",
    "timestamp": true
  },
  "dns": {
    "servers": [
      {
        "tag": "cloudflare",
        "address": "1.1.1.1",
        "detour": "socks-out"
      },
      {
        "tag": "local",
        "address": "local",
        "detour": "direct"
      }
    ],
    "rules": [
      {
        "outbound": "any",
        "server": "cloudflare",
        "disable_cache": true
      }
    ],
    "strategy": "ipv4_only"
  },
  "inbounds": [
    {
      "type": "tproxy",
      "tag": "tproxy-in",
      "listen": "::",
      "listen_port": 9898,
      "sniff": true
    }
  ],
  "outbounds": [
    {
      "type": "socks",
      "tag": "socks-out",
      "server": "192.168.1.11",
      "server_port": 8080,
      "version": "5",
      "network": "udp",
      "udp_over_tcp": false
    },
    {
      "type": "dns",
      "tag": "dns"
    },
    {
      "type": "direct",
      "tag": "direct"
    },
    {
      "type": "block",
      "tag": "block"
    }
  ],
  "route": {
    "rules": [
      {
        "port": 53,
        "outbound": "dns"
      }
    ],
    "final": "socks-out",
    "auto_detect_interface": false
  }
}
log ``` +0000 2024-05-18 18:48:53 INFO router: using dns[dns] as default outbound for connection +0000 2024-05-18 18:48:53 INFO router: using socks[socks-out] as default outbound for packet connection +0000 2024-05-18 18:48:53 INFO router: updated default interface wlan0, index 16, vpn disabled +0000 2024-05-18 18:48:53 INFO inbound/tproxy[tproxy-in]: tcp server started at [::]:9898 +0000 2024-05-18 18:48:53 INFO inbound/tproxy[tproxy-in]: udp server started at [::]:9898 +0000 2024-05-18 18:48:53 INFO sing-box started (0.00s) +0000 2024-05-18 18:48:57 INFO [2954390041 0ms] inbound/tproxy[tproxy-in]: inbound connection from 192.168.1.41:42872 +0000 2024-05-18 18:48:57 INFO [2954390041 0ms] inbound/tproxy[tproxy-in]: inbound connection to 142.250.189.174:443 +0000 2024-05-18 18:48:57 DEBUG [2954390041 1ms] router: sniffed protocol: tls, domain: play-fe.googleapis.com +0000 2024-05-18 18:48:58 INFO [2561511886 0ms] inbound/tproxy[tproxy-in]: inbound connection from 192.168.1.41:42876 +0000 2024-05-18 18:48:58 INFO [2561511886 0ms] inbound/tproxy[tproxy-in]: inbound connection to 142.250.189.174:443 +0000 2024-05-18 18:48:58 INFO [3886906365 0ms] inbound/tproxy[tproxy-in]: inbound connection from 192.168.1.41:40616 +0000 2024-05-18 18:48:58 INFO [3470913107 1ms] inbound/tproxy[tproxy-in]: inbound connection from 192.168.1.41:42878 +0000 2024-05-18 18:48:58 INFO [3470913107 2ms] inbound/tproxy[tproxy-in]: inbound connection to 142.250.189.174:443 +0000 2024-05-18 18:48:58 INFO [3886906365 2ms] inbound/tproxy[tproxy-in]: inbound connection to 142.250.191.42:443 +0000 2024-05-18 18:48:58 DEBUG [3470913107 3ms] router: sniffed protocol: tls, domain: play-fe.googleapis.com +0000 2024-05-18 18:48:58 DEBUG [2561511886 1ms] router: sniffed protocol: tls, domain: play-fe.googleapis.com +0000 2024-05-18 18:48:58 DEBUG [3886906365 7ms] router: sniffed protocol: tls, domain: play.googleapis.com +0000 2024-05-18 18:49:01 INFO [2900828353 0ms] inbound/tproxy[tproxy-in]: inbound packet connection from 192.168.1.41:46085 +0000 2024-05-18 18:49:01 INFO [2900828353 0ms] inbound/tproxy[tproxy-in]: inbound packet connection to 8.8.8.8:53 +0000 2024-05-18 18:49:01 DEBUG [2900828353 0ms] router: sniffed packet protocol: dns +0000 2024-05-18 18:49:01 DEBUG [2900828353 0ms] router: match[0] port=53 => dns +0000 2024-05-18 18:49:01 DEBUG dns: exchange www.google.ru. IN A +0000 2024-05-18 18:49:01 INFO outbound/socks[socks-out]: outbound packet connection to 1.1.1.1:53 +0000 2024-05-18 18:49:04 INFO [2937715998 0ms] inbound/tproxy[tproxy-in]: inbound packet connection from 192.168.1.41:30474 +0000 2024-05-18 18:49:04 INFO [2937715998 0ms] inbound/tproxy[tproxy-in]: inbound packet connection to 114.114.114.114:53 +0000 2024-05-18 18:49:04 DEBUG [2937715998 0ms] router: sniffed packet protocol: dns +0000 2024-05-18 18:49:04 DEBUG [2937715998 0ms] router: match[0] port=53 => dns +0000 2024-05-18 18:49:04 DEBUG dns: exchange www.google.ru. IN A +0000 2024-05-18 18:49:08 DEBUG dns: exchange www.google.ru. IN A +0000 2024-05-18 18:49:11 ERROR dns: exchange failed for www.google.ru. IN A: context deadline exceeded +0000 2024-05-18 18:49:11 DEBUG [1176772088 10.0s] inbound/tproxy[tproxy-in]: connection closed: io: read/write on closed pipe | upstream: context canceled +0000 2024-05-18 18:49:11 ERROR dns: exchange failed for www.google.ru. IN A: context canceled +0000 2024-05-18 18:49:11 INFO outbound/socks[socks-out]: outbound packet connection to 1.1.1.1:53 +0000 2024-05-18 18:49:11 DEBUG dns: exchange www.google.ru. IN A +0000 2024-05-18 18:49:14 ERROR dns: exchange failed for www.google.ru. IN A: context deadline exceeded +0000 2024-05-18 18:49:14 INFO outbound/socks[socks-out]: outbound packet connection to 1.1.1.1:53 +0000 2024-05-18 18:49:14 DEBUG [293763425 10.0s] inbound/tproxy[tproxy-in]: connection closed: io: read/write on closed pipe | upstream: context canceled +0000 2024-05-18 18:49:15 ERROR dns: exchange failed for www.google.ru. IN A: context canceled +0000 2024-05-18 18:49:27 ERROR [2954390041 30.1s] inbound/tproxy[tproxy-in]: process connection from 192.168.1.41:42872: unexpected EOF +0000 2024-05-18 18:49:27 INFO [3884017762 0ms] inbound/tproxy[tproxy-in]: inbound packet connection from 192.168.1.41:43421 +0000 2024-05-18 18:49:27 INFO [3884017762 0ms] inbound/tproxy[tproxy-in]: inbound packet connection to 142.250.189.174:443 +0000 2024-05-18 18:49:27 INFO [393830923 0ms] inbound/tproxy[tproxy-in]: inbound connection from 192.168.1.41:42936 +0000 2024-05-18 18:49:27 INFO [393830923 0ms] inbound/tproxy[tproxy-in]: inbound connection to 142.250.189.174:443 +0000 2024-05-18 18:49:27 DEBUG [3884017762 2ms] router: sniffed packet protocol: quic, domain: play-fe.googleapis.com +0000 2024-05-18 18:49:27 INFO [3884017762 2ms] outbound/socks[socks-out]: outbound packet connection to 142.250.189.174:443 +0000 2024-05-18 18:49:27 DEBUG [393830923 2ms] router: sniffed protocol: tls, domain: play-fe.googleapis.com +0000 2024-05-18 18:49:28 ERROR [2561511886 30.0s] inbound/tproxy[tproxy-in]: process connection from 192.168.1.41:42876: unexpected EOF +0000 2024-05-18 18:49:28 ERROR [3470913107 30.0s] inbound/tproxy[tproxy-in]: process connection from 192.168.1.41:42878: unexpected EOF +0000 2024-05-18 18:49:28 INFO [985630623 0ms] inbound/tproxy[tproxy-in]: inbound connection from 192.168.1.41:42940 +0000 2024-05-18 18:49:28 INFO [985630623 0ms] inbound/tproxy[tproxy-in]: inbound connection to 142.250.189.174:443 +0000 2024-05-18 18:49:28 DEBUG [985630623 4ms] router: sniffed protocol: tls, domain: play-fe.googleapis.com +0000 2024-05-18 18:49:30 INFO [2220690807 0ms] inbound/tproxy[tproxy-in]: inbound connection from 192.168.1.41:42942 +0000 2024-05-18 18:49:30 INFO [2220690807 0ms] inbound/tproxy[tproxy-in]: inbound connection to 142.250.189.174:443 +0000 2024-05-18 18:49:30 DEBUG [2220690807 2ms] router: sniffed protocol: tls, domain: play-fe.googleapis.com ``` socks5-server log: ``` 2024/05/18 18:51:13 socks.go:1216: [socks5-udp] 192.168.1.41:40558 >-< 192.168.1.11:61315 2024/05/18 18:51:13 socks.go:1149: [socks5-udp] 192.168.1.41:40562 - 192.168.1.11:16667 BIND ON 192.168.1.11:61317 OK 2024/05/18 18:51:13 socks.go:1209: [socks5-udp] 192.168.1.41:40562 <-> 192.168.1.11:61317 [tun: 192.168.1.11:61318] 2024/05/18 18:51:13 socks.go:1212: [socks5-udp] 192.168.1.41:40562 <-> 192.168.1.11:61317 2024/05/18 18:51:14 socks.go:1216: [socks5-udp] 192.168.1.41:40562 >-< 192.168.1.11:61317 2024/05/18 18:51:14 socks.go:1149: [socks5-udp] 192.168.1.41:40566 - 192.168.1.11:16667 BIND ON 192.168.1.11:61319 OK 2024/05/18 18:51:14 socks.go:1209: [socks5-udp] 192.168.1.41:40566 <-> 192.168.1.11:61319 [tun: 192.168.1.11:61320] 2024/05/18 18:51:14 socks.go:1212: [socks5-udp] 192.168.1.41:40566 <-> 192.168.1.11:61319 2024/05/18 18:51:14 socks.go:1216: [socks5-udp] 192.168.1.41:40566 >-< 192.168.1.11:61319 2024/05/18 18:51:14 socks.go:1149: [socks5-udp] 192.168.1.41:40568 - 192.168.1.11:16667 BIND ON 192.168.1.11:61321 OK 2024/05/18 18:51:14 socks.go:1209: [socks5-udp] 192.168.1.41:40568 <-> 192.168.1.11:61321 [tun: 192.168.1.11:61322] 2024/05/18 18:51:14 socks.go:1212: [socks5-udp] 192.168.1.41:40568 <-> 192.168.1.11:61321 2024/05/18 18:51:24 socks.go:1216: [socks5-udp] 192.168.1.41:40568 >-< 192.168.1.11:61321 2024/05/18 18:51:24 socks.go:1149: [socks5-udp] 192.168.1.41:40596 - 192.168.1.11:16667 BIND ON 192.168.1.11:61323 OK 2024/05/18 18:51:24 socks.go:1209: [socks5-udp] 192.168.1.41:40596 <-> 192.168.1.11:61323 [tun: 192.168.1.11:61324] 2024/05/18 18:51:24 socks.go:1212: [socks5-udp] 192.168.1.41:40596 <-> 192.168.1.11:61323 2024/05/18 18:51:24 socks.go:1216: [socks5-udp] 192.168.1.41:40596 >-< 192.168.1.11:61323 2024/05/18 18:51:24 socks.go:1149: [socks5-udp] 192.168.1.41:40598 - 192.168.1.11:16667 BIND ON 192.168.1.11:61325 OK 2024/05/18 18:51:24 socks.go:1209: [socks5-udp] 192.168.1.41:40598 <-> 192.168.1.11:61325 [tun: 192.168.1.11:61326] 2024/05/18 18:51:24 socks.go:1212: [socks5-udp] 192.168.1.41:40598 <-> 192.168.1.11:61325 2024/05/18 18:51:25 socks.go:1216: [socks5-udp] 192.168.1.41:40598 >-< 192.168.1.11:61325 2024/05/18 18:51:25 socks.go:1149: [socks5-udp] 192.168.1.41:40602 - 192.168.1.11:16667 BIND ON 192.168.1.11:61327 OK 2024/05/18 18:51:25 socks.go:1209: [socks5-udp] 192.168.1.41:40602 <-> 192.168.1.11:61327 [tun: 192.168.1.11:61328] 2024/05/18 18:51:25 socks.go:1212: [socks5-udp] 192.168.1.41:40602 <-> 192.168.1.11:61327 2024/05/18 18:51:27 socks.go:1216: [socks5-udp] 192.168.1.41:40602 >-< 192.168.1.11:61327 ```
CHIZI-0618 commented 1 month ago

太长懒得看 如果 sing-box 出问题请尝试注释或删除此3行 https://github.com/CHIZI-0618/box4magisk/blob/f900e66ae6a7da9e4cb27088db9589ea73ee39d0/box/scripts/box.tproxy#L187-L189

scruel commented 1 month ago

谢谢,不过发现是 server 侧的问题,后续有其他问题俺再补充