Phantomsocks

维基教科书,自由的教学读本
跳到导航 跳到搜索
PhantomSocks
原作者 macronut
初始版本 2019年12月5日,​3年前​(2019-12-05
源代码库 github.com/macronut/phantomsocks
编程语言 Go
操作系统 Linux、macOS、Microsoft Windows
许可协议 LGPL-3.0

Phantomsocks是由macronut开发的自由及开放源代码软件,可以使用它修改TCP包实现desync以绕过防火长城的检测,支持Windows、Linux、macOS操作系统。

如何编译[编辑]

下载好phantomsocks的源代码之后,请在其目录运行 go build -tags 修改包所用API

“修改包所用API”可以为pcap, windivertrawsocket。Windows推荐使用windivert,Linux/Android推荐使用rawsocket,macOS仅pcap可用。

配置文件1[编辑]

phantomsocks 有两个配置文件,一个是 config.json,该文件必须置于 phantomsocks 可执行文件同一目录下,一个是在 config.json 指明的配置文件(我们称之为 default.conf)。

以下是 config.json 的示例。

{
  "profiles": [
          "/Users/v/config/phantomsocks/default.conf"
  ],
  "services": [
  {
   "name": "socks",
   "protocol": "socks",
   "address": "127.0.0.1:1681"
  }
  ],
  "interfaces": [
  {
   "name": "default",
   "device": "en0",
   "dns": "tcp://208.67.220.220:5353",
   "hint": "w-seq,https,w-md5"
  },
  {
   "name": "v6",
   "device": "en0",
   "dns": "tcp://208.67.220.220:443",
   "hint": "ipv6,w-seq,w-md5"
  },
  {
   "name": "df",
   "device": "en0",
   "dns": "tcp://208.67.220.220:443",
   "hint": "df"
  },
  {
   "name":"http",
   "device": "en0",
   "dns": "tcp://208.67.220.220:5353",
   "hint": "http,ttl",
   "ttl": 15
  }
   ]
}

其中第一段的 profiles 下是另一个所需的配置文件,该配置文件设定了对于各域名应该使用什么修改方式。你可以使用相对路径(如果该文件就在当前目录下)填写"default.conf"或者绝对路径(像示例中写的那样)。

第二段的 services 是phantomsocks向本机提供的代理接口,一般为 socks ,这样你就可以在浏览器或者系统代理中填入该地址以将流量转发给 phantomsocks。

第三段的 interface 设定了一些策略组,如defaultv6dfhttp,每个策略组下的 hint 是修改包的方式。如我们看到第一个 default 修改包的方式为 w-seq,https,w-md5interface中的device是本地网络设备的名字,在macOS下一般为 en0,在使用windivert的Windows无需设置,在Linux上一般为eth0

如何查找网络设备的名字[编辑]

macOS/FreeBSD: 打开命令行运行 ifconfig 会列出所有网络设备名字。

Linux: cat /proc/net/dev 会列出所有网络设备名字。

配置文件2[编辑]

另一个配置文件 default.conf 的示例如下。

[default]
google.com=108.177.111.90,108.177.126.90,108.177.127.90,108.177.97.100,142.250.1.90,142.250.112.90,142.250.13.90,142.250.142.90,142.250.145.90,142.250.148.90,142.250.149.90,142.250.152.90,142.250.153.90,142.250.158.90,142.250.176.64,142.250.176.95,142.250.178.160,142.250.178.186,142.250.180.167,142.250.193.216,142.250.27.90,142.251.0.90,142.251.1.90,142.251.111.90,142.251.112.90,142.251.117.90,142.251.12.90,142.251.120.90,142.251.160.90,142.251.161.90,142.251.162.90,142.251.166.90,142.251.167.90,142.251.169.90,142.251.170.90,142.251.18.90,172.217.218.90,172.253.117.90,172.253.63.90,192.178.49.10,192.178.49.174,192.178.49.178,192.178.49.213,192.178.49.24,192.178.50.32,192.178.50.43,192.178.50.64,192.178.50.85,216.239.32.40,64.233.189.191,74.125.137.90,74.125.196.113
ajax.googleapis.com=[google.com]
.google.com=[google.com]
.google.com.hk=[google.com]
.googleusercontent.com=[google.com]
.ytimg.com=[google.com]
.youtube.com=[google.com]
youtube.com=[google.com]
.youtube-nocookie.com=[google.com]
youtu.be=[google.com]
.ggpht.com=[google.com]
.gstatic.com=[google.com]
.translate.goog=[google.com]
blogspot.com=[google.com]
.blogspot.com=[google.com]
blogger.com=[google.com]
.blogger.com=[google.com]
fonts.googleapis.com=120.253.250.225
.googleapis.com=[google.com]
.googleusercontent.com=[google.com]

[df]
.mega.nz
.mega.co.nz
.mega.io
mega.nz
mega.co.nz
mega.io

[v6]
.googlevideo.com

[http]
ocsp.int-x3.letsencrypt.org
captive.apple.com
neverssl.com
www.msftconnecttest.com

在各个 [名称] 下面的域名将使用 “名称” 的interfacehint(修改方式)。除此之外,没有列入default.conf的域名将使用default的修改方式。

Windows特定问题[编辑]

如果你在Windows上使用WinDivert API,你需要在phantomsocks.exe相同目录下放置 WinDivert.dllWinDivert64.sys ,您可以到仓库中WinDivert64.sys的位置WinDivert的发布页面获取。

修改方式[编辑]

修改方式是填在 config.jsoninterface 下的 hint 部分,部分可填入的修改方式有:

  • ipv6: 只使用 ipv6 连接
  • ipv4: 只使用 ipv4 连接
  • https: 强制使用 HTTPS 连接
  • http: 强制使用 HTTP 连接
  • h3: HTTPS记录中添加h3并允许使用HTTP/3
  • s-seg: TCP连接的首包小于8字节
  • w-md5: 发出的TCP包带有错误的md5值
  • w-ack: 发出的TCP包带有错误的确认码
  • w-csum: 发出的TCP包带有错误的校验和
  • w-time: 发出的TCP包带有错误的时间戳
  • w-seq: 发出的TCP包带有错误的序号
  • tfo: 建立连接时使用TFO(TCP Fast Open)发送首包数据(仅windivert和pcap可用)
  • mode2: 以另一种顺序注入TCP包
  • df: 发出的 TCP 包不会分段。(Don’t Fragment)
  • sat: 持续注入TCP包直到TLS握手完成
  • ttl: 发出的TCP包将使用下一段ttl中注明的TTL(Time To Live)
  • mss: 建立连接时修改MSS(Maximum segment size)

更多的修改方式请查询源码中pcap.goraw.gowindivert.go文件。

关于修改方式的评论[编辑]

在过去很长一段时间里(2019-2022),防火长城都未能彻底封锁某种修改方式,但在最近(2022年11月)笔者观察到s-seg、w-md5、w-ack、w-time方法修改TCP包容易被重置,具体表现为打开某网页时出现“连接被重置”错误,刷新几次可能会遇到1-3次重置,之后一切正常,可以连接。而ttl方式看起来是最稳定的,笔者使用此方式没有遇到重置。

FAQ[编辑]

Q: 日志里一直显示 connection not exist 。

A: 一般是编译没加tags或者device不对。

Q: 显示 operation not permitted 。

A: 没权限,请使用 sudo 运行。

Q: Windows上面打开就立即退出

A: config.json 里 config 指定的目录有误或者目录下没放 WinDivert.dll。

Q: Windows上面显示 Cannot find the file specified

A: 目录下没放 WinDivert64.sys。

参见[编辑]