cadl / seeker

通过使用 tun 来实现透明代理。实现了类似 surge 增强模式与网关模式。

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Seeker

badge
badge

使用 Tun 实现透明代理(支持 Mac & Linux 系统),支持 TCP、UDP。

Download

访问 https://github.com/gfreezy/seeker/releases 下载最新 release

chmod +x seeker-osx  # or  chmod+x seeker-linux

Usage

  1. 启动 seeker

    Seeker 0.5.0
    gfreezy <gfreezy@gmail.com>
    Tun to Shadowsockets proxy. https://github.com/gfreezy/seeker
    
    USAGE:
        seeker [FLAGS] [OPTIONS]
    
    FLAGS:
            --encrypt    Encrypt config file and output to terminal
        -h, --help       Prints help information
        -V, --version    Prints version information
    
    OPTIONS:
        -c, --config <FILE>              Sets config file. Sample config at
                                         https://github.com/gfreezy/seeker/blob/master/sample_config.yml
            --config-url <CONFIG_URL>    URL to config
            --key <KEY>                  Key for encryption/decryption
        -l, --log <PATH>                 Log file
        -u, --uid <UID>                  User id to proxy

    本地配置文件启动

    sudo seeker --config path/to/config.yml

    远程配置文件启动

    sudo seeker --config-url https://pastebin.com/raw/config --key encrypt-key

    生成远程配置文件

    sudo seeker --config path/to/config.yml --encrypt --key encrypt-key
  2. seeker 启动的时候会自动将本机 DNS 修改为 127.0.0.1,退出的时候将 DNS 设置为默认值

Config

  • seeker 直接使用的 clash 的规则。目前支持 DOMAIN DOMAIN-KEYWORD DOMAIN-SUFFIX MATCH 规则,不支持 IP 相关的规则。

  • 支持的 Action:

  • PROXY 走代理

  • DIRECT 直连

  • REJECT 拒绝

  • PROBE 默认尝试直连,如果超时,则走代理。由 direct_connect_timeout 控制超时时间

  • 确保系统没有重复的 tun_name

  • 确保 TUN 的网络 tun_iptun_cidr 与当前所处网络环境不在一个网段

  • seeker 支持 socks5 代理、http 代理和 shadowsocks 代理。优先级为 socks5 代理 > shadowsocks 代理 > http 代理。

  • redir 模式下使用 iptables 的 redirect 功能,只支持 tcp 流量。

verbose: false
dns_start_ip: 10.0.0.10
# 可以指定多个 DNS 服务器,如果不指定则使用系统默认的 DNS 服务器。一般最好指定,否则Wi-Fi切换的时候可能会出现 DNS 服务器无法访问的问题。
# 一般 DHCP 获取 IP 的时候会自动获取 DNS 服务器,切换 Wi-Fi 的时候,DNS 服务器也会发生变化。
dns_servers:
  - 223.5.5.5:53
  - 114.114.114.114:53
  - tcp://114.114.114.114:53
dns_timeout: 1s
tun_bypass_direct: true  # 直连的域名直接返回真实IP,不走tun
# redir 模式使用 iptable 的 redirect 功能: iptables -t nat -A PREROUTING -d 11.0.0.0/16 -p tcp -j REDIRECT --to-ports 1300
# redir 模式下只支持 tcp 流量。默认使用 tun 模式。特殊设备不支持 tun 的情况,可以使用 redir 模式。
redir_mode: false
tun_name: utun4
tun_ip: 10.0.0.1
tun_cidr: 10.0.0.0/16
dns_listen: 0.0.0.0:53
gateway_mode: true
ping_timeout: 2s
# probe_timeout 时间内如果可以建立 TCP 连接则直连(443端口会额外建立 SSL 连接),否则走代理。不要调的太低,国内有些网站会有很长的 SSL 握手时间。
# 如果目标端口为 443,TCP 连接的超时时间为 probe_timeout, SSL 连接超时时间也为 probe_timeout,总的超时时间为 probe_timeout * 2;
# 如果目标端口不为 443,TCP 连接的超时时间为 probe_timeout。
probe_timeout: 200ms
connect_timeout: 1s
read_timeout: 30s
write_timeout: 5s
# geoip 数据库路径,如果使用相对路径,相对于可执行文件的路径。默认会搜索可执行文件同级目录下的 geoip.mmdb 文件
# 可以从 https://github.com/Hackl0us/GeoIP2-CN 下载 mmdb 格式的文件
geo_ip: path/to/geoip.mmdb

max_connect_errors: 2  # ss 服务器重试次数,到达重试次数后会自动选择下一个最快的服务器
ping_urls:
  - host: www.facebook.com
    port: 80
    path: /
  - host: www.youtube.com
    port: 80
    path: /
  - host: twitter.com
    port: 80
    path: /

remote_config_urls:  # ss 订阅地址,启动时自动拉群配置,并将配置的服务器地址自动加入服务器列表
  - https://addr-to-ss-subscribe-url

servers:
  - name: socks5 proxy server
    addr: domain-or-ip-to-socks5-server:port
    protocol: Socks5  # Https or Http or Socks5 or Shadowsocks

  - name: http proxy server
    addr: domain-or-ip-to-socks5-server:port
    username: username
    password: pass
    protocol: Https  # Https or Http or Socks5 or Shadowsocks

  - name: https proxy server
    addr: domain-or-ip-to-socks5-server:port
    username: username
    password: pass
    protocol: Https  # Https or Http or Socks5 or Shadowsocks

  - name: server1
    addr: domain-or-ip-to-ss-server:port
    method: chacha20-ietf
    password: password
    protocol: Shadowsocks
    obfs:  # 不设置默认不使用 obfs。只有 Shadowsocks 支持 obfs
      mode: Http  # 目前只支持 Http
      host: c61be5399e.microsoft.com

  - name: server2
    addr: domain-or-ip-to-ss-server:port
    method: chacha20-ietf
    password: password
    protocol: Shadowsocks

