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
| Layer | PDU | Job | Typical protocols / devices | Typical attack | Mitigation |
|---|---|---|---|---|---|
| 7 Application | Message | Network services for applications | HTTP, DNS, SMTP, FTP, SSH, DHCP | HTTP flood, SQL injection, XSS | WAF, input validation |
| 6 Presentation | Data | Syntax: translation, compression, encryption | TLS, JSON/XML/ASN.1, JPEG | TLS downgrade, malformed input, XXE | Disable old TLS, hardened parsers |
| 5 Session | Data | Dialogue control, checkpoints, tokens | RPC, NetBIOS, SOCKS | Session hijacking, fixation | Random IDs, regenerate on login, Secure/HttpOnly |
| 4 Transport | Segment / datagram | Process-to-process delivery, ports, reliability | TCP, UDP | SYN flood, UDP amplification, port scans | SYN cookies, rate limits, ACLs |
| 3 Network | Packet | Logical addressing, routing, fragmentation | IP, ICMP, IPsec, OSPF/BGP; routers | IP spoofing, ping flood, BGP hijack | uRPF, ICMP rate limits, BGPsec |
| 2 Data link | Frame | Framing, MAC addressing, FCS error detection, medium access | Ethernet, Wi-Fi, ARP, PPP; switches | ARP spoofing, MAC flooding, VLAN hopping | DAI, DHCP snooping, port security |
| 1 Physical | Bit | Signals, rates, topology, duplex | Cables, connectors, hubs, repeaters | Jamming, wiretapping, cable cuts | Physical 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.
| Field | Changes at each router? |
|---|---|
| Source / destination MAC | Yes: rewritten for every link |
| Source / destination IP | No (except where NAT is used) |
| Source / destination port | No |
| TTL and IP header checksum | Yes: 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.