文件上傳 安鸞 Writeup



目錄

Nginx解析漏洞

文件上傳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>

image

  • 最后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]形式

image

image

  • 最后shell地址:
    http://whalwl.site:8025/images/2.php

所用的圖片一句話木馬:

點我下載圖片一句話木馬


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM