This guide will help you set up both the vulnerable and secure versions of the authentication demo on your local machine. Total setup time: 5 minutes.
Prerequisites
Before you begin, ensure you have:Python 3.8+
Check version:
python --version or python3 --versionpip Package Manager
Usually comes with Python. Check:
pip --versionGit
For cloning the repository:
git --versionWeb Browser
Chrome, Firefox, Safari, or Edge for testing
Installation
Clone the Repository
Open your terminal and clone the project:This downloads the complete project including both vulnerable and secure versions.
Set Up the Vulnerable Version
Navigate to the vulnerable directory and install dependencies:Expected output:
Initialize the Vulnerable Database
Create the SQLite database with default users:Expected output:This creates
users.db with two default accounts:- admin / admin123 (admin role)
- usuario / password123 (user role)
Passwords are stored in plaintext in this version - this is intentional for educational purposes.
Start the Vulnerable Application
Launch the Flask development server:Expected output:Open your browser and navigate to:You should see the vulnerable application’s home page.
Set Up the Secure Version
Open a new terminal window (keep the vulnerable version running), then:This installs additional security packages:
- Werkzeug - For password hashing
- Flask-WTF - For CSRF protection
Initialize the Secure Database
Create the secure database with hashed passwords:Expected output:Same default users, but passwords are now bcrypt hashed.
Verify Installation
Now you should have both applications running:Vulnerable Version
Secure Version
Quick Test
Test that both applications are working:Default Credentials
Both applications come with the same test accounts:| Username | Password | Role | Use Case |
|---|---|---|---|
admin | admin123 | admin | Testing admin functions and privilege escalation |
usuario | password123 | user | Testing standard user access and IDOR |
Your First Vulnerability Test
Let’s verify the vulnerable version has SQL injection:Navigate to Vulnerable Login
Open http://localhost:5000/login in your browser
Try SQL Injection Payload
Enter these credentials:
- Username:
admin - Password:
x' OR '1'='1
The password field contains a SQL injection payload that will bypass authentication.
Click Login
Click the login button. If successful, you’ll be logged in as admin without knowing the real password!Check the terminal where the vulnerable app is running - you’ll see the malformed SQL query:
Try the Same on Secure Version
Now try the exact same payload on http://localhost:5001/loginResult: Login fails with “Credenciales incorrectas”The secure version uses parameterized queries, so the SQL injection is prevented.
Application Features
Both versions include these pages:Home Page (/)
Home Page (/)
Landing page with links to login and registration
Login (/login)
Login (/login)
Authentication page - vulnerable version has SQL injection
Register (/register)
Register (/register)
Create new user accounts
Dashboard (/dashboard)
Dashboard (/dashboard)
Protected page after login - vulnerable version has XSS
Profile (/profile)
Profile (/profile)
User profile page - vulnerable version has IDOR
Logout (/logout)
Logout (/logout)
End session and clear cookies
Project Structure
Understand the codebase layout:Key Files to Study
The main differences between versions are in
app.py (application logic) and database.py (password storage). Compare them side-by-side to learn.Using Virtual Environments (Recommended)
For cleaner Python package management, use virtual environments:Troubleshooting
Port Already in Use
Port Already in Use
Error:
Address already in useSolution: Change the port in the code or kill the process:Module Not Found
Module Not Found
Error: Make sure you’re in the correct directory (vulnerable/ or secure/).
ModuleNotFoundError: No module named 'flask'Solution: Install requirements:Database Locked
Database Locked
Error:
sqlite3.OperationalError: database is lockedSolution: Close any other connections to the database:Permission Denied
Permission Denied
Error:
Permission denied when running scriptsSolution: Check file permissions or use python3:Next Steps
Now that you have both applications running:SQL Injection
Start with the most critical vulnerability
Cross-Site Scripting
Learn about XSS attacks and prevention
IDOR
Test unauthorized data access
Password Storage
See why plaintext passwords are dangerous
Running on Different Ports
If you need to change the default ports:Stopping the Applications
To stop the Flask servers:- Press
Ctrl+Cin each terminal window - Or close the terminal windows
The SQLite database files (
users.db) persist after stopping. Delete them and re-run python database.py to reset to default state.Using with Docker (Advanced)
For isolated container environments:Dockerfile.vulnerable
Build and Run
Docker setup is optional. The standard Python installation works great for learning.
Ready to Exploit?
You now have a complete lab environment. Time to learn by doing:Test on Vulnerable Version
Try the exploits on http://localhost:5000
Verify Fix on Secure Version
Confirm the same exploit fails on http://localhost:5001
Start Learning
Begin with SQL Injection - the most critical web vulnerability