
Apache HTTP Server 소스 코드 노출(CVE-2024-40725) 스캐너; 직접 경로와 하위 요청(subrequest) 경로를 검사하고, 영향을 받는 버전을 식별하며, CI/CD용 JSON 보고서를 출력합니다.
CVE-2024-40725용 Python 기반 탐지 도구로, 2.4.0 및 2.4.61 버전에 영향을 미치는 Apache HTTP Server 소스 코드 노출 취약점입니다.
법적 고지: 이 스캐너는 본인이 소유하거나 명시적인 서면 테스트 승인을 받은 서버에서만 실행하십시오. 무단 사용은 컴퓨터 사기 관련 법률(예: CFAA, Computer Misuse Act)을 위반할 수 있습니다.
CVE-2024-40725은 버전 2.4.0에 도입된 Apache 내부 요청 파이프라인의 회귀(regression)입니다(CVE-2024-39884에 대한 불완전한 수정). 서버가 레거시 AddType 지시문(예: AddType application/x-httpd-php .php)을 사용하여 구성된 경우, 하위 요청(subrequest) 처리 중(DirectoryIndex, mod_rewrite 또는 mod_dir에 의해 트리거됨) Apache의 내부 핸들러 할당이 조용히 제거됩니다.
그 결과 PHP 스크립트 인터프리터는 호출되지 않습니다. 대신 Apache의 내장 default-handler가 디스크에서 파일을 열어 데이터베이스 자격 증명, API 키, 애플리케이션 로직을 포함한 원시 바이트를 클라이언트에게 직접 스트리밍합니다.
영향받는 버전: Apache httpd 2.4.0 – 2.4.61
수정된 버전: Apache httpd 2.4.62+
requests 라이브러리pip install requests
# Clone or download the scanner
curl -O https://your-host/cve_2024_40725_scanner.py
# Make executable (optional)
chmod +x cve_2024_40725_scanner.py
python3 cve_2024_40725_scanner.py --target <URL> [OPTIONS]
| 플래그 | 유형 | 기본값 | 설명 |
|---|---|---|---|
--target | URL | (필수) | 테스트할 Apache 서버의 기본 URL |
--paths | PATH [PATH ...] | 내장 목록 | 직접 프로브할 하나 이상의 PHP 경로 |
--wordlist | FILE | — | 워드리스트 파일 경로(줄당 하나의 경로) |
--no-directory-check | 플래그 | 꺼짐 | 하위 요청/디렉터리 인덱스 프로브(프로브 B) 건너뛰기 |
--timeout | int(초) | 10 | 요청별 제한 시간 |
--delay | float(초) | 0.0 | 요청 간 지연(속도 제한) |
--no-verify-ssl | 플래그 | 꺼짐 | SSL 인증서 검증 비활성화 |
--output | FILE | — | 전체 JSON 보고서를 이 파일에 작성 |
--verbose | 플래그 | 꺼짐 | 디버그 출력 활성화 |
# Quickstart: scan localhost with built-in default paths
python3 cve_2024_40725_scanner.py --target http://localhost
# Scan specific paths
python3 cve_2024_40725_scanner.py \
--target http://192.168.1.10 \
--paths /index.php /admin/config.php /wp-config.php
# Use a wordlist file
python3 cve_2024_40725_scanner.py \
--target http://192.168.1.10 \
--wordlist php_paths.txt
# Combine wordlist + extra inline paths (merged, deduplicated)
python3 cve_2024_40725_scanner.py \
--target http://192.168.1.10 \
--wordlist php_paths.txt \
--paths /extra/secret.php
# HTTPS with self-signed certificate
python3 cve_2024_40725_scanner.py \
--target https://myserver.local \
--no-verify-ssl
# Polite scan with 1 second delay and JSON report
python3 cve_2024_40725_scanner.py \
--target http://myserver.local \
--wordlist php_paths.txt \
--delay 1.0 \
--output results.json \
--verbose
# CI/CD usage (exit code 1 = vulnerable, 0 = clean)
python3 cve_2024_40725_scanner.py --target http://localhost || echo "VULNERABLE"
줄당 하나의 경로입니다. #로 시작하는 줄은 주석으로 처리되어 건너뜁니다. 빈 줄은 무시됩니다. 선행 슬래시는 자동으로 정규화됩니다.
# Common PHP entrypoints
/index.php
/info.php
/phpinfo.php
# Admin panels
/admin/index.php
/admin/config.php
# CMS files
/wp-config.php
/wp-login.php
/configuration.php
# API internals
/api/v1/status.php
스캐너는 경로당 두 가지 프로브를 실행합니다:
GET /index.php HTTP/1.1
PHP 파일을 직접 요청했을 때 원시 소스 코드가 반환되는지 확인합니다. AddType이 직접 요청에서도 손상된 잘못 구성된 서버에서 영향을 받습니다.
GET / HTTP/1.1
파일 자체 대신 상위 디렉터리를 요청합니다. Apache는 내부적으로 DirectoryIndex → index.php를 해석하여 하위 요청을 생성합니다. 이것은 Apache 2.4.0–2.4.61에서 r->handler가 NULL로 떨어지는 정확한 코드 경로입니다.
프로브 B가 더 중요하고 현실적인 테스트입니다. 많은 서버가 직접 파일 경로가 아닌 하위 요청 경로를 통해서만 취약합니다.
스캐너는 응답 본문에서 PHP 소스 코드 시그니처를 확인합니다:
<?php<?PHP<?=일치 항목이 발견되면 전체 응답 본문을 출력하는 대신 분류를 위해 유출 위치 주변의 150자 스니펫을 추출합니다.
Server: 응답 헤더를 읽어 Apache 버전을 감지합니다. 유출이 확인되기 전에도 버전 2.4.0 또는 2.4.61을 보고하는 서버에 플래그를 표시합니다.
참고: 강화된 서버는
Server:헤더를 숨길 수 있습니다(ServerTokens Prod). 스캐너는 그와 관계없이 모든 프로브를 계속 실행합니다.
============================================================
CVE-2024-40725 -- Apache Source Code Disclosure Scanner
============================================================
Target : http://localhost
Paths : 6
Time : 2024-08-01T12:00:00
[*] Fingerprinting server: http://localhost
Server Header : Apache/2.4.61 (Debian)
Apache Version: 2.4.61
[!] Version is in vulnerable range (2.4.0 - 2.4.61)
[*] Testing 6 path(s)...
--- /index.php
Direct (HTTP 200): OK
Subreq (HTTP 200): LEAKED
[!] VULNERABLE via: subrequest (directory index)
Leaked snippet: '<?php\n$db_pass = "supersecretpassword";'
--- /info.php
Direct (HTTP 404): OK
Subreq (HTTP 404): OK
[+] Safe
============================================================
SCAN SUMMARY
============================================================
Target : http://localhost
Apache Version : 2.4.61
Paths Tested : 6
Vulnerable Paths : 1
Safe Paths : 5
[!] RESULT: VULNERABLE
Vulnerable paths:
* /index.php (trigger: subrequest (directory index))
Remediation:
1. Upgrade to Apache httpd >= 2.4.62
2. Replace 'AddType' with 'SetHandler' in <FilesMatch> blocks
============================================================
--output results.json){
"target": "http://localhost",
"scan_time": "2024-08-01T12:00:00",
"apache_version": "2.4.61",
"apache_in_range": true,
"paths_tested": 6,
"vulnerable_paths": [
{
"path": "/index.php",
"direct_url": "http://localhost/index.php",
"directory_url": "http://localhost/",
"direct_status": 200,
"direct_leaked": false,
"direct_snippet": null,
"directory_status": 200,
"directory_leaked": true,
"directory_snippet": "<?php\n$db_pass = \"supersecretpassword\";",
"server_header": "Apache/2.4.61 (Debian)",
"vulnerable": true,
"trigger": "subrequest (directory index)"
}
],
"safe_paths": [...]
}
| 코드 | 의미 |
|---|---|
0 | 취약한 경로가 감지되지 않음 |
1 | 취약한 경로가 하나 이상 발견됨 |
종료 코드 덕분에 이 스캐너는 CI/CD 파이프라인 및 자동화된 인프라 감사에 적합합니다.
# Debian / Ubuntu
sudo apt update && sudo apt install apache2
# RHEL / CentOS / AlmaLinux
sudo dnf update httpd
# Verify version (must be >= 2.4.62)
apache2 -v
AddType을 SetHandler로 교체PHP 실행에 사용되는 모든 AddType 지시문을 교체하십시오:
# ❌ Vulnerable Configs
AddType application/x-httpd-php .php
# ✅ Safe Configs
<FilesMatch "\.php$">
SetHandler "proxy:unix:/run/php/php8.2-fpm.sock|fcgi://localhost"
</FilesMatch>
# VULNERABLE
<VirtualHost *:80>
DocumentRoot /var/www/html
AddType application/x-httpd-php .php # ← triggers CVE
DirectoryIndex index.php
</VirtualHost>
# SAFE
<VirtualHost *:80>
DocumentRoot /var/www/html
<FilesMatch "\.php$">
SetHandler "proxy:unix:/run/php/php8.2-fpm.sock|fcgi://localhost"
</FilesMatch>
DirectoryIndex index.php
</VirtualHost>
| CVE | 버전 | 설명 |
|---|---|---|
| CVE-2024-39884 | 2.4.0 | 최초 소스 노출 회귀(regression) |
| CVE-2024-40725 | 2.4.61 | 불완전한 수정 — 동일한 유형의 버그 |
| CVE-2024-40898 | 2.4.61 | mod_rewrite의 별도 SSRF(Windows 전용) |