Ethical Hacking Series, Part 9. Over Parts 6 to 8 we covered hardware, protocols, IP addresses and firewalls. The OSI model is the framework that ties all of it together. It splits network communication into seven layers, so you can say exactly where a piece of technology sits, and where an attack happens. In the second half of this post we build out the hacking lab with two practice targets: Metasploitable 3 and a Windows 10 virtual machine.
The seven layers
The OSI (Open Systems Interconnection) model describes networking as seven layers, each with its own job, from the application you see down to the cable or radio signal. Here they are from the top down.
Layer 7, Application. The protocols applications use directly, such as HTTP, HTTPS, FTP, SMTP and DNS. This is where your browser and the web server meet.
Layer 6, Presentation. Makes sure data is in a format both sides understand. It handles encoding, compression and encryption. SSL/TLS encryption is usually described here.
Layer 5, Session. Opens, manages and closes the conversations between two systems, for example keeping track of your logged-in session with a website.
Layer 4, Transport. Splits data into segments, adds port numbers so it reaches the right service, and decides how reliable delivery is: TCP or UDP, from Part 7.
Layer 3, Network. IP addresses and routing. Data becomes packets, and routers decide the path they take across networks (Part 8).
Layer 2, Data Link. Delivery within a local network using MAC addresses. Data becomes frames, switches forward them, and ARP maps IP addresses to MAC addresses (Part 6).
Layer 1, Physical. The actual bits on the medium: cables, connectors, hubs, fibre light and Wi-Fi radio signals.
Remembering the order
From Layer 1 up to Layer 7, the mnemonic is “Please Do Not Throw Sausage Pizza Away”: Physical, Data Link, Network, Transport, Session, Presentation, Application.
Encapsulation: down one side, up the other
When you send data, it travels down the layers from 7 to 1. Each layer wraps it with its own header: port numbers at Layer 4, IP addresses at Layer 3, MAC addresses at Layer 2. This wrapping is called encapsulation. The receiving machine goes the other way, up from 1 to 7, removing each header in turn until the application gets the original data.
That’s also what you’re looking at in Wireshark. When you click a packet, the panes show each layer’s header, from Ethernet (Layer 2) through IP (3) and TCP (4) to HTTP (7).
OSI vs TCP/IP
OSI is a teaching and troubleshooting model. The internet actually runs on the simpler TCP/IP model, which has four layers:
- Application (OSI Layers 5, 6 and 7)
- Transport (OSI Layer 4)
- Internet (OSI Layer 3)
- Network Access / Link (OSI Layers 1 and 2)
You’ll hear both in interviews and documentation. “Layer 7 load balancer” or “Layer 2 switch” always refer to OSI numbers.
Walking through a login, layer by layer
Here’s what happens when you open a website and log in:
- Layer 7: your browser sends an HTTP request containing your username and password.
- Layer 6: TLS encrypts it. The padlock in the address bar confirms this is happening.
- Layer 5: a session is set up, and after login the site gives you a session cookie that keeps you logged in.
- Layer 4: TCP carries it to destination port 443, from a random source port on your machine.
- Layer 3: IP adds your public IP and the server’s IP, and routers move the packets across the internet.
- Layer 2: on each hop, MAC addresses get the frame to the next device, starting with your router.
- Layer 1: the bits leave your laptop as Wi-Fi radio signals.
Why layers matter in security
Attacks target specific layers, and so do defences. Thinking in layers tells you what a control can and can’t stop. Some examples:
- Layer 7: SQL injection, cross-site scripting, phishing pages. A WAF works here.
- Layer 6: weak or outdated TLS, and attacks that strip encryption.
- Layer 5: session hijacking, where a stolen session cookie lets an attacker act as the logged-in user.
- Layer 4: port scanning and SYN floods. Security groups and firewalls filter by port here.
- Layer 3: IP spoofing and ICMP floods.
- Layer 2: ARP spoofing and MAC flooding on a local network.
- Layer 1: physical access, cable tapping and Wi-Fi jamming.
This is why a firewall that only checks ports (Layer 4) can’t stop an XSS payload sent over an allowed port 443 (Layer 7). We saw that in the AWS WAF post.
Building the lab: Metasploitable 3
Metasploitable 3 is a deliberately vulnerable machine built by Rapid7 for practising penetration testing. It’s full of weak configurations and old, exploitable services, so you can try attacks legally and safely.
In the video I download it, import it into VirtualBox (File → Import Appliance), set the network adapter to Bridged so it gets an address on my network, and boot it. Then I check that it’s reachable from Kali over SSH with its default credentials:
ssh vagrant@<metasploitable-ip>
The username and password are both vagrant.
A safety note that matters here: Metasploitable is meant to be hacked. On a bridged adapter, it’s visible to every device on your home or office network. Use it only on a network you trust, shut it down when you’re not practising, and never expose it to the internet. Once your lab is set up, a safer option is a VirtualBox Host-only or Internal network shared only by Kali and your targets.
Building the lab: a Windows 10 target
Real networks are full of Windows machines, so the lab needs one too. Download the Windows 10 ISO from Microsoft, then create a new virtual machine in VirtualBox:
- Type: Microsoft Windows, version Windows 10 (64-bit)
- Memory: 4 GB RAM
- Disk: 60 GB virtual hard disk (dynamically allocated, so it only uses space as it fills)
- Attach the ISO as the optical drive, then start the VM and run the installer
Windows 10 has reached end of support, so it no longer gets security updates. That makes it a realistic target for a lab, but another reason to keep it on an isolated lab network.
Practice tasks
- Write the seven layers from memory, then place these on the right layer: switch, router, TLS, port 22, ARP, session cookie, Wi-Fi signal.
- Capture any HTTPS request in Wireshark and identify the Layer 2, 3 and 4 headers.
- Import Metasploitable 3 and SSH into it from Kali.
- Install the Windows 10 VM, then find its IP with
ipconfigand ping it from Kali. If ping fails, remember the Windows firewall from Part 8.
A note on ethics: lab machines like these are the right place to practise attacks. Never point tools at systems you don’t own or have permission to test.
What’s next
With the lab ready, the series moves from networks to web applications. Part 10 covers how frontends, backends and databases fit together, and why pentesters care. For the networking foundations, see Part 6, Part 7 and Part 8, or go back to Part 1: Kali lab setup.
Watch Part 9 on my YouTube channel, Madhukar Reddy (@awsandevops).
