These are the notes for Cybersecurity Fundamentals (defensive), episode 25. Last time we built walls inside Ravi's network. Today his staff work from outside those walls, and his Wi-Fi leaks through them. One problem at a time, we invent the VPN (virtual private network) and tunnelling, IPsec with IKE, security associations, AH and ESP, transport mode and tunnel mode, site-to-site and remote-access VPNs, the SSL/TLS VPN, WireGuard, split tunnelling vs a full tunnel, then Wi-Fi security: why WEP is broken, WPA2-Personal and its pre-shared key (PSK), WPA3 and SAE, WPA-Enterprise with 802.1X, EAP and RADIUS, network access control (NAC), evil twins and rogue access points, and guest network isolation. Every term is explained the first time it appears, and the Glossary at the end defines them all again.
Ravi, Priya, Arjun, Meena, every network, address, password and key here are made up. Addresses are private (RFC 1918, like 10.1.0.5, 192.168.1.23) or documentation-only (RFC 5737, like 192.0.2.44, 198.51.100.1, 203.0.113.1). Everything is a toy simulation in plain Python: no packets are sent and no real network is touched. Every code sample runs with Python 3.13 using only the standard library; outputs are real, copied from actual runs.
The problems you'll solve
| Problem | Idea it teaches |
|---|---|
| Café Wi-Fi reads Priya's password | Untrusted network, sniffing, tunnel, encapsulation, VPN, VPN gateway |
| What exactly does the tunnel hide? | IPsec, IKE, security association, AH vs ESP, transport vs tunnel mode |
| Branches, people, blocked ports | Site-to-site VPN, remote-access VPN, SSL/TLS VPN, WireGuard |
| Should everything go through the office? | Split tunnelling vs full tunnel |
| The shop Wi-Fi reaches the car park | WEP (broken), IV reuse, WPA2, PSK, SSID, offline guessing, WPA3, SAE |
| Forty people, one password | WPA-Enterprise, 802.1X, EAP, RADIUS, NAC, quarantine VLAN |
| Fake networks and customers | Evil twin, rogue access point, server-certificate checks, guest network isolation |
Problem 1: the café Wi-Fi
Priya, Ravi's stock manager, works from a café two days a week, on its free, open Wi-Fi (no password). She logs in to the shop's stock server, an old app that only speaks plain HTTP (no encryption, episode 21).
On Wi-Fi, data travels as radio. Every device in range receives the signal. An untrusted network is any network you don't control and can't vouch for: café, hotel, airport, even your mobile operator's network. Assume anything you send across it can be read. Reading other people's traffic as it passes is called sniffing (episode 23).
Demo 1: what the café sees
The switch TUNNEL = False sends the request as it is.
import hashlib, hmac
KEY = b"ravi-vpn-demo-key" # shared by Priya's laptop and the office VPN gateway
def seal(data): # stand-in for AES-GCM: encrypt + tag (toy, never use)
stream = hashlib.sha256(KEY + b"stream").digest() * 8
ct = bytes(a ^ b for a, b in zip(data, stream))
return ct + hmac.new(KEY, ct, "sha256").digest()[:4]
inner = b"to 203.0.113.1:80 GET /stock?user=priya&pass=Ravi@123"
TUNNEL = False # <- send it as is, or through a VPN tunnel
if TUNNEL:
packet = b"to 203.0.113.1:51820 " + seal(inner).hex().encode()
else:
packet = inner
print("Anyone on the cafe Wi-Fi sees:")
print(packet.decode()[:60])
Output:
Anyone on the cafe Wi-Fi sees:
to 203.0.113.1:80 GET /stock?user=priya&pass=Ravi@123
Everything is visible: the server's address, the page, her username and her password. Why? Nothing protects the data on the untrusted part of the path. Fixing the old app will take months; we need something that protects every app at once.
The fix: a sealed courier pouch
| Sending office papers | A VPN |
|---|---|
| The papers inside, addressed to the stock room | The inner packet: Priya's original request |
| A locked pouch only head office can open, with a tamper seal | Encryption plus an integrity tag (AEAD, episode 12) |
| A courier label: "deliver to Ravi HQ", the only thing anyone can read | A new outer packet addressed to the VPN gateway |
- Encapsulation: putting one packet inside another as its data (episode 17).
- Tunnel: a path where packets travel encapsulated inside other packets, so the network in between only sees the outer packet.
- VPN (virtual private network): an encrypted tunnel across an untrusted network that makes a remote device or office behave as if it were plugged into the private network.
- VPN gateway: the device at the office end of the tunnel that decrypts packets and passes them inside (and does the reverse on the way out).
- VPN client: the software on the laptop or phone that builds the tunnel.
Demo 2: the same request, tunnelled
The same program with TUNNEL = True. The laptop seals the whole request and sends it in a new packet to the gateway on port 51820.
import hashlib, hmac
KEY = b"ravi-vpn-demo-key" # shared by Priya's laptop and the office VPN gateway
def seal(data): # stand-in for AES-GCM: encrypt + tag (toy, never use)
stream = hashlib.sha256(KEY + b"stream").digest() * 8
ct = bytes(a ^ b for a, b in zip(data, stream))
return ct + hmac.new(KEY, ct, "sha256").digest()[:4]
inner = b"to 203.0.113.1:80 GET /stock?user=priya&pass=Ravi@123"
TUNNEL = True # <- send it as is, or through a VPN tunnel
if TUNNEL:
packet = b"to 203.0.113.1:51820 " + seal(inner).hex().encode()
else:
packet = inner
print("Anyone on the cafe Wi-Fi sees:")
print(packet.decode()[:60])
Output:
Anyone on the cafe Wi-Fi sees:
to 203.0.113.1:51820 51a9c6ed103b1636041d412e827a6efe436fe26
Now the café sees only "Priya's laptop is talking to the office gateway", followed by random-looking bytes.
Honest warning.
seal()is a toy stand-in (a keystream from SHA-256 XORed with the data, plus a short HMAC tag) so the code fits on screen. It reuses the same keystream for every packet, which is exactly the nonce-reuse failure from episode 12. Real VPNs use vetted AEAD ciphers such as AES-GCM or ChaCha20-Poly1305 with a fresh nonce per packet.
What a VPN does not hide: the listener still sees that you are connected to the gateway, when, and how much data flows (the metadata). A VPN hides contents, not the fact of communication. And it only protects the path to the gateway; after that, traffic is as safe as the office network.
Problem 2: IPsec, IKE, AH and ESP
IPsec (IP security) is a family of standards that protects IP packets themselves, at the network layer, so every app above it is protected without changes.
Step 1: agree on keys with IKE
Before any data flows, the two ends run IKE (the Internet Key Exchange; the current version is IKEv2):
- Authenticate: both sides prove who they are, with certificates (episode 16) or a pre-shared key.
- Key exchange: they run Diffie-Hellman (episode 15) to agree on fresh secret keys that never cross the wire.
- The result is a security association (SA): the agreed keys, algorithms and lifetimes for one direction of traffic. SAs expire and are re-keyed regularly.
Step 2: protect packets with AH or ESP
| Protocol | Full name | Integrity (detects changes) | Confidentiality (hides contents) |
|---|---|---|---|
| AH | Authentication Header | Yes, including most of the outer IP header | No |
| ESP | Encapsulating Security Payload | Yes | Yes |
In practice, real VPNs use ESP almost always.
Step 3: choose a mode
- Transport mode: protects only the packet's data; the original IP header (real source and destination) stays. Used host to host.
- Tunnel mode: wraps the whole original packet (header included) inside a new packet between the two gateways. Used gateway to gateway and for remote access.
Demo 3: what an eavesdropper sees in each combination
# One packet: Priya's laptop -> the stock server. What does an eavesdropper on the path see?
packet = {"src": "10.8.0.21", "dst": "10.1.0.5", "data": "GET /stock"}
gateways = {"src": "gw-Pune", "dst": "gw-HQ"} # the two VPN gateways
def on_the_wire(protocol, mode):
hdr = gateways if mode == "tunnel" else packet # tunnel: a NEW outer header
inner = f"{packet['src']}>{packet['dst']} {packet['data']}" if mode == "tunnel" else packet["data"]
body = inner if protocol == "AH" else "<encrypted>" # AH signs, it does not encrypt
return f"{hdr['src']} -> {hdr['dst']} | {body}"
for protocol in ("AH", "ESP"):
for mode in ("transport", "tunnel"):
print(f"{protocol:3} {mode:9} {on_the_wire(protocol, mode)}")
Output:
AH transport 10.8.0.21 -> 10.1.0.5 | GET /stock
AH tunnel gw-Pune -> gw-HQ | 10.8.0.21>10.1.0.5 GET /stock
ESP transport 10.8.0.21 -> 10.1.0.5 | <encrypted>
ESP tunnel gw-Pune -> gw-HQ | <encrypted>
- AH, both modes: the request is readable. It's signed (nobody can change it unnoticed) but not secret.
- ESP transport: data hidden, but the real inside addresses are visible.
- ESP tunnel: only the two gateways are visible. Nobody on the path even learns which inside machine talks to which. This is why office-to-office VPNs use ESP in tunnel mode.
Three kinds of VPN
| Real life | VPN type | What it connects |
|---|---|---|
| A private rail line between two branches, always running | Site-to-site VPN | Two whole networks, gateway to gateway (Pune branch ↔ head office) |
| A staff cab that picks one person up when they need it | Remote-access VPN | One device (laptop, phone) to the office network |
| A cab that uses the ordinary road nobody stops | SSL/TLS VPN | A VPN that runs over TLS on port 443 (episode 22), so it works on networks that block other ports |
"SSL VPN" is the old name; the protocol underneath today is TLS (SSL is long deprecated).
WireGuard
WireGuard is a newer VPN built for simplicity:
- Each device has a key pair (like SSH keys); peers are configured by their public keys.
- The cryptographic algorithms are fixed and modern; there is no menu of old ciphers to misconfigure.
- The code is small. Its homepage says it is "meant to be comprehensively reviewable by single individuals", unlike much larger stacks such as IPsec and OpenVPN (The Register, 29 Jan 2020).
- It was merged into the Linux kernel for version 5.6 (2020); its developer is Jason Donenfeld.
This is economy of mechanism (episode 3) in action: fewer options mean fewer mistakes. WireGuard commonly uses UDP port 51820, the port in Demo 2.
Problem 3: split tunnelling
Priya's VPN is on. Should her video calls and news sites also travel all the way through the office? Split tunnelling means only traffic for the office networks goes through the tunnel; everything else goes straight to the internet. A full tunnel sends everything through the office.
Demo 4: route each connection
import ipaddress
OFFICE = ipaddress.ip_network("10.1.0.0/16") # the office networks behind the VPN
SPLIT = True # <- split tunnel, or send everything through it
def route(dst):
if not SPLIT or ipaddress.ip_address(dst) in OFFICE:
return "VPN -> office firewall"
return "direct via cafe Wi-Fi"
for name, dst in [("stock server", "10.1.0.5"), ("video call", "198.51.100.80"),
("news site", "192.0.2.44"), ("malware download", "203.0.113.66")]:
print(f"{name:16} {dst:14} {route(dst)}")
Output with SPLIT = True:
stock server 10.1.0.5 VPN -> office firewall
video call 198.51.100.80 direct via cafe Wi-Fi
news site 192.0.2.44 direct via cafe Wi-Fi
malware download 203.0.113.66 direct via cafe Wi-Fi
Output with SPLIT = False (full tunnel):
stock server 10.1.0.5 VPN -> office firewall
video call 198.51.100.80 VPN -> office firewall
news site 192.0.2.44 VPN -> office firewall
malware download 203.0.113.66 VPN -> office firewall
| Split tunnel | Full tunnel | |
|---|---|---|
| Speed and office bandwidth | Faster, lighter | Slower, heavier |
| Office firewall, egress rules, monitoring (episode 24) | Skipped for internet traffic | Applied to everything |
| Laptop's exposure | On the café network and the office network at the same time | Only the tunnel |
Common practice: a full tunnel for company-managed laptops, or a split tunnel only for a short allowlist of trusted services (like video calls), plus a strong host-based firewall on the laptop (episode 24).
Problem 4: WEP, WPA2 and WPA3
The staff Wi-Fi, RaviShop-Staff, connects the tills, tablets and laptops. Walls don't stop radio: the signal reaches the car park. So Wi-Fi itself must encrypt everything over the air.
- SSID (service set identifier): the Wi-Fi network's name, like
RaviShop-Staff. - Access point (AP): the radio device that devices connect to.
WEP: the first attempt, and why it's broken
WEP (Wired Equivalent Privacy) builds each packet's key from the Wi-Fi password plus a 24-bit IV (initialisation vector, episode 11) that is sent in the clear. A key + IV pair must never repeat; if it does, the same keystream encrypts two packets, and combining them cancels the key (the nonce-reuse failure from episode 12).
Demo 5: how soon does a 24-bit IV repeat?
import random
random.seed(7)
# WEP: every packet's key = the Wi-Fi password + a 24-bit IV (a number sent in the clear)
IV_BITS = 24
print("possible IVs:", 2 ** IV_BITS)
for trial in range(3):
seen = {}
for packet in range(1, 10**7):
iv = random.getrandbits(IV_BITS)
if iv in seen:
print(f"trial {trial + 1}: packet {packet} repeats the IV of packet {seen[iv]}")
break
seen[iv] = packet
Output:
possible IVs: 16777216
trial 1: packet 5197 repeats the IV of packet 2817
trial 2: packet 2872 repeats the IV of packet 116
trial 3: packet 7669 repeats the IV of packet 1941
Over 16 million possible IVs, yet the first repeat arrives after a few thousand packets: the birthday paradox (episode 13). Expected first repeat ≈ √(π/2 × 2²⁴) ≈ 5,134 packets. A busy network sends that many in seconds. WEP had further design flaws too. WEP is broken: never use it.
WPA2-Personal and the pre-shared key
WPA2 replaced WEP (via WPA) and uses AES encryption (in a mode called CCMP). In WPA2-Personal, everyone types the same Wi-Fi password, the pre-shared key (PSK).
The key is derived from the password and the SSID with PBKDF2 (the slow key-derivation function from episode 14, here 4,096 rounds of HMAC-SHA1). When a device joins, the 4-way handshake proves both sides know that key, using random numbers (nonces) sent in the clear. The encryption is strong, but a recorded handshake lets an eavesdropper test password guesses offline, as fast as their computer allows, without ever talking to the network again.
Demo 6: a defender's check on a made-up network
The "proof" is a simplified stand-in for what the handshake reveals. A tiny list of five common passwords is tried against two real passwords.
import hashlib, hmac
# WPA2-Personal: the key comes from the Wi-Fi password and the network name (SSID)
def pmk(password, ssid):
return hashlib.pbkdf2_hmac("sha1", password.encode(), ssid.encode(), 4096, 32)
SSID = "RaviShop-Staff"
nonces = b"AP-nonce|laptop-nonce" # sent in the clear during the handshake
for real_password in ["ravi1234", "tamarind-kettle-monsoon-42"]:
proof = hmac.new(pmk(real_password, SSID), nonces, "sha1").digest() # what a listener records
guesses = ["password", "12345678", "ravishop", "ravi1234", "welcome1"]
found = [g for g in guesses if hmac.new(pmk(g, SSID), nonces, "sha1").digest() == proof]
print(f"{real_password!r:29} guessed offline: {found[0] if found else 'no'}")
Output:
'ravi1234' guessed offline: ravi1234
'tamarind-kettle-monsoon-42' guessed offline: no
ravi1234 is found offline; the four-word passphrase isn't in any list. For WPA2-Personal, password length is the whole defence.
WPA3 and SAE
- The Wi-Fi Alliance released WPA3 on 25 June 2018 (BleepingComputer, 26 Jun 2018).
- WPA3-Personal replaces the PSK handshake with SAE (Simultaneous Authentication of Equals), a password-based key exchange that is "resistant to offline dictionary attacks": each guess needs a live exchange with the access point, which can slow guessers down.
- SAE gives forward secrecy (episode 15): learning the password later doesn't decrypt traffic recorded earlier.
- The new WPA2 certification also tests that devices are patched against KRACK, the key reinstallation attack against WPA2 (Mathy Vanhoef, 2018).
| WEP | WPA2-Personal | WPA3-Personal | |
|---|---|---|---|
| Encryption | RC4 + 24-bit IV | AES (CCMP) | AES |
| Joining | Shared key | PSK, 4-way handshake | SAE |
| Offline guessing from a recording | Trivial | Yes, if the password is weak | No (online only) |
| Forward secrecy | No | No | Yes |
| Verdict | Broken | OK with a long passphrase, AES only, patched | Use it where devices support it |
Problem 5: 802.1X, EAP, RADIUS and NAC
Forty staff share one Wi-Fi password, on a sticky note at the till. Arjun leaves the company and still knows it. Changing it means re-typing it on every till, tablet and laptop, so nobody does. A shared secret can't tell people apart, so you can't revoke one person.
| An office building | WPA-Enterprise |
|---|---|
| A turnstile that asks before letting you in | 802.1X: the access point lets no traffic through until the device has authenticated |
| Your own badge, one per person | EAP (Extensible Authentication Protocol): carries each person's own login, often a username and password inside a protected TLS tunnel (PEAP), or better a device certificate (EAP-TLS) |
| The security office's single list | RADIUS server: answers each login with accept or reject, and can say which VLAN to put the device in |
Together this is WPA2-Enterprise or WPA3-Enterprise. In 802.1X terms, the device is the supplicant, the access point is the authenticator, and the RADIUS server is the authentication server.
NAC (network access control) adds a check of the device itself, not just the person: is it patched, is its disk encrypted, is its antivirus running? Devices that fail go to a quarantine VLAN where they can only reach the update server.
Demo 7: a toy RADIUS server with NAC
# WPA2/WPA3-Enterprise: the access point asks a RADIUS server about EVERY person (802.1X)
USERS = {"priya": {"password": "long-pass-1", "role": "staff", "active": True}, # toy: real servers
"arjun": {"password": "long-pass-2", "role": "staff", "active": False}, # store hashes (ep 14)
"meena": {"password": "long-pass-3", "role": "admin", "active": True}}
VLAN = {"staff": 20, "admin": 30}
def radius(user, password, device):
u = USERS.get(user)
if not u or u["password"] != password or not u["active"]:
return "Access-Reject"
if not (device["patched"] and device["disk_encrypted"]): # NAC: check the device too
return "Access-Accept, VLAN 99 (quarantine: fix your device)"
return f"Access-Accept, VLAN {VLAN[u['role']]} ({u['role']})"
good = {"patched": True, "disk_encrypted": True}
for user, pw, dev in [("priya", "long-pass-1", good), ("arjun", "long-pass-2", good),
("meena", "long-pass-3", {"patched": False, "disk_encrypted": True}),
("meena", "long-pass-3", good)]:
print(f"{user:6} -> {radius(user, pw, dev)}")
Output:
priya -> Access-Accept, VLAN 20 (staff)
arjun -> Access-Reject
meena -> Access-Accept, VLAN 99 (quarantine: fix your device)
meena -> Access-Accept, VLAN 30 (admin)
- Priya: accepted into the staff VLAN 20.
- Arjun: rejected even with his old, correct password, because his account was switched off once, centrally.
- Meena: right password, but her laptop is unpatched, so NAC puts it in quarantine VLAN 99; once patched, she's in the admin VLAN 30.
(Toy shortcut: real RADIUS servers never store plain passwords; see episode 14.)
Problem 6: evil twins, rogue access points and guest networks
| A hotel lobby | Wi-Fi |
|---|---|
| A fake reception desk with the same sign and uniform | Evil twin: a fake access point broadcasting the same SSID (RaviShop-Staff), run by an attacker, so devices join it and their traffic flows through the attacker |
| A staff member opens a side door nobody guards | Rogue access point: an unapproved access point plugged into your own network, often by an employee wanting better signal; it skips every control |
| Real staff check the hotel's ID, not just the sign | Verify the server: Enterprise clients must be configured to check the RADIUS server's certificate, so a fake network fails |
Defences:
- WPA3-Enterprise / WPA2-Enterprise with server-certificate validation configured on every device (an unchecked certificate makes Enterprise Wi-Fi as easy to fake as the name).
- WPA3-SAE for personal networks, and always-on VPN on laptops that leave the office.
- Wireless intrusion detection (WIDS): scans the air for unknown access points and SSIDs that copy yours.
- 802.1X on wired switch ports too, so a plugged-in rogue device can't get onto the network.
Guest Wi-Fi, isolated
Customers want Wi-Fi too. Never give them the staff network.
- A separate guest SSID on its own guest VLAN (episode 24).
- A firewall rule: guest → internet only; nothing internal is reachable.
- Client isolation: guest devices can't talk to each other either, so a hacked phone in the queue can't reach the next customer's phone or Ravi's tills.
A guest network is simply a zone with one exit.
The next problem
Ravi now has firewalls, VPNs and strong Wi-Fi. But one phished password and an attacker is inside anyway: prevention is never perfect. Who notices? Next episode: intrusion detection and network monitoring.
The whole chain
- Café Wi-Fi reads the password → VPN tunnel, encapsulation, VPN gateway.
- Keys and protection → IPsec: IKE, SAs, AH vs ESP, transport vs tunnel mode.
- Branches vs people, blocked ports → site-to-site, remote-access, SSL/TLS VPN.
- Too many options → WireGuard.
- What goes through? → split vs full tunnel.
- Radio leaks → WEP (broken), WPA2 + PSK, WPA3 + SAE.
- One password, leavers → 802.1X, EAP, RADIUS, NAC.
- Fake networks, customers → evil twin / rogue AP defences, guest isolation.
...and you just invented secure remote access.
Common mistakes (and what they print)
| Mistake | What you see | Why it's wrong | Fix |
|---|---|---|---|
| Plain HTTP over café Wi-Fi | GET /stock?user=priya&pass=Ravi@123 |
Anyone on the network reads it | VPN tunnel, and HTTPS everywhere |
| IPsec with AH only | AH tunnel gw-Pune -> gw-HQ | ... GET /stock |
AH signs but doesn't encrypt | ESP in tunnel mode |
| Short WPA2 password | 'ravi1234' ... guessed offline: ravi1234 |
A recorded handshake allows offline guessing | WPA3-SAE, or a long random passphrase |
| One PSK for all staff | A leaver keeps access | You can't revoke one person | 802.1X + RADIUS, per-user logins |
| Split tunnel for everything | malware download ... direct via cafe Wi-Fi |
Internet traffic skips office controls | Full tunnel, or a small allowlist of exceptions |
| WEP still enabled on an old device | packet 5197 repeats the IV of packet 2817 |
24-bit IVs repeat within seconds | Replace the device; WPA3 or WPA2-AES |
| Enterprise Wi-Fi without certificate checks | Devices join an evil twin silently | The name alone proves nothing | Configure server-certificate validation |
Mini project: Ravi's wireless and remote-access auditor
A small checker that reads a (made-up) configuration and flags risky settings: WEP, old ciphers, short shared passwords, Enterprise without certificate checks, guest networks without isolation, AH-only IPsec and split tunnelling.
# Ravi's wireless and remote-access auditor: flags risky settings in a made-up config
NETWORKS = [
{"ssid": "RaviShop-Staff", "security": "WPA2-PSK", "cipher": "AES", "psk": "ravi1234", "vlan": 20},
{"ssid": "RaviShop-Tills", "security": "WPA3-Enterprise", "cipher": "AES", "verify_server_cert": True, "vlan": 40},
{"ssid": "RaviShop-Guest", "security": "WPA3-SAE", "cipher": "AES", "psk": "guest-tea-garden-77",
"vlan": 99, "client_isolation": False, "guest_internet_only": True},
{"ssid": "Old-Backroom", "security": "WEP", "cipher": "RC4", "psk": "12345", "vlan": 20},
]
VPN = {"protocol": "IPsec", "ipsec_protection": "AH", "mode": "tunnel", "split_tunnel": True}
def audit_network(n):
issues = []
if n["security"] == "WEP": issues.append("WEP is broken: replace with WPA3")
if n["cipher"] in ("TKIP", "RC4"): issues.append(f"{n['cipher']} cipher: use AES")
if "PSK" in n["security"] or "SAE" in n["security"]:
if len(n.get("psk", "")) < 16: issues.append("shared password shorter than 16 characters")
if "Enterprise" in n["security"] and not n.get("verify_server_cert"): issues.append("clients don't verify the RADIUS certificate")
if "Guest" in n["ssid"]:
if not n.get("client_isolation"): issues.append("guest client isolation is off")
if not n.get("guest_internet_only"): issues.append("guests can reach internal networks")
return issues
for n in NETWORKS:
issues = audit_network(n)
print(f"{n['ssid']:15} {n['security']:16} " + ("OK" if not issues else "; ".join(issues)))
vpn_issues = []
if VPN["protocol"] == "IPsec" and VPN["ipsec_protection"] == "AH": vpn_issues.append("AH only: traffic is not encrypted, use ESP")
if VPN["split_tunnel"]: vpn_issues.append("split tunnel on: internet traffic skips office controls")
print("VPN:", "; ".join(vpn_issues) or "OK")
Output:
RaviShop-Staff WPA2-PSK shared password shorter than 16 characters
RaviShop-Tills WPA3-Enterprise OK
RaviShop-Guest WPA3-SAE guest client isolation is off
Old-Backroom WEP WEP is broken: replace with WPA3; RC4 cipher: use AES
VPN: AH only: traffic is not encrypted, use ESP; split tunnel on: internet traffic skips office controls
Ideas to extend it: flag WPA2-PSK networks with a suggestion to move to WPA3; check that the guest VLAN differs from every staff VLAN; read the config from a JSON file.
Practice
1. Split tunnel with an allowlist. Change Demo 4 so only an approved video-call service (198.51.100.80) may skip the tunnel; everything else, including unknown internet sites, goes through the office.
Solution
import ipaddress
OFFICE = ipaddress.ip_network("10.1.0.0/16")
DIRECT_OK = {"198.51.100.80"} # an approved video-call service may skip the tunnel
def route(dst):
if ipaddress.ip_address(dst) in OFFICE or dst not in DIRECT_OK:
return "VPN tunnel -> office firewall"
return "direct (approved exception)"
for name, dst in [("stock server", "10.1.0.5"), ("video call", "198.51.100.80"),
("news site", "192.0.2.44"), ("malware download", "203.0.113.66")]:
print(f"{name:17} {dst:15} {route(dst)}")
Output:
stock server 10.1.0.5 VPN tunnel -> office firewall
video call 198.51.100.80 direct (approved exception)
news site 192.0.2.44 VPN tunnel -> office firewall
malware download 203.0.113.66 VPN tunnel -> office firewall
2. How much do more IV bits help? Using the birthday estimate √(π/2 × N), compute the expected packets until the first repeat for 24-, 48- and 96-bit IVs.
Solution
import math
# Expected packets until the first IV repeat is about sqrt(pi/2 * N) (birthday paradox)
for bits in (24, 48, 96):
n = 2 ** bits
print(f"{bits:2}-bit IV: {n:.3e} values, first repeat expected after ~{math.sqrt(math.pi / 2 * n):,.0f} packets")
Output:
24-bit IV: 1.678e+07 values, first repeat expected after ~5,134 packets
48-bit IV: 2.815e+14 values, first repeat expected after ~21,027,122 packets
96-bit IV: 7.923e+28 values, first repeat expected after ~352,776,567,612,016 packets
24 bits repeat within thousands of packets; 96 bits (the nonce size AES-GCM uses) practically never by chance, as long as nonces are generated correctly.
3. Expiring accounts. Give each RADIUS user an expiry date and reject expired accounts, like a contractor whose contract ended.
Solution
from datetime import date
USERS = {"priya": {"role": "staff", "expires": date(2027, 3, 31)},
"vendor-ac": {"role": "contractor", "expires": date(2026, 10, 31)}}
TODAY = date(2026, 11, 3)
def allowed(user):
u = USERS.get(user)
if not u: return "Access-Reject (unknown user)"
if u["expires"] < TODAY: return f"Access-Reject (account expired {u['expires']})"
return f"Access-Accept ({u['role']})"
for user in ["priya", "vendor-ac", "arjun"]:
print(f"{user:10} {allowed(user)}")
Output:
priya Access-Accept (staff)
vendor-ac Access-Reject (account expired 2026-10-31)
arjun Access-Reject (unknown user)
4. How strong is a random-word passphrase? If each word is picked at random from a 7,776-word list (6⁵, five dice rolls per word), each word adds log₂(7,776) ≈ 12.9 bits. Print the strength for 3 to 6 words, and generate an example with secrets.
Solution
import math, secrets
# A passphrase of random words: each word from a list of 7,776 adds log2(7776) bits
WORDS = ["tamarind", "kettle", "monsoon", "rickshaw", "mango", "lantern", "pepper", "harbour"] # demo list only
bits_per_word = math.log2(7776)
for n in (3, 4, 5, 6):
print(f"{n} words from 7,776: {n * bits_per_word:5.1f} bits")
print("example (from the tiny demo list):", "-".join(secrets.choice(WORDS) for _ in range(4)))
Output (the example line is random and changes every run):
3 words from 7,776: 38.8 bits
4 words from 7,776: 51.7 bits
5 words from 7,776: 64.6 bits
6 words from 7,776: 77.5 bits
example (from the tiny demo list): pepper-lantern-kettle-pepper
A 4-word passphrase from a big list beats ravi1234 by a huge margin, and is easier to type. The demo list has only 8 words, so its example is not strong: use a real 7,776-word list.
5. Concept check: which is which? For each, name the right tool: (a) the Pune branch must reach the head-office servers all day; (b) a salesperson's laptop on hotel Wi-Fi that blocks most ports; (c) you must remove one leaver's Wi-Fi access in one step; (d) customers in the shop want internet.
Solution
(a) A site-to-site VPN (IPsec ESP tunnel mode between gateways). (b) A remote-access VPN over TLS on port 443 (an SSL/TLS VPN). (c) WPA-Enterprise with 802.1X + RADIUS: disable the account centrally. (d) A guest SSID on a guest VLAN, internet only, with client isolation.
Quick quiz
Two offices are joined over the internet with IPsec. Which setting shows an eavesdropper the least?
- A: AH, transport mode
- B: AH, tunnel mode
- C: ESP, transport mode
- D: ESP, tunnel mode
Answer
D. AH never encrypts, so A and B show the data. ESP transport hides the data but reveals the real inside addresses. ESP tunnel encrypts the whole original packet and shows only the two gateways.
Interview questions
- What is a VPN, and what does it not protect? An encrypted tunnel across an untrusted network that encapsulates packets inside new packets to a VPN gateway. It hides contents on the path to the gateway, not the metadata (that you're connected, when, how much), and it doesn't protect traffic beyond the gateway or a compromised endpoint.
- AH vs ESP? AH (Authentication Header) gives integrity and origin authentication but no confidentiality; ESP (Encapsulating Security Payload) gives confidentiality and integrity. ESP is used almost everywhere.
- Transport vs tunnel mode? Transport mode protects the payload and keeps the original IP header (host to host). Tunnel mode encapsulates the whole original packet in a new header between gateways, hiding the inner addresses (site-to-site, remote access).
- What does IKE do? Authenticates the peers (certificates or a pre-shared key), runs Diffie-Hellman to derive fresh keys, and negotiates security associations (algorithms, keys, lifetimes), re-keying them regularly.
- Site-to-site vs remote-access VPN? Site-to-site joins two networks gateway to gateway, always on; remote-access connects a single device to a network on demand via client software.
- Why might you choose WireGuard? Small, auditable codebase, fixed modern cryptography with no negotiation of weak options, simple key-pair configuration, in the Linux kernel since 5.6.
- Split tunnelling: pros and cons? Pros: less office bandwidth, faster internet access. Cons: internet traffic bypasses corporate firewalls, egress filtering and monitoring; the device is simultaneously on an untrusted network and the corporate network. Mitigate with full tunnels or small allowlists plus endpoint controls.
- Why is WEP broken? Its 24-bit IV is too small and sent in the clear, so key streams repeat quickly (birthday paradox), and it has further design flaws in key handling and integrity.
- WPA2-Personal vs WPA3-Personal? WPA2-PSK derives the key from the password and SSID; a captured handshake allows offline dictionary attacks on weak passwords. WPA3 uses SAE, which resists offline guessing (each guess needs the AP) and provides forward secrecy.
- Explain 802.1X, EAP and RADIUS. 802.1X is port-based access control: the access point (authenticator) blocks traffic until the device (supplicant) authenticates. EAP carries the authentication method (e.g. EAP-TLS with certificates). RADIUS is the central server that decides accept/reject and can assign a VLAN.
- What is an evil twin and how do you defend against it? A fake AP with the same SSID that lures devices. Defend with Enterprise Wi-Fi plus enforced server-certificate validation, WPA3, always-on VPN, and wireless IDS scanning for impostor SSIDs.
- How should guest Wi-Fi be set up? Separate SSID and VLAN, firewall rules allowing internet only, client isolation, no access to internal networks, ideally rate-limited.
Glossary
| Term | Meaning in plain words | Example |
|---|---|---|
| Untrusted network | A network you don't control and can't vouch for | Café, hotel or airport Wi-Fi |
| Sniffing | Reading other people's traffic as it passes (episode 23) | The café sees Priya's password |
| Remote access | Reaching the office network from outside it | Priya working from a café |
| Encapsulation | Putting one packet inside another as its data | The inner request inside the outer packet |
| Inner / outer packet | The original packet / the new packet that carries it | to 203.0.113.1:51820 ... is the outer one |
| Tunnel | A path where packets travel encapsulated inside other packets | The courier pouch |
| VPN (virtual private network) | An encrypted tunnel across an untrusted network | Priya's laptop to the office |
| VPN gateway | The office end of the tunnel that decrypts and forwards | 203.0.113.1 |
| VPN client | Software on a device that builds the tunnel | The app on Priya's laptop |
| Metadata | Data about traffic: who, when, how much, not the contents | The café still sees "laptop talks to gateway" |
| AEAD | Authenticated encryption: secret and tamper-evident at once (episode 12) | AES-GCM, ChaCha20-Poly1305 |
| IPsec | A family of standards protecting IP packets at the network layer | A site-to-site office VPN |
| IKE / IKEv2 | Internet Key Exchange: authenticates peers and agrees keys for IPsec | Runs before any data flows |
| Security association (SA) | The agreed keys, algorithms and lifetimes for one direction of IPsec traffic | Re-keyed every few hours |
| Pre-shared key (PSK) | A secret both sides already know, typed in by hand | A Wi-Fi password; an IPsec shared secret |
| AH (Authentication Header) | IPsec protocol giving integrity only, no encryption | Readable but tamper-proof |
| ESP (Encapsulating Security Payload) | IPsec protocol giving encryption and integrity | <encrypted> in Demo 3 |
| Transport mode | Protects only the data; keeps the original IP header | Host to host |
| Tunnel mode | Wraps the whole original packet in a new header between gateways | Office to office |
| Site-to-site VPN | A VPN joining two whole networks, gateway to gateway | Pune branch ↔ head office |
| Remote-access VPN | A VPN connecting one device to a network | A laptop on hotel Wi-Fi |
| SSL/TLS VPN | A VPN that runs over TLS, usually on port 443 | Works where other ports are blocked |
| WireGuard | A small, modern VPN with fixed algorithms and key pairs; in Linux since 5.6 (2020) | UDP port 51820 |
| Key pair | A private key kept secret plus its public key (episode 15) | Each WireGuard peer has one |
| Economy of mechanism | Keep security designs small and simple (episode 3) | WireGuard's small codebase |
| Split tunnelling | Only office-bound traffic uses the VPN; the rest goes direct | Demo 4, SPLIT = True |
| Full tunnel | All traffic goes through the VPN | Demo 4, SPLIT = False |
| Wi-Fi | Wireless networking over radio | RaviShop-Staff |
| SSID | Service set identifier: a Wi-Fi network's name | RaviShop-Guest |
| Access point (AP) | The radio device that Wi-Fi devices connect to | The box on the shop ceiling |
| WEP | Wired Equivalent Privacy: the first Wi-Fi encryption, broken | Old backroom router |
| IV (initialisation vector) | A per-packet number mixed into the key so key streams differ (episode 11) | WEP's 24-bit IV |
| Keystream | The stream of key bytes XORed with data by a stream cipher | Repeats when IVs repeat |
| Birthday paradox | Repeats show up after about the square root of the number of possibilities (episode 13) | ~5,000 packets for 2²⁴ IVs |
| RC4 | An old stream cipher used by WEP; deprecated | "cipher": "RC4" in the mini project |
| WPA2 | Wi-Fi Protected Access 2: AES-based Wi-Fi security | RaviShop-Staff |
| CCMP | The AES-based encryption mode used by WPA2 | "AES" in router settings |
| TKIP | An older WPA cipher; avoid it | "WPA2-TKIP" in old routers |
| WPA2-Personal | WPA2 with one shared password (PSK) | A home router |
| 4-way handshake | WPA2's join exchange proving both sides know the key | What a listener records |
| PBKDF2 | A slow password-to-key function (episode 14) | 4,096 rounds in WPA2 |
| Nonce | A number used once (episode 12) | AP-nonce, laptop-nonce |
| Offline guessing (dictionary attack) | Testing many password guesses on a recording, without contacting the system | ravi1234 found in Demo 6 |
| Passphrase | A long password made of several words | tamarind-kettle-monsoon-42 |
| WPA3 | The Wi-Fi security standard released 25 June 2018 | WPA3-SAE |
| SAE | Simultaneous Authentication of Equals: WPA3's password handshake, resistant to offline guessing | WPA3-Personal |
| Forward secrecy | Old recorded traffic stays secret even if a long-term secret leaks later (episode 15) | SAE |
| KRACK | Key reinstallation attack against WPA2; fixed by patches | Keep devices patched |
| Wi-Fi Alliance | The industry group that certifies Wi-Fi devices and released WPA3 | WPA3 certification |
| WPA-Enterprise | WPA2/WPA3 with a separate login per person via 802.1X | RaviShop-Tills |
| 802.1X | Port-based access control: no traffic until the device authenticates | The turnstile |
| Supplicant / authenticator / authentication server | The device / the access point or switch / the RADIUS server in 802.1X | Laptop / AP / RADIUS |
| EAP | Extensible Authentication Protocol: carries the login method | EAP-TLS with certificates |
| EAP-TLS / PEAP | EAP with device certificates / EAP with a password inside a TLS tunnel | Certificates are stronger |
| RADIUS | A central server that accepts or rejects logins and can assign a VLAN | Demo 7 |
| Access-Accept / Access-Reject | RADIUS answers | arjun -> Access-Reject |
| NAC (network access control) | Checking the device's health as well as the person | Meena's unpatched laptop |
| Quarantine VLAN | A restricted network for devices that fail NAC | VLAN 99 |
| VLAN | A separate network on shared switches (episodes 23-24) | Staff VLAN 20 |
| Evil twin | A fake access point copying a real network's name | A fake RaviShop-Staff in the car park |
| Rogue access point | An unapproved access point plugged into your network | A staff member's own router |
| Server-certificate validation | Clients checking that the RADIUS server's certificate is the real one | Stops evil twins on Enterprise Wi-Fi |
| WIDS | Wireless intrusion detection: scans the air for unknown APs | Finds evil twins |
| Always-on VPN | A VPN the device starts automatically and keeps up | Laptops outside the office |
| Guest network | A separate Wi-Fi for visitors with internet-only access | RaviShop-Guest |
| Client isolation | Devices on the same Wi-Fi can't talk to each other | Guest phones can't reach each other |
| Host-based firewall | A firewall on the device itself (episode 24) | Protects a split-tunnel laptop |
Summary
- On an untrusted network, assume everything is read. A VPN encapsulates and encrypts every packet to a VPN gateway; it hides contents, not metadata.
- IPsec: IKE authenticates and agrees keys (Diffie-Hellman) into SAs; AH only signs, ESP encrypts; tunnel mode hides inner addresses. Use ESP tunnel mode.
- Site-to-site joins networks; remote-access joins one device; SSL/TLS VPNs ride on port 443; WireGuard keeps things small and fixed (Linux 5.6, 2020).
- Split tunnelling saves bandwidth but lets internet traffic skip office controls; prefer full tunnels or small allowlists.
- WEP is broken (24-bit IVs repeat within thousands of packets). WPA2-Personal is fine only with a long passphrase, because recorded handshakes allow offline guessing. WPA3 (25 June 2018) with SAE stops offline guessing and adds forward secrecy.
- WPA-Enterprise gives each person their own login: 802.1X + EAP + RADIUS, with NAC checking device health. Leavers are removed once, centrally.
- Defend against evil twins and rogue APs with certificate validation, WPA3, always-on VPN and wireless monitoring; isolate guest networks.
Next episode: intrusion detection and network monitoring: IDS vs IPS, signatures vs anomalies, false positives, NetFlow, PCAP, Suricata and Zeek, honeypots.
Sources: BleepingComputer (26 Jun 2018), "New WPA3 Wi-Fi standard released"; Mathy Vanhoef's blog (March 2018, updated 26 Jun 2018) on WPA3 and KRACK; The Register (29 Jan 2020), "WireGuard VPN will be in Linux 5.6 kernel". Code outputs from Python 3.13. Fetched 3 Nov 2026.