目錄
- 可以先學習一下文件上傳相關漏洞文章:
https://www.geekby.site/2021/01/文件上傳漏洞/
https://xz.aliyun.com/t/7365
Nginx解析漏洞
-
題目URL:http://www.whalwl.site:8020/
漏洞成因,參考文章:
https://www.cnblogs.com/HelloCTF/p/14098983.html
https://xz.aliyun.com/t/6801 -
漏洞利用
正常上傳一張圖片馬,服務器給我們返回上傳路徑。上傳成功后訪問圖片,並加上/.php后綴。將.jpg文件解析成php文件。
文件上傳01
- 題目URL:http://www.whalwl.site:8024/
進入后台找個上傳點。
因為只是Javascript限制上傳格式,所以只需先上傳一張正常圖片再使用burp sutie抓包改包即可:
<script type="text/javascript">
function checkFile() {
var file = document.getElementsByName('upfile')[0].value;
if (file == null || file == "") {
alert("你還沒有選擇任何文件,不能上傳!");
return false;
}
//定義允許上傳的文件類型
var allow_ext = ".jpg|.jpeg|.png|.gif|.bmp|";
//提取上傳文件的類型
var ext_name = file.substring(file.lastIndexOf("."));
//alert(ext_name);
//alert(ext_name + "|");
//判斷上傳文件類型是否允許上傳
if (allow_ext.indexOf(ext_name + "|") == -1) {
var errMsg = "該文件不允許上傳,請上傳" + allow_ext + "類型的文件,當前文件類型為:" + ext_name;
alert(errMsg);
return false;
}
}
</script>
- 最后shell地址就是:
http://www.whalwl.site:8024/upload/payload_1.php
文件上傳02
題目URL:http://whalwl.site:8025/
upload.php 源碼
<?php
header("Content-type: text/html;charset=utf-8");
error_reporting(0);
$is_upload = false;
$msg = null;
if(isset($_POST['submit'])){
$ext_arr = array('jpg','png','gif');
$file_ext = substr($_FILES['upload_file']['name'],strrpos($_FILES['upload_file']['name'],".")+1);
if(in_array($file_ext,$ext_arr)){
$temp_file = $_FILES['upload_file']['tmp_name'];
$img_path = $_POST['file_path'].rand(10, 99).date("YmdHis").".".$file_ext;
if(move_uploaded_file($temp_file,$img_path)){
$is_upload = true;
}
else{
$msg = "上傳失敗";
}
}
else{
$msg = "只允許上傳.jpg|.png|.gif類型文件!";
}
}
?>
- 可以看到雖然對文件名做了限制重命名,但文件路徑“file_path”卻未限制並且可控:
我們利用 00 截斷
利用 Burp suite
將images/2.php%00
中%00
選中進行編碼 改成images/2.php[二進制00]
形式
- 最后shell地址:
http://whalwl.site:8025/images/2.php