当前位置:网站首页>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
边栏推荐
- [neural network] convolutional neural network CNN [including Matlab source code 1932]
- @What happens if bean and @component are used on the same class?
- 如何理解服装产业链及供应链
- Fleet tutorial 19 introduction to verticaldivider separator component Foundation (tutorial includes source code)
- SQL injection -- Audit of PHP source code (take SQL lab 1~15 as an example) (super detailed)
- 从工具升级为解决方案,有赞的新站位指向新价值
- 111. Network security penetration test - [privilege escalation 9] - [windows 2008 R2 kernel overflow privilege escalation]
- 112.网络安全渗透测试—[权限提升篇10]—[Windows 2003 LPK.DDL劫持提权&msf本地提权]
- Visual Studio 2019 (LocalDB)\MSSQLLocalDB SQL Server 2014 数据库版本为852无法打开,此服务器支持782版及更低版本
- Fleet tutorial 15 introduction to GridView Basics (tutorial includes source code)
猜你喜欢
Improve application security through nonce field of play integrity API
Time bomb inside the software: 0-day log4shell is just the tip of the iceberg
[shortest circuit] acwing1128 Messenger: Floyd shortest circuit
消息队列消息丢失和消息重复发送的处理策略
Simple network configuration for equipment management
超标量处理器设计 姚永斌 第8章 指令发射 摘录
[filter tracking] strapdown inertial navigation simulation based on MATLAB [including Matlab source code 1935]
Solutions to cross domain problems
Tutorial on principles and applications of database system (009) -- conceptual model and data model
Camera calibration (2): summary of monocular camera calibration
随机推荐
The hoisting of the upper cylinder of the steel containment of the world's first reactor "linglong-1" reactor building was successful
DOM parsing XML error: content is not allowed in Prolog
What are the technical differences in source code anti disclosure
[full stack plan - programming language C] basic introductory knowledge
108.网络安全渗透测试—[权限提升篇6]—[Windows内核溢出提权]
Solutions to cross domain problems
超标量处理器设计 姚永斌 第10章 指令提交 摘录
盘点JS判断空对象的几大方法
问题:先后键入字符串和字符,结果发生冲突
HCIA复习整理
C#中在路径前加@的作用
[texture feature extraction] LBP image texture feature extraction based on MATLAB local binary mode [including Matlab source code 1931]
What are the top-level domain names? How is it classified?
NGUI-UILabel
Sort out the garbage collection of JVM, and don't involve high-quality things such as performance tuning for the time being
@What happens if bean and @component are used on the same class?
Inverted index of ES underlying principle
@Bean与@Component用在同一个类上,会怎么样?
30. Feed shot named entity recognition with self describing networks reading notes
About web content security policy directive some test cases specified through meta elements