33.7 Red vs Blue, Project and Real Incidents
Chala mitrano, hashing vs encryption, bcrypt/Argon2 vs MD5, AES-GCM, TLS 1.2/1.3, key management, certificates/PKI – aata Purple Team loop. Red OWN PHP lab app (kiwa Ch.16 reels app on OWN EC2) madhe weak MD5/no-salt password storage, hard-coded DB secret, kiwa weak TLS dakhavto; Blue password_hash bcrypt/Argon2 + secrets baher + TLS 1.2+ ne band karto. Tumhi Raja-Rani Traders style OWN lab madhe build → hack → fix karun Purple report liha. Algorithm nav aikun thambu naka – key ani config suddha. Samjla ka? Dusryacha site – kadhi nahi.
Red Team vs Blue Team – cryptography basics
| Red team (attacker) does | Blue team (defender) detects / stops |
|---|---|
| Crack OWN lab MD5 / unsalted password hashes (Hashcat/John awareness) | Store passwords with bcrypt / Argon2 (password_hash / password_verify); unique salt per user |
| Steal hard-coded DB password or API key from source / Git | Secrets in env / SSM / Secrets Manager; never commit keys; rotate after leak |
| Force or find weak TLS (old protocols, weak ciphers) on OWN HTTPS | TLS 1.2/1.3 only; disable SSLv3/TLS 1.0/1.1; sslscan / testssl.sh / nmap --script ssl-enum-ciphers |
| Abuse ECB / homemade crypto in a toy lab app | AES-GCM or ChaCha20-Poly1305 via standard libraries (OpenSSL, libsodium) |
| Ignore cert warnings / use expired or wrong-host certs in lab "forever" | CA-signed certs in real deploy; monitor expiry; fix hostname mismatch |
| Treat Base64 / encoding as "encryption" in notes or code | Teach encoding ≠ encryption; encrypt with a real key and AEAD mode |
Defender chi simple checklist: bcrypt/Argon2 for passwords → secrets out of code → AES-GCM (or libsodium) for data → TLS 1.2/1.3 + valid certs → no homemade crypto → re-prove with hash crack attempt fail + ssl scan clean. Red = weak crypto config on OWN app; Blue = fix + prove. Interview madhe "We used MD5 because it is fast" peksha "I migrated an OWN lab app from MD5 to password_hash bcrypt, moved the DB secret out of PHP, forced TLS 1.2+, and re-proved" jast strong.
# OWN lab only – Raja-Rani Traders (Nashik) PHP app / Ch.16 reels on YOUR EC2
mkdir -p ~/labs/raja-rani-crypto
# 1) BASELINE weak checks (OWN app only):
# # find MD5-style password storage in YOUR PHP (example pattern to search):
# grep -Rn "md5(" ~/labs/raja-rani-crypto/app --include='*.php' | tee ~/labs/raja-rani-crypto/md5-hits.txt
# # find hard-coded secrets (example):
# grep -Rn "password\s*=" ~/labs/raja-rani-crypto/app --include='*.php' | head
# # TLS surface on YOUR HTTPS site:
# nmap --script ssl-enum-ciphers -p 443 YOUR_EC2_OR_LAB_IP \
# | tee ~/labs/raja-rani-crypto/tls-before.txt
# 2) FIX examples (Blue – code YOU own):
# # PHP password storage (concept – put in your register/login):
# # $hash = password_hash($plain, PASSWORD_ARGON2ID); # or PASSWORD_BCRYPT
# # password_verify($plain, $hash);
# # Move DB secret to environment (example):
# # export RR_DB_PASS='...' # not inside config.php committed to Git
# # On Amazon Linux web host YOU own – after nginx/apache TLS edit:
# # sudo nginx -t # or: sudo apachectl configtest
# # sudo service nginx reload # or httpd
# # sudo yum update -y # stay current on OpenSSL / packages
# 3) RE-VERIFY:
# # old MD5 test hash should no longer be how new users are stored
# # nmap / sslscan again → only TLS 1.2+ ; weak protocols gone
# nmap --script ssl-enum-ciphers -p 443 YOUR_EC2_OR_LAB_IP \
# | tee ~/labs/raja-rani-crypto/tls-after.txt
echo 'Scope: Raja-Rani OWN PHP/EC2 lab – no third-party sites' \
> ~/labs/raja-rani-crypto/scope.txt
echo 'Fix: password_hash bcrypt/Argon2 | secrets out of code | TLS 1.2+' \
>> ~/labs/raja-rani-crypto/scope.txt
Ravindra Bagale's Tip
Students take an sslscan screenshot and stop there – but leave MD5 passwords and a hard-coded DB secret in the code. The second mistake: using Base64 as "encryption". Rule: OWN app only → find MD5/secret/weak TLS → fix with password_hash + env secrets + TLS 1.2+ → re-prove → Purple report. The crypto chapter is really a key management chapter. Don't worry, the checklist gets you there.
Ravindra Bagale's Tip – मराठी
Students sslscan screenshot घेऊन थांबतात – पण MD5 passwords आणि hard-coded DB secret code मध्ये ठेवतात. दुसरी चूक: "encryption" म्हणून Base64. Rule: OWN app only → find MD5/secret/weak TLS → fix with password_hash + env secrets + TLS 1.2+ → re-prove → Purple report. Crypto chapter = key management chapter. घाबरू नका, checklist ने जमते.
Ravindra Bagale's Tip – हिंदी
Students sslscan screenshot लेकर रुक जाते हैं – पर MD5 passwords और hard-coded DB secret code में रखते हैं. दूसरी गलती: "encryption" के नाम पर Base64. Rule: OWN app only → find MD5/secret/weak TLS → fix with password_hash + env secrets + TLS 1.2+ → re-prove → Purple report. Crypto chapter = key management chapter. घबराओ मत, checklist से आ जाता है.
Lab
Tumchya OWN PHP lab app (kiwa Ch.16 reels on YOUR EC2) madhe shodha: passwords MD5/unsalted aahet ka? DB password config.php madhe hard-coded aahe ka? nmap --script ssl-enum-ciphers -p 443 tumchya OWN HTTPS var weak protocol dakhavto ka? Mag ek fix: new users sathi password_hash (bcrypt/Argon2), secret environment variable madhe, TLS 1.2+ only. Notes ~/labs/raja-rani-crypto/. Dusryacha website scan nahi.
Project: Build it, hack it, fix it
Build: For fictional Raja-Rani Traders (Nashik shop web lab) on your own PHP app or Ch.16 reels stack on Free Tier EC2:
- Deliberately weak short-lived state: MD5 (or plaintext) password column for a test user only, or DB password in a committed
config.php, or TLS allowing an old protocol on the lab vhost - Scope file: app path / EC2 id / lab URL; written note that hashes and secrets are OWN test data only
- Ethics card: IT Act – crack only hashes you created; do not attack other people's HTTPS; no stealing real customer passwords
Hack (lab awareness – OWN systems only):
- Export or copy the weak test hash from your DB; show with John/Hashcat awareness (Ch.22) that MD5/unsalted falls quickly – lab hash only
- Point to the hard-coded secret in your repo as a finding (do not push real secrets to public Git)
- Run
ssl-enum-ciphers/sslscanagainst your HTTPS endpoint; list any TLS 1.0/1.1 or weak cipher
Do not run password crackers against third-party dumps you do not own, do not MITM real users, do not disable TLS on a shared production host.
Fix:
- Migrate login/register to
password_hash/password_verify(bcrypt or Argon2id); re-hash on next login or force reset for test users - Move DB/API secrets to environment variables or SSM/Secrets Manager; remove from Git history if they ever leaked
- Configure Nginx/Apache for TLS 1.2/1.3 only; valid certificate for the lab hostname;
sudo nginx -t/apachectl configtestthensudo service ... reload - Prefer AES-GCM / libsodium for any app-level secrets at rest; never roll your own cipher
Re-verify: New test user hash is not MD5; secret not in config.php; tls-after scan shows only modern protocols. 1-page Purple report for owners Raja and Rani: finding → crypto control → fix → evidence. Peer-review with Zoya / Salman. IT Act: only systems and data you own or are authorised to test.
Real incident: Heartbleed – OpenSSL CVE-2014-0160 (2014)
In April 2014, the Heartbleed bug in OpenSSL (CVE-2014-0160) became public. A bounds mistake in the TLS heartbeat extension could let a remote reader pull chunks of process memory from a vulnerable server or client – memory that could include private keys, session cookies, or passwords. Researchers at Google Security and Codenomicon publicly described the issue; operators worldwide raced to patch OpenSSL, revoke and reissue certificates, and rotate secrets that might have leaked. Weakness: critical crypto library implementation flaw + slow inventory of what still linked vulnerable OpenSSL. What would have reduced blast radius: fast patch pipelines for OpenSSL/NSS stacks, certificate and key rotation habits, and TLS configuration hygiene (this chapter's "stay current + TLS 1.2/1.3" line). Lab lesson: crypto is not only picking AES – library patching and key rotation are Blue work. Source: OpenSSL security advisory for CVE-2014-0160, heartbleed.com summary, and major CERT/vendor advisories (April 2014); verify current summaries.
Real incident: DigiNotar CA compromise (2011)
In 2011, Dutch certificate authority DigiNotar was compromised. Investigators and public reporting described fraudulent certificates issued under DigiNotar's trust – including certificates for Google domains – in an incident widely linked to use against users in Iran for HTTPS interception. Major browser and OS vendors distrusted DigiNotar's roots; the company filed for bankruptcy after the trust collapse. Weakness: CA / PKI compromise breaks the "padlock" story for everyone who trusted that CA – not a weak password on one shop site, but a broken issuer. What would have reduced harm: stronger CA security and auditing, faster revocation / distrust, certificate transparency style monitoring (later industry practice), and defence-in-depth so one bad cert is noticed. Lab lesson: your Raja-Rani TLS work includes who signed the cert, not only "HTTPS on". Source: DigiNotar / Fox-IT incident reporting (2011), Dutch government and browser-vendor distrust announcements, and contemporary major news summaries; verify current summaries.
Interview model (clean English): "I find MD5 or a hard-coded secret or weak TLS on my own lab app, switch to password_hash bcrypt or Argon2, move secrets out of code, force TLS 1.2 or 1.3, and re-prove with a clean ssl scan."
Thodkyaat: weak hash/TLS olakha, pan bcrypt/Argon2 + secrets baher + TLS 1.2+ + re-prove shika. Aata pudhe Bharatatle cyber kayde ani cyber crime complaint. Chala pudhe, mitrano!
Thodkyaat sangaycha tar
- Encoding changes format, hashing makes a one-way fingerprint, encryption hides data with a key.
- Use SHA-256 for integrity and bcrypt/Argon2 with salts for passwords; MD5 and SHA-1 are broken.
- Symmetric (AES) is fast with one shared key; asymmetric (RSA/ECC) uses a public and private pair.
- Signatures and certificates prove identity; TLS combines certificates, ECDHE and AES.
- Most real failures come from key management and old settings, not broken algorithms.
Samjla ka? Aata HTTPS, SSH ani password hash maagche shastra tumhala kalle. Pudhchya chapter madhe Bharatatle cyber kayde ani cyber crime complaint kashi karaychi. Chala pudhe, mitrano!