Ravindra BagaleCourses & study guides मराठी Track your progress

33. Cryptography Basics

Cyber Security

33.2 Hashing, Salts and Password Storage

A hash function turns any input into a fixed-length fingerprint. Good hashes are one-way, and a tiny change in input gives a completely different output (the "avalanche effect").

Algorithm Output Status
MD5 128-bit Broken – collisions are practical; never for security
SHA-1 160-bit Broken for collisions; being retired
SHA-256 / SHA-3 256-bit Safe for integrity and signatures
bcrypt, scrypt, Argon2, PBKDF2 Variable Designed for passwords – slow on purpose

Uses: checking downloads (compare the published SHA-256 of the Kali ISO), file integrity (Wazuh FIM, Chapter 31), digital forensics (hash evidence before and after, Chapter 28), and password storage.

Passwords need special care. A plain fast hash like SHA-256 lets Hashcat try billions of guesses per second (Chapter 22). So we use:

  • a salt – a random value added per user, so the same password gives different hashes and rainbow tables fail;
  • a slow algorithm (bcrypt/Argon2) with a work factor, so each guess is expensive.
sha256sum kali-linux-installer-amd64.iso     # compare with the value on kali.org
php -r 'echo password_hash("Pune123", PASSWORD_BCRYPT), PHP_EOL;'   # different every run (salt)
openssl passwd -6 -salt Xy12 Pune123         # SHA-512 crypt, like /etc/shadow ($6$)

A HMAC (hash + secret key) proves both integrity and that the sender knew the key – used in API signatures and JWT tokens (HS256).

Ravindra Bagale's Tip

Students store passwords with md5($password) or sha256($password) and ask, "It's a hash, so it's safe, right?" No! A fast hash is easy to crack. In PHP always use password_hash() and password_verify() – you get salt and bcrypt automatically.

Lab

In your lab, create two users with the same password and compare their lines in /etc/shadow – note the different salts. Then use john (Chapter 22) on an MD5 hash and a bcrypt hash of the same weak password and compare how long each takes.

Extended teaching notes

Why this lesson matters

Cryptography fails when people invent it. Use standard libraries, modern algorithms (AES-GCM, TLS 1.2+, bcrypt/argon2) and protect keys in a KMS or secrets manager.

Where crypto shows up

[('Passwords', 'bcrypt/argon2/PBKDF2 via the framework hasher — never plain MD5/SHA1.'), ('TLS', "Terminate on ALB/nginx with ACM/Let's Encrypt; redirect HTTP to HTTPS."), ('JWT / API tokens', 'Short lifetime, rotate signing keys, store secrets outside Git.'), ('Disk / S3', 'Provider or customer-managed keys; least privilege on decrypt.')]

Mini case study

Suppose we are on a purple-team exercise for an Indian mid-size company (sample data). Red notes a technique from this lesson against a lab clone. Blue must show the control that stops it, the log that would have fired, and the ticket that hardens production. That is the standard this course trains you for.

Defender's worksheet (do this today)

  1. Write the lesson title, date and the exact lab target you are allowed to use.
  2. List three owned systems (VMs, apps, or cloud accounts) where this lesson applies.
  3. Run one safe check from the lesson on a lab system only. Paste the command and output.
  4. Write a two-sentence fix you would give a teammate.
  5. Name one related public advisory (CERT-In, CISA, NVD, or a vendor bulletin) with its date.

Indian workplace (sample data)

Suppose we are a junior analyst at Infosys, TCS, Wipro or a fintech SOC in Bengaluru/Pune. Turn this lesson into one checklist item with an owner, a due date and a place to store evidence (ticket + screenshot).

Global practice

Compare your notes with OWASP, CIS Benchmarks, NIST CSF/IR guidance or a cloud Well-Architected security question. Write five lines on what overlaps.

Everyday analogy

Explain the risk and the fix to a family member without jargon. If they can repeat the warning, you understand it well enough to teach juniors.

Key terms

  • Control: a safeguard (patch, config, process, detection).
  • Finding: a weakness backed by evidence.
  • Remediation: the fix plus how you verified it.
  • Scope: systems you have written permission to touch.
  • Least privilege: only the access the task needs.
  • Defence in depth: several layers so one failure does not end the story.

