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

33. Cryptography Basics

33.6 Common Crypto Mistakes and Attacks

Mistake Why it is dangerous Fix
Storing passwords with MD5/SHA-1 or no salt Cracked quickly with Hashcat and rainbow tables bcrypt/Argon2 via password_hash()
Hard-coded keys in source code Anyone with the code has the key KMS, Secrets Manager, environment variables
Using ECB mode or old ciphers (DES, RC4) Patterns leak, known breaks AES-GCM or ChaCha20-Poly1305
Rolling your own crypto Subtle bugs you cannot see Use well-known libraries (OpenSSL, libsodium)
Old TLS versions, expired certificates Downgrade and MITM attacks TLS 1.2/1.3 only, auto-renew certificates
Weak random numbers Predictable tokens and keys Use a cryptographic random generator (random_bytes() in PHP)
Treating encoding as encryption Anyone can decode Encrypt properly

Common attack names you should recognise: brute force (try every key), dictionary/rainbow table (pre-computed hashes), man-in-the-middle (intercept and relay), downgrade (force weaker protocol), side-channel (leak through timing or power), and "harvest now, decrypt later" – the reason organisations are planning moves to post-quantum cryptography, which NIST began standardising in 2024.

Ravindra Bagale's Tip

Most crypto breaches happen not because an algorithm was broken, but because of key management mistakes – the key in the code, the key in an email, the key never rotated. Even with AES, if the key isn't looked after, everything is wasted.

Practice task

Review the PHP code of your reels app (Chapter 16) and find: how passwords are stored, where the DB password lives, how session tokens are generated and which TLS versions your server allows. Write one fix for each weakness you find, using the table above.

Crypto quick reference

Need Use
Check a file did not change SHA-256 (sha256sum)
Store user passwords bcrypt / Argon2 (password_hash())
Encrypt data at rest AES-256-GCM, keys in KMS
Share a secret with someone new Their public key (RSA/ECC) or ECDHE key exchange
Prove who sent it Digital signature with a private key
Secure a website TLS 1.2/1.3 with a CA-signed certificate

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.