ikow/wp2shell

GitHub: ikow/wp2shell

针对 WordPress Core 认证前 RCE 漏洞链(CVE-2026-63030 + CVE-2026-60137)的漏洞利用工具包,集成检测、利用与修复方案。

Stars: 5 | Forks: 2

# wp2shell — WordPress Core 认证前 RCE **CVE-2026-63030** (Batch Route Confusion, CVSS 7.5) + **CVE-2026-60137** (SQL 注入, CVSS 9.1) WordPress Core 中的一个认证前远程代码执行链,无需插件,无需特殊配置,且在默认安装下即可生效。 ## 受影响版本 | 版本范围 | 影响 | 修复版本 | |---------------|--------|----------| | WordPress 7.0.0 – 7.0.1 | 完全 RCE | 7.0.2 | | WordPress 6.9.0 – 6.9.4 | 完全 RCE | 6.9.5 | | WordPress 6.8.0 – 6.8.5 | 仅限 SQL 注入 | 6.8.6 | **前提条件:** 无持久化对象缓存 (Redis/Memcached)。这是绝大多数 WordPress 安装的默认配置。 ## 漏洞概述 该漏洞利用链由两个漏洞组成: 1. **REST API Batch Route Confusion** — 批量子请求中的畸形路径会导致 `wp_parse_url()` 返回 false,从而生成一个 `WP_Error`,使得 `$matches[]` 和 `$requests[]` 数组发生失步(desynchronize)。后续的请求会被分发给错误的处理程序,从而绕过身份验证。 2. **WP_Query 中的 SQL 注入** — 当 `author__not_in` 作为字符串(而非数组)传递时,会跳过 `absint()` 的数据净化,导致原始值被直接插入到 SQL WHERE 子句中。 结合 WordPress 的 oEmbed 缓存系统(写入原语)、Customizer changeset 自动发布(权限提升)以及 REST API 重入(特权分发),这可以实现未认证的代码执行。 ## 仓库结构 ``` wp2shell/ ├── README.md ← This file │ ├── wp2shell-exploit/ ← Exploitation tools │ ├── exploit.py # Full pre-auth RCE (no password cracking) │ ├── exploit_hash.py # Hash extraction + authenticated RCE │ ├── detect.py # Non-destructive vulnerability scanner │ └── README.md │ ├── wp2shell-patch/ ← Remediation │ ├── patch.sh # Source code patch (mirrors official fix) │ ├── wp2shell-shield.php # Drop-in mu-plugin (30-second deploy) │ ├── block-batch.conf # Nginx mitigation │ ├── block-batch.htaccess # Apache mitigation │ └── README.md │ ├── docker-compose.yml # Vulnerable test environment (WP 7.0.1) └── Dockerfile.debug # XDebug-enabled image for research ``` ## 快速开始 ### 检测(安全,非破坏性) ``` cd wp2shell-exploit # 单个目标 python3 detect.py https://target.example # 通过 SQL injection 时间确认 python3 detect.py https://target.example --confirm-sqli # 从文件批量扫描 python3 detect.py targets.txt -q ``` ### 漏洞利用 ``` # 完整 pre-auth RCE(推荐 — 无需破解密码) python3 exploit.py https://target.example -c "id" # 仅通过 blind SQLi 提取数据 python3 exploit.py https://target.example "SELECT user_login FROM wp_users LIMIT 1" # 备选方案:提取 hash + 破解 + auth RCE python3 exploit_hash.py https://target.example # 破解完成后: python3 exploit_hash.py https://target.example --user admin --pass cracked_pw -c "id" ``` ### 修复方案 ``` cd wp2shell-patch # 选项 1:Drop-in plugin(最快,无需重启) cp wp2shell-shield.php /path/to/wordpress/wp-content/mu-plugins/ # 选项 2:Web server 拦截 # Nginx:在 server block 中包含 block-batch.conf # Apache:将 block-batch.htaccess 前置于 .htaccess # 选项 3:Source patch(彻底修复) sudo bash patch.sh /path/to/wordpress # 最佳选项:直接更新 WordPress wp core update # or Dashboard → Updates ``` ## 漏洞利用链 ``` ┌─────────────────────────────┐ │ Anonymous HTTP Request │ │ POST /?rest_route=/batch/v1 │ └──────────────┬──────────────┘ │ ┌──────────────▼──────────────┐ │ Batch Desync (outer) │ │ Malformed path → WP_Error │ │ $matches[] array shifts │ └──────────────┬──────────────┘ │ ┌──────────────▼──────────────┐ │ Steal /batch/v1 handler │ │ (no permission_callback!) │ │ → nested batch executes │ └──────────────┬──────────────┘ │ ┌──────────────▼──────────────┐ │ Batch Desync (inner) │ │ GET methods now allowed │ │ author_exclude unsanitized │ └──────────────┬──────────────┘ │ ┌────────────────────┼────────────────────┐ │ │ │ ┌──────────▼──────────┐ ┌──────▼──────┐ ┌──────────▼──────────┐ │ Phase 1: oEmbed │ │ Phase 2: │ │ Phase 3: Escalation │ │ UNION SELECT fake │ │ Blind SQLi │ │ Cache poison + │ │ post with [embed] │ │ extract IDs │ │ Changeset publish │ │ → WP creates cache │ │ + admin ID │ │ → wp_set_current_ │ │ posts (write prim.) │ │ │ │ user(admin) │ └─────────────────────┘ └─────────────┘ └──────────┬──────────┘ │ ┌──────────────▼──────────────┐ │ Re-entrancy │ │ parse_request triggers │ │ serve_request() re-entry │ │ → now running as admin! │ └──────────────┬──────────────┘ │ ┌──────────────▼──────────────┐ │ POST /wp/v2/users │ │ Creates new administrator │ │ → Login → Plugin → Shell │ └─────────────────────────────┘ ``` ## 补丁分析 WordPress 6.9.5 / 7.0.2 应用了三个修复程序,每个修复程序都打破了利用链中的一个环节: | 修复内容 | 文件 | 效果 | |-----|------|--------| | 数组对齐 | `class-wp-rest-server.php` | 针对WP_Error条目执行 `$matches[] = $single_request` — 防止失步 | | 重入防护 | `class-wp-rest-server.php` + `rest-api.php` | `if ($this->is_dispatching()) return false` — 防止嵌套 `serve_request` | | SQL 净化 | `class-wp-query.php` | 始终应用 `wp_parse_id_list()` — 防止注入 | WordPress 7.0.2 额外移除了协作功能(深度防御)。 ## 测试环境 ``` # 启动存在漏洞的 WordPress 7.0.1 docker compose up -d # 等待 MySQL 初始化,然后安装 curl -s "http://localhost:8888/wp-admin/install.php?step=2" \ --data-urlencode "weblog_title=Test" \ --data-urlencode "user_name=admin" \ --data-urlencode "admin_password=TestPassword123" \ --data-urlencode "admin_password2=TestPassword123" \ --data-urlencode "admin_email=admin@test.local" \ --data-urlencode "blog_public=0" \ --data-urlencode "Submit=Install WordPress" # Exploit python3 wp2shell-exploit/exploit.py http://localhost:8888 -c "id" # 清理 docker compose down ``` ## 参考文献 - [Searchlight Cyber 安全公告](https://slcyber.io/research-center/wp2shell-pre-authentication-rce-in-wordpress-core/) - [Hadrian 技术博客](https://hadrian.io/blog/wp2shell-a-pre-authentication-rce-in-wordpress-cores-rest-batch-api) - [WordPress 7.0.2 发布公告](https://wordpress.org/news/2026/07/wordpress-7-0-2-release/) - [CVE-2026-63030 (GHSA)](https://github.com/WordPress/wordpress-develop/security/advisories/GHSA-ff9f-jf42-662q) - [CVE-2026-60137 (GHSA)](https://github.com/WordPress/wordpress-develop/security/advisories/GHSA-fpp7-x2x2-2mjf) ## 免责声明 本仓库仅用于授权的安全研究、渗透测试和教育目的。请仅在您拥有或获得明确书面测试许可的系统上使用。
标签:CISA项目, Python, WordPress, 应用安全, 无后门, 漏洞修复, 编程工具, 网络安全培训, 请求拦截, 远程代码执行, 逆向工具