Vulnerability Guide - 文件上传漏洞

admin 2021年11月19日15:04:53Vulnerability Guide - 文件上传漏洞已关闭评论140 views字数 3056阅读10分11秒阅读模式

0x0a 基础

一、思路:

危害+原因+利用+修复+讲解(例题分析)

二、危害:

利用上传的恶意文件可以对整个网站的服务器进行控制,上传webshell脚本后门

三、常见语言和函数

语言:文件包含漏洞在php web application中居多 而在JSP,ASP,ASP NET程序中都非常少

include():包含并运行指定的文件,包含文件发生错误时,程序警告,但会继续执行。

require():包含并运行指定的文件,包含文件发生错误时,程序直接终止执行。

include_once():和 include 类似,不同处在于 include_once 会检查这个文件是否已经被导入,如果已导入,下文便不会再导入,直面 once 理解就是只导入一次。

require_once():和 require 类似,不同处在于 require_once 只导入一次。

四、常见利用方式

一、黑名单部分

1、特殊解析后缀
2、.htaccess解析
3、大小写绕过
4、点绕过
5、空格绕过
6、::$DATA绕过
7、配合解析漏洞
8、双后缀名绕过

二、白名单部分

1、mime信息绕过
2、%00截断(有条件限制)

原理:00表示结束符 所以会把00后面的所有字符都删除

使用条件:PHP版本小于 5.3.4 PHP的magic+quotes_gpc为OFF状态。长度限制:windows长度 256 linux长度 4000+

%00阶段的另外一种使用途径 :通过burp抓包之后 对%00进行url编码,在进行绕过

3、0x00截断
4、0x0a截断
其他部分:文件头检测。二次渲染。条件竞争。突破getimagesize。突破exif_imagesize

0x0b、利用

5.1 low

漏洞分析: 没有任何过滤 ,可以直接使用图片马进行getshell

```php
<?php

if( isset( $_POST[ 'Upload' ] ) ) {
// Where are we going to be writing to?
//这里没有任何过滤,
$target_path = DVWA_WEB_PAGE_TO_ROOT . "hackable/uploads/";
$target_path .= basename( $_FILES[ 'uploaded' ][ 'name' ] );

// Can we move the file to the upload folder?
if( !move_uploaded_file( $_FILES[ 'uploaded' ][ 'tmp_name' ], $target_path ) ) {
    // No
    $html .= '<pre>Your image was not uploaded.</pre>';
}
else {
    // Yes!
    $html .= "<pre>{$target_path} succesfully uploaded!</pre>";
}

}

?>
```

漏洞利用:

直接上传一个shell.php文件上去,使用蚁剑连接

Vulnerability Guide - 文件上传漏洞

5.2 medium

漏洞分析 :判断了文件类型

```php
<?php

if( isset( $_POST[ 'Upload' ] ) ) {
// Where are we going to be writing to?
$target_path = DVWA_WEB_PAGE_TO_ROOT . "hackable/uploads/";
$target_path .= basename( $_FILES[ 'uploaded' ][ 'name' ] );

// File information
$uploaded_name = $_FILES[ 'uploaded' ][ 'name' ];
$uploaded_type = $_FILES[ 'uploaded' ][ 'type' ];
$uploaded_size = $_FILES[ 'uploaded' ][ 'size' ];

// Is it an image?、
//这里就是判断文件类型是哪个类型,然后看看文件大小
if( ( $uploaded_type == "image/jpeg" || $uploaded_type == "image/png" ) &&
    ( $uploaded_size < 100000 ) ) {

    // Can we move the file to the upload folder?
    if( !move_uploaded_file( $_FILES[ 'uploaded' ][ 'tmp_name' ], $target_path ) ) {
        // No
        $html .= '<pre>Your image was not uploaded.</pre>';
    }
    else {
        // Yes!
        $html .= "<pre>{$target_path} succesfully uploaded!</pre>";
    }
}
else {
    // Invalid file
    $html .= '<pre>Your image was not uploaded. We can only accept JPEG or PNG images.</pre>';
}

}

?>
```

漏洞利用:

Vulnerability Guide - 文件上传漏洞

5.3 high

%00截断(直接使用%00有条件限制 PHP版本小于5.3.4 ,可以对%00进行URL编码) 0x00截断 0x0a截断

图片马制作 copy 1.jpg/a+2.php/b hack.jpg 或者直接使用notepad进行操作

漏洞分析

```php
<?php

if( isset( $_POST[ 'Upload' ] ) ) {
// Where are we going to be writing to?
$target_path = DVWA_WEB_PAGE_TO_ROOT . "hackable/uploads/";
$target_path .= basename( $_FILES[ 'uploaded' ][ 'name' ] );

// File information
$uploaded_name = $_FILES[ 'uploaded' ][ 'name' ];
$uploaded_ext  = substr( $uploaded_name, strrpos( $uploaded_name, '.' ) + 1); //对在文件名后缀后接着加.
$uploaded_size = $_FILES[ 'uploaded' ][ 'size' ];
$uploaded_tmp  = $_FILES[ 'uploaded' ][ 'tmp_name' ];

// Is it an image?
if( ( strtolower( $uploaded_ext ) == "jpg" || strtolower( $uploaded_ext ) == "jpeg" || strtolower( $uploaded_ext ) == "png" ) &&
    ( $uploaded_size < 100000 ) &&
    getimagesize( $uploaded_tmp ) )//getimagesize直接检查文件是不是图片,所以要使用图片马
{

    // Can we move the file to the upload folder?
    if( !move_uploaded_file( $uploaded_tmp, $target_path ) ) {
        // No
        $html .= '<pre>Your image was not uploaded.</pre>';
    }
    else {
        // Yes!
        $html .= "<pre>{$target_path} succesfully uploaded!</pre>";
    }
}
else {
    // Invalid file
    $html .= '<pre>Your image was not uploaded. We can only accept JPEG or PNG images.</pre>';
}

}

?>
```
漏洞利用

1、上传图片马

2、使用文件包含漏洞进行连接 使用 PHP file://伪协议

Vulnerability Guide - 文件上传漏洞

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2021年11月19日15:04:53
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   Vulnerability Guide - 文件上传漏洞https://cn-sec.com/archives/632631.html