$ cat writeup.md…
$ cat writeup.md…
HackTheBox
A Node.js note-taking application with Express, Mongoose 7.2.4, and MongoDB. The flag endpoint only responds to requests from localhost (127.0.0.1).
$ cat /etc/rate-limit
Rate limit reached (20 reads/hour per IP). Showing preview only — full content returns at the next hour roll-over.
We built this note-taking app to be so simple, there can't possibly be any bugs. We even added a door to claim the flag. However, only those who knock from inside may enter!
A Node.js note-taking application with Express, Mongoose 7.2.4, and MongoDB. The flag endpoint only responds to requests from localhost (127.0.0.1).
The application provides three main endpoints:
POST /create - Create a new notePOST /update - Update an existing noteGET /flag - Returns flag only if request comes from localhostapp.get('/flag', (req, res) => { const remoteAddress = req.connection.remoteAddress; if (remoteAddress === '127.0.0.1' || remoteAddress === '::1' || remoteAddress === '::ffff:127.0.0.1') { res.send(process.env.FLAG ?? 'HTB{f4k3_fl4g_f0r_t3st1ng}'); } else { res.status(403).json({ Message: 'Access denied' }); } });
The flag is protected by an IP check - only localhost can access it. The hint "knock from inside" suggests we need to make the server think our request comes from localhost.
app.post('/update', async (req, res) => { const { noteId } = req.body; await Note.findByIdAndUpdate(noteId, req.body); // req.body passed directly! let result = await Note.find({ _id: noteId }); res.json(result); });
Critical vulnerability: The entire req.body is passed directly to findByIdAndUpdate(), allowing MongoDB operators like $rename to be injected.
Mongoose version 7.2.4 is vulnerable to Prototype Pollution via the $rename operator. When using $rename with a path like __proto__.something, Mongoose's init() function will create nested objects and pollute Object.prototype.
Key insight: MongoDB's $rename operator creates nested objects, not dotted field names. So:
$rename: {"title": "__proto__._peername.address"}
Creates:
{__proto__: {_peername: {address: "127.0.0.1"}}}
...
$ grep --similar