当前位置:网站首页>File operation protection
File operation protection
2022-07-27 19:50:00 【Leisurely summer】
1、 File upload vulnerability
On the Internet , We often use the file upload function , For example, upload a custom image ; Share a video or photo ; An attachment is attached when posting on the Forum ; Attach attachments when sending mail , wait .
The file upload function itself is a normal business requirement , For websites , In many cases, users do need to upload files to the server . therefore “ Upload files ” There's nothing wrong with it , But the problem is that after the file is uploaded , What to do with the server 、 Explanatory documents . If the processing logic of the server is not secure enough , Will lead to serious consequences .
File upload vulnerability means that the user uploads an executable script file , And through this script file to obtain the ability to execute server-side commands . This kind of attack is the most direct and effective , Sometimes there is little technical threshold .
Common security problems caused by file upload are :
- The upload file is Web Scripting language , Server's Web The container interprets and executes the script uploaded by the user , Causes code execution ;
- Upload file is virus 、 Trojan files , Hackers are used to trick users or administrators into downloading and executing ;
- The upload file is a phishing image or an image that contains a script , It will be executed as a script in some versions of browsers , Used for fishing and fraud .
in the majority of cases , File upload vulnerabilities generally refer to “ Upload Web Scripts can be parsed by the server ” The problem of , That is to say web shell The problem of . To complete this attack , To meet the following requirements
Conditions :
First , Uploaded files can be Web Container interpretation execution . So the directory where the file is uploaded is Web Path covered by container .
secondly , Users are able to access from Web Access this file on . If the file is uploaded , But users can't get through Web visit , Or can't make Web The container interprets the script , Then it can't be called a vulnerability .
Last , If the files uploaded by users are checked for security 、 format 、 Image compression and other functions change the content , It can also lead to unsuccessful attacks .
Solution :
- Check the extension white list of uploaded files , Not on the white list , Upload is not allowed .
- The directory of the uploaded file must be http The request cannot directly access . If you need access to , Must upload to other ( and web Different servers ) Under domain name , And set the directory as an executable directory .
- The file name and directory name to be saved are generated by the system according to the time , Do not allow user customization .
- Image upload , To be processed ( thumbnail 、 Watermark, etc ), No exception can be saved to the server .
- Uploading files requires logging .
2、 File download and directory browsing vulnerability
It is caused by the lack of rigor in program design and coding , A good design should be : Users are not allowed to submit any file path for download , Instead, the user clicks the download button to deliver by default ID To the background program .
File download and directory browsing vulnerability :File download and Directory traversal, Arbitrary file download attack and directory traversal attack .
When processing a user request to download a file , Allow users to submit arbitrary file paths , And send the corresponding file on the server directly to the user , This will cause the threat of arbitrary file download . If you ask the user to submit the file directory address , Send the list of files in the directory to the user , Will cause directory traversal security threats .
Malicious users will change directory or file addresses , Download sensitive files on the server 、 Database link profile 、 Website source code, etc .
Code to process user requests :
String path = request.getParameter("path");
OutputStream os = response.getOutputStream();
FileInputStream fis = new FileInputStream(path);
byte[] buff = new byte[1024];
int i = 0;
while((i=fis.read(buff))>0){
os.write(buff,0,i);
}
fis.close();
os.flush();
os.close(); Protection plan :
- The address of the file to be downloaded is saved in the database .
- Save the file path to the database , Let the user submit a file corresponding to ID Download the file .
- Do permission judgment before downloading files .
- Files in web Can't directly access the directory .
- Record the file download log .
- Directory traversal service is not allowed .
Nginx The directory browsing function is not enabled by default , If you find that the function is currently turned on , Can edit nginx.conf file , Delete the following two lines :
autoindex on;
autoindex_exact_size on
And then restart Nginx.
边栏推荐
- Pytorch reports CUDA error: no kernel image is available for execution on the device error
- 【深度学习基础知识 - 41】深度学习快速入门学习资料
- [basic knowledge of deep learning - 39] comparison of BN, LN and WN
- SharePreference(存储)
- ArrayAdapter(数组适配器)与SimpleAdapter(简单适配器)
- HDU1171_ Big event in HDU [01 backpack]
- C language: 12. GDB tool debugging C program
- MarqueeTextview(跑马灯)
- Embedded C language structure
- [Huawei cloud stack] [shelf presence] issue 13: have you seen the decoupling architecture of the management area? Help government and enterprise customers solve big problems
猜你喜欢

influxDB系列(四)TSM引擎(存储原理)

Flink 算子简介

C language: 10. Input stream, output stream, error stream

Embedded C language structure

Low code implementation exploration (45) business parameters

S32k series chips -- Introduction

Binary search tree

Release Samsung 3J1 sensor: the code implies that the safety of pixel 7 face recognition will be greatly increased

Make your chat bubbles colorful

RadioGroup(单选框)
随机推荐
A lock faster than read-write lock. Don't get to know it quickly
IEC104 规约详细解读(一) 协议结构
ContextMenu(上下文菜单)
C language: 10. Input stream, output stream, error stream
jvisualvm的使用
Turn Hyper-V on and off
Pytorch reports CUDA error: no kernel image is available for execution on the device error
Big guys, Oracle CDC, local operation, always encounter this an exception occurred in
C language: 5. Multidimensional array
ReferenceError: __ dirname is not defined in ES module scope
注入攻击
【深度学习基础知识 - 47】贝叶斯网络与朴素贝叶斯
IDEA:解决代码没有提示问题
【深度学习基础知识 - 40】CNN为什么比DNN在图像领域更具优势
[basic knowledge of deep learning - 45] distance calculation methods commonly used in machine learning
BroadcastReceiver(广播)
Map and set
influxDB系列(三)influxDB配置文件详解
[daily accumulation - 07] CUDA multi version switching
[Huawei cloud stack] [shelf presence] issue 13: have you seen the decoupling architecture of the management area? Help government and enterprise customers solve big problems