Authentication is the process of verifying the identity of a user or system before granting access to protected resources. This typically involves checking credentialsâsuch as usernames, passwords, tokens, or biometric dataâagainst a trusted source (e.g., a database) to ensure only authorized entities can access the application.
Attacks on authentication aim to bypass or compromise the verification process, giving attackers unauthorized access. Common tactics include enumerating valid users, brute-forcing passwords, abusing password reset mechanisms, and exploiting weak session token generation.
User enumeration involves discovering valid usernames by analyzing subtle differences in server responses or error messages. For instance, a login form might return:
Such discrepancies allow attackers to identify which usernames are valid. Armed with a list of valid usernames, attackers can proceed to brute-force passwords or launch more targeted attacks.
Brute-forcing passwords involves systematically attempting a large number of password combinations until the correct one is found. Attackers often use automated tools like Hydra, Medusa, or Burp Suite Intruder to expedite this process.
# Example Hydra command
hydra -L users.txt -P passwords.txt http://target.com/login
Mitigations typically include:
Password reset tokens are intended to be short-lived and unpredictable. However, if these tokens are generated via weak or predictable methods, attackers can brute-force them:
token
in ?token=XYZ123
).Two-factor authentication (2FA) requires a second verification step, often a six-digit code. Without rate limiting, an attacker can brute-force all possible codes. For a 6-digit code, there are 1,000,000 combinations. Proper lockout policies and rate limiting are critical to prevent this attack.
Sometimes 2FA can be bypassed or brute-forced if the application does not implement proper rate limiting or has weak 2FA logic. For instance, if a TOTP (Time-Based One-Time Password) code is expected, an attacker might fuzz the code parameter:
# Generate potential 4-digit codes
seq -w 0 9999 > tokens.txt
# Use ffuf to test each code
ffuf -w ./tokens.txt -u http://bf_2fa.htb/2fa.php -X POST \
-H "Content-Type: application/x-www-form-urlencoded" \
-b "PHPSESSID=fpfcm5b8dh1ibfa7idg0he7l93" \
-d "otp=FUZZ" -fr "Invalid 2FA Code"
If the server does not implement a lockout or a robust rate limit, an attacker could discover the correct 2FA code and bypass this security measure.
Rate limiting aims to restrict how many login attempts can be made within a certain time. However, attackers can sometimes circumvent it by setting arbitrary HTTP headersâlike X-Forwarded-Forâto appear as though each request originates from a different IP address. This technique bypasses naive IP-based rate limiting.
CAPTCHAs are designed to distinguish human users from automated scripts. However, if the CAPTCHA solution is provided in the serverâs response or if the attacker employs automated CAPTCHA-solving tools (including AI-driven solutions), CAPTCHAs can be bypassed or automatically solved.
Some applications rely on security questions or other easily brute-forced mechanisms for password resets. Attackers can fuzz these questions if they are not properly rate-limited or if the questions are too simple (e.g., âWhat is your petâs name?â). By systematically guessing answers, attackers might reset the userâs password.
Many systems are deployed with default credentials that are widely documented (e.g., admin:admin
). If not changed during setup, these credentials present an easy attack vector. Attackers routinely test well-known default logins for common services or hardware.
Weaknesses in the password reset process can allow attackers to reset user passwords without adequate verification. Common pitfalls include:
Sometimes critical resources (like an admin panel) are exposed to the internet without any authentication checks. Simply navigating to a hidden URL might grant administrative privileges if the developer assumed âsecurity through obscurity.â
Example:
http://target.com/admin
If no login is required, anyone can access it.
Developers may store access level or role information in user-controllable parameters. Attackers can modify these parameters to escalate privileges or bypass authentication checks.
Example:
http://target.com/dashboard?user=123
Changing user=123
to user=124
might grant access to another userâs dashboard if the application does not verify the userâs identity on the server side.
Take the following example of session tokens:
2c0c58b27c71a2ec5bf2b4b6e892b9f9
2c0c58b27c71a2ec5bf2b4546092b9f9
2c0c58b27c71a2ec5bf2b497f592b9f9
2c0c58b27c71a2ec5bf2b48bcf92b9f9
2c0c58b27c71a2ec5bf2b4735e92b9f9
Notice that 28 of the 32 characters are static. The tokens share the prefix 2c0c58b27c71a2ec5bf2b4
and the suffix 92b9f9
, leaving only 4 characters of actual randomness. This severely weakens the token, as an attacker only needs to brute-force 4 characters to potentially hijack all active sessions.
In more realistic scenarios, the token might appear random on the surface, but the underlying generation logic can be predictable. Attackers who gain insight into how the token is generated can predict valid tokens and hijack sessions.
Sometimes tokens contain encoded or serialized data that can be manipulated:
# Decoding base64
echo -n dXNlcj1odGItc3RkbnQ7cm9sZT11c2Vy | base64 -d
user=htb-stdnt;role=user
An attacker might modify the role:
echo -n 'user=htb-stdnt;role=admin' | base64
dXNlcj1odGItc3RkbnQ7cm9sZT1hZG1pbg==
If the application does not verify the integrity of this data, the attacker can gain elevated privileges by simply replacing the token with the modified version. Similar logic applies to hex-encoded or URL-encoded tokens:
echo -n 'user=htb-stdnt;role=admin' | xxd -p
757365723d6874622d7374646e743b726f6c653d61646d696e
An Execution After Redirect (EAR) vulnerability arises when a web application issues an HTTP redirect (usually via a 3xx
status code and a Location
header) but continues processing the request afterward. Under normal circumstances, developers will typically include a return
, die
, or exit
statement immediately after sending the redirect header to ensure no further code executes. However, if they omit this step, the server can still process the rest of the codeâeven though the client receives a redirect response.
if (!isset($_SESSION['user'])) {
header('Location: login.php');
// Missing exit/die here
}
// Code below still executes!
Reference: For a real-world example and further reading, see this article. It highlights how improper handling of redirects and continued execution of user-supplied data can lead to severe security vulnerabilities.