rules:
  - 'DOMAIN,audio-ssl.itunes.apple.com,DIRECT'
  - 'DOMAIN,gspe1-ssl.ls.apple.com,REJECT'
  - 'DOMAIN-SUFFIX,aaplimg.com,DIRECT'
  - 'DOMAIN-SUFFIX,apple.co,DIRECT'
  - 'DOMAIN-KEYWORD,bbcfmt,PROXY'
  - 'DOMAIN-KEYWORD,uk-live,PROXY'
  - 'DOMAIN-SUFFIX,snssdk.com,DIRECT'
  - 'DOMAIN-SUFFIX,toutiao.com,PROBE'
  - 'IP-CIDR,19.23.212.0/16,PROXY'
  - 'IP-CIDR,19.23.21.0/16,PROBE'
  - 'GEOIP,CN,DIRECT'
  - 'MATCH,PROBE'

支持的 method

Table
Plain

Aes128Cfb
Aes128Cfb1
Aes128Cfb8
Aes128Cfb128
Aes192Cfb
Aes192Cfb1
Aes192Cfb8
Aes192Cfb128
Aes256Cfb
Aes256Cfb1
Aes256Cfb8
Aes256Cfb128
Aes128Ctr
Aes192Ctr
Aes256Ctr

Camellia128Cfb
Camellia192Cfb
Camellia256Cfb
Camellia128Cfb1
Camellia192Cfb1
Camellia256Cfb1
Camellia128Cfb8
Camellia192Cfb8
Camellia256Cfb8
Camellia128Cfb128
Camellia192Cfb128
Camellia256Cfb128

Rc4
Rc4Md5

ChaCha20
Salsa20
XSalsa20
ChaCha20Ietf

Aes128Gcm
Aes256Gcm

ChaCha20IetfPoly1305
XChaCha20IetfPoly1305

Aes128PmacSiv
Aes256PmacSiv

⚠️使用 Socks5 或 http 代理服务器

使用 socks5 代理的时候,需要将所有直连的域名设置在配置文件里面,如果使用 ss 或者 vmess 之类的,需要将 ss 或 vmess server 的域名也加入配置文件。否则有可能会导致死循环,没法正常使用。

⚠️ http 代理只支持 CONNECT 协议,而且不支持 UDP 协议。

指定 IP 或某网段走代理

在配置文件中增加 IP-CIDR 规则即可。默认情况下 IP 都是是直连,所以只需要添加 PROXYPROBE。如下:

rules:
  - 'IP-CIDR,19.23.212.0/16,PROXY'
  - 'IP-CIDR,19.23.21.0/16,PROBE'

代理局域网内其他机器

  1. 打开 gateway_modegateway_mode 开启后, dns_server 会自动覆盖为 0.0.0.0:53

    gateway_mode: true
  2. 查看本地 IP

    ifconfig
  3. 打开希望走代理的手机或者电脑的网络设置,将 DNS网关 修改为步骤2获取到的 IP

重置 DNS 分配

rm -rf seeker.sqlite

FAQ

  1. If you encountered "seeker" cannot be opened because the developer cannot be verified., you can go to System PreferencesSecurity & PrivacyGeneral and enable any blocked app from Allow apps downloaded from pane at the bottom of the window.

  2. Ubuntu 提示 Address already used, 查看这里 https://unix.stackexchange.com/questions/304050/how-to-avoid-conflicts-between-dnsmasq-and-systemd-resolved

Build (latest stable)

git clone https://github.com/gfreezy/seeker.git
cd seeker
OPENSSL_STATIC=yes cargo build --release

编译完成后,程序在 target/release/seeker

musl 编译

docker run -v $PWD:/volume -e OPENSSL_STATIC=yes --rm -t clux/muslrust cargo build --release

会在 target/x86_64-unknown-linux-musl/release 目录下生成 seeker 文件。

实现原理

seeker 参考了 Surge for Mac 的实现原理,基本如下:

  1. seeker 会在本地启动一个 DNS server,并自动将本机 DNS 修改为 seeker 的 DNS 服务器地址

  2. seeker 会创建一个 TUN 设备,并将 IP 设置为 10.0.0.1,系统路由表设置 10.0.0.0/16 网段都路由到 TUN 设备

  3. 有应用请求 DNS 的时候, seeker 会为这个域名返回 10.0.0.0/16 网段内一个唯一的 IP

  4. seeker 从 TUN 接受到 IP 包后,会在内部组装成 TCP/UDP 数据

  5. seeker 会根据规则和网络连接的 uid 判断走代理还是直连

  6. 如果需要走代理,将 TCP/UDP 数据转发到 SS 服务器/ socks5 代理,从代理接受到数据后,在返回给应用;如果直连,则本地建立直接将数据发送到目标地址

如何发布新版本

With cargo-workspace

cargo ws version

Plain git

git tag v10.0.0
git push origin v10.0.0

Github Action 会自动编译并发布新的 release。

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

通过使用 tun 来实现透明代理。实现了类似 surge 增强模式与网关模式。

License:Apache License 2.0


Languages

Language:Rust 99.9%Language:Shell 0.1%