小伙伴们大家好!本期为大家带来的文件上传漏洞之后端黑名单绕过。
目录
前言
由于前端的验证,被攻击者修改一下审查元素中的HTML代码就能轻松绕过,所以,开发人员又想了一个方法就是在后端进行黑名单绕过。例如,php开发的网站中如果后端检测到上传的文件的后缀是php,就不允许用户上传。
绕过原理
有些apache服务器是允许解析其他文件后缀的,如果在httpd.conf中配置了一下代码,则能够解析php与phtml文件。
AddType application/x-httpd-php .php .phtml
这样如果后端服务器仅仅只是对php做了黑名单处理,我们就可以上传一个后缀名为phtml的webshell,达到跟php webshell一样的效果。
实战演示
啥都不说,直接上实战演示!
源码:
3.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>后端绕过黑名单</title>
</head>
<body>
<center>
<form action="file03.php" method="post" enctype="multipart/form-data">
<label for="file">请上传png格式图片:</label>
<input type="file" name="file" id="file"/><br/>
<input type="submit" name="submit" value="上传" />
</form>
</center>
</body>
</html>
file03.php
<?php
header('Content-type:text/html;charset=utf-8');
if ($_FILES["file"]["error"] > 0) {
echo "Return Code:".$_FILES["file"]["error"]."<br/>";
} else {
$info = pathinfo($_FILES['file']['name']);
$ext = $info['extension'];
if (strtolower($ext) == "php"){
exit("不允许的后缀名");
}
echo "<center><br/>";
echo "upload: ".$_FILES["file"]["name"]."<br/>";
echo "type: ".$_FILES["file"]["type"]."<br/>";
echo "size: ".($_FILES["file"]["size"] / 1024)."KB<br/>";
echo "Temp file: ".$_FILES["file"]["tmp_name"]."<br/>";
if (file_exists("upload/".$_FILES["file"]["name"])) {
echo $_FILES["file"]["name"]." already exists. ";
} else {
move_uploaded_file($_FILES["file"]["tmp_name"],"upload/".$_FILES["file"]["name"]);
echo "Stored in: "."upload/".$_FILES["file"]["name"];
}
echo "</center>";
}
1、测试网站功能
首先我们还是先来测试一下网站的功能是否正常。
先来上传一个图片试一下。
经过测试,网站确实可以上传文件。
2、尝试上传webshell
我们上传一个2.php文件。
上传失败,说明我们的php文件不能被上传,回显显示为“不允许的后缀名”。可能后端对文件名的后缀做了白名单处理导致后端不接受php类型的文件。
这样的话,我们就可以尝试上传一个phtml的类型的文件(前提是httpd-conf文件配置了AddType application/x-httpd-php .php .phtml) ,如果httpd-conf没有配置的话可以尝试搭配.user.ini文件来进行上传,这个知识点后面会讲。
抓包修改文件名或者上传之前把文件名改为phtml都行的。
上传成功!
3、使用连接工具连接webshell
我们讲存储的路径记录下来,然后放在连接工具了就可以尝试连接我们上传的webshell了。
我这里使用的是中国蚁剑。
测试成功!
成功拿下!!!
总结
绕过后端的黑名单其实主要起作用的就是httpd-conf文件中的“AddType application/x-httpd-php .php .phtml”这个配置,这句话的配置就是把.phtml文件当作.php文件来解析,这样我们才顺利的修改后缀名为.phtml的文件来绕过黑名单。