当前位置:网站首页>File upload vulnerability - upload labs (1~2)
File upload vulnerability - upload labs (1~2)
2022-07-07 12:24:00 【hcjtn】
File upload vulnerability ——upload-labs(1~2)
The user uploaded a pointing script file , And through this script, you get the ability to execute server-side commands
In everyday life , We often upload various files , But if there is no restriction on the upload type or the restriction is not strict , An attacker may upload an executable file or web script ( Cause file upload vulnerability ), Cause the website to be controlled or even fall
Harm caused by file upload vulnerability :
- Make hackers hang black chains on your website
- Hang a malicious Trojan ( Automatically pop up advertisements , Brush Click ) Or mining
- Cause file data leakage
The premise of file upload vulnerability
- The website upload function can be used normally
- File types allow uploading such as :php asp In a word, the Trojan horse can enter the interior
- The upload path can be determined
- Files can be accessed , Can be executed or included
Therefore, we can start from the following three points to prevent loopholes
such as :
According to the second point, we can prohibit users from uploading php asp that will do ,
for instance , If users want to upload avatars , We can only let users upload jpg png gif jpeg The format of ( White list ) Filter at the front , Check the format of user's Avatar
We should try to check in advance , The workload of the back-end can be greatly reduced
Upload vulnerability basic process :
- Whether the pictures can be uploaded normally
- Whether the uploaded content of the picture is infected ( Content substitution )
- Whether the uploaded domain name is the target server ( If not , Judge whether the image server parses php、asp、aspx、jsp、cfm、shtml etc. )
- Whether the uploaded directory supports parsing php、asp、aspx、jsp、pht、phtml etc.
- Judge black and white list verification
With upload-labs-1 For example
To upload pictures , Found upload successful
Upload shell Find out :
Found a white list , So from the front we know , It is very likely that there is a filter at the front end , Let's check :
Find out checkFile() It has the effect of checking and filtering , We delete it and submit Find out :
Then use Chinese ant sword Link Find success
Find success
At the same time, we find that just filtering at the front end is not enough , We can easily delete , So apart from the front end , The backend must also be verified
upload-labs-2(MIME verification )
Let's take a look at its source code first :
$is_upload = false;
$msg = null;
if (isset($_POST['submit'])) {
if (file_exists($UPLOAD_ADDR)) {
if (($_FILES['upload_file']['type'] == 'image/jpeg') || ($_FILES['upload_file']['type'] == 'image/png') || ($_FILES['upload_file']['type'] == 'image/gif')) {
if (move_uploaded_file($_FILES['upload_file']['tmp_name'], $UPLOAD_ADDR . '/' . $_FILES['upload_file']['name'])) {
$img_path = $UPLOAD_ADDR . $_FILES['upload_file']['name'];
$is_upload = true;
}
} else {
$msg = ' Incorrect file type , Please upload again !';
}
} else {
$msg = $UPLOAD_ADDR.' Folder does not exist , Please create... By hand !';
}
}
Find out :
if (($_FILES['upload_file']['type'] == 'image/jpeg') || ($_FILES['upload_file']['type'] == 'image/png') || ($_FILES['upload_file']['type'] == 'image/gif')) {
if (move_uploaded_file($_FILES['upload_file']['tmp_name'], $UPLOAD_ADDR . '/' . $_FILES['upload_file']['name'])) {
$img_path = $UPLOAD_ADDR . $_FILES['upload_file']['name'];
$is_upload = true;
}
} else {
$msg = ' Incorrect file type , Please upload again !';
At this time, we will have questions : How does the browser get the type of file we upload
This is about MIME type ( Multipurpose Internet mail extension type )
MIME(Multipurpose Internet Mail Extensions) Multipurpose Internet mail extension type . Is to set some kind of Extension Of file Use one kind Applications To open the way type , When the extension file is accessed , browser Will automatically use the specified application to open . Mostly used to specify some client-side customized file names , And some ways to open media files .
It's an Internet standard , Extended e-mail standards , To enable it to support :
Not ASCII Character text ; Non text attachments ( Binary system 、 voice 、 Image, etc ); By many parts (multiple parts) The body of the message ; Include non ASCII Character header information (Header information).
Common types :
Upload files | multipart/from-data |
---|---|
Hypertext markup language text . | text/html |
xml file .xml | text/xml |
XHTML file .xhtml | application/xhtml+xml |
jpg Image format | image/jpeg |
RTF Text .rtf | application/rtf |
PDF file .pdf | application/pdf |
Microsoft Word file .word | application/msword |
MIME usage :
Client usage :
- Tell the server , The type of file I uploaded
- Tell the server , The types of documents I can accept
Server use :
- Tell the client , The data type I respond to
So when doing this problem, we should think of a reform Put it content-type Get rid of
So we use burp suite Carry out bag grabbing and package changing
Find will content-type Change it
Change it to image/jpeg;
Click Send ,
Find success
边栏推荐
- Up meta - Web3.0 world innovative meta universe financial agreement
- Solve server returns invalid timezone Go to ‘Advanced’ tab and set ‘serverTimezone’ property manually
- 2022 8th "certification Cup" China University risk management and control ability challenge
- [filter tracking] comparison between EKF and UKF based on MATLAB extended Kalman filter [including Matlab source code 1933]
- SQL injection -- Audit of PHP source code (take SQL lab 1~15 as an example) (super detailed)
- 盘点JS判断空对象的几大方法
- wallys/Qualcomm IPQ8072A networking SBC supports dual 10GbE, WiFi 6
- 《看完就懂系列》天哪!搞懂节流与防抖竟简单如斯~
- Attack and defense world ----- summary of web knowledge points
- SQL blind injection (WEB penetration)
猜你喜欢
Fleet tutorial 15 introduction to GridView Basics (tutorial includes source code)
108. Network security penetration test - [privilege escalation 6] - [windows kernel overflow privilege escalation]
2022 年第八届“认证杯”中国高校风险管理与控制能力挑战赛
How to connect 5V serial port to 3.3V MCU serial port?
Visual studio 2019 (localdb) \mssqllocaldb SQL Server 2014 database version is 852 and cannot be opened. This server supports version 782 and earlier
Sort out the garbage collection of JVM, and don't involve high-quality things such as performance tuning for the time being
Tutorial on principles and applications of database system (010) -- exercises of conceptual model and data model
[filter tracking] comparison between EKF and UKF based on MATLAB extended Kalman filter [including Matlab source code 1933]
Completion report of communication software development and Application
解密GD32 MCU产品家族,开发板该怎么选?
随机推荐
Flet tutorial 17 basic introduction to card components (tutorial includes source code)
Common locking table processing methods in Oracle
"Series after reading" my God! It's so simple to understand throttling and anti shake~
[texture feature extraction] LBP image texture feature extraction based on MATLAB local binary mode [including Matlab source code 1931]
zero-shot, one-shot和few-shot
@What happens if bean and @component are used on the same class?
什么是局域网域名?如何解析?
NGUI-UILabel
全球首堆“玲龙一号”反应堆厂房钢制安全壳上部筒体吊装成功
How to understand the clothing industry chain and supply chain
What is a LAN domain name? How to parse?
Swiftui tutorial how to realize automatic scrolling function in 2 seconds
《通信软件开发与应用》课程结业报告
Fleet tutorial 15 introduction to GridView Basics (tutorial includes source code)
解决 Server returns invalid timezone. Go to ‘Advanced’ tab and set ‘serverTimezone’ property manually
Inverted index of ES underlying principle
[neural network] convolutional neural network CNN [including Matlab source code 1932]
超标量处理器设计 姚永斌 第8章 指令发射 摘录
消息队列消息丢失和消息重复发送的处理策略
<No. 9> 1805. Number of different integers in the string (simple)