In this post, we demonstrated file upload vulnerability and how to exploit it using a vulnerable app called Mutillidae.

Upload forms are common places where attackers try to upload malicious files that execute system command on the target.

Since we are dealing with a vulnerable app, we don’t expect any kind of upload filters so we used the regular php-reverse-shell.
It can be found here
https://github.com/pentestmonkey/php-reverse-shell

Upload the shell and start a listener on your machine with the below
command:
Nc -lvp 4545
After successfully uploading the shell, we trigger the shell by navigating to its path in the URL

The Vulnerability: What’s the Big Deal?

The problem with an unrestricted file upload is that if a server doesn’t check what kind of files are being uploaded, an attacker can upload a malicious file, like a script or an executable. When that file is accessed, it can run commands on the server, which can lead to all sorts of trouble, from crashing the server to giving the attacker complete control.

A Malicious PHP File

To exploit this vulnerability, I created a simple but powerful PHP file. This file was designed to do two things:

  1. List the contents of the /etc/passwd file: This is a common way to test for command execution and see if you can access sensitive files on a Linux system.
  2. Create a reverse shell: This is the real prize. The script would use Netcat to connect back to my Kali Linux machine on port 1234, giving me a shell on the server.

From Upload to Shell

Here’s how I put my plan into action:

  1. Uploading the File: I went to the “Unrestricted File Upload” section in Mutillidae and uploaded my malicious PHP file.
  2. Setting up a Listener: Before I did anything else, I set up a Netcat listener on my Kali machine. This was crucial because I needed to be ready to catch the incoming connection from the server.
  3. Triggering the Payload: I copied the path to my uploaded PHP file and pasted it into my web browser. This caused the server to execute the script.
  4. Shell on the Server: As soon as the script ran, it connected back to my Netcat listener, and just like that, I had a shell on the target server!

Post-Exploitation: Now What?

With a shell on the server, I was able to run commands as if I were sitting right in front of it. I listed the files in the current directory and, as a final proof of concept, I displayed the contents of the /etc/passwd file. This showed that I had full control over the system and could do whatever I wanted.

This was a great demonstration of how dangerous unrestricted file upload vulnerabilities can be. It’s a reminder that you should always, always validate the files that are uploaded to your servers!

Video Walkthrough

About the Author

Mastermind Study Notes is a group of talented authors and writers who are experienced and well-versed across different fields. The group is led by, Motasem Hamdan, who is a Cybersecurity content creator and YouTuber.

View Articles