22. Password Attacks
Chala mitrano, aaj passwords cha vishay – hacking cha sarvat junaa pan aajhi sarvat prabhavi darvaja. Log weak passwords thevtat, reuse kartat, aani hech attacker la sarvat sopa marg deto. Aaj aapan shiku ki passwords kase todle jatat (cracking) aani services var kase try kele jatat (guessing) – aani sarvat mahatvacha, aapan swatahche aani users che passwords kase surakshit thevaycha. Punha ekda: sagle labs fakt tumchya lab machines var (Metasploitable 2, tumcha swatahcha server). Baherchya konatyahi account var nahi. Samjla ka? Chala suru!
What you will learn in this chapter
- How passwords are stored: plain text, hashing, salting
- Offline vs online password attacks
- Wordlists and rules; rockyou.txt
- John the Ripper: cracking captured hashes
- Hashcat: fast, GPU-based cracking and attack modes
- Hydra: online login testing against services
- Defences: strong hashing, account lockout, MFA and rate limiting
Lab scope for this whole chapter
Crack only hashes you captured from your own lab (Metasploitable 2, your own server) and run Hydra only against lab services. Trying passwords against anyone else's account, email or website is a crime under the IT Act, sections 43 and 66.
Concepts in this chapter
- 22.1How Passwords Are Stored
- 22.2Online vs Offline Attacks, and Wordlists
- 22.3John the Ripper: Cracking Hashes
- 22.4Hashcat: Fast GPU Cracking
- 22.5Hydra: Online Login Testing
- 22.6Defending Against Password Attacks
- 22.7Red vs Blue, Project and Real Incidents
- 22.8Password Spraying
The chapter recap is at the end of the last concept page.
Chapter 22: Password attacks — practice tasks
Open chapter lessons · Full guided lab: password manager and gmail 2 step verification (not repeated here)
22.1 Hash and crack a lab password
EasyITWhy: Understand why weak passwords fall.
What: Hash Summer2020 and crack it offline on your own file.
How:
echo -n 'Summer2020' | md5sum | tee hash.txthashcat -m 0 hash.txt /usr/share/wordlists/rockyou.txt --potfile-disable(or john).
Expected output: Cracked: Summer2020.
Hint
Never crack someone else's hashes.
Answer / how to check
- Output shows the clear password.
22.2 Compare hash speeds (paper + demo)
MediumBankingWhy: Slow hashes protect passwords even after a leak.
What: Time 1000 MD5 vs a few bcrypt hashes in Python.
How:
- Use hashlib.md5 in a loop of 1000, then bcrypt.hashpw with gensalt for 20 hashes; print both times.
Expected output: MD5 finishes in milliseconds; bcrypt is much slower.
Hint
Apps should use bcrypt/argon2, never MD5.
Answer / how to check
- bcrypt takes longer for far fewer hashes.
22.3 Turn on 2FA and a password manager
EasyHealthcareWhy: Even a cracked password fails without the second factor.
What: Set up a password manager and 2FA on an account you own.
How:
- Install Bitwarden or KeePassXC.
- Save a new long random password for a test account.
- Enable TOTP 2FA in the account settings.
Expected output: Login needs password + code.
Hint
Never share the recovery codes digitally.
Answer / how to check
- You can log in with the code from the app.
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)
- Write the lesson title, date and the exact lab target you are allowed to use.
- List three owned systems (VMs, apps, or cloud accounts) where this lesson applies.
- Run one safe check from the lesson on a lab system only. Paste the command and output.
- Write a two-sentence fix you would give a teammate.
- 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.
Extra depth
Re-read the original short section at the top of the page, then this expansion. Together they should exceed a solid lesson length. If anything still feels thin, add your own lab screenshot and a paragraph in your notebook — that personal evidence is what interviews ask for.
- Permission before tools.
- Patch and config before exploits.
- Logs and backups before blame.
- Teach one junior the warning from this page.