Get a Pentest and security assessment of your IT network.

Cyber Security

Password Length Guessing from Hashes

TL;DR

Yes, an attacker can sometimes guess your password length from a hash, especially if you use common password patterns or weak hashing algorithms. This guide explains how and what you can do to protect yourself.

How Attackers Guess Password Length

  1. Hash Length: The most basic clue is the length of the hash itself. Different hashing algorithms produce hashes of different lengths. However, this only tells them which algorithm you might be using, not necessarily your password length.
  2. Rainbow Tables & Precomputed Hashes: Attackers use pre-calculated tables (rainbow tables) to quickly find passwords that match known hash values. If a table is built for specific lengths, it can narrow down the possibilities.
  3. Length Extension Attacks: Some older hashing algorithms (like MD5 and SHA1) are vulnerable to length extension attacks. These allow an attacker to modify the hash without knowing the original password, but they require knowledge of the message length. This is less common with modern algorithms.
  4. Timing Attacks: Attackers can measure how long it takes a system to verify a password against its hash. Variations in timing can reveal information about the password’s complexity and length. A longer password generally takes more time to check.
  5. Brute-Force with Length Prioritization: Attackers often start brute-forcing passwords by trying shorter lengths first, as these are quicker to test. If they get a hit quickly, it suggests the password is short.

Protecting Yourself

  1. Use Strong Hashing Algorithms: This is the most important step. Avoid MD5 and SHA1 entirely. Use modern algorithms like Argon2, bcrypt, or scrypt. These are designed to be slow and resistant to brute-force attacks.
    # Example using Python with bcrypt
    import bcrypt
    hash = bcrypt.hashpw(b'yourpassword', bcrypt.gensalt())
    print(hash)
  2. Salt Your Passwords: A salt is a random string added to each password before hashing. This makes rainbow table attacks much harder.
    # Example using Python with Argon2
    from argon2 import PasswordHasher
    ph = PasswordHasher()
    hash = ph.hash('yourpassword', salt_length=16)
    print(hash)
  3. Password Complexity Requirements: Enforce strong password policies that require a minimum length (at least 12 characters, ideally more), and a mix of uppercase letters, lowercase letters, numbers, and symbols.
  4. Key Stretching: Algorithms like bcrypt and Argon2 automatically perform key stretching, which makes brute-forcing much slower.
  5. Rate Limiting: Limit the number of login attempts allowed within a certain timeframe to prevent brute-force attacks.
  6. Two-Factor Authentication (2FA): Add an extra layer of security by requiring a code from another device in addition to your password.
  7. Regular Password Updates: Encourage users to change their passwords regularly, although this is less effective than strong hashing and salting.

Checking Your System

  1. Identify Hashing Algorithm: Determine which hashing algorithm your system uses. This can often be found in configuration files or database schemas.
  2. Test for Vulnerabilities: Use online tools or security scanners to check for known vulnerabilities in your hashing implementation (e.g., length extension attacks).
Related posts
Cyber Security

Zip Codes & PII: Are They Personal Data?

Cyber Security

Zero-Day Vulnerabilities: User Defence Guide

Cyber Security

Zero Knowledge Voting with Trusted Server

Cyber Security

ZeroNet: 51% Attack Risks & Mitigation