Study/Hacking
[cce2023jr QUALS CTF] pphhpp
dys4nt
2023. 6. 15. 21:20
문제 소스를 보면
[config.php]
<?php
$flag = file_get_contents("/flag");
function is_safe_url($url) {
// Allow only http(s)
if(!preg_match('/^https?:\/\/.*$/', $url)){
return false;
}
$host = parse_url($url, PHP_URL_HOST);
if(!host) {
return false;
}
$ip = gethostbyname($host);
$ip = ip2long($ip);
if($ip === false){
return false;
}
$is_inner_ipaddress = ip2long('127.0.0.0') >> 24 == $ip >> 24 or
ip2long('10.0.0.0') >> 24 == $ip >> 24 or
ip2long('172.16.0.0') >> 20 == $ip >> 20 or
ip2long('192.168.0.0') >> 16 == $ip >> 16 ;
if($is_inner_ipaddress){
return false;
}
return true;
}
extract($_GET);
?>
index.php에서 config.php를 로드한 후 ?url=http(s):// 형태로 GET 요청을 보내면 is_safe_url을 통해서 내부 IP가 아님을 검증한 후 프록시 역할을 하는 서버임을 알 수 있는데, 0.0.0.0은 필터링이 되어있지 않다.
?url=http://0.0.0.0/flag.php를 입력하면 문제가 풀리게 된다.