通过 Admin API 移除 Ghost CMS 网站上每篇文章和每个页面中注入的代码。
使用此工具可清理被入侵的 Ghost 站点——例如受代码注入漏洞 CVE-2026-26980 影响的站点——通过从每篇文章和每个页面的 Header 和 Footer 代码注入字段中剥离攻击者提供的 <script> 标签及其他注入标记。
该工具默认安全(先试运行,再应用)且严格限定范围:它只清除这两个每篇文章字段。站点级代码注入(Ghost Admin → Settings → Code injection)、文章内容以及所有其他设置均不会被触及。
requirements.txt):pip install -r requirements.txt
6478abc123def456:8f9e0d1c2b3a4567890abcdef1234567890abcdef1234567890abcdef12345678
在脚本所在的同一目录下创建一个名为 ghost_cleaner_config.json 的文件:
{
"ghost_url": "https://yourdomain.com",
"admin_api_key": "YOUR_KEY_ID:YOUR_KEY_SECRET"
}
如果你跳过此步骤,脚本将在首次运行时为你创建一个示例配置文件并退出——只需填写该文件并重新运行即可。
请始终先运行此命令,以便在改动任何内容之前准确查看将被清除的内容:
python3 ghost_injection_cleaner.py
示例输出:
Ghost Injection Remover
Mode : DRY-RUN (read-only)
Target: https://yourdomain.com
NOTE: /ghost/api/admin/settings/ (site-wide injection) is
never read or written by this script.
============================================================
POSTS
============================================================
47 posts fetched.
✦ 'My First Post'
HEAD: '<script>(function(){var _x="...obfuscated..."</script>'
🔍 DRY-RUN - would be cleared.
============================================================
PAGES
============================================================
6 pages fetched.
============================================================
SUMMARY
============================================================
Would clear : 1 posts/pages
Already clean: 52 posts/pages
Re-run with --apply to commit these changes.
一旦你对 dry-run 的输出感到满意,就可以使用 --apply 运行。系统会提示你进行确认:
python3 ghost_injection_cleaner.py --apply
Type YES to confirm changes to posts and pages: YES
...
✅ Cleared.
python3 ghost_injection_cleaner.py --config /path/to/my_config.json
对于每篇文章和每个页面,它都会将以下两个字段设置为 null:
| 字段 | 在 Ghost 编辑器中的位置 |
|---|---|
codeinjection_head | 文章/页面设置 → 代码注入 → 页头 |
codeinjection_foot | 文章/页面设置 → 代码注入 → 页脚 |
没有注入内容的文章和页面会被静默跳过。
Missing dependencies
运行 pip install -r requirements.txt 后重试。
admin_api_key must be in 'id:secret' format
请确保你的密钥中间有一个冒号。它应该看起来像两个由 : 分隔的十六进制字符串。直接从 Ghost 管理后台复制,不要添加空格。
ERROR: Ghost API returned HTTP 401
你的 Admin API 密钥可能有误,或者该集成可能已被删除。请返回 Ghost 管理后台 → 设置 → 集成进行核实。
ConnectionError 或超时
检查配置中的 ghost_url 是否正确,以及运行脚本的机器能否访问该站点。
脚本在大型站点上卡住 每页 50 篇文章都会生成一个新的 JWT 并等待 API 响应。这是正常现象——请稍等一分钟。