Learn › Part 1 ยท Networking foundations

OSI model and layer-wise threats

The seven OSI layers, encapsulation hop by hop, and the typical attack and mitigation at each layer.

Why layering

The OSI model breaks network communication into seven layers so that each one can be designed, replaced and tested on its own. Four principles explain it: divide and conquer, encapsulation (each layer adds its own header and reads only its own), abstraction (a layer uses the service below without knowing how it works), and systematic troubleshooting (check layer by layer, bottom-up or top-down).

The seven layers at a glance

LayerPDUJobTypical protocols / devicesTypical attackMitigation
7 ApplicationMessageNetwork services for applicationsHTTP, DNS, SMTP, FTP, SSH, DHCPHTTP flood, SQL injection, XSSWAF, input validation
6 PresentationDataSyntax: translation, compression, encryptionTLS, JSON/XML/ASN.1, JPEGTLS downgrade, malformed input, XXEDisable old TLS, hardened parsers
5 SessionDataDialogue control, checkpoints, tokensRPC, NetBIOS, SOCKSSession hijacking, fixationRandom IDs, regenerate on login, Secure/HttpOnly
4 TransportSegment / datagramProcess-to-process delivery, ports, reliabilityTCP, UDPSYN flood, UDP amplification, port scansSYN cookies, rate limits, ACLs
3 NetworkPacketLogical addressing, routing, fragmentationIP, ICMP, IPsec, OSPF/BGP; routersIP spoofing, ping flood, BGP hijackuRPF, ICMP rate limits, BGPsec
2 Data linkFrameFraming, MAC addressing, FCS error detection, medium accessEthernet, Wi-Fi, ARP, PPP; switchesARP spoofing, MAC flooding, VLAN hoppingDAI, DHCP snooping, port security
1 PhysicalBitSignals, rates, topology, duplexCables, connectors, hubs, repeatersJamming, wiretapping, cable cutsPhysical security, shielded cable, WIPS

The data link layer has two sublayers: LLC (upper, interface to Layer 3) and MAC (lower, hardware addressing and access to the medium). In TCP/IP practice, Layers 5 and 6 are folded into the application layer: TLS libraries, cookies and JSON encoding all live in application code.

Encapsulation hop by hop

On the way down the sender's stack the message gains a transport header (ports), an IP header (source and destination IP) and a frame header and trailer (MACs and FCS). A router only goes up to Layer 3: it checks the FCS, strips the frame, reads the destination IP, looks up the next hop and builds a new frame.

FieldChanges at each router?
Source / destination MACYes: rewritten for every link
Source / destination IPNo (except where NAT is used)
Source / destination portNo
TTL and IP header checksumYes: TTL decremented, checksum recomputed

Worked example: what does a compromised router see?

Path S → R1 → R2 → R3 → server, payload protected by TLS. A compromised R2 sees the encrypted payload, the source and destination ports, the source and destination IPs, and the MAC addresses on its own links (R1's and R3's interfaces). It does not see the plaintext, because TLS encrypts only what sits above TCP.

Frame size check: 1,000 B of data + 20 B TCP + 20 B IP + 14 B Ethernet header + 4 B FCS = 1,058 B.

Logical versus physical addresses

A MAC address (48 bits) identifies an interface on the local link; an IP address (32 bits for IPv4) is logical and depends on the network the host has joined. Move a laptop between networks and its IP changes while its MAC normally stays the same (MAC spoofing is the exception).

Common pitfalls

  • Routers do not use ports to forward; ports belong to Layer 4.
  • CRC in the FCS detects errors; it does not correct them. A bad frame is dropped at that hop.
  • Layer 3/4 firewalls cannot see SQL injection in an allowed HTTPS session; that needs Layer 7 inspection.
  • Applications such as browsers sit above the OSI model; Layer 7 holds the protocols they use.