30 Mins

1. The OSI 7-Layer Architecture

Understanding the 7 Layers of the OSI Model

The Open Systems Interconnection (OSI) model is a conceptual framework that standardizes the functions of a telecommunication or computing system into seven distinct layers. By breaking down network communication, we can isolate issues and define protocols for each stage of the data transit.

The layers are categorized as follows: Physical (Layer 1), Data Link (Layer 2), Network (Layer 3), Transport (Layer 4), Session (Layer 5), Presentation (Layer 6), and Application (Layer 7). Each layer communicates only with its corresponding layer on another device, passing data down the stack on the sender's side and up on the receiver's side.

Security Operator Note: Remember the mnemonic 'Please Do Not Throw Sausage Pizza Away' to recall the layers from Physical to Application.
Text
# Using tcpdump to inspect physical/data link layer frame activity
tcpdump -i eth0 -nn -c 5
Visual Architecture Map • OSI 7-Layer Model vs. TCP/IP 4-Layer Stack
L7: Application HTTP, DNS, SSH, FTP
L6: Presentation SSL/TLS, JPEG, ASCII
L5: Session NetBIOS, RPC, Sockets
L4: Transport TCP (Segments), UDP
L3: Network IPv4, IPv6, ICMP, IPsec
L2: Data Link Ethernet, MAC, ARP, VLAN
L1: Physical Fiber, Twisted Pair, Signals
Application Layer Encapsulates Data & Formatting (OSI L5-L7)
Transport Layer Host-to-Host Flow & Ports (OSI L4)
Internet Layer Logical Addressing & Packets (OSI L3)
Network Access Layer Hardware Framing & Bits (OSI L1-L2)

Encapsulation and Decapsulation Process

Encapsulation is the process of wrapping data with protocol information at each layer of the OSI model. As data moves down the stack, each layer adds a header (and sometimes a trailer) containing control information. The unit of data changes names: Data (Apps) -> Segment (Transport) -> Packet (Network) -> Frame (Data Link) -> Bits (Physical).

Decapsulation is the reverse process: as the data travels up the receiver's stack, each layer strips away its corresponding header and processes the payload until the raw data is restored to the application.

Security Operator Note: Always inspect the PDU (Protocol Data Unit) size if you suspect fragmentation issues at the Network layer.
Python 3
import struct

def encapsulate_mock_packet(payload):
    # Simulate a 16-byte header prepended to data
    header = struct.pack('!I', len(payload))
    packet = header + payload.encode()
    return packet

print(f'Encapsulated Data: {encapsulate_mock_packet("HelloVoidX").hex()}')

Comparing the OSI Model vs the TCP/IP 4-Layer Stack

While the OSI model is a theoretical reference, the TCP/IP stack is the practical implementation used in modern networking. The TCP/IP model collapses the OSI's top three layers (Session, Presentation, Application) into one Application layer and combines Physical and Data Link into a 'Network Access' layer.

OSI LayerTCP/IP Layer
Application/Presentation/SessionApplication
TransportTransport
NetworkInternet
Data Link/PhysicalNetwork Access
Security Operator Note: Security professionals often use the OSI model to troubleshoot, even if the underlying hardware runs on the TCP/IP implementation.
Text
# Querying DNS (Application Layer) via terminal
dig google.com +short

Inspecting Protocol Headers

Analyzing protocol headers is vital for forensic analysis and identifying network anomalies. Using tools like Scapy in Python, we can craft or dissect raw packets to verify header fields like TTL (Time to Live) or sequence numbers.

Below is a demonstration of how to interpret raw byte streams from a TCP header capture.

Security Operator Note: When debugging, always filter by specific protocols in Wireshark (e.g., 'tcp.flags.syn == 1') to cut through the noise.
Python 3
import struct

# Mock TCP header: 20 bytes
raw_header = b'\x00\x50\x1f\x90\x00\x00\x00\x01\x00\x00\x00\x00\x50\x02\x72\x10\x00\x00\x00\x00'
header = struct.unpack('!HHIIBBHHH', raw_header)
print(f'Source Port: {header[0]}')
print(f'Dest Port: {header[1]}')

Knowledge Check

Ready to test your understanding of 1. The OSI 7-Layer Architecture?

Back