Skip to content

Disable none cipher for shadowsocks#6303

Open
OfficialKatana wants to merge 13 commits into
XTLS:mainfrom
OfficialKatana:main
Open

Disable none cipher for shadowsocks#6303
OfficialKatana wants to merge 13 commits into
XTLS:mainfrom
OfficialKatana:main

Conversation

@OfficialKatana

Copy link
Copy Markdown
Contributor

Remove "NONE Cipher" which is not widely used.

Forbid insecure outbound settings.
增加了内网地址检测(IsLoopback和IsPrivate应该够了)
Removed duplicated TLS outbound detection on hysteria2 (should always with QUIC)
Add extra detection for Trojan protocol

@bytecategory bytecategory left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

加个标签: 破坏性变更
问题在于即使是CipherType_NONE 也可以再套一层TLS(依旧安全)

@OfficialKatana

OfficialKatana commented Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

加个标签: 破坏性变更 问题在于即使是CipherType_NONE 也可以再套一层TLS(依旧安全)

理论上Shadowsocks不应该出现无加密这种组合
不需要加密的情况下应该使用vless或者别的任何协议结合TLS
虽然确实可以用TLS不过TLS+无加密貌似还不如Socks5结合无加密(同理Socks5也可以套

@bytecategory

Copy link
Copy Markdown
Contributor

加个标签: 破坏性变更 问题在于即使是CipherType_NONE 也可以再套一层TLS(依旧安全)

理论上Shadowsocks不应该出现无加密这种组合 不需要加密的情况下应该使用vless或者别的任何协议结合TLS 虽然确实可以用TLS不过TLS+无加密貌似还不如Socks5结合无加密(同理Socks5也可以套

也就是把以前的换成Socks5了 ... 我先去忙Astrbot事件了

@bytecategory

Copy link
Copy Markdown
Contributor

为什么不删Vmess的 None安全模式

@RPRX

RPRX commented Jun 10, 2026

Copy link
Copy Markdown
Member

毕竟计划是 #5640 (comment) ,似乎的确可以直接把 SS 和 VMess 不加密的模式删掉,只剩 VLESS 和 Trojan 需要配置检查了

@LjhAUMEM 有空给 Hy2 协议加个限制,只能搭配 Hy2 传输层,避免有人搞出公网明文传输的配置

@Fangliding

Copy link
Copy Markdown
Member

俩pr都是一个人合一起不就行了吗

@RPRX

RPRX commented Jun 10, 2026

Copy link
Copy Markdown
Member

这个 PR base 更新一些,@OfficialKatana 可以把 #5640 的内容并入这个 PR

Private IP 段的话 Freedom 那里有,可以移到 common 那里

至于判断我想了一下,确实应该仅认可 VLESS Encryption 和 TLS/REALITY,毕竟 Finalmask 那些东西被认为不够可靠

这下正好防止有人配出明文 VLESS+mKCP+XDNS,得加个 Encryption 才行

@RPRX

RPRX commented Jun 10, 2026

Copy link
Copy Markdown
Member

此外还有个 dialerProxy 感觉不太好处理

@LjhAUMEM

Copy link
Copy Markdown
Collaborator

@LjhAUMEM 有空给 Hy2 协议加个限制,只能搭配 Hy2 传输层,避免有人搞出公网明文传输的配置

#6287 之后 in out 的 init 可以拿到 streamSettings,可以在里面判断

@RPRX

RPRX commented Jun 10, 2026

Copy link
Copy Markdown
Member

VMess 的 none 和 zero 直接删了吧都没人用,然后 VMess 不用判断了,Hy2 也是,@LjhAUMEM 直接在 #6287 限制一下吧

Private IP 段改为 Freedom 那里的,内网段允许用,注意留着 "localhost",应该不会有人 hosts 把它改到公网吧,那得炸多少

@RPRX

RPRX commented Jun 10, 2026

Copy link
Copy Markdown
Member

@OfficialKatana 以及修一下 test 和 fmt

@LjhAUMEM

LjhAUMEM commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

Hy2 也是,@LjhAUMEM 直接在 #6287 限制一下吧

done,这下手写 proto 的也无法绕过了

RPRX pushed a commit that referenced this pull request Jun 16, 2026
@RPRX

RPRX commented Jun 16, 2026

Copy link
Copy Markdown
Member

看了下代码,private IP 段貌似和 @Meo597 写的不太一样?

Comment thread common/geodata/ip_matcher.go Outdated
if ip4 == nil && ip16 == nil {
return false
}
private := ip.IsPrivate() || ip.IsLoopback() || ip.IsMulticast() || ip.IsLinkLocalUnicast()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IsPrivate() IsLoopback() ... 内部实现会多次 To4() To16()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以手写,不过为了简洁和美观目前还是保持这个实现,测试下来是纳秒级别的差距,后续维护起来也方便

Comment thread common/geodata/ip_matcher.go Outdated
return subs[0], nil
default:
return &HeuristicMultiIPMatcher{matchers: subs}, nil
return &GeneralMultiIPMatcher{matchers: subs}, nil

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

只要用户的规则含有 geoip:private 启发式优化就被扬掉了

而且直觉上 PrebuildPrivateIPMatcher 不会比 go4.org/netipx 的二分查找更快
为啥不考虑用 geodata.ParseIPRules 手写那些 CIDR 呢?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个确实可以改

@Meo597

Meo597 commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

不应该造 PrivateIPMatcher 这破坏了原本的设计
各种 Matcher 都应支持所有 CIDR,只是查找方法的不同,而非内容的不同

应该用 ParseIPRule 直接 new Matcher 实例

RPRX pushed a commit that referenced this pull request Jun 17, 2026
@RPRX RPRX force-pushed the main branch 2 times, most recently from 4af24e9 to 829d54d Compare June 17, 2026 12:20
@RPRX

RPRX commented Jun 17, 2026

Copy link
Copy Markdown
Member

@OfficialKatana 你俩讨论下

Maolaohei pushed a commit to Maolaohei/Bray-Core that referenced this pull request Jun 17, 2026
@Meo597

Meo597 commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

IPMatcher 部分改成一行 geodata.IPReg.BuildIPMatcher(geodata.ParseIPRules(...)) 就完事了

m, err := buildOptimizedIPMatcher(r.ipsetFactory, rules)
expanded := make([]*IPRule, 0, len(rules))
for _, rule := range rules {
if geoip, ok := rule.Value.(*IPRule_Geoip); ok && isPrivateGeoIPCode(geoip.Geoip.Code) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ext:xxx.dat:private 被破坏,社区修改 private 全部无效

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个是为了避免通过修改private段来绕过限制,故意的

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

此外应该禁止使用自定义的private ip段(即使配置了也强制使用内置的内网段),第一是防止绕过限制,第二是固定private ip段防止被dat内部的规则篡改预期行为。

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要这样做破坏了抽象,而且是负收益,后面都是维护债

篡改方面不用担心
你的 isInternalOrInvalidAddress 不会被 geoip.dat:private 影响

新开个 common/geodata/consts.go 然后 PRIVATE_xxxx = must2(geodata.IPReg.BuildIPMatcher(must2(geodata.ParseIPRules(...)))) 就行了


// NewPrivateIPMatcher returns an IPMatcher prebuilt with all IANA
// private/special-use IP ranges. It does not require geoip.dat.
func NewPrivateIPMatcher() IPMatcher {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议开个新的文件,这里对外基本不可见

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以

}
}

func TestNewPrivateIPMatcher(t *testing.T) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个测试没有意义,重复了

expanded := make([]*IPRule, 0, len(rules))
for _, rule := range rules {
if geoip, ok := rule.Value.(*IPRule_Geoip); ok && isPrivateGeoIPCode(geoip.Geoip.Code) {
for _, cidrStr := range PrivateCIDRStrings {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IPRegistry 只负责宏观调控

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants