File upload vulnerabilities

circle-exclamation

Understanding File Upload Vulnerabilities

What are File Upload Vulnerabilities?

File upload vulnerabilities occur when web applications allow users to upload files without proper validation, filtering, or security controls. These vulnerabilities can lead to remote code execution, malware distribution, denial of service, and other security compromises.

Vulnerable Code Example

// PHP vulnerable file upload
$uploadDir = '/var/www/html/uploads/';
$uploadFile = $uploadDir . basename($_FILES['file']['name']);

if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadFile)) {
    echo "File uploaded successfully: " . $uploadFile;
} else {
    echo "Upload failed";
}

Normal Upload:

  • File: document.pdf

  • Result: /var/www/html/uploads/document.pdf

Malicious Upload:

  • File: shell.php

  • Content: <?php system($_GET['cmd']); ?>

  • Result: /var/www/html/uploads/shell.php (executable web shell)

How File Upload Vulnerabilities Work

File upload vulnerabilities exploit insufficient validation and security controls in file upload functionality. Attackers can upload malicious files that are then executed by the server, accessed by other users, or used to compromise the application and underlying system.

Common Attack Vectors

Remote Code Execution:

  • Uploading executable scripts (PHP, ASP, JSP)

  • Server-side template injection via uploaded templates

  • Binary executable uploads

Client-Side Attacks:

  • Cross-site scripting via HTML/SVG files

  • Malware distribution through file downloads

  • Social engineering via malicious documents

Denial of Service:

  • Large file uploads consuming disk space

  • ZIP bombs and archive exploits

  • Resource exhaustion attacks

Impact and Consequences

  • Remote Code Execution - Complete server compromise

  • Data Breach - Access to sensitive information

  • Malware Distribution - Hosting malicious files

  • Defacement - Uploading malicious content

  • Denial of Service - Resource exhaustion

  • Privilege Escalation - Gaining higher system access

Common Upload Mechanisms

HTML Form Uploads

Basic File Upload Form:

Multiple File Uploads:

AJAX File Uploads

JavaScript File Upload:

XMLHttpRequest Upload:

API-Based Uploads

REST API Upload:


Basic File Upload Attacks

Executable File Upload

Web Shell Upload

PHP Web Shells:

ASP Web Shells:

JSP Web Shells:

Binary Executable Upload

Compiled Malware:

Script Interpreters:

File Extension Bypass

Extension Blacklist Bypass

Alternative Extensions:

Double Extensions:

Null Byte Injection:

MIME Type Bypass

Content-Type Manipulation:

Magic Byte Prepending:

Archive-Based Attacks

ZIP File Exploits

Zip Slip Attack:

ZIP Bomb:

Archive with Executables:

TAR/GZIP Exploits

TAR Path Traversal:

Symbolic Link Attack:


Advanced File Upload Attacks

Image File Exploitation

Polyglot Files

PHP-JPEG Polyglot:

SVG with Embedded JavaScript:

GIF with PHP Code:

EXIF Data Exploitation

EXIF PHP Injection:

EXIF XSS Payload:

Document Format Attacks

Office Document Macros

Excel Macro Upload:

Word Macro Upload:

PDF Exploits

PDF with JavaScript:

PDF Form Exploitation:

Server-Side Template Injection

Template File Upload

Jinja2 Template Injection:

Freemarker Template Injection:

Twig Template Injection:


Language and Framework Specific Attacks

PHP Upload Attacks

PHP Configuration Bypass

Upload via .htaccess:

PHP.ini Upload:

Web.config for PHP on IIS:

PHP Stream Wrappers

Data URI Upload:

PHP Filter Upload:

Java/JSP Upload Attacks

JSP Shell Upload

Advanced JSP Shell:

WAR File Upload

Malicious WAR Archive:

ASP.NET Upload Attacks

ASPX Shell Upload

Advanced ASPX Shell:

Web.config Upload

Malicious Web.config:

Python Upload Attacks

Python Script Upload

Python Reverse Shell:

Flask Template Upload

Malicious Flask Template:

Node.js Upload Attacks

JavaScript Payload Upload

Node.js Backdoor:


Client-Side Attack Vectors

Cross-Site Scripting via File Upload

HTML File XSS

Malicious HTML Upload:

SVG XSS Upload

SVG with Advanced XSS:

Content Sniffing Attacks

MIME Type Confusion

Fake Image with Script:

Polyglot GIFAR:

Last updated

Was this helpful?