Hashing
Table of Contents
Hashing is a one-way cryptographic function that converts data of any size into a fixed-length string of characters. This process is irreversible — the original data cannot be recovered from the hash value directly, which is the property that makes hashing useful for password storage and integrity verification but fundamentally different from encryption.
Related: Encryption Integrity Authentication Message Authentication Codes [[Denote query for ‘20260716T070800’]] John the Ripper Broken Authentication
Core Concepts
- Hash function: The algorithm used to create a hash value.
- Hash value: The output of a hash function, also known as a digest or message digest.
- Collision: When two different inputs produce the same hash value.
Hashing vs Encryption — The Distinction That Matters Most
The single most common conceptual mix-up, worth stating explicitly since it drives real security decisions:
| Aspect | Hashing | Encryption |
|---|---|---|
| Direction | One-way — irreversible | Two-way — designed to be decrypted |
| Key | No key required | Requires a key (symmetric or asymmetric) |
| Purpose | Verify integrity/identity, never intended to be reversed | Protect confidentiality, intended to be reversed by the holder of the key |
| Correct for | Passwords, file integrity checks | Data that needs to be read again later |
Storing a password encrypted rather than hashed is itself a finding — it implies the application (or an attacker with the key) can recover the plaintext password, which a properly hashed password never allows even with full database access.
Properties of a Good Hash Function
- Deterministic: The same input always produces the same hash value.
- Efficient: The hash function can be computed quickly.
- Avalanche effect: Small changes in the input result in large changes in the hash value.
- Collision resistance: It is computationally infeasible to find two inputs that produce the same hash value.
- Preimage resistance: It is computationally infeasible to find the input that produces a given hash value.
Salting — Why "Fast" Is Bad for Password Hashing
The "efficient" property above is desirable for data integrity checks but actively dangerous for password storage — a fast hash function makes brute-forcing every possible password fast too.
- Salt: Random data added to each password before hashing, unique per user. Defeats precomputed rainbow table attacks, since an attacker can no longer reuse one lookup table across every hashed password in a breach — each salt requires its own table.
- Purpose-built slow hashes: bcrypt, scrypt, and Argon2 are deliberately slow and memory-intensive, specifically to make brute-forcing computationally expensive even at scale — this is the opposite tradeoff from MD5/SHA-256's speed, and the reason finding MD5 used for password storage is itself a reportable finding regardless of anything else about the implementation
- Pepper: A secret value added in addition to the salt, stored separately from the database (e.g. in application config or a secrets manager) — protects against an attacker who obtains the database but not the application server
Identifying Hash Types
Recognizing a hash format from its structure before attempting to crack it:
# hashid identifies likely hash types from format/length hashid '$2b$12$KIXQ...' # Common format signatures: # 32 hex chars -> MD5 # 40 hex chars -> SHA-1 # 64 hex chars -> SHA-256 # $1$... -> md5crypt # $2a$/$2b$/$2y$... -> bcrypt # $6$... -> sha512crypt
See [[Denote query for ‘20260716T070800’]] and John the Ripper for cracking methodology once the type is identified.
Use Cases
- Password storage: Storing hashed (and salted) passwords instead of plain text — see the salting section above for why this alone isn't sufficient without a slow hash function
- Data Integrity: Verifying data hasn't been altered
- Digital signatures: Creating digital signatures for Authentication
- Blockchain technology: Securing and verifying transactions
Common Hash Functions
- MD5: Widely used but considered insecure due to vulnerabilities.
- SHA-1: More secure than MD5 but also showing signs of weakness.
- SHA-256, SHA-512: Stronger hash functions with longer output lengths.
Tips
- On the exam, finding a fast/general-purpose hash (MD5, SHA-1, unsalted SHA-256) used specifically for password storage is worth flagging as its own finding — Security Misconfiguration or Insecure Authentication Mechanism depending on context — distinct from whatever you do with the cracked credentials afterward
- If you find hashes without an obvious source password, check whether the format is even a password hash at all before attempting to crack it — Message Authentication Codes and password hashes can look superficially similar but require entirely different attack approaches
- Length and prefix are the fastest way to identify a hash type manually without a tool — memorize the common signatures above, since misidentifying the type wastes time running the wrong hashcat mode against it