Lost Pyramid
Challenge
A massive sandstorm revealed this pyramid that has been lost (J)ust over 3300 years.. Iโm interested in (W)here the (T)reasure could be?
โ cpan57
Directorystatic/
- *.webp
Directorytemplates/
- anubis_chamber.html
- hallway.html
- kings_lair.html
- osiris_hall.html
- pyramid.html
- scarab_room.html
- Dockerfile
- app.py
- private_key.pem
- public_key.pub
- requirements.txt
Solution
The /scarab_room route is vulnrable to SSTI via the name
parameter. However,
it does it processed before the SSTI. Only alphanumeric characters and โ{โ and
โ}โ are allowed.
The exact characters that are allowed are:
We can leak two out of the three variables we need, but PRIVATE_KEY
has an
โ_โ, so we canโt leak it via SSTI.
This next part took me a while to figure out. I tried many different jinja2 (the templating language) SSTI tricks
but they all list PRIVATE_KEY
as None
.
The vulnrability came from the
Because some of the default keys are symmetcric, and we know PUBLICKEY
, we can
treat it as the secret for a symmetric encryption algorithm.
If we encode our own jwt with the correct date KINGSDAY
and correct role
(decoded.get("ROLE") == "royalty"
), we can access the route with the flag.
The jwt.io website is an easy way to play around with encoding and decoding jwts.
(This may fail depending on the version of the JWT library, as they check for things like this, so the jwt.io website is my preferred method)
I also saw people check the versions of the library initially, and found the jwt library had a CVE, but I had fun figuring this out myself.