zeroexploitable

The OSI Model: complete guide (free)

by @zeroexploitable · security, explained in 60 seconds

Yaad rakhne ka trick (top to bottom): All People Seem To Need Data Processing

7 layers at a glance

LayerNameKaam (job)PDUProtocolsDevices
L7ApplicationWhere apps talk to the networkDataHTTP/HTTPS, DNS, SMTP, FTP, SSHHosts, proxies, WAFs
L6PresentationFormats, encrypts and compresses dataDataTLS/SSL encryption, JPEG, ASCII, UTF-8Hosts
L5SessionOpens, keeps and closes conversationsDataNetBIOS, RPC, session tokensHosts
L4TransportSplits data, numbers it, delivers it reliablySegmentTCP, UDP, portsFirewalls, load balancers
L3NetworkAddresses and routes packets between networksPacketIPv4, IPv6, ICMPRouters
L2Data LinkMoves frames between devices on the same networkFrameEthernet, Wi-Fi (802.11), ARP, MAC addressesSwitches, bridges
L1PhysicalSends raw bits as signalsBitsCopper, fibre, radio (Wi-Fi), USBCables, hubs, repeaters

India Post analogy

Encapsulation (send dabate hi)

Attacks and defences per layer

LayerAttackDefence
L7 ApplicationPhishing, SQL injectionInput validation, MFA, WAF
L6 PresentationSSL strippingHTTPS everywhere, HSTS
L5 SessionSession hijackingSecure cookies, short session timeouts
L4 TransportSYN floodSYN cookies, rate limiting
L3 NetworkIP spoofingIngress filtering, ACLs
L2 Data LinkARP spoofingDynamic ARP inspection, port security
L1 PhysicalCable tapping, rogue devicesLocked network rooms, port control

OSI vs TCP/IP

TCP/IPOSI
ApplicationL7, L6, L5
TransportL4
InternetL3
LinkL2, L1

Note: OSI (ISO/IEC 7498-1) is a conceptual model. Real networks run TCP/IP; in practice TLS runs above TCP even though textbooks place encryption at L6.

Ports to know

SSH 22/TCP · DNS 53/UDP+TCP · HTTP 80/TCP · HTTPS 443/TCP

10 interview questions

  1. PDU at each layer? Data (L7-L5), Segment (L4), Packet (L3), Frame (L2), Bits (L1).
  2. Switch vs router? Switch: L2, forwards by MAC. Router: L3, forwards by IP.
  3. TCP vs UDP? TCP: connection-oriented, reliable, ordered. UDP: connectionless, lighter, no delivery guarantee.
  4. TCP 3-way handshake? SYN, SYN-ACK, ACK.
  5. SYN flood? Many SYNs, handshake never completed, half-open table fills. Defence: SYN cookies, rate limiting.
  6. ARP spoofing? Forged ARP replies map attacker MAC to another IP (MITRE ATT&CK T1557.002). Defence: Dynamic ARP Inspection.
  7. Which layer are ports? Transport (L4).
  8. Where do firewalls work? Packet filters L3/L4; next-gen firewalls and WAFs up to L7.
  9. OSI vs TCP/IP? TCP/IP has 4 layers: Application (5-7), Transport (4), Internet (3), Link (1-2).
  10. Why troubleshoot bottom-up? Lower layers fail cheaply and break everything above: cable, link, IP, then app.

Sources

ISO/IEC 7498-1 · Cloudflare Learning: What is the OSI model? · Codecademy OSI guide · Cloudflare: SYN flood · MITRE ATT&CK T1557.002, T1566


OSI Daily: roz ek layer. Follow @zeroexploitable on Instagram: https://www.instagram.com/zeroexploitable/