PHP-CTF-Docker /day2
代码:
<?php $url = $_GET['url']; if(isset($url) && filter_var($url, FILTER_VALIDATE_URL)){ $site_info = parse_url($url); print_r($site_info); if(preg_match('/sec-redclub.com$/',$site_info['host'])){ exec('curl "'.$site_info['host'].'"', $result); echo 'curl "'.$site_info['host'].'"'; echo "<center><h1>You have curl {$site_info['host']} successfully!</h1></center> <center><textarea rows='20' cols='90'>"; echo implode(' ', $result); } else{ die("<center><h1>Error: Host not allowed</h1></center>"); } } else{ echo "<center><h1>Just curl sec-redclub.com!</h1></center><br> <center><h3>For example:?url=http://sec-redclub.com</h3></center>"; } ?>
这里需要对传入的url进行filter_var函数和parse_url函数进行绕过:
思路:需要传入一个经过filter_var函数检验的合法url并且经过parse_url函数的分解,将host拼接在exec函数中的curl命令后面,需要对curl命令进行一个闭合,然后执行我们想要执行的命令。
1、绕过filter_var
替换URL schema http
可以看到http schema是无法使用将双引号放入host中的
当我改变了http schema之后就可以在host当中添加双引号,来闭合curl命令中的双引号
2、命令构造
当我想用cat命令查询时发现无法通过filter_var函数的url检验,应该是host当中不能包含空格,使用cat<f1agi3hEre.php就可以查看到内容了
payload:
?url=0://";cat<f1agi3hEre.php;"sec-redclub.com