The Four Layers and What Lives at Each
Why the Model Matters for Security
The TCP/IP model groups network communication into four layers. Understanding which layer a protocol operates at is not academic — it determines which security controls can protect against which attacks. A firewall that filters at the network layer cannot inspect application-layer content. An intrusion detection system that monitors the transport layer cannot detect DNS tunneling.
Layer 1: Link Layer (Network Interface)
The link layer handles communication between devices on the same physical network segment. It deals with MAC addresses, Ethernet frames, and ARP (Address Resolution Protocol).
Protocols: Ethernet, Wi-Fi (802.11), ARP, PPP
Security concerns:
- ARP spoofing: ARP is stateless and unauthenticated. Any device on the local network can send an ARP reply claiming to be any other device. An attacker sends gratuitous ARP replies associating their MAC address with the gateway's IP, causing all traffic to flow through the attacker's machine (man-in-the-middle).
# Detect ARP spoofing: check for duplicate MAC addresses in the ARP cache
arp -a
# Look for multiple IP addresses mapped to the same MAC address
MAC flooding: An attacker sends frames with thousands of different source MAC addresses, filling the switch's MAC address table. When the table is full, the switch falls back to broadcasting all traffic, allowing the attacker to capture everything.
VLAN hopping: An attacker sends frames with double 802.1Q tags to jump from one VLAN to another, bypassing network segmentation.
Defenses: Dynamic ARP inspection (DAI), port security (limiting MAC addresses per port), static ARP entries for critical systems, 802.1X network access control.
Layer 2: Internet Layer
The internet layer handles routing and addressing across networks. It deals with IP addresses and determines how packets travel from source to destination.
Protocols: IP (IPv4, IPv6), ICMP, IPsec
Security concerns:
- IP spoofing: The source IP address in a packet header is trivially forgeable. An attacker sends packets with a spoofed source IP to evade IP-based access controls, hide their identity, or amplify DDoS attacks (reflection attacks).
# Detect IP spoofing: check for packets with internal source IPs arriving on external interfaces
# On a router or firewall:
# deny ip 10.0.0.0/8 any in outside
ICMP abuse: ICMP echo requests (ping) can be used for network reconnaissance, and ICMP redirect messages can manipulate routing tables. ICMP tunneling can exfiltrate data bypassing firewall rules that allow ICMP.
IP fragmentation attacks: Attackers craft fragmented packets that overlap or exceed the maximum packet size, causing the target's reassembly buffer to overflow (Ping of Death, Teardrop).
Defenses: Ingress/egress filtering (BCP 38) to block spoofed source addresses, ICMP rate limiting, IP fragmentation reassembly validation, IPsec for authentication and encryption.
Layer 3: Transport Layer
The transport layer provides end-to-end communication services. It deals with ports, connections, and reliability.
Protocols: TCP, UDP
Security concerns:
- TCP SYN flood: An attacker sends TCP SYN requests without completing the three-way handshake, exhausting the server's connection table. Each half-open connection consumes memory until the server cannot accept legitimate connections.
# Detect SYN flood: count half-open connections
netstat -n -p tcp | grep SYN_RECV | wc -l
# Or on Linux:
ss -n state syn-recv | wc -l
TCP session hijacking: An attacker predicts or captures a TCP sequence number and injects packets into an established session. If the attacker can sniff the traffic, they can take over the session.
Port scanning: An attacker probes for open ports to discover running services. SYN scans, FIN scans, and NULL scans each exploit different TCP behaviors to evade detection.
UDP flood: UDP is connectionless, so an attacker can flood a target with UDP packets to random ports, forcing the target to send ICMP port unreachable responses, consuming bandwidth and CPU.
Defenses: SYN cookies (allow the server to handle SYN floods without storing state), TCP sequence number randomization, stateful firewalls that track connection state, rate limiting.
Layer 4: Application Layer
The application layer provides services directly to user applications. It deals with data formats, sessions, and application-specific protocols.
Protocols: HTTP, HTTPS, DNS, SSH, FTP, SMTP, TLS/SSL
Security concerns:
This is where the majority of attacks occur because this is where the data is most valuable and the attack surface is largest:
- HTTP attacks: SQL injection, cross-site scripting, request smuggling, HTTP response splitting
- DNS attacks: DNS poisoning, DNS tunneling, DNS amplification
- TLS attacks: Downgrade attacks, certificate spoofing, heartbleed (OpenSSL vulnerability)
- Application-layer DDoS: HTTP floods that mimic legitimate traffic, making them harder to distinguish from real users
Defenses: Web application firewalls (WAF), input validation, TLS 1.3, DNSSEC, application-layer rate limiting, API gateways.
Why Layer Matters for Security Controls
The critical insight: a control at one layer cannot protect against attacks at another layer.
- A network-layer firewall (Layer 3) can block traffic to a specific IP and port, but it cannot detect SQL injection in an HTTP request (Layer 4).
- A WAF (Layer 4) can detect and block SQL injection, but it cannot prevent ARP spoofing on the local network (Layer 1).
- TLS (Layer 4) encrypts application data, but it does not prevent IP spoofing of the underlying packets (Layer 2).
- A host-based intrusion detection system that monitors system calls cannot detect a SYN flood at the network interface (Layer 3).
This is why defense in depth requires controls at multiple layers. No single control is sufficient because no single layer is the only attack surface.
Mapping Attacks to Layers and Selecting Defenses
From Attack Description to Layer to Defense
The practical skill is taking a described attack, identifying which layer it targets, and selecting the appropriate defensive control. Let's work through real scenarios.
Scenario 1: The Man-in-the-Middle on the Coffee Shop Wi-Fi
An attacker at a coffee shop sets up a rogue access point with the same SSID as the shop's Wi-Fi. Victims connect to the attacker's AP, and the attacker intercepts all traffic.
Layer: Link (Layer 1) — the attack exploits the wireless association process and ARP.
Why a higher-layer control does not help: TLS encrypts the application data, but the attacker can still see which sites you visit (through DNS queries and SNI), and if any traffic is unencrypted, the attacker reads it directly. TLS does not prevent the interception — it only limits what the attacker can read from intercepted traffic.
Appropriate defenses:
- VPN (creates an encrypted tunnel at Layer 3, protecting all traffic regardless of the wireless network)
- Certificate pinning (prevents the attacker from presenting a fake TLS certificate)
- HSTS (prevents SSL stripping downgrade attacks)
- 802.1X authentication (prevents unauthorized APs from joining the network)
Scenario 2: The DDoS Attack on the DNS Server
An attacker uses a botnet to flood a company's DNS server with queries, preventing domain resolution.
Layer: Application (Layer 4) — the attack targets the DNS protocol specifically, not the network connectivity.
Why a network-layer control is insufficient: A network-layer firewall can rate-limit traffic to the DNS server's IP, but it cannot distinguish legitimate DNS queries from malicious ones. Rate-limiting all DNS traffic blocks legitimate users along with the attack.
Appropriate defenses:
- DNS rate limiting (RRL — Response Rate Limiting) at the DNS server
- Anycast DNS (distributes queries across multiple geographically dispersed servers)
- DNS filtering (blocks queries to known malicious domains)
- Upstream DDoS mitigation (absorbs the flood before it reaches your network)
Scenario 3: The IP Spoofing Attack on the Firewall
An attacker sends packets with a spoofed source IP matching an allowed internal address, bypassing the firewall's IP-based access rules.
Layer: Internet (Layer 2) — the attack exploits the forgeable source IP address in the packet header.
Why an application-layer control does not help: The firewall makes its allow/deny decision based on the source IP before the application layer is even involved. By the time the application sees the request, the firewall has already allowed it through.
Appropriate defenses:
- Ingress filtering (BCP 38): block packets with internal source IPs arriving on external interfaces
- Stateful inspection: track connection state rather than just source IP
- IPsec authentication: cryptographically verify the source of each packet
- Unicast Reverse Path Forwarding (uRPF): verify that the source IP is reachable via the interface the packet arrived on
Scenario 4: The TCP Session Hijacking Attack
An attacker on the same network segment sniffs TCP traffic, predicts the sequence number, and injects a malicious packet into an established session.
Layer: Transport (Layer 3) — the attack exploits the predictability of TCP sequence numbers.
Why a link-layer control does not help: The attacker is on the same network segment, so link-layer controls (port security, 802.1X) have already been satisfied — the attacker is an authorized device on the network.
Appropriate defenses:
- TCP sequence number randomization (modern operating systems implement this)
- TLS encryption (the attacker can read the sequence numbers but cannot inject valid encrypted packets)
- Network segmentation (limits the attacker's ability to sniff traffic on other segments)
- Intrusion detection systems that detect anomalous sequence numbers
The Layer-Appropriate Defense Matrix
| Attack | Layer | Ineffective Defense | Effective Defense |
|---|---|---|---|
| ARP spoofing | Link | TLS encryption | Dynamic ARP inspection, static ARP |
| IP spoofing | Internet | WAF | Ingress filtering, uRPF, IPsec |
| SYN flood | Transport | Input validation | SYN cookies, stateful firewall |
| SQL injection | Application | Network firewall | WAF, parameterized queries |
| DNS tunneling | Application | Port blocking | DNS monitoring, egress filtering |
| MAC flooding | Link | Antivirus | Port security, switch configuration |
The pattern is clear: match the defense to the layer of the attack. A mismatched defense wastes resources and creates a false sense of security.
Practice: Analyze Your Network
For each service in your environment, ask:
- Which layer does this service operate at?
- Which layers are exposed to potential attackers?
- What controls exist at each exposed layer?
- Where are the gaps — layers with no controls?
The gaps are your highest-risk areas because they are the layers where an attacker can operate without detection.
Practice Problems
Solution
The firewall operates at Layer 3 (internet) and makes allow/deny decisions based on IP addresses and port numbers. It allows all traffic to port 443 because that is the port HTTPS uses. The buffer overflow exploit is in the TLS library, which operates at Layer 4 (application). The firewall cannot inspect the content of the encrypted TLS traffic — it only sees that the destination port is 443 and allows it through. The additional control needed is a web application firewall (WAF) or an intrusion prevention system (IPS) that can inspect application-layer content. However, since the traffic is encrypted, the WAF would need to be deployed as a TLS termination point (reverse proxy) to inspect the decrypted content. Alternatively, host-based controls like memory protection (ASLR, DEP) and patching the TLS library would prevent the exploit from succeeding. Solution
ARP spoofing targets Layer 1 (link layer). ARP is used to resolve IP addresses to MAC addresses on the same network segment, and it is stateless and unauthenticated — any device can send an ARP reply at any time. Higher-layer controls do not prevent it because: TLS encrypts application data but does not prevent the attacker from intercepting the traffic flow; a WAF inspects HTTP content but the attack occurs before any HTTP traffic is generated; an IDS may detect the spoofing if it monitors ARP traffic, but it cannot prevent it. The specific control that prevents ARP spoofing is Dynamic ARP Inspection (DAI) on the network switch, which validates ARP packets against a trusted database (DHCP snooping bindings) and drops invalid ARP replies. Static ARP entries for critical systems (like the default gateway) also prevent spoofing for those specific mappings. Quiz
1. An attacker floods a web server with HTTP POST requests containing SQL injection payloads. Which TCP/IP layer does this attack target, and why can't a network-layer firewall stop it?
2. Why does TLS encryption not prevent ARP spoofing?
3. A company implements ingress filtering (BCP 38) on its edge router to block packets with spoofed source IP addresses. Which type of attack does this specifically prevent?
Flashcards
Question
What are the four layers of the TCP/IP model?
Click to reveal answer
Answer
Link (Layer 1), Internet (Layer 2), Transport (Layer 3), Application (Layer 4).
Question
Which layer does ARP spoofing target and why?
Click to reveal answer
Answer
Link layer (Layer 1). ARP is stateless and unauthenticated — any device on the local network can send ARP replies claiming to be any other device, enabling man-in-the-middle attacks.
Question
Which layer does IP spoofing target and what is the primary defense?
Click to reveal answer
Answer
Internet layer (Layer 2). The source IP in a packet header is forgeable. Primary defense is ingress/egress filtering (BCP 38) to block packets with impossible source addresses.
Question
What is a SYN flood and which layer does it target?
Click to reveal answer
Answer
Transport layer (Layer 3). An attacker sends TCP SYN requests without completing the three-way handshake, exhausting the server's connection table. Defense: SYN cookies.
Question
Why can't a network-layer firewall prevent SQL injection?
Click to reveal answer
Answer
A network firewall makes allow/deny decisions based on IP addresses and port numbers. SQL injection is embedded in the HTTP payload at the application layer, which the firewall cannot inspect. A WAF is needed.
Question
What is the key principle for selecting security controls based on the TCP/IP model?
Click to reveal answer
Answer
Match the defense to the layer of the attack. A control at one layer cannot protect against attacks at another layer — this is why defense in depth requires controls at multiple layers.
Revision Notes
Key Takeaways
- 1. The TCP/IP model has four layers: Link, Internet, Transport, Application
- 2. Each layer has distinct protocols, attack types, and defensive controls
- 3. A security control at one layer cannot protect against attacks at another layer — this is the fundamental reason defense in depth is necessary
- 4. ARP spoofing (L1), IP spoofing (L2), SYN flood (L3), and SQL injection (L4) each require different defenses
- 5. Match the defense to the layer of the attack — a mismatched defense wastes resources and creates false security
- 6. Most real-world attacks target the application layer because that is where the valuable data resides
Interview Tips
- • When asked about a specific attack, identify which TCP/IP layer it targets before discussing defenses — this demonstrates systematic thinking
- • Be ready to explain why a control at one layer fails against an attack at another — this is a common interview probe
- • Discuss how you would design a multi-layer defense for a specific service, identifying controls at each layer
- • Connect the TCP/IP model to defense in depth — the model explains WHY multiple layers of controls are necessary
- • Give examples of attacks that span multiple layers (e.g., ARP spoofing to enable TLS stripping)
Cheat Sheet
The TCP/IP Model for Security Cheat Sheet
Phase: Networking for Security | Level: beginner
The Four Layers:
- Link (Layer 1): MAC addresses, Ethernet, ARP. Attacks: ARP spoofing, MAC flooding, VLAN hopping.
- Internet (Layer 2): IP addresses, routing, ICMP. Attacks: IP spoofing, ICMP abuse, fragmentation.
- Transport (Layer 3): TCP, UDP, ports. Attacks: SYN flood, session hijacking, port scanning.
- Application (Layer 4): HTTP, DNS, SSH, TLS. Attacks: SQLi, XSS, DNS poisoning, DDoS.
Key Principle:
A control at one layer CANNOT protect against attacks at another layer.
- Network firewall (L3) cannot detect SQL injection (L4)
- WAF (L4) cannot prevent ARP spoofing (L1)
- TLS (L4) cannot prevent IP spoofing (L2)
Attack-to-Defense Mapping:
| Attack | Layer | Defense |
|---|---|---|
| ARP spoofing | Link | DAI, static ARP, 802.1X |
| IP spoofing | Internet | Ingress filtering, uRPF |
| SYN flood | Transport | SYN cookies, stateful firewall |
| SQL injection | Application | WAF, parameterized queries |
| DNS tunneling | Application | DNS monitoring, egress filtering |
Practice Framework:
For each service: Which layer? Which layers are exposed? What controls exist? Where are the gaps?