Hashes, stored passwords and pass the hash

9 min 6 sections 4 practice questions 12 sources citedISC2 objective 3.7

A hash is a short fingerprint of any amount of data: the same data always gives the same fingerprint, and the fingerprint cannot be turned back into the data. Systems use hashes to spot changed files and to store passwords without keeping the passwords themselves. No background beyond the basic vocabulary of cryptography is assumed. Attackers crack stolen password hashes, and on some networks they skip the cracking and use the hash itself to sign in.

By the end of this unit you will be able to:

  • Explain what a hash function does and tell apart preimage, second preimage and collision resistance
  • Tell apart MD5, SHA-1, SHA-2 and SHA-3 by digest length and standing
  • Calculate the work of a birthday attack on a hash of a given length
  • Explain how salt, pepper and key stretching protect stored passwords against dictionary and rainbow table attacks
  • Explain, step by step, how pass the hash works and choose the defences that limit it

Into the bursar's computer without a password

An illustrative example

A teaching assistant at a secondary school opens an attachment that installs an attacker's program on her laptop. Within an hour the attacker is signed in to the bursar's computer and the school's file server.

The investigation finds that the attacker never learnt a single password. Every laptop in the school had been built from one master copy, with the same local administrator password.

How could the attacker sign in to other computers without ever knowing a password?

A fingerprint for data

A hash function takes data of any size and produces a short value of fixed length, called a digest or . A whole book and a single word each give a digest of the same length. The same input always gives the same digest.

A good hash function is one-way: nothing practical turns the digest back into the data. It also shows the avalanche effect: changing one letter of the input changes about half of the bits of the digest, so similar inputs give unrelated digests.

Preimage resistance
Given a digest, nobody can find any input that produces it. This is the one-way property.
Second preimage resistance
Given one input, nobody can find a different input with the same digest. A forger cannot make a second contract that matches the first.
Collision resistance
Nobody can find any two different inputs with the same digest, both chosen freely. A pair with the same digest is a collision.

A hash has no key. It detects accidental change, such as a damaged download, when the expected digest arrives by a trusted route. It does not stop deliberate change: an attacker who alters a file simply calculates a new digest for it.

Common misconception

“Hashing is a kind of encryption, so a hashed value can be decrypted with the right key.”

Encryption is reversible with the key. A hash has no key and is not reversed. Attackers recover hashed passwords by guessing inputs and comparing digests.

The hash algorithms and their standing

Hash algorithms by digest length and standing
AlgorithmDigest lengthStanding
MD5128 bitsBroken: collisions are easy to make. Not acceptable for signatures
SHA-1160 bitsCollision strength below 80 bits. Disallowed for signatures since the end of 2013; to be phased out by 2030
SHA-2 family224, 256, 384 or 512 bitsCurrent
SHA-3 family224, 256, 384 or 512 bitsCurrent. Built on a different design, called Keccak

The number in a name such as SHA-256 is the digest length in bits. The Secure Hash Algorithm (SHA) families are United States federal standards. SHA-3 won an open competition run by the National Institute of Standards and Technology (NIST) and gives an alternative of a different design.

Strength depends on the property attacked. Finding an input for a given digest takes about 2 to the power n tries for an n-bit digest. Finding any collision takes far fewer, as the next section shows.

The birthday attack: why collisions come early

In a room of 23 people the chance that two share a birthday is 50.7%, although there are 365 possible birthdays. Each new person is compared with everyone already there, so the number of pairs grows quickly: 23 people make 253 pairs.

The birthday attack applies the same effect to a hash. The attacker makes many versions of two documents and looks for any pair, one of each, that share a digest. A collision turns up far sooner than when attacking one fixed digest.

Work to find a collision

Tries ≈ 2^(n ÷ 2)

n
The digest length in bits.

A 128-bit digest such as MD5 gives a collision after about 2^64 tries. SHA-256 needs about 2^128.

A collision lets a forger obtain a signature on a harmless document and attach it to a harmful one with the same digest. The defence is a longer digest: collision strength is half the digest length, so SHA-256 gives 128 bits.

Dictionary attacks and rainbow tables

A system checks a password by hashing what was typed and comparing the result with the stored digest. A thief who copies the file of digests cannot reverse them, and guesses instead.

In a dictionary attack the attacker hashes a long list of likely passwords, such as common words, names and leaked passwords, and looks for matching digests. It is brute force limited to probable choices, run on the attacker's own computers, where no lockout applies.

A rainbow table is a vast table of passwords and their digests, worked out in advance and stored in compressed form. The attacker looks a stolen digest up instead of calculating. One table serves against every system that uses the same hash function in the same way.

Three ways to recover passwords from stolen digests
MethodWhat the attacker doesWork done
Brute forceTries every possible passwordAt attack time, enormous
DictionaryTries likely passwords onlyAt attack time, much less
Rainbow tableLooks digests up in a table built earlierIn advance, reused against many victims

