BSides Canberra 2026 - Web/Museum

To start it off, I gotta say that it’s pretty interesting how I failed to solve an “easier” web challenge but managed to crack this one under 15 minutes when I was having a good time watching the Inside of an Android talk at BSides Canberra 2026. Usually it’s the other way around, but oh well.

Either way, it is still a pretty cool challenge where I guess a lot of players will tunnel vision on using SQLi the wrong way when, in fact, it was intended to produce a Path Traversal.

Source code Analysis

So… here’s the thing: a few pretty interesting spot-ons that immediately attracted my attention when I skimmed over the source code:

  • A very obvious SQL Injection inside index.js.
app.get('/:id', async (req, res) => {
    const id = req.params.id;
    try {
        const stmt = db.prepare(`SELECT * FROM gallery_pieces WHERE id = ${id}`);
        const row = stmt.get();

 ...
  • The flag is stored as an environment variable.
FROM node:26-alpine

WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN node seed.js gallery
ENV FLAG=skbdg{replaceme}
ENV PORT=1337
EXPOSE 1337
CMD ["node", "index.js"]
  • This weird-looking snippet of code seems like a Path Traversal inside index.js.
 ...

        // We don't want to get hacked, so we send the image back as base64 instead.
        const image = await fs.readFile(path.join(__dirname, 'images', row.filename));
        res.render("exhibit", {
            title: row.title,
            description: row.description,
            artist: row.artist,
            medium: row. medium,
            exhibition_period: row.exhibition_period,
            mimetype: mime.lookup(row.filename) || 'application/octet-stream',
            data: image.toString('base64')
        });
 } catch (err) {
        console.error(`Error querying database: ${err.message}`);
        res.status(500).send('Internal Server Error');
 }
});

Exploitation

Now imagine if we can somehow overwrite the row.filename attribute with ../../etc/passwd, we can actually produce a Path Traversal. Good thing that we already have the SQLi to begin with, so we can do this using a UNION-based attack by injecting /:id with something like 1337 UNION SELECT 0,'','','','','','/../../etc/passwd' .

Tried and it worked like a charm…

alt text

The content of /etc/passwd was clearly displayed. But now, how is this gonna lead to the flag? Apparently, if you are comfortable with the Linux filesystem, you will know that all environment variables of the currently running process are stored at /proc/self/environ. This means all we have to do is grab that juicy file.

alt text

Base64-decode that text and boom! Enjoy your flag.

How about another way to solve it?

Still the same idea: abuse the existing SQLi to produce a Path Traversal, but this time instead of leaking /proc/self/environ, go for the Dockerfile inside the /app directory.