Skip to content

Shadowsocks — mihomo

mihomo 双端支持 Shadowsocks,并自带丰富的插件生态:可把线路格式包进 obfs、WebSocket(v2ray-plugin / gost-plugin)、Shadow-TLS、 REALTLS 或 KCP。插件配置以 plugin-opts 这一类型化 YAML 映射形式 提供。

出站

proxies:type: ss 条目。内嵌 BasicOption

字段类型默认值允许值描述
namestring(required)<string>唯一的代理名。
serverstring(required)<host>上游服务器主机名或 IP。
portint(required)<port>上游服务器端口。
passwordstring(required)<string> | <base64 key>服务端密码(AEAD)或 EIH 密钥(SS-2022)。
cipherstring(required)aes-128-gcm | aes-256-gcm | chacha20-ietf-poly1305 | xchacha20-ietf-poly1305 | 2022-blake3-aes-128-gcm | 2022-blake3-aes-256-gcm | 2022-blake3-chacha20-poly1305 | nonemihomo 中 Shadowsocks 加密 / 密钥派生算法的字段名。
udpboolfalsetrue | false允许 UDP 包经此出站转发。
pluginstring(unset)obfs | v2ray-plugin | gost-plugin | shadow-tls | restls | kcptun用于包装流的混淆 / 传输插件。每种插件有自己的 `plugin-opts` schema(下方分节说明)。
plugin-optsmap[string]any{}<plugin-specific YAML map>插件专属配置。schema 取决于 `plugin` —— 见下方子节。
udp-over-tcpboolfalsetrue | false把 UDP 包包装在 TCP 流中。
udp-over-tcp-versionint21 | 2UoT 帧版本。
client-fingerprintstring(global)chrome | firefox | safari | ios | edge | random | randomized当插件启用 TLS 时使用的 uTLS ClientHello 指纹。

源码: adapter/outbound/shadowsocks.go:41-54 · 锚定版本 v1.19.27 (5184081)

plugin-opts —— plugin: obfs

把流包进 simple-obfs(TLS 形态或 HTTP 形态)。

字段类型默认值允许值描述
modestringtlstls | httpobfs 模式。`tls` 模拟 TLS ClientHello;`http` 模拟普通 HTTP 请求。
hoststring(unset)<host>obfs 载荷中使用的伪装主机名。

源码: adapter/outbound/shadowsocks.go:56-59 · 锚定版本 v1.19.27 (5184081)

plugin-opts —— plugin: v2ray-plugin

把流包进 WebSocket 握手。可选 TLS。

字段类型默认值允许值描述
modestring(required)websocket目前仅支持 `websocket`。
hoststring(unset)<host>WS 握手发送的 Host 头。
pathstring//<path>WebSocket 路径。
tlsboolfalsetrue | false用 TLS 包裹 WS 握手。
ech-optsECHOptions
fingerprintstring(unset)<SHA256 hex>锚定服务端 TLS 证书指纹。
certificatestring(unset)<PEM file path>客户端证书(mTLS)。
private-keystring(unset)<key file path>与 `certificate` 配对的私钥。
headersmap[string]string{}{<header>: <value>}upgrade 请求附加的 HTTP 头。
skip-cert-verifyboolfalsetrue | false禁用 TLS 校验。
muxboolfalsetrue | false在 WS 流上启用 smux。
v2ray-http-upgradeboolfalsetrue | false用 V2Ray HTTP-upgrade 替代标准 WebSocket。
v2ray-http-upgrade-fast-openboolfalsetrue | false在 HTTP-upgrade 请求中捎带载荷。

源码: adapter/outbound/shadowsocks.go:61-75 · 锚定版本 v1.19.27 (5184081)

plugin-opts —— plugin: shadow-tls

在 Shadowsocks 流之前加一层 Shadow-TLS 握手。

字段类型默认值允许值描述
passwordstring(unset)<string>Shadow-TLS v2/v3 密码。
hoststring(required)<host>TLS 握手的伪装主机名。
fingerprintstring(unset)<SHA256 hex>锚定伪装服务器的 TLS 证书。
certificatestring(unset)<PEM file path>客户端证书。
private-keystring(unset)<key file path>私钥。
skip-cert-verifyboolfalsetrue | false禁用证书校验(仅供测试)。
versionint31 | 2 | 3Shadow-TLS 协议版本。v3 为当前生产版本。
alpn[]string[]h2 | http/1.1伪装 TLS 握手时宣告的 ALPN 列表。

