一、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(加密过滤器)

三、练习:


> #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信息

请输入图片描述