Menu

Timing Attack Demo

This page demonstrates a timing side-channel vulnerability where password comparison timing leaks information about the correct password.

About this vulnerability:

Timing attacks are a type of side-channel attack where an attacker learns information about secret data by measuring how long operations take.

The Problem:

Attack Strategy:

  1. Try all characters at position 0, measure timing
  2. The slowest response reveals the correct first character
  3. Differences will be very small, so may need to repeat requests to get reliable timing data
  4. Repeat for position 1, 2, 3... until full password is discovered

How to fix it:

Secure Example:

// SECURE: Constant-time comparison
if (hash_equals($secret_password, $guess)) {
    // Correct password
} else {
    // Incorrect password
}

// Or for hashed passwords:
if (password_verify($guess, $hashed_password)) {
    // Correct password
}