โšก Rate Limiting Lab

Brute Force Protection

โš ๏ธ FOR EDUCATIONAL PURPOSES ONLY - DO NOT USE ON REAL SYSTEMS

๐Ÿ“š What is Rate Limiting?

Rate Limiting is a security control that restricts the number of requests a user can make within a specific time period. It's crucial for preventing:

๐Ÿงช PIN Verification Demo

๐Ÿ“Œ Demo Information

Correct PIN: 1234

Try guessing the PIN with and without rate limiting enabled to see the difference!

0
Total Attempts
Status:
Ready to test. Try entering a PIN.

๐ŸŽฏ Try This Experiment

  1. With Rate Limiting OFF:
    • Try multiple incorrect PINs (e.g., 0000, 1111, 2222, 3333, etc.)
    • Notice you can keep trying indefinitely
    • This allows brute force attacks (10,000 possible 4-digit combinations)
  2. With Rate Limiting ON:
    • Try 5 incorrect PINs
    • After 5 attempts, you'll be locked out for 30 seconds
    • This makes brute force attacks impractical

๐Ÿ” Understanding the Vulnerability

Without Rate Limiting:

// โŒ VULNERABLE: No protection against brute force
function verifyPIN(pin) {
  if (pin === correctPIN) {
    return { success: true };
  }
  return { success: false };
}

// Attacker can try all 10,000 combinations!
for (let i = 0; i < 10000; i++) {
  verifyPIN(i.toString().padStart(4, '0'));
}

With Rate Limiting:

// โœ… SECURE: Rate limiting implemented
const attempts = {};

function verifyPIN(pin, userId) {
  // Check attempt count
  if (attempts[userId] >= 5) {
    const timeSinceFirst = Date.now() - attempts[userId].firstAttempt;
    if (timeSinceFirst < 30000) { // 30 seconds
      return { error: 'Too many attempts. Try again later.' };
    }
    // Reset after cooldown
    attempts[userId] = 0;
  }
  
  // Increment attempts
  attempts[userId]++;
  
  // Verify PIN
  if (pin === correctPIN) {
    return { success: true };
  }
  return { success: false };
}

โš ๏ธ Real-World Impact

Real Example:

A 4-digit PIN has 10,000 possible combinations (0000-9999). Without rate limiting, an attacker could try all combinations in seconds using automation. With rate limiting of 5 attempts per 30 seconds, it would take over 16 hours to try all combinations!

๐Ÿ”’ Rate Limiting Best Practices

๐Ÿ“Š Rate Limiting Strategies

๐Ÿ’ก Detection Tips

Test for missing rate limiting: