# Insecure file upload

## What is it?

Insecure File Upload vulnerability is when an application allows uncontrolled and unvalidated upload of files. An attacker can exploit this vulnerability to upload malicious files, like web shells, which can lead to code execution, data leakage, or other types of attacks.

**A simple example**

An application allows users to upload profile pictures without validating the file type and content, or without properly handling the file storage. An attacker can upload a PHP shell script disguised as an image file. When this file is served by the server, the malicious script can be executed.

The impact of insecure file uploads includes:&#x20;

* Remote Code Execution (RCE)&#x20;
* Data Leakage&#x20;
* Server Compromise

**Other learning resources:**&#x20;

* OWASP: <https://owasp.org/www-community/vulnerabilities/Unrestricted\\_File\\_Upload&#x20>;
* Swisskyrepo: <https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Upload%20Insecure%20Files>

## Checklist

* [ ] Understand the file upload functionality&#x20;
* [ ] Are there file type restrictions?&#x20;
* [ ] Are there file size restrictions?&#x20;
* [ ] Are files renamed after upload?&#x20;
* [ ] Are files checked for content type matching the extension?&#x20;
* [ ] Test for bypassing file extension filters&#x20;
* [ ] Upload a file with a double extension (e.g., .jpg.php)&#x20;
* [ ] Upload a file with a null byte injection (e.g., .php%00.jpg)&#x20;
* [ ] Test for malicious content within a file&#x20;
* [ ] Upload a file with a simple XSS payload in its content&#x20;
* [ ] Test for inadequate file storage handling&#x20;
* [ ] Are uploaded files accessible from the internet? (Path/URL guessing)&#x20;
* [ ] Can other users access the uploaded files?&#x20;

## Exploitation

```
# Bypass extension filters
# Note: req server misconfig to execute or the ability to rename once it's up
shell.php.jpg

# Null byte injection
shell.php%00.jpg

# Blocklist bypass
shell.php5
shell.phtml
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://appsecexplained.gitbook.io/appsecexplained/common-vulns/insecure-file-upload.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
