Ir al contenido

📕 FIELD MANUAL 2.1: AUTHENTICATION BYPASS (LOGIN)

Objective: We will bypass authentication mechanisms without knowing legitimate credentials.

0views

Classification: RED TEAM EYES ONLY

Objective: We will bypass authentication mechanisms without knowing the legitimate credentials.

bWAPP Targets: SQL Injection (Login Form/Hero), SQL Injection (Login Form/User).

MITRE ATT&CK: T1078 (Valid Accounts), T1190.

To bypass a login, we must visualize the code that is executing in the backend.

The vast majority of vulnerable logins follow this SQL structure:

SELECT * FROM users WHERE username = '$user' AND password = '$password';

If this query returns at least one row, the application will let us in. Generally, the first row in the users table is the Administrator (id=1).

We have two ways to win this battle:

  1. Tautology: Making the WHERE condition always TRUE (True), regardless of the password.
  2. Mutilation (Commenting): We will remove the part of the query that verifies the password.

TECHNIQUE A: The Universal Bypass (Tautology)

Sección titulada «TÉCNICA A: El Bypass Universal (Tautología)»

We want to inject a condition that is always true.

  • Logic: OR 1=1 (Or one equals one). Since 1 is always equal to 1, the database will accept the input.

  • The Payload:

    admin' OR 1=1 -- -
  • What the server sees:

    SELECT * FROM users WHERE username = 'admin' OR 1=1 -- -' AND password = '...';

    Analysis: The database will read: “Is the user admin? (Maybe not) OR Is 1 equal to 1? (YES)”. Since there is a OR and one part is true, everything is true. The dashes (--) will comment and cancel the verification of the remaining password.

If we know the username (e.g., admin, root, administrator), we will simply tell the database to ignore the rest.

  • The Payload:

    admin' -- -

    (Note: The space after the dashes is vital in MySQL).

  • Payload (MSSQL): admin' --

  • Payload (Hash/MySQL): admin' #

  • What the server sees:

    SELECT * FROM users WHERE username = 'admin' -- -' AND password = '...';

    Analysis: Everything after admin' will be converted into a comment. The effective query is SELECT * FROM users WHERE username = 'admin'. If the user exists, we will log in without a password.

TECHNIQUE C: “Blind” Bypass (Without knowing the username)

Sección titulada «TÉCNICA C: Bypass “A Ciegas” (Sin saber el usuario)»

What if we don't know that the admin is named “admin”? We will use the tautology to log us in as the first user in the table (which is usually the Super Admin).

  • Payload in Username field:

    ' OR 1=1 -- -

    Result: The query will look for anything or 1=1. It will return the first row of the table. Access granted as id=1.

Sometimes WAFs block OR 1=1. We will need to test hundreds of variations.

  1. Capture: We will intercept the failed login attempt in Burp Proxy.
  2. Intruder: We will send the request to Intruder (Ctrl + I).
  3. Payloads: We will select the user field and load a list of “Auth Bypass” (Seclists has Generic-SQLi-Auth-Bypass.txt).
    • Examples:
      • ' OR '1'='1
      • " OR "1"="1
      • admin' --
      • admin' #
      • ' OR TRUE --
  4. Attack: We will launch the attack and look for responses that have a different length (Length) or a 302 Redirect status code (success).

4. ESCALATION: WHAT IF IT IS NOT ENOUGH? (MAGIC HASHES)

Sección titulada «4. ESCALADA: ¿Y SI NO ES SUFICIENTE? (MAGIC HASHES)»

Reference to “Master Plan - Phase 2”

In old or poorly coded PHP systems, SQL injection is sometimes combined with “Type Juggling”.

If the application does this after the query:

// Comparación débil (==) en lugar de estricta (===)
if ($hash_de_la_db == "0e12345...") { ... }

We can try to inject values that generate hashes starting with 0e (which PHP interprets as scientific notation 0).

  • Practical Case: It is rare to see it purely in SQLi nowadays, but we will keep this in mind if classical injection fails but we see strange behaviors in PHP errors.

🕵️ Detection (IoC - Indicators of Compromise)

Sección titulada «🕵️ Detección (IoC - Indicadores de Compromiso)»
  1. Authentication Logs: We look for users that contain non-alphanumeric characters (', -, #, =) in the username field.
    • Log Example: Login success for user: admin' --
  2. Massive Attempts: Multiple login attempts from the same IP in less than a second (use of Burp Intruder).
  3. Concurrent Sessions: If the legitimate admin is connected and suddenly another session is opened from a China IP with the same user, red alert.
  1. Principle of Least Privilege: The application should not connect to the DB as root or sa.

  2. Prepared Statements (ALWAYS):

    // El WAF no es suficiente. Esto es lo único que funciona.
    $stmt = $pdo->prepare('SELECT * FROM users WHERE username = :user AND password = :pass');
    $stmt->execute(['user' => $user, 'pass' => $pass]);

    By parameterizing, the database literally looks for a user named admin' OR 1=1, which does not exist.

Status: Module 2.1 Completed. Mission: We will go to bWAPP -> SQL Injection (Login Form/Hero) and attempt to enter without knowing the password.