源码: adapter/outbound/shadowsocks.go:91-100 · 锚定版本 v1.19.27 (5184081)

其他插件变体(gost-pluginrestlskcptun)在 plugin-opts 下 各有自己的 schema。它们的结构体(gostObfsOptionrestlsOptionkcpTunOption)位于同一源文件;完整字段列表见提取出的数据。

入站

listeners:type: ss 条目。内嵌 BaseOption

字段类型默认值允许值描述
passwordstring(required)<string> | <base64 key>服务端密码或 SS-2022 密钥。
cipherstring(required)<cipher>加密算法集合同出站。
udpboolfalsetrue | false接受 UDP 包。
mux-optionMuxOption(disabled)MuxOptionsing 风格的多路复用。
shadow-tlsShadowTLS(disabled)ShadowTLS可选的入站 Shadow-TLS 包装。
kcp-tunKcpTun(disabled)KcpTun可选的入站 KCP 传输。
simple-obfsSimpleObfs(disabled)SimpleObfssimple-obfs(obfs-local)设置:`{ enable, mode }`,其中 `mode` 为 `http` 或 `tls`。

源码: listener/inbound/shadowsocks.go:12-21 · 锚定版本 v1.19.27 (5184081)

simple-obfs

监听器内置的 simple-obfs 包装 —— 无需外部插件二进制。

字段类型默认值允许值描述
enableboolfalsetrue | false在监听器上启用 simple-obfs。
modestringtlshttp | tlsobfs 模式。`tls` 模拟 TLS ClientHello;`http` 模拟普通 HTTP 请求。

源码: listener/inbound/shadowsocks.go:23-26 · 锚定版本 v1.19.27 (5184081)

示例

普通 SS 出站:

yaml
proxies:
  - name: ss-aead
    type: ss
    server: example.com
    port: 8388
    password: <password>
    cipher: aes-256-gcm
    udp: true

启用 UDP-over-TCP 的 SS-2022 出站:

yaml
proxies:
  - name: ss22
    type: ss
    server: example.com
    port: 8388
    password: <base64 16-byte key>
    cipher: 2022-blake3-aes-128-gcm
    udp-over-tcp: true
    udp-over-tcp-version: 2

走 v2ray-plugin(WebSocket + TLS)的 SS:

yaml
proxies:
  - name: ss-v2ray
    type: ss
    server: example.com
    port: 443
    password: <password>
    cipher: aes-256-gcm
    udp: true
    plugin: v2ray-plugin
    plugin-opts:
      mode: websocket
      tls: true
      host: example.com
      path: /ss

在 Shadow-TLS v3 前的 SS:

yaml
proxies:
  - name: ss-stls
    type: ss
    server: example.com
    port: 443
    password: <ss password>
    cipher: aes-256-gcm
    plugin: shadow-tls
    plugin-opts:
      password: <stls password>
      host: www.cloudflare.com
      version: 3

listeners 下的入站:

yaml
listeners:
  - name: ss-in
    type: ss
    listen: 0.0.0.0
    port: 8388
    password: <password>
    cipher: aes-256-gcm
    udp: true

说明

  • mihomo 出站把 plugin-opts 解码到一个按插件命名的结构体上。 这些结构体上的字段使用 obfs: 而非 proxy: 标签 —— 这是 mihomo 内部约定,不直接面向用户,例如 adapter/outbound/shadowsocks.go:56-59simpleObfsOption
  • plugin: obfs 是 mihomo 中 simple-obfs 的名字;TLS 形态用 mode: tls,HTTP 形态用 mode: http
  • mihomo 监听器入站目前不支持 users[] 多用户 —— 同一端口上的多 SS-2022 用户请按用户各定义一个监听器。

跨内核说明

  • Xray 使用 method(而非 cipher)以及 uot / uotVersion。 它没有插件系统 —— 在另一个 streamSettings 传输中包装 Shadowsocks 载荷。参见 Shadowsocks — Xray-core
  • sing-box 使用 method,对 SS-2022 支持 destinations[] 中继 形态,UoT 以对象形式表示 udp_over_tcp: {enabled, version},并 通过 plugin / plugin_opts 接受外部插件二进制。参见 Shadowsocks — sing-box

源码: adapter/outbound/shadowsocks.go:41-100 · v1.19.27 (5184081)

由 Argsment 出品的 Core Tutorial