php://filter协议在任意文件读取漏洞中的利用(学习总结)

本文介绍了PHP的php://协议,用于访问各种I/O流,并详细阐述了php://filter如何作为元器封装,用于对PHP的IO流进行处理。通过示例展示了如何使用不同的过滤器,如base64编码、解码,字符串转换等,以及在实际问题中如何利用这些过滤器解决文件读取漏洞。最后,提供了一个简单的PHP文件读取漏洞的修复示例,演示了如何通过过滤器获取原本被注释隐藏的信息。
摘要由CSDN通过智能技术生成

一、php://协议 

官网解释为:

        php:// — Accessing various I/O streams

PHP provides a number of miscellaneous I/O streams that allow access to PHP's own input and output streams, the standard input, output and error file descriptors, in-memory and disk-backed temporary file streams, and filters that can manipulate other file resources as they are read from and written to

个人理解为php在访问或打开文件时为建立一个IO流的方式,而php://协议则可以访问这个IO流,

二、php://filter

        php://fiter 中文叫 元器封装,咱也不知道为什么这么翻译,目前我的理解是可以通过这个玩意对上面提到的php IO流进行处理,及现在可以对php的 IO流进行一定操作。

        过滤器:及通过php://filter 对php 的IO流进行的具体操作

              格式为:php://filter / [read|write =] 过滤器 / resource= 目标文件 

        解释:对目标文件的IO流的输出流(read)或输入流(write)进行 过滤器的操作 处理 

       过滤器的分类(及常见过滤器):

        string filter(字符过滤器)
                string.rot13  (对字符串执行 ROT13 转换)
                        例:php://filter/string.rot13/resource=flag.php
                string.toupper (转大写)
                        例:php://filter/string.toupper/resource=flag.php
                string.tolower (转小写)
                string.strip_tags (去除 HTML 和 PHP 标记,尝试返回给定的字符串 str 去除空字符、HTML 和 PHP 标记后的结果)
                        例:php://filter/string.strip_tags/resource=flag.php
        conversion filter (转换过滤器)
                convert.base64-encode & convert.base64-decode (base64加密 base64解密)
                        例:php://filter/convert.base64-encode/resource=flag.php
                convert.quoted-printable-encode & convert.quoted-printable-decode(在字符串后加=0A,及恢复)
        compression filter(压缩过滤)
                zlib.deflate & zlib.inflate(压缩 解压)
                        例:php://filter/zlib.deflate/resource=flag.php                                                       php://filter/zlib.inflate/resource=flag.php
                bzip2.compress & bzip2.decompress(zip 压缩 解压)
        encryption filter(加密过滤器) 

三、练习: 

 简单的demo

#index.php 文件
<?php
    include($_GET[file]);      //一个简单的任意文件读取漏洞
?>


#falg.php 文件
<?php
    echo "hello world";
    # flag{test_filter}
?>

 直接传入flag.php 文件名 (可见读不到flag信息,因为被被 # 注释了 在 web 服务器会过滤掉)

 使用php://filter/read=convert.base64-encode/resource=flag.php (使用base64对flag.php输出流进行编码)

 对信息进行base64解码得到flag信息

  • 5
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值