Repository navigation
Lua: Sandbox by default (whitelisted functions); Disable inline scripts for now; Add more checks for security reasons - #7136
Conversation
|
env 未来可能是会包含在“下发订阅”里的,所以不能直接把 lua 的那些敏感操作禁掉吗?比如访问文件和连接网络 |
|
能,但总感觉被和谐了不太爽 |
|
现在仅本地脚本允许特权模式 还发现了一个上游的内存和安全问题 |
|
理论上一个恶意的lua甚至因为可以访问xray内置dns可以通过dns tunnel获得网络然后挖矿啥的 任意代码执行权限还是太危险了 要么就改成使用lua(特权)功能需要 start 的时候加一个 lua-(privileged) 的 flag |
|
主要还是靠下游,核心做啥都没用,意思到了就行 核心本身是安全的,威胁来自于订阅和链接分享 |
|
那俩敏感权限无条件砍掉吧, |
|
我觉得特权模式没必要进一步限制 xray 的 lua 不像游戏里的插件只需要最小沙盒,连 debug string.dump print load 都不给 而且就连 os.exec 也有潜在的实际用途,比如运行时操纵 iptables、节点不通 curl 我觉得应该让沙盒模式最小白名单,安全到可以随便被下发订阅,分享链接 目前本地文件型的没什么攻击面了 目前的特权模式风险点在 env 上 可以让 再进一步就是改为启动参数(用起来麻烦点) |
|
或者特权模式 psk 改为公私钥签名脚本 |
|
|
|
所以 geodata 只允许下载已经存在的文件,并且目录给限定死了,还抠了半天防逃逸检查 内联脚本的安全性我倒不是特别担心,全锁在最小沙盒里,白名单定好 倒是目前特权模式设计的 psk 只能防小白复制一份网络大神脚本 |
|
|
基本一秒就没了因为下载后必定立刻重载 |
|
geodata 那边没有暴露 reload download 那些 api |
|
还好是 pure go 没有溢出再导致 rce 问题 |
|
|
如果按照之前那样文件模式默认特权,或者说能下发完整 json,这个攻击就成功了 密钥放在启动参数就没办法了 |
|
沙盒模式现在限制了哪些东西? |
|
沙盒模式限制: |
|
即使这样,我觉得内联 lua 还是有点危险,要不先暂时禁止了吧,且加载本地 lua 也必须需要签名 |
|
能用的库和函数都是白名单了 沙盒模式也签名的话有点过度防御了 |
|
然后 go 那边的反射函数也有白名单 |
|
@RPRX 目前这个 PR 已经是你想要的状态了 NEXT 架构和可编程协议若要继续推进,必须在合理的威胁模型下设计安全架构 签名、特权模式、内联脚本这些,后续功能演进的时候再说吧 目前我已经燃尽了 |
|
Astra 6: @Meo597 Rechecked the latest commit, The earlier findings should be updated as follows.
Validation on
The first DNS test run lacked The main previous findings are now closed or withdrawn. The actionable follow-up is the regular-file stdin regression, plus the retained |
|
pool 的问题需要放到另一个 PR 处理 |
|
后缀检测本意就是尽力而为,因为判定 stdin 有没有本地路径非常容易,顺手就做了 不行,有本地路径不意味着一定是本地文件来源 |
|
|
|
Incorrect suggestion |
Well, if you say so )) So we don’t forget. |
|
准备合并,你记得修改一下 PR 描述 @Meo597 |
…ts for now; Add more checks for security reasons (#7136) #7136 (comment) #7136 (comment) #7136 (comment)
|
描述改好了你看看,手打小作文 |
|
@RPRX 权限的问题我想了一下,可以按能力申请,像手机那样摄像头、相册、网络等分开,最后统一签名 具体的实现是,用户不能用命令加参数显式授权,必须是脚本的注解 declare 权限 内联脚本永远不可能申请权限,这样自定义协议、自定义 Finalmask 有基础能力可以下发订阅 |
|
What if providers supplied JSON describing behavior according to a predefined set of rules, rather than a ready-made Lua file? A dedicated handler could validate the structure and allowed operations, discard unsupported fields or reject invalid documents, and then generate a Lua script for Xray using trusted templates. The provider would supply only permitted parameters and rules, with no embedded Lua code; the executable code would be generated on the client side. Some functionality would be restricted, but this could provide a way to support Lua policies from subscriptions now. |
|
The expectation is a programmable protocol, where JSON subscriptions will directly deliver Lua scripts—stripped of sensitive permissions—to customize traffic appearances, or even protocols, and perhaps even configure routing and DNS rules. |
|
I suggest separating the two: providers get JSON with allowed parameters and rules; users get full Lua scripting. Both approaches can be implemented at the same time without interfering with each other. Giving providers too much control seems excessive to me: they could go overboard with DNS, routing, and other settings. For users, we could also put together a separate library of example scripts on GitHub. |
|
Yes, that was indeed current design, which is why I refused to delete the signature mechanism and chose to comment it out instead. |
|
@Meo597 Thanks for the clarification! If you need help with testing through Codex, feel free to reach out here. |
|
I'm testing how to select the best path for each new connection in my fork. The first scenario uses one node: I query different DNS resolvers for the destination domain, then test access to the resource through that node using each returned IP address. The second scenario uses multiple nodes: I repeat this for each node with different DNS resolvers, then choose which path to use for a new connection. The preference can be faster or more stable access. The main challenge is actually applying that choice: the DNS cache can return a previous IP even after a different option has been selected. Changing the DNS resolver or node alone is not enough—the new connection must actually use the selected path. Have you considered supporting this scenario through Lua? |
Thanks, I will reach out if needed.
为了能选择最快 ip 我认为应该使用 happyeyeballs 我会进一步修改 Lua 让 splice[] 可以编辑,比如加个 spliceObj:ToTable() |
原则是零信任策略以预期 Lua 脚本可以被安全的分享、订阅下发随意使用
因此沙箱的实现是白名单提供有限的函数和库,并进一步防止随机数种子和内存布局探测以被更高级的攻击手段利用
经得起历史和人民的检验再开启为防下游校验不严且全盘接收订阅下发,core 本地配置文件和 Lua 脚本穿透后的路径必须是合法扩展名否则拒绝启动
这同样是出于安全审慎,因为沙箱本就足够安全,且下游订阅实现从不是整个 json/yaml... 而是自行拼装
威胁模型是下游接收同一来源的
geodatadnsrouterfinalmask块的订阅,攻击者可依赖特定时序导致 Lua 脚本被下发后启动现 core 的 geodata 下载器会写入头
\x12\x01\x00杜绝此风险,因为它是非法 Lua 字节如果下游自己下载 geodata 且来源和订阅都是攻击者,那么还有 core 的扩展名防护和沙箱机制
这同样是出于安全审慎的预防性措施,因为沙箱足够安全,且此潜在攻击路径对攻击者(你的机场)要求过于苛刻
slice只读防止 race