File Upload Vulnerabilities

Lab: Remote code execution via web shell upload

This lab contains a vulnerable image upload function. It doesn't perform any validation on the files users upload before storing them on the server's filesystem.

To solve the lab, upload a basic PHP web shell and use it to exfiltrate the contents of the file /home/carlos/secret. Submit this secret using the button provided in the lab banner.

You can log in to your own account using the following credentials: wiener:peter

Solution

First, we will login into the web application using the credentials that was given.

After logging in, we should see this web page.

We can try to upload a webshell directly. The payload that we will be using is this:

After uploading, we can see this message.

We can visit that webpage by right clicking on the broken image file and Open image in new tab.

We should be able to see this

If we type ls and press Execute, it should return us this page.

Since we need to know the content of /home/carlos/secret, we just need to cat that folder to get the content of that folder

Lab: Web shell upload via Content-Type restriction bypass

This lab contains a vulnerable image upload function. It attempts to prevent users from uploading unexpected file types, but relies on checking user-controllable input to verify this.

To solve the lab, upload a basic PHP web shell and use it to exfiltrate the contents of the file /home/carlos/secret. Submit this secret using the button provided in the lab banner.

You can log in to your own account using the following credentials: wiener:peter

Solution

Same as the previous lab, we will login first to see the My Account page.

This time we will upload an image file to see how does it work.

We can see that they use multipart form to upload the image file.

We will try to use upload the webshell that we uploaded in the previous lab.

However, this time they prevented us from uploading it.

So, we can try to upload the payload as .png file but modify the request on Burp Suite before sending to the application as the check might not be done in the backend.

This is the request that we are intercepting:

We will just modify this 1 line to this:

After modifying, we can just release the request to the application. We can see that the file has been uploaded.

Next, we can visit that file just like how we did in the previous lab and execute the same command to get the content of /home/carlos/secret.

Lab: Web shell upload via path traversal

This lab contains a vulnerable image upload function. The server is configured to prevent execution of user-supplied files, but this restriction can be bypassed by exploiting a secondary vulnerability.

To solve the lab, upload a basic PHP web shell and use it to exfiltrate the contents of the file /home/carlos/secret. Submit this secret using the button provided in the lab banner.

You can log in to your own account using the following credentials: wiener:peter

Solution

Same as the previous lab, we will login first to see the My Account page.

We can try to upload the payload from the 1st lab. It turns out we can upload it.

If we try to run any commands, we can see that the command cannot be executed.

There is a possibility that this folder does not allow execution of PHP code. Let see if we can upload the previous file directory.

First we will send the request for uploading the file to Repeater.

Next, we will change this line to this:

Finally, we will send the request and see does it upload successfully.

However, it seems that the application remove any path traversal before using the filename. We can try to URL encode ../ and see if it works

Sure enough, after sending in the request, we can see this in the response.

Finally, we are able to execute the PHP code

From there, we can get the content of /home/carlos/secret.

Lab: Web shell upload via extension blacklist bypass

This lab contains a vulnerable image upload function. Certain file extensions are blacklisted, but this defense can be bypassed due to a fundamental flaw in the configuration of this blacklist.

To solve the lab, upload a basic PHP web shell, then use it to exfiltrate the contents of the file /home/carlos/secret. Submit this secret using the button provided in the lab banner.

You can log in to your own account using the following credentials: wiener:peter

Solution

Same as the previous lab, we will login first to see the My Account page.

This is very similar to .htaccess vulnerability

So if we follow the same step, first we need to upload a .htaccess file with this as the content:

Next, we will try to upload this file first and we are able to do so.

So the next file, we can upload is the same exploit file that we have been using but with .dork extention.

We are also able to upload the .dork file.

After which, we should be able to execute commands on that web page.

From there, we should be able to get the content of /home/carlos/secret.

Lab: Web shell upload via obfuscated file extension

This lab contains a vulnerable image upload function. Certain file extensions are blacklisted, but this defense can be bypassed using a classic obfuscation technique.

To solve the lab, upload a basic PHP web shell, then use it to exfiltrate the contents of the file /home/carlos/secret. Submit this secret using the button provided in the lab banner.

You can log in to your own account using the following credentials: wiener:peter

Solution

Same as the previous lab, we will login first to see the My Account page.

We will first try to upload the same payload as before.

However, we are unable to upload it.

Next, we will send this request to Repeater to play around the request.

If we modify the filename to be this:

We are able to upload the file

From there, we are able to access that website and execute commands.

From there, we are able to get the content of /home/carlos/secret

Lab: Remote code execution via polyglot web shell upload

This lab contains a vulnerable image upload function. Although it checks the contents of the file to verify that it is a genuine image, it is still possible to upload and execute server-side code.

To solve the lab, upload a basic PHP web shell, then use it to exfiltrate the contents of the file /home/carlos/secret. Submit this secret using the button provided in the lab banner.

You can log in to your own account using the following credentials: wiener:peter

Solution

Same as the previous lab, we will login first to see the My Account page.

Next, we will use exiftool to create a polygot web shell.

Finally, we will upload the file that we have just created to the application

We can see that the polygot web shell is uploaded.

We will just visit that web page and capture the request on Burp Suite.

Finally, we just need to search for START and END to find the content of /home/carlos/secret.

Last updated