<?php
if(isset($_GET['url'])){
$url = $_GET['url'];
if(strpos($url, 'http') !== 0 ){ #http가 url에 존재하지 않으면
die('http only !');
}else{ # http가 url에 있다면
$result = shell_exec('curl '. escapeshellcmd($_GET['url']));
#
$cache_file = './cache/'.md5($url);
file_put_contents($cache_file, $result);
echo "<p>cache file: <a href='{$cache_file}'>{$cache_file}</a></p>";
echo '<pre>'. htmlentities($result) .'</pre>';
return;
}
}else{
?>
사용자가 입력한 url에 http라는 문자가 없다면 http only
있다면 result = curl [사용자 입력값] <- 입력 검증 없음
사용자가 입력한 값을 md5로 인코딩하고 ./cache/ 경로에 저장
그리고 curl [사용자 입력값]의 결과를 ./cache/md5(url)에 저장
취약점 분석
url로 사용자 입력을 받을 때 입력을 검증하지 않음. --> curl로 웹셸 업로드 가능
익스플로잇
https://github.com/WhiteWinterWolf/wwwolf-php-webshell
GitHub - WhiteWinterWolf/wwwolf-php-webshell: WhiteWinterWolf's PHP web shell
WhiteWinterWolf's PHP web shell. Contribute to WhiteWinterWolf/wwwolf-php-webshell development by creating an account on GitHub.
github.com
위의 github에 올라온 웹셸을 사용하여 command injection 공격
url에
payload 삽입하면
./cache/ 경로에 webshell이 저장된다.

webshell을 실행하고 /cache/webshell.php에 접속하면 위와 같이 webshell에 접속할 수 있다.
flag : DH{8ca5256a49452e4db9de7691a9c69b7678271383}
'CTF & Wargame(WEB)' 카테고리의 다른 글
| XSS Filtering Bypass Advanced level 3 (0) | 2025.04.18 |
|---|---|
| level 1 XSS Filtering Bypass (1) | 2025.04.17 |
| My Best Friend level 1 (0) | 2025.04.16 |
| session beginner (0) | 2025.04.14 |
| web-misconf-1 beginner (0) | 2025.04.14 |