Common mistakes

  • Skipping written permission "just for a quick scan".
  • Practising on hostel, office or public targets without authorisation.
  • Collecting tool output without writing the fix.
  • Copying attack steps onto production to "verify". Defenders verify with versions, configs and patches.
  • Publishing screenshots that contain secrets, cookies or internal hostnames.

Recap

  • Evidence, fix, owner, date.
  • Own lab only.
  • Fix > spectacle.

Real incident: Todoist – an attacker reached production and downloaded old salted SHA-1 password hashes of early users (Nov 2026)

1. What happened

In this lesson you learnt that passwords must be stored with a slow password hash like bcrypt or Argon2, not a fast one like SHA-1. Why does this case matter? Because a real company still had old SHA-1 hashes for some users, and an attacker took them.

  • Todoist is a popular to-do list and task app.
  • Todoist says that between 22 and 23 November 2026 an attacker used a stolen credential for its version control system. With it, they changed automated workflows in three repositories and got more credentials. They could also read source code. Todoist found no changes to app code.
  • One of those credentials let the attacker change how employees sign in to internal systems. They took over an employee's work account and reached Todoist's cloud infrastructure.
  • On 23 November the attacker downloaded a file for some early users whose passwords were still stored with an older method: salted SHA-1. It had email addresses, password hashes and account creation dates. This was about 6% of users. Todoist saw no sign that the attacker signed in to those accounts.
  • For much smaller groups, the attacker took Todoist API tokens and Slack integration tokens, searched some customer content for credentials, and read email details through connected Todoist for Outlook accounts.
  • Those old hashes stayed because those users had not changed their password since Todoist stopped using SHA-1 over ten years ago. Todoist said it should have retired it sooner, and has now done so.
  • Todoist blocked the attack paths, replaced exposed internal credentials and protected affected accounts. It has not found how the first credential was stolen; its leading theory is a compromised employee device, which is unconfirmed.

2. How the hack happened (public reporting only – high-level)

  1. The attacker had a stolen credential for Todoist's code platform.
  2. They changed automated workflows (CI jobs) in three repositories to collect more credentials.
  3. One of those credentials let them change employee sign-in settings, so they took over an employee's work account.
  4. From there they reached the cloud and production systems.
  5. They downloaded a file of old salted SHA-1 password hashes, plus some tokens.
  6. Why this hurts: SHA-1 is fast. Attackers can try many password guesses per second on a fast hash, offline, so weak or reused passwords are at risk.

3. How to stop it / defend (this lesson: hashing, salts and password storage)

Why: a salt stops one guess working on many users at once, but only a slow hash makes each guess expensive.

What a team can do:

  1. Use a slow password hash: Argon2, bcrypt or scrypt, with a good work factor.
  2. Upgrade old hashes. When a user signs in, check the old hash and save a new Argon2 or bcrypt hash at once.
  3. Set an end date for old methods. Users who never sign in again get a forced password reset, so no SHA-1 hash stays for years.
  4. Keep the password table hard to reach. Only the login service should read it, and big exports should raise an alert.
  5. Protect the path to production too: short-lived tokens for code and CI, and review for any change to workflows.

Example: a simple "old hash" count.

  1. Rule: every stored password uses Argon2 or bcrypt.
  2. Action: count how many user rows still use any other hash type (each hash usually shows its type at the start).
  3. Check: the number should be zero. If not, upgrade at next sign-in and set a reset date for the rest.
  4. What it means: if the database ever leaks, attackers get only slow, hard-to-guess hashes.

4. How to take care so it won't happen again (checklist)

  • [ ] All passwords are stored with Argon2, bcrypt or scrypt.
  • [ ] Old hashes are upgraded at sign-in, and old methods have an end date.
  • [ ] Only the login service can read password hashes; large exports raise an alert.
  • [ ] Code platform and CI tokens are short-lived, and workflow changes need review.
  • [ ] As a user: use a unique password for every app, keep it in a password manager, and change it at once if a breach notice comes.
  • [ ] Never keep API keys or recovery phrases in task notes or comments.

Source: Todoist, "Security incident in November 2026" (help centre notice), 25 November 2026; TechCrunch, "Todoist confirms 6% of customers’ details were stolen in data breach", 25 November 2026.

Ravindra Bagale's Tip

A salt is not enough. Ask your team one question: "Which hash do our oldest users still have?" If the answer is SHA-1 or MD5, upgrade at next sign-in and force a reset for the rest. Old hashes are a time bomb.

Check if you're safe: Password Strength Checker