This repository contains a Dockerized Flask application to demonstrate common web application vulnerabilities, including Broken Authentication, Insecure Direct Object References (IDOR), and Cross-Site Scripting (XSS). Each vulnerability is showcased with a vulnerable version and a patched version to demonstrate how to identify, exploit, and secure each flaw.
- Docker and Flask setup allows for easy manipulation and resetting of vulnerable and secure states.
- Burp Suite is used for intercepting and modifying requests to demonstrate each vulnerability.
- Broken Authentication: Demonstrates a login bypass where entering a specific username bypasses authentication.
- Insecure Direct Object References (IDOR): Allows unauthorized data access by manipulating parameters in the URL.
- Cross-Site Scripting (XSS): Demonstrates how unsanitized user input can lead to script injection.
- Build: Vulnerable code is built using Docker and VS Code.
- Exploit: Burp Suite is used to intercept and exploit each vulnerability.
- Patch and Re-Test: Vulnerabilities are fixed, and functionality is re-tested to confirm the fix.
- Vulnerability: Bypassing login credentials by using a specific username (
admin_bypass
). - Exploit: Login as
admin_bypass
without a password to gain access. - Fix: Remove the
admin_bypass
condition in the login route. - Outcome: Only users with valid usernames and passwords can log in.
- Vulnerability: Allows users to access other users' data by changing the
username
parameter in the URL. - Exploit: Log in as
user1
and modify the URL to accessuser2
's data. - Fix: Use session-based access by replacing
username
parameter withsession.get("username")
. - Outcome: Only the logged-in user can access their own data.
- Vulnerability: Unsanitized user input is displayed directly, allowing for JavaScript injection.
- Exploit: Inject
<script>alert('XSS')</script>
in thequery
parameter to trigger an alert. - Fix: Use Flask’s
escape()
function to sanitize the input. - Outcome: Input is displayed as plain text, preventing script execution.
- Set the Vulnerable Code: Uncomment
admin_bypass
in the login route. - Explain the Vulnerability: Describe how the
admin_bypass
condition allows unauthorized access. - Demonstrate: Log in with
admin_bypass
and any password to show bypass. - Apply the Fix: Remove
admin_bypass
from the login route. - Explain the Fix: Only valid credentials are now allowed.
- Verify: Attempt to log in with
admin_bypass
—it should be rejected.
- Set the Vulnerable Code: Use
username = request.args.get('username')
in the dashboard route. - Explain the Vulnerability: Describe how URL manipulation allows unauthorized data access.
- Demonstrate: Log in as
user1
, then modify the URL to accessuser2
's data. - Apply the Fix: Use
session.get("username")
in the dashboard route. - Explain the Fix: Data access is now restricted to the session user.
- Verify: Log in as
user1
, modify the URL—onlyuser1
's data should show.
- Set the Vulnerable Code: Display
query
directly in thesearch
route. - Explain the Vulnerability: Describe how unsanitized input allows script injection.
- Demonstrate: Inject
<script>alert('XSS')</script>
to trigger an alert. - Apply the Fix: Use
escape(query)
in thesearch
route. - Explain the Fix: Input is now displayed as text, preventing script execution.
- Verify: Inject the script again—it should display as plain text.
- Clone the repository.
- Build and start the Docker container:
docker-compose up --build