Storing passwords: salt, pepper and stretching

A salt is a random value made for each password and stored beside its digest. The password and the salt are hashed together. Two people with the same password now have different digests, and a table built in advance is useless, because it would need an entry for every possible salt. NIST requires a salt of at least 32 bits.

A pepper is a further secret added to every password before hashing, kept apart from the password file, for example in a hardware security module, a sealed device that holds keys. A thief who copies only the password file lacks it.

Key stretching makes each guess slow by repeating the hash many times or by demanding much memory. A delay too small for a user to notice multiplies an attacker's time by the same factor.

  • PBKDF2 (Password-Based Key Derivation Function 2) repeats a ; NIST recommends at least 1,000 repetitions, and far more where practical.
  • Argon2 is memory-hard: each guess needs a large amount of memory, which is costly to supply at scale. Argon2id is its standard form.

Salt beats tables built in advance. Pepper beats a thief who has only the database. Stretching slows every guess.

Pass the hash: the hash itself becomes the password

Windows networks still support NTLM (Windows Challenge/Response), an older sign-in protocol. NTLM proves knowledge of the password's hash, not of the password. It is a challenge-response protocol: the server sends a random challenge and the client must return an answer calculated from it.

  1. The client hashes the password and discards the password. It sends the user name.
  2. The server sends an 8-byte random challenge.
  3. The client the challenge with the password hash and returns the result.
  4. The domain controller, which holds every domain account's hash, does the same calculation and compares. For a local account, such as the laptops' administrator, the computer itself holds the hash and checks the answer.

In pass the hash, an attacker with administrator rights on one computer copies password hashes from its memory or account store. The attacker then answers NTLM challenges on other computers with the stolen hash. No password is cracked or known.

A stolen hash is replayed to sign in elsewhere

A stolen hash is replayed to sign in elsewhereAbove, an attacker copies a stored hash from a first laptop. Below, the attacker answers a second computer's challenge with that hash, and the domain controller finds the response correct and confirms the sign-in.First laptopattacker is adminStored hashin memoryAttackercopies hashChallenge8 random bytesfrom the secondcomputerResponsechallengeencrypted withstolen hashDomaincontrollerfinds itcorrectSecondcomputerattackersigned inA stolen hash is replayed to sign in elsewhereAbove, an attacker copies a stored hash from a first laptop. Below, the attacker answers a second computer's challenge with that hash, and the domain controller finds the response correct and confirms the sign-in.First laptopattacker is adminStored hashin memoryAttackercopies hashChallenge8 random bytesfrom the secondcomputerResponsechallengeencrypted withstolen hashDomaincontrollerfinds itcorrectSecondcomputerattackersigned in
Read this figure as text

NTLM, an older Windows sign-in protocol, proves knowledge of the password's hash, not of the password. Whoever holds the hash can answer its challenge.

  1. The attacker has administrator rights on a first laptop. A user or administrator signed in there, so a password hash sits in its memory or account store.
  2. The attacker copies the hash. No password is cracked or learnt.
  3. The attacker asks a second computer for access as the same account. The second computer sends an 8-byte random challenge.
  4. The attacker encrypts the challenge with the stolen hash and returns it as the response.
  5. The second computer passes the user name, challenge and response to the domain controller, which holds every account's hash. It repeats the calculation, finds a match and confirms the sign-in.
  6. The defences: a unique local administrator password on every computer, privileged accounts kept off ordinary laptops, stored credentials isolated from the operating system, and Kerberos preferred to NTLM.

The defences limit where a stolen hash works and where it can be found.

  • A unique local administrator password on every computer, changed automatically, so one hash opens one machine.
  • Privileged accounts that sign in only to the systems they manage, in separate tiers, so their hashes never sit on ordinary laptops.
  • Isolating stored credentials from the operating system, so malware cannot copy them.
  • Turning off NTLM where Kerberos, a newer sign-in protocol based on tickets, can replace it, and the security updates that limit local administrator accounts over the network. The same hash can still be used to request Kerberos tickets, so the other defences remain needed.

Worked example: What a salt costs the attacker

A thief copies a file of 10,000 password digests. The attacker's dictionary holds 1 billion likely passwords.

  1. Without salt, the attacker hashes each of the 1 billion words once and compares every result with all 10,000 digests: 1 billion hash calculations in all.
  2. Users who chose the same password share a digest, so one match reveals all of them at once.
  3. With a unique salt for each user, each guess must be hashed again with each user's salt: 1 billion × 10,000 = 10 million million calculations.
  4. Add stretching of 100,000 repetitions, and each of those calculations costs 100,000 times as much.

Salt multiplies the attack by the number of users and makes tables built in advance useless. Stretching multiplies it again. Neither helps a user whose password is in the dictionary, which is why password rules still matter.

A question, worked through

