Exploiting Human Error
A Flask application used a weak secret key ('CHANGEME') to sign session cookies, allowing an attacker to crack the key and forge a session cookie to bypass authentication. The author demonstrated this by cracking the key from a wordlist and crafting a cookie that made the server believe the attacker was logged in.
Published on blog.paradoxis.nl
A few weeks back, I and a friend of mine were discussing web frameworks and how he claimed to have made an ‘Impossible to Bypass’ login form. After asking him if I could see the code, he obliged and sent me a copy.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
The application used a weak, easily guessable secret key to sign session cookies, and the session data was stored client-side without encryption, allowing an attacker to crack the key and forge cookies.
Impact
An attacker could bypass authentication and impersonate any user if the secret key is weak and the session data is used for authorization.
What the attacker needed
Access to a Python interpreter; Flask installed; Ability to obtain a session cookie
The fix
Use a strong, random secret key and consider server-side sessions to prevent tampering and disclosure.
How it was found
- Obtain a session cookie from the server by making a request or using a browser extension.
- Create a wordlist of potential secret keys by scraping sources like GitHub and StackOverflow.
- Use the cookie and wordlist to brute-force the secret key by validating signatures.
- Once the key is found, craft a new session cookie with arbitrary data (e.g., logged in status).
- Send a request with the crafted cookie to bypass authentication.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
Flask stores session data in a cookie on the user's computer. The cookie is signed with a secret key to prevent tampering, but if that key is weak or guessable, an attacker can figure it out and create their own cookie with any data they want, like pretending to be logged in. This report shows how a weak secret key allowed bypassing login.
What is Crypto?
Encryption, signatures, randomness or certificate checks that do not protect what they claim to.