3. OSI Model, TCP/IP Model, TCP vs UDP and the 3-Way Handshake
Chala mitrano, aaj aapan networking cha "map" shikuya – OSI aani TCP/IP models. Production madhe kahi bighadla ki changla engineer ghabrat nahi, to layer-by-layer check karto. Security madhe pan tasech – firewall kontya layer var kaam karto, WAF kontya layer var, Wireshark madhe kontya layer cha header disto – he sagla ya chapter nantar ekdum clear hoil. Ghabru naka, majhya sobat raha.
What you will learn in this chapter
- The seven OSI layers, their PDUs, protocols and devices
- Encapsulation (आवरण घालणे) and decapsulation
- The four-layer TCP/IP model and how it maps to OSI
- TCP vs UDP, and when each is used
- The TCP 3-way handshake, TCP flags and connection close
- What happens when you open a website – the favourite interview question
Concepts in this chapter
- 3.1The Seven OSI Layers
- 3.2Encapsulation and Decapsulation
- 3.3The TCP/IP Model and OSI Comparison
- 3.4TCP vs UDP
- 3.5The TCP 3-Way Handshake, TCP Flags and Connection Close
- 3.6What Happens When You Open a Website?
The chapter recap is at the end of the last concept page.
Chapter 3: OSI, TCP/IP, TCP vs UDP, 3-way handshake — practice tasks
Open chapter lessons · Full guided lab: watch dns and https traffic in wireshark (not repeated here)
3.1 See the TCP 3-way handshake with tcpdump
MediumITWhy: Attack logs talk about SYN floods and half-open scans. You must recognise SYN, SYN-ACK, ACK.
What: Capture the handshake when you curl a local web server.
How:
- Start
python3 -m http.server 8000 --bind 127.0.0.1. - Run
sudo tcpdump -i lo -n port 8000 -c 6. - In a third terminal run
curl -s http://127.0.0.1:8000/ >/dev/null. - Read the flags: [S], [S.], [.].
Expected output: Three lines in order: Flags [S], Flags [S.], Flags [.].
Hint
[S.] means SYN+ACK.
Answer / how to check
- The first three packets must be S, S., . between the same two ports.
3.2 Put incidents on the right OSI layer
EasyBankingWhy: Saying the right layer helps the right team fix it fast.
What: Use the data file and assign an OSI layer to each incident.
Data file: incidents.csv
| Incident | City |
|---|---|
| Cable cut to ATM | Chennai |
| ARP spoofing on branch LAN | Dubai (AED) |
| Wrong route to payment gateway | Singapore (S$) |
| SYN flood on port 443 | Hyderabad |
| SQL injection on login form | New York ($) |
About this file: Made-up incident list. Each row is one incident. Columns: Incident = what happened; City = where.
How:
- Read the 7 layers in the chapter.
- Match physical, data link, network, transport, application.
- Write the layer number next to each row.
Expected output: Cable 1, ARP 2, route 3, SYN flood 4, SQL injection 7.
Hint
ARP works with MAC addresses.
Answer / how to check
- Compare with the expected list; one mark per row.
3.3 TCP vs UDP with DNS lookups
MediumHealthcareWhy: DNS normally uses UDP; seeing it helps you spot DNS tunnelling later.
What: Capture one DNS query and see the protocol.
How:
- Run
sudo tcpdump -n -i any port 53 -c 4. - In another terminal run
dig example.com. - Then run
dig +tcp example.com.
Expected output: First lookup shows UDP packets; the +tcp lookup shows TCP flags [S].
Hint
tcpdump prints 'UDP' or flags for TCP.
Answer / how to check
- Two different transport types for the same question = correct.
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.
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.