Skip to content
SQL injection Write-up Beginner

Hacked, Audited, Fixed — 10 Vulnerabilities in One Flask App.

A deliberately vulnerable Flask training app contained ten planted flaws, including SQL injection in the login form, command injection on a ping endpoint, an unauthenticated admin panel and unsafe pickle deserialisation. An attacker could log in without a password, run commands as root and read the full user table with plaintext passwords.

nilanjan.calculus Follow

Published on medium.com

Task 3 of my cybersecurity internship was a secure code review — audit a vulnerable Flask application, find every weakness, prove it, then fix it.

Nilanjan Chowdhury, on medium.com

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

Likely the app trusted user input everywhere: it concatenated input into SQL, passed it to a shell, exposed routes without guards and deserialised untrusted pickle data.

Impact

An attacker could take over the admin account, execute commands as root, and read every user's credentials; the author also describes a chain where a debug endpoint leaks the secret key, allowing forged sessions that bypass the access control.

What the attacker needed

Access to the app; none

The fix

The author says a hardened version was built with parameterised queries, shell disabled, JSON instead of pickle, environment variables for secrets, bcrypt hashing, route guards, path checks, upload restrictions and generic error messages.

How it was found

  1. Open the login page and submit a crafted username so the rest of the query is commented out
  2. Observe the response welcoming the admin user without a password
  3. Request the ping endpoint with a host value containing a shell separator and a command
  4. Observe the command output showing root privileges
  5. Request the admin route directly without logging in
  6. Observe the full user list including plaintext passwords

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.

This is a write-up of a practice app built with known holes on purpose, not a real company's site. The author showed that typing special characters into a login box can trick the database into skipping the password check, and that a page which runs system commands can be made to run any command. The lesson is that user input must never be trusted by the database, the shell or the code that rebuilds saved objects.

What is SQL injection?

Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.

More by nilanjan.calculus

View all

1 more disclosed report, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

SQL injection

The lesson behind this report.

Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.