Skip to content

[求助] 如何利用 sing-box tun mode 全局代理特性, 配合其他工具(如 Charles)实现全局抓包? #2816

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

Closed
lemisky opened this issue Apr 2, 2025 · 3 comments
Labels

Comments

@lemisky
Copy link

lemisky commented Apr 2, 2025

自己尝试一圈, 没有成功, 大家有类似的需求吗?

不考虑科学上网需求, 纯抓包, 目前 httpdebug & proxifier 是可以直接实现的.

但还是想用 sing-box 试试.

@lemisky
Copy link
Author

lemisky commented Apr 2, 2025

尝试了如下规则:

config.json

{
    "log": {
        "level": "info"
    },
    "inbounds": [
        {
            "type": "tun",
            "tag": "tun-in",
            "interface_name": "tun0",
            "address": [
                "172.18.0.1/30",
                "fdfe:dcba:9876::1/126"
            ],
            "mtu": 9000,
            "auto_route": true,
            "auto_redirect": false,
            "strict_route": true,
            "route_address": [
                "0.0.0.0/1",
                "128.0.0.0/1",
                "::/1",
                "8000::/1"
            ],
            "route_exclude_address": [
                "192.168.0.0/16",
                "fc00::/7"
            ],
            "endpoint_independent_nat": false,
            "udp_timeout": "5m",
            "stack": "gvisor"
        }
    ],
    "outbounds": [
        {
            "type": "dns",
            "tag": "dns-out"
        },
        {
            "type": "http",
            "tag": "http-out",
            "server": "127.0.0.1",
            "server_port": 8888
        },
        {
            "type": "direct",
            "tag": "direct-out"
        }
    ],
    "route": {
        "auto_detect_interface": true,
        "rules": [
            {
                "protocol": [
                    "dns"
                ],
                "outbound": "dns-out"
            },
            {
                "process_name": [
                    "Charles.exe"
                ],
                "outbound": "direct-out"
            },
            {
                "ip_version": 4,
                "protocol": [
                    "http"
                ],
                "outbound": "http-out"
            }
        ],
        "final": "direct-out"
    }
}

现象是 Charles 没有抓到一个请求, 电脑正常可上网(开始), 后续错误日志挺多的

ERROR[0081] [1964902063 5.0s] connection: open outbound connection: dial tcp 172.18.0.2:53: i/o timeout
INFO[0081] router: failed to search process: process not found
INFO[0081] [213757545 0ms] inbound/tun[tun-in]: inbound connection from 172.18.0.1:5004
INFO[0081] [213757545 0ms] inbound/tun[tun-in]: inbound connection to 172.18.0.2:53
ERROR[0081] [3285394717 5.0s] connection: open outbound connection: dial tcp 172.18.0.2:53: i/o timeout
INFO[0081] [213757545 2ms] router: failed to search process: process not found
INFO[0081] [213757545 2ms] outbound/direct[direct-out]: outbound connection to 172.18.0.2:53
ERROR[0081] [2720308450 4.69s] connection: open outbound connection: dial tcp 172.18.0.2:53: operation was canceled
ERROR[0081] [2870770415 1.35s] connection: open outbound connection: dial tcp 172.18.0.2:53: operation was canceled
...
INFO[0081] router: failed to search process: process not found
INFO[0081] [979934125 0ms] inbound/tun[tun-in]: inbound connection from 172.18.0.1:5005
INFO[0081] [979934125 0ms] inbound/tun[tun-in]: inbound connection to 172.18.0.2:53
INFO[0081] [979934125 2ms] router: failed to search process: process not found
INFO[0081] [979934125 10ms] outbound/direct[direct-out]: outbound connection to 172.18.0.2:53
ERROR[0081] [964739930 1.24s] connection: open outbound connection: dial tcp 172.18.0.2:53: operation was canceled
ERROR[0081] [93837687 2.50s] connection: open outbound connection: dial tcp 172.18.0.2:53: operation was canceled
ERROR[0081] [473246996 1.14s] connection: open outbound connection: dial tcp 172.18.0.2:53: operation was canceled
ERROR[0081] [1902153616 3.90s] connection: open outbound connection: dial tcp 172.18.0.2:53: operation was canceled
ERROR[0081] [1545128821 468ms] connection: open outbound connection: dial tcp 172.18.0.2:53: operation was canceled
ERROR[0081] [4090813877 2.13s] connection: open outbound connection: dial tcp 172.18.0.2:53: operation was canceled
ERROR[0081] [1313946070 92ms] connection: open outbound connection: dial tcp 172.18.0.2:53: operation was canceled
...
ERROR[0081] [3724368303 3.64s] connection: open outbound connection: dial tcp 172.18.0.2:53: operation was canceled
ERROR[0081] [3120143786 1.42s] connection: open outbound connection: dial tcp 172.18.0.2:53: operation was canceled
ERROR[0081] [3032584737 3.85s] connection: open outbound connection: dial tcp 172.18.0.2:53: operation was canceled
ERROR[0081] [4012382569 3.56s] connection: open outbound connection: dial tcp 172.18.0.2:53: operation was canceled

@solanab
Copy link

solanab commented Apr 2, 2025

@lemisky
Copy link
Author

lemisky commented Apr 2, 2025

https://linux.do/t/topic/127658?u=whiredj

老哥,你好

这个我看过,它需要启动两个实例,尽管如此我还是尝试了,但也是不行的,和我上面给出的示例类似。我有尝试修正过期的配置方式,并且也用旧版运行,都不行,也许哪里我的方式不对,但这个需求,不应该要用两个实例实现,我想找一个最优的方式。

@dyhkwong dyhkwong added the spam label Apr 2, 2025
@dyhkwong dyhkwong closed this as not planned Won't fix, can't repro, duplicate, stale Apr 2, 2025
@SagerNet SagerNet locked as spam and limited conversation to collaborators Apr 2, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants