24. Traffic Sniffing and Analysis
Chala mitrano, aaj network cha "CCTV" shikuya – sniffing. Network var je packets jatat te vachta ale, tar khup kahi kalte: kon konashi bolto, konti service vaparli jate, ani – dhokyachi goshta – plain text madhla password suddha disto! Aapan Wireshark ani tcpdump ne he baghu, ani mag sarvat mahatvacha dhada gheu: mhanunach HTTPS garjeche aahe (Chapter 13 madhe aapan Certbot ne HTTPS lavla hota, aata ka te kalel). Sagle capture fakt tumchya swatahchya lab network var. Samjla ka? Chala suru!
What you will learn in this chapter
- What sniffing is, and why switches limit it (and ARP spoofing gets around it)
- tcpdump: capturing packets from the command line
- Wireshark: capturing and reading traffic in a GUI
- Display filters and following a TCP stream
- Seeing why HTTP leaks passwords and HTTPS does not
- ARP spoofing / man-in-the-middle in concept, and how to detect and prevent it
Lab scope for this whole chapter
Capture traffic only on your own lab network and machines. Sniffing someone else's traffic, or ARP-spoofing a network you do not own, is interception under the IT Act (sections 43 and 66) and a serious offence. Keep everything on the host-only lab.
Concepts in this chapter
- 24.1What Sniffing Is
- 24.2tcpdump: Command-Line Capture
- 24.3Wireshark: Reading Traffic in a GUI
- 24.4Display Filters and Following a Stream
- 24.5Why HTTP Leaks and HTTPS Protects; ARP Spoofing
- 24.6Red vs Blue, Project and Real Incidents
The chapter recap is at the end of the last concept page.
Chapter 24: Traffic sniffing and analysis — practice tasks
Open chapter lessons · Full guided lab: http vs https login wireshark why tls (not repeated here)
24.1 Capture a clear-text login
EasyITWhy: HTTP sends passwords as plain text.
What: Log in over HTTP on your lab and find the password in the capture.
How:
- Start nginx + a tiny login form over HTTP.
sudo tcpdump -i lo -A port 80 -c 30- Submit user=me password=Secret123.
Expected output: Secret123 appears in the capture.
Hint
Compare with the HTTPS lab.
Answer / how to check
- Password visible in ASCII dump.
24.2 Filter Wireshark for one host
MediumLogisticsWhy: Big captures need filters.
What: Capture and filter your VM's HTTPS.
How:
- Capture while browsing https://example.com.
- Display filter: ip.addr==YOUR_IP && tls.
- Follow → TLS Stream.
Expected output: Encrypted Application Data, not passwords.
Hint
TLS hides the content.
Answer / how to check
- You cannot read the password from the stream.
24.3 Spot DNS queries in a pcap
EasyHealthcareWhy: DNS shows which sites were contacted.
What: Extract DNS names from a short capture.
How:
sudo tcpdump -n port 53 -c 10 -w dns.pcapwhile you dig.tcpdump -n -r dns.pcap
Expected output: example.com (or your dig name) listed.
Hint
Useful in incident reviews.
Answer / how to check
- Queried name appears in the output.
Extended teaching notes
Why this lesson matters
Use this lesson to strengthen systems you own: understand the risk, practise safely in a lab, then write and apply the fix.
Apply the fix across stacks
Same class of bug, same idea in every language.
Java / Spring Boot
Parameterise queries, encode output, CSRF tokens, limited Actuator, dependency scanning.
ASP.NET Core
EF Core / parameterised SQL, Razor encoding, HTTPS, Data Protection.
Node.js / Express
helmet, parameterised SQL, npm audit, avoid eval and shell concat.
Python / Django / Flask / FastAPI
ORM, autoescape, pip-audit, Bandit; never shell=True with user input.
PHP / Laravel
PDO/Eloquent, Blade escaping, composer audit.
Go / Ruby
database/sql placeholders / ActiveRecord; html/template / ERB escaping; govulncheck / Brakeman.
nginx / Apache / Tomcat
Hide versions, TLS, security headers, least-open ports.
MySQL / PostgreSQL / MongoDB / Redis
Private networks, auth on, least-privilege users, no 0.0.0.0/0.
AWS / Azure / GCP
Roles not long-lived keys, private data stores, cloud audit logs on.
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.