Lesson 1 of 4 Networking Fundamentals

The OSI and TCP/IP Models

Network models divide communication into layers, giving practitioners a shared language for where devices operate, where attacks occur and which controls apply. This lesson explains the OSI and TCP/IP models, encapsulation and the TCP and UDP transport protocols.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe the layers of the OSI model and example attacks at each.
  • Map the TCP/IP model to the OSI model.
  • Explain encapsulation.
  • Compare TCP and UDP.

Why layered models matter

Network communication involves many tasks: turning bits into signals, delivering frames on a local network, routing packets across networks, ensuring reliable delivery and presenting data to applications. Layered models divide these tasks so that each layer provides services to the one above and relies on the one below. For security, layers tell you what a device can see and control: a switch makes decisions on MAC addresses at layer 2, a router on IP addresses at layer 3, and a web application firewall on HTTP content at layer 7. Attacks are described the same way, such as a layer 2 ARP spoofing attack or a layer 7 application flood.

Sort into groups

Which OSI layer?

Exam skills 6.1.1

Place each device or protocol at its main OSI layer.

Log in to try this activity Interactive activities are free with an account.

The OSI model

The Open Systems Interconnection (OSI) model, published by ISO, has seven layers. The following table lists them with their data units, functions, example protocols and devices, and example attacks.

LayerData unitFunctionExamplesExample attacks
7 ApplicationDataNetwork services for applicationsHTTP, DNS, SMTP, SSHSQL injection, application floods
6 PresentationDataFormatting, encoding, encryptionTLS (often placed here), character encodingSSL stripping
5 SessionDataEstablishing and managing sessionsRPC, NetBIOS sessionsSession hijacking
4 TransportSegment (TCP) or datagram (UDP)End-to-end delivery, ports, reliabilityTCP, UDPSYN floods, port scanning
3 NetworkPacketLogical addressing and routingIP, ICMP, IPsec; routersIP spoofing, ICMP floods
2 Data linkFrameLocal delivery, MAC addressingEthernet, 802.11, ARP; switchesARP spoofing, MAC flooding, VLAN hopping
1 PhysicalBitsSignals on the mediumCables, radio, hubsTapping, jamming, cutting cables

A common memory aid from layer 1 upwards is "Please Do Not Throw Sausage Pizza Away".

The following diagram places three security events at their layers of the OSI model.

Placing three security events in the OSI model. Flooding a switch's MAC address table so it forwards frames to all ports is a layer 2 attack; a firewall rule blocking TCP port 23 is a layer 4 decision, typically with layer 3 addresses; and a web application firewall blocking a SQL injection string inspects HTTP at layer 7.
The scenario is illustrative.
Put in order

The OSI layers

Exam skills 6.1.1

Put the OSI layers in order from layer 1 to layer 7.

Log in to try this activity Interactive activities are free with an account.

The TCP/IP model and encapsulation

The TCP/IP model, on which the internet is actually built, has four layers. The network access (link) layer corresponds to OSI layers 1 and 2; the internet layer to layer 3 (IP); the transport layer to layer 4 (TCP and UDP); and the application layer to OSI layers 5 to 7.

As data moves down the layers on the sending host, each layer adds its own header, a process called encapsulation: application data is wrapped in a TCP segment with port numbers, then an IP packet with addresses, then an Ethernet frame with MAC addresses. The receiver removes the headers in reverse (de-encapsulation). Security tools inspect different headers: a packet filter reads IP and port fields, while deep packet inspection examines the payload.

TCP and UDP

The Transmission Control Protocol (TCP) is connection-oriented and reliable. It sets up a connection with the three-way handshake (the client sends SYN, the server replies SYN-ACK, the client sends ACK), numbers segments, acknowledges them, retransmits losses and closes connections with FIN or aborts them with RST. Applications that need complete, ordered data use it, such as web, email and file transfer.

The User Datagram Protocol (UDP) is connectionless: it sends datagrams without a handshake, acknowledgement or ordering, which makes it fast and suited to DNS queries, voice, video and streaming. Because there is no handshake, UDP source addresses are easy to spoof, which is why UDP services such as DNS and NTP are abused in reflection and amplification DDoS attacks.

TCP
ConnectionThree-way handshake
ReliabilityAcknowledged, ordered, retransmitted
Speed and overheadSlower, more overhead
Typical usesHTTP(S), SMTP, SSH, file transfer
Abused inSYN floods
UDP
ConnectionNone
ReliabilityBest effort
Speed and overheadFaster, less overhead
Typical usesDNS queries, VoIP, streaming, SNMP, DHCP
Abused inReflection and amplification attacks
Sort into groups

TCP or UDP?

Exam skills 6.1.1

Decide which transport protocol each statement describes.

Log in to try this activity Interactive activities are free with an account.
Worked example

Which layer?

Name the OSI layer of each: (1) an attacker floods a switch's MAC address table so it forwards frames to all ports; (2) a firewall rule blocks TCP port 23; (3) a web application firewall blocks a request containing a SQL injection string.

(1) MAC flooding is a layer 2 (data link) attack. (2) Filtering on a port is a layer 4 (transport) decision, typically combined with layer 3 addresses. (3) Inspecting HTTP content is layer 7 (application).

Worked example

Half-open connections

A web server's connection table fills with thousands of connections from many addresses that sent SYN and never completed the handshake. What is happening?

A SYN flood: the attacker exploits the TCP three-way handshake by sending SYNs, often with spoofed sources, so the server holds half-open connections and runs out of resources. Countermeasures include SYN cookies, which avoid reserving resources until the handshake completes, rate limiting, firewalls and upstream DDoS protection.

Check yourself

At which OSI layer does ARP spoofing operate?

Show answer

Layer 2, the data link layer, because it manipulates the mapping between IP addresses and MAC addresses on a local network.

Exam Tips

Remember for the exam

  • Switches: layer 2; routers: layer 3; WAFs and proxies: layer 7.
  • TCP/IP's four layers map to OSI 1-2, 3, 4 and 5-7.
  • TCP uses the SYN, SYN-ACK, ACK handshake; UDP is connectionless and easy to spoof.