RedTeam Nexus Labs
Module 15 · Lesson 01 // Hashes

Hash properties

Hashes · CTF

Freereading · 10 min
On this page
LESSON

Overview

A hash function takes an input of any size and produces a fixed-size output called a hash, digest, or checksum. Hashes appear everywhere in a CTF: verifying downloads, storing passwords, fingerprinting files, and building signatures. Before you can attack or defend anything that uses hashing, you need to understand the properties a cryptographic hash function is designed to have. This lesson covers those properties in a safe, educational context.

Learning objectives

  • Define what a cryptographic hash function is and what it produces.
  • Explain the core properties: deterministic, fixed-length, one-way, and collision resistant.
  • Describe the avalanche effect and why it matters.
  • Distinguish a general-purpose hash from a password hash (previewing later lessons).

Core concept

A cryptographic hash function maps arbitrary input to a fixed-length output in a way that is fast to compute forward but infeasible to reverse. The output is often written in hexadecimal. The function itself is public and contains no secret key — anyone can compute the hash of a given input — yet the design goal is that the output reveals nothing useful about the input and cannot be feasibly inverted.

Four properties define a good cryptographic hash:

  • Deterministic — the same input always produces the same output. Hash "hello" today and next year and you get identical digests. This is what makes hashes useful for verification.
  • Fixed-length output — no matter how large or small the input, the digest is a fixed size. Hashing one byte or a gigabyte with SHA-256 both yield a 256-bit result.
  • One-way (preimage resistance) — given a hash, it is infeasible to find an input that produces it. You cannot "decrypt" a hash back to its input.
  • Collision resistance — it is infeasible to find two different inputs that produce the same hash.

How it works

The three security properties are worth separating precisely, because CTF challenges and real attacks target them individually:

  • Preimage resistance — given a digest h, it is infeasible to find any message m such that hash(m) = h. This is the "one-way" property.
  • Second-preimage resistance — given a specific message m1, it is infeasible to find a different message m2 (with m1 != m2) such that hash(m1) = hash(m2).
  • Collision resistance — it is infeasible to find any two distinct messages m1 and m2 with hash(m1) = hash(m2). The attacker gets to choose both.

Collisions must exist mathematically: inputs are unlimited, outputs are finite (this is the pigeonhole principle). The security claim is only that finding them is computationally infeasible for a strong function.

Another crucial behavior is the avalanche effect: changing even a single bit of the input flips roughly half the output bits, producing a completely different-looking digest. There is no partial similarity — a near-match input does not give a near-match hash. This is why you cannot "hill-climb" toward a target by trying inputs that are "close."

Practical example

Consider hashing two almost identical strings with the same function in an isolated lab:

input:  "flag"      ->  digest A
input:  "flags"     ->  digest B

Even though the inputs differ by a single character, digests A and B share no visible relationship — they look entirely unrelated. Hash "flag" again and you get exactly digest A once more, because the function is deterministic. And no matter which input you feed in, the digest is always the same fixed length. These three observations — determinism, fixed length, and the avalanche effect — are the everyday fingerprints of a hash function you will rely on throughout the module.

[!NOTE] A hash is not encryption. Encryption is reversible with a key; a hash has no key and is designed to be irreversible. Saying a hash is "decrypted" is incorrect — attackers recover inputs by guessing and hashing, never by inverting the function.

Cybersecurity relevance

Hash properties underpin much of practical security. One-wayness is why systems store password hashes instead of plaintext: a stolen hash should not reveal the password directly. Determinism and fixed length make hashes ideal for integrity checks — recompute the digest of a file and compare it to a known value to detect any change. Collision resistance is what makes a hash trustworthy as a fingerprint or inside a digital signature: if collisions were easy, an attacker could substitute a malicious file with the same digest as a legitimate one.

When these properties weaken, security breaks. Older functions such as MD5 and SHA-1 are no longer collision resistant — practical collisions have been publicly demonstrated — so they must not be used where collision resistance matters (like signatures). Understanding which property a challenge depends on tells you exactly where to look.

Common mistakes

  • Confusing hashing with encryption and expecting to "decrypt" a hash back to its input.
  • Assuming a hash is unbreakable — weak functions (MD5, SHA-1) fail collision resistance, and weak inputs can be guessed.
  • Believing similar inputs give similar hashes — the avalanche effect means they do not.
  • Using a fast general-purpose hash for passwords, which the password-hashing lesson shows is unsafe.

Key takeaways

  • A cryptographic hash function produces a fixed-length, deterministic digest from any input and is designed to be one-way.
  • The security properties are preimage resistance (one-way), second-preimage resistance, and collision resistance.
  • The avalanche effect means a tiny input change produces a completely different digest, and collisions exist in theory but should be infeasible to find.
  • Hashing is not encryption: there is no key and no legitimate way to reverse it; general-purpose hashes are also not suitable for passwords.

Check your understanding

  • What is the difference between preimage resistance and collision resistance?
  • Why can two identical inputs never produce different hashes, while two different inputs producing the same hash is called a collision?
FINISH THIS LESSON

Sign in to save your progress.