A security manager at a trust of five schools reviews an attack in which an intruder took the local administrator password hash from one laptop and signed in to forty others with it. Every laptop is built from one master copy with the same local administrator password. The trust has no budget for new hardware this year.

Which action would BEST prevent the same spread happening again?

  1. Give each laptop a unique local administrator password that changes automatically
  2. Raise the local administrator password on the master copy to twenty characters
  3. Store the local administrator password digests with a salt and key stretching
  4. Encrypt every laptop's disk with AES under a key held in the laptop's chip
Decide on your answer, then open the reasoning
  1. The question asks what stops one stolen hash opening forty laptops. This is pass the hash: the hash is used directly, never cracked.
  2. Rule out d. Disk encryption protects a laptop that is switched off and stolen. The intruder worked on running machines.
  3. Rule out c. Salt and stretching slow the cracking of digests. Pass the hash needs no cracking, and the sign-in protocol accepts the hash as it is.
  4. Between a and b: a longer password still gives one hash shared by every laptop, and that hash still works everywhere.
  5. Option a makes each laptop's hash different, so a hash taken from one opens no other. It needs no new hardware.

Answer: A. Give each laptop a unique local administrator password that changes automatically

Choosing between good answers

An attacker signs in with a stolen hash and no password is ever cracked
it is pass the hash. Choose controls that make credentials unique or keep them off machines, not longer passwords.
A question asks what defeats precomputed rainbow tables
choose a unique salt for each password.
An option offers a plain hash to detect deliberate tampering
reject it. An attacker recalculates the hash. Deliberate change needs a keyed check or a signature.
A question asks the work to find a collision in an n-bit hash
it is about 2^(n/2): the birthday attack.

Check your understanding

4 questions on this unit, easiest first. Confirm an answer to see the reasoning for it, then the right answer, the other options and the rule to reuse. Your answers are kept in this browser and feed readiness and review.

These questions are drafts that no named reviewer has approved yet.

Question 1 of 4

A law firm stores the digest of each signed contract. It needs assurance that nobody, given one of its contracts, can write a different contract with the same digest. Which property of the hash function gives this?

What to remember

  • A hash function turns any data into a fixed-length digest. It is one-way, has no key and cannot be decrypted.
  • MD5 (128 bits) and SHA-1 (160 bits) are broken for collision resistance. SHA-2 and SHA-3 are current.
  • The birthday attack finds a collision in about 2^(n/2) tries, so collision strength is half the digest length.
  • Store passwords hashed with a unique salt and a slow, stretched function such as PBKDF2 or Argon2, and add a pepper held elsewhere.
  • Pass the hash reuses a stolen NTLM hash to sign in elsewhere without knowing the password. Unique local passwords, limited privileged sign-in, credential isolation and turning off NTLM where possible limit it.

Say it from memory

  1. How does a pass-the-hash attack work, and what are the main defences?

    NTLM proves knowledge of a password's hash, not the password. An attacker with administrator rights on one computer copies stored hashes, then answers sign-in challenges on other computers with them, moving sideways without cracking anything. Defences: a unique, rotated local administrator password per computer; privileged accounts used only on the systems they manage; credential isolation; NTLM turned off where Kerberos can replace it; current security updates. The same hash can still obtain Kerberos tickets.

    Read this part again

  2. How do preimage resistance, second preimage resistance and collision resistance differ?

    Preimage resistance: given a digest, nobody can find any input that produces it. Second preimage resistance: given one input, nobody can find a different input with the same digest. Collision resistance: nobody can find any two different inputs with the same digest, both chosen freely.

    Read this part again

  3. Give the digest length and standing of MD5, SHA-1, SHA-2 and SHA-3.

    MD5: 128 bits, broken, with collisions easy to make. SHA-1: 160 bits, disallowed for signatures since the end of 2013. SHA-2 and SHA-3: 224, 256, 384 or 512 bits, both current; SHA-3 is built on a different design called Keccak.

    Read this part again

  4. How much work does a birthday attack need to find a collision, and what is the defence?

    About 2^(n ÷ 2) tries for an n-bit digest, so MD5 gives a collision after about 2^64 tries and SHA-256 needs about 2^128. The defence is a longer digest, because collision strength is half the digest length.

    Read this part again

  5. How does a dictionary attack differ from a rainbow table attack?

    A dictionary attack hashes a long list of likely passwords at attack time and looks for matching digests. A rainbow table is a vast table of passwords and digests worked out in advance, so the attacker looks a stolen digest up. One table serves against every system using the same hash function in the same way.

    Read this part again

  6. What does a salt, a pepper and key stretching each defeat?

    A salt is a random value per password, at least 32 bits, hashed with it; it defeats tables built in advance. A pepper is a secret added to every password and kept apart from the password file; it defeats a thief who has only the database. Key stretching, as in PBKDF2 or Argon2, slows every guess.

    Read this part again

Sources