BUUCTF WEB [SUCTF 2019]CheckIn
打开页面是一个上传界面:
而且题目提示给了源码!GitHub上面,看了看还有flag嘞~~
这不重要,我是来看源码的!!!index.php源码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Upload Labs</title>
</head>
<body>
<h2>Upload Labs</h2>
<form action="index.php" method="post" enctype="multipart/form-data">
<label for="file">文件名:</label>
<input type="file" name="fileUpload" id="file"><br>
<input type="submit" name="upload" value="提交">
</form>
</body>
</html>
<?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!");
}
$upload_file_path = $userdir . "/" . $name;
move_uploaded_file($tmp_name, $upload_file_path);
echo "Your dir " . $userdir. ' <br>';
echo 'Your files : <br>';
var_dump(scandir($userdir));
}
分析一下,可以看见后缀名的检测,内容检测,类型检测:
内容还是可以绕过的!!类型检测也可以绕过,,,,
后缀检测怎么办,,,后面可以上传图片马,但是图片不能解析啊!!
先构造一个图片马:
改名为1.gif上传成功!
路径也是知道的!尝试了一下apache解析漏洞,发现不行,,,,
应该是让我们上传图片,然后解析成PHP代码执行,可是.htacess被过滤了,,
后面知道了还有个配置文件同样也有.htacess的功能,那就是.user.ini文件
在.user.ini中可以识别PHP_INI_PERDIR和PHP_INI_USER模式的INI设置,我们可以看一下选项列表
php.ini 配置选项列表
auto_append_file、auto_prepend_file两个配置自动包含文件,,,区别好像就是文件前后包含
进行构造上传:
GIF89a
auto_prepend_file=1.gif
没错,上传成功
而且看代码我们也知道,自动生成了一个内容为空的index.php文件,不过由于.user.ini的存在
index.php会自动包含1.gif文件,访问index.php可以看见:
没毛病,直接使用蚁剑连接:
得到flag: