• 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 最小权限化

  • 相关阅读:
    Python 实现自动化测试 dubbo 协议接口
    Element Plus中Cascader 级联选择器(选择任意一级选项 - 更改下拉框选中方式)
    Dart笔记:glob 文件系统遍历
    Linux内核作业
    internship:项目频繁出现的lambda表达式及MyBatis-Plus的理解
    Linux内核由哪些组成,这些你了解不
    搜索与图论——Kruskal算法求最小生成树
    湖南省政协副主席赖明勇一行莅临麒麟信安调研
    box-sizing: border-box;box-sizing:content-box;讲解
    effective c++ 41 隐式接口和编译器多态
  • 原文地址:https://blog.csdn.net/weixin_43893278/article/details/126915513