Protecting Camp
Challenge Description
I made a small site to keep a list of things I need to buy to keep me safe before I go camping, maybe it's keeping some other things safe too!
Attachments
Solution
Going through the code, it looks vulnerable to
SSRF(Server Side Request Forgery)In the
index.jsfile
app.get('/api/flag', (req, res) => {
var url = req.protocol + '://' + req.get('host') + req.originalUrl;
try{
parsed = parseUrl(url)
if (parsed.resource != '127.0.0.1'){
res.send("Hey... what's going on here\n");
}else{
fs.readFile("./flag.txt", 'utf8', (err, data) => {
if (err) {
res.send("There was an error and this is sad :(\n")
}else{
res.send(data+"\n")
}
});
}} catch (error) {
res.status(400).json({ success: false, message: 'Error parsing URL' });
}
});We can see theres a
/api/flagendpoint that reads theflag.txtfileSending a request to
/api/flagwill returnHey... what's going on hereIn the
index.jswe see that the server is looking for request coming from127.0.0.1which is the localhostAdding the
Hostheader with value as127.0.0.1and sending the request to/api/flag, we get the flag
FLAG
flag{d716dd8ab70bbc51a5f1d0182c84bcc8}Last updated