Default Credentials in Python
Introduction
Welcome to the very first lesson of the "Security Misconfiguration" course! In this lesson, we'll explore the concept of default credentials and their impact on web application security. Default credentials are pre-set usernames and passwords that come with many applications and devices. While convenient for initial setup, they pose significant security risks if not changed.
By the end of this lesson, you'll learn how to identify, exploit, and secure endpoints that use default credentials. Let's dive in! 🚀
Understanding Default Credentials
Default credentials are the factory-set usernames and passwords that come with many software frameworks, applications, and hardware devices. They are intended for the initial setup process, allowing an administrator to log in for the first time without having to go through a complex user creation flow. Common examples include admin/admin, root/password, or test/test.
This vulnerability falls under the broader OWASP Top 10 category A07:2021 - Identification and Authentication Failures. The core issue is that these credentials are well-known and publicly documented. Attackers often use automated tools to scan for systems that still have these defaults enabled.
Default credentials exist primarily to help developers quickly test and set up applications during development. However, they often find their way into production environments due to rushed deployments, poor documentation, or simple oversight. Sometimes, teams intentionally keep them unchanged for "easier maintenance," which creates significant security risks. It's crucial to change all default credentials immediately upon deployment to prevent unauthorized access and protect your application from potential breaches.
Vulnerable Code Example
Let's look at a code snippet that demonstrates the use of default credentials in an admin panel. This example shows how an attacker might exploit these credentials to gain unauthorized access.
In this code, the admin panel uses hardcoded default credentials (admin and admin123). Let's break down the vulnerabilities:
- Hardcoded Credentials: The
DEFAULT_ADMINdictionary stores the username and password directly in the source code. This is a major security risk, as anyone with access to the code repository can see the credentials. - Weak Authentication Logic: The
/loginendpoint performs a simple string comparison to check the credentials. If they match, it returns a success message that includes"access": "FULL_ADMIN". This response explicitly tells the user how to authenticate for other endpoints. - Insecure Authorization: The
/usersendpoint is particularly vulnerable because it relies on a simple, predictable header check (access == "FULL_ADMIN") for authorization. An attacker who has logged in with default credentials can easily access all user data by including this header in their request. Worse, an attacker who understands the system could potentially skip the login step and directly query the/usersendpoint with the required header.
