• File Inclusion 全级别


    File Inclusion 全级别

    在此之前需要打开php响应配置

    在这里插入图片描述

    low级别

    先查看一下代码:

    
    // The page we wish to display
    $file = $_GET[ 'page' ];
    ?> 
    

    没有做任何的安全检查
    page参数输入’/etc/passwd’,可以获取到网站目录在C:\phpstudy_pro\WWW\dvwa\vulnerabilities\fi\下
    在这里插入图片描述
    也可以输入phpinfo
    在这里插入图片描述

    当服务器的php配置中,选项allow_url_fopen与allow_url_include为开启状态时,服务器会允许包含远程服务器上的文件,如果对文件来源没有检查的话,就容易导致任意远程代码执行。

    在这里插入图片描述
    可以通过fputs函数进行木马写入,写一个webshell.txt的文件

    fputs(fopen("shell.php","w"),'')?> 
    

    通过菜刀进行连接
    在这里插入图片描述


    medium级别
    
    
    // The page we wish to display
    $file = $_GET[ 'page' ];
    
    // Input validation
    $file = str_replace( array( "http://", "https://" ), "", $file );
    $file = str_replace( array( "../", "..\"" ), "", $file );
    
    ?> 
    

    可以看到,str_replace函数对特殊字符进行了替换,但是可以通过双写或者大小写绕过
    在这里插入图片描述
    在这里插入图片描述
    str_replace()函数对 …/ …\进行了替换,不能通过相对路径来获取相关信息,但是可以通过绝对路径获取。


    high级别
    
    
    // The page we wish to display
    $file = $_GET[ 'page' ];
    
    // Input validation
    if( !fnmatch( "file*", $file ) && $file != "include.php" ) {
        // This isn't the page we want!
        echo "ERROR: File not found!";
        exit;
    }
    
    ?> 
    

    fnmatch() 函数根据指定的模式来匹配文件名或字符串。
    可以通过file协议绕过
    在这里插入图片描述


    impossible级别
    
    
    // The page we wish to display
    $file = $_GET[ 'page' ];
    
    // Only allow include.php or file{1..3}.php
    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;
    }
    
    ?> 
    

    简单粗暴的白名单保护法


    文件包含漏洞的防护:
    1、使用 str_replace 等方法过滤掉危险字符;
    2、配置 open_basedir,防止目录遍历(open_basedir 将 php 所能打开的文件限制在指定的目录 树中);
    3、php 版本升级,防止%00 截断;
    4、对上传的文件进行重命名,防止被读取;
    5、对于动态包含的文件可以设置一个白名单,不读取非白名单的文件;
    6、做好管理员权限划分,做好文件的权限管理,allow_url_include 和 allow_url_fopen 最小权限化

  • 相关阅读:
    通过Patch-Base来优化VSR中的时间冗余
    STM学习记录(四)———中断及NVIC
    使用eclipce ,将java项目打包成jar包
    续:关于JS中代理Proxy的一些知识
    CentOS如何查找java安装路径
    Maven第三章:IDEA集成与常见问题
    基于HAL库的stm32中定时器的使用--定时器中断每隔一秒进行led灯的闪烁以及定时器生成PWM
    微信小程序--微信开发者工具使用小技巧(3)
    Java中的继承——详解
    python pandas提取正无穷inf与负无穷-inf所在数据行/列
  • 原文地址:https://blog.csdn.net/weixin_43893278/article/details/126915513