Networking for Security Exercises
Eighteen exercises across the whole course. Most are hand calculations or short analyses of the kind you do during an investigation; try each before opening the answer. Two answers include a program that checks the hand work, which you can edit and run.
| # | Exercise | Practises |
|---|---|---|
| 1 | Read a frame header | Ethernet Frames and MAC Addresses |
| 2 | Which ARP message poisons the cache? | ARP on the Wire, ARP Spoofing |
| 3 | Can this frame hop? | VLANs, VLAN Hopping |
| 4 | An IPv4 header by hand | The IPv4 Header Byte by Byte |
| 5 | Is it in scope? | CIDR and Subnetting |
| 6 | A rogue Router Advertisement | IPv6 Basics |
| 7 | Spoofed or not? | Routing and Spoofed Sources |
| 8 | Read a traceroute | ICMP, Ping and Traceroute |
| 9 | Who was behind the NAT? | NAT |
| 10 | Sequence numbers | The TCP Header, The TCP Handshake |
| 11 | Flood or flash crowd? | SYN Floods and SYN Cookies |
| 12 | Amplification arithmetic | UDP and Amplification |
| 13 | Decode a DNS header | DNS Messages in Packets, DNS Spoofing |
| 14 | Two DHCP offers | DHCP and Rogue DHCP Servers |
| 15 | Protocol triage | HTTP, SSH vs Telnet, FTP, Mail, SMB, NFS, RDP |
| 16 | What does the ClientHello say? | TLS Records and the ClientHello, OpenSSL |
| 17 | Write the filters | Wireshark Display Filters, tcpdump and BPF |
| 18 | Read the scan and the sockets | Nmap, ss, ip and nftables |
Exercise 1: Read a frame header
A frame starts 01 00 5e 00 00 fb 02 00 00 0a 0a 21 08 00 45 …. Give the destination and source MAC, say whether each is unicast or group and universal or local, and name the payload.
Answer
Destination 01:00:5e:00:00:fb: 0x01 has the I/G bit set, so it is a group address (the IPv4 multicast range 01:00:5e, here for 224.0.0.251, mDNS). Source 02:00:00:0a:0a:21: unicast, locally administered (0x02). EtherType 0x0800: IPv4, and the next byte 0x45 confirms an IPv4 header with IHL 5.
Exercise 2: Which ARP message poisons the cache?
A host's cache has 10.10.0.1 → 02:00:00:0a:0a:01. It then receives, in order: (a) a request "who-has 10.10.0.20 tell 10.10.0.1" from …:01; (b) a reply "10.10.0.1 is-at …:66" that it never asked for; (c) a gratuitous ARP from …:01 for 10.10.0.1. What does a naive cache hold after each, and which message would dynamic ARP inspection drop?
Answer
(a) unchanged, the sender pair matches; (b) 10.10.0.1 → …:66, poisoned; (c) back to …:01, the real gateway re-announces itself. DAI drops (b), because (…:66, 10.10.0.1) isn't in the DHCP-snooping binding table. A detector would report (b) as a change and (c) as a flip-flop back.
Exercise 3: Can this frame hop?
An attacker sits on an access port in VLAN 30. The uplink trunk's native VLAN is 1, allowed VLANs 1, 10, 20, 30. The attacker sends a frame tagged 30 outside and 10 inside. Does it reach VLAN 10? What if the attacker's port were in VLAN 1?
Answer
From VLAN 30: no. The switch strips tag 30 (it matches the access VLAN) and sends the frame on the trunk tagged 30, because 30 isn't the native VLAN; the far switch delivers it to VLAN 30. From VLAN 1 with outer tag 1: yes, the outer tag is stripped and VLAN 1 is sent untagged, exposing tag 10. Fix: native VLAN on an unused ID or tagged, no users in VLAN 1.
Exercise 4: An IPv4 header by hand
Decode 45 00 00 3c 1c 46 40 00 3f 06 00 00 c0 00 02 0a 0a 0a 00 0a and compute the checksum that belongs in bytes 10–11.
Answer
Version 4, IHL 5 (20 bytes), total length 60, ID 0x1c46, flags 0x4000 = DF set, offset 0, TTL 63 (probably 64 minus one router), protocol 6 (TCP), source 192.0.2.10, destination 10.10.0.10. The checksum:
import struct
h = bytes.fromhex("4500003c1c4640003f060000c000020a0a0a000a") # checksum field zeroed
s = sum(w for (w,) in struct.iter_unpack("!H", h))
while s >> 16:
s = (s & 0xFFFF) + (s >> 16)
c = ~s & 0xFFFF
print(f"checksum 0x{c:04x}")
fixed = h[:10] + struct.pack("!H", c) + h[12:]
t = sum(w for (w,) in struct.iter_unpack("!H", fixed))
while t >> 16:
t = (t & 0xFFFF) + (t >> 16)
print("verifies:", t == 0xFFFF)checksum 0x5358
verifies: True
Exercise 5: Is it in scope?
Your written scope is 192.0.2.32/27 and 198.51.100.0/25, excluding 192.0.2.33. Which of 192.0.2.31, 192.0.2.33, 192.0.2.62, 192.0.2.64, 198.51.100.127, 198.51.100.128 may you scan?
Answer
/27 is 32 addresses, 192.0.2.32–63; /25 is 198.51.100.0–127. In scope: 192.0.2.62 and 198.51.100.127. Not in scope: .31 and .64 (outside the block), .33 (excluded), 198.51.100.128 (outside). Note that .62 is the last usable host and .127 is the broadcast address of its block; scanning a broadcast address is in scope but rarely useful.
Exercise 6: A rogue Router Advertisement
Hosts on an "IPv4-only" office LAN suddenly have addresses in 2001:db8:666::/64 and a default route via fe80::66. What happened, what is the risk, and what do you do?
Answer
Something on the LAN sent Router Advertisements (ICMPv6 type 134) with that prefix: a rogue RA, malicious or a misconfigured device. Hosts now send IPv6 traffic through fe80::66, unmonitored. Find its MAC in captures (icmpv6.type == 134) or neighbour caches, locate the switch port, enable RA Guard on access ports, and decide deliberately whether IPv6 is run (and monitored) or blocked.
Exercise 7: Spoofed or not?
A router has routes 0.0.0.0/0 via wan0, 10.10.0.0/16 via core0, 192.0.2.0/24 via dmz0. Classify with strict uRPF: (a) source 10.10.5.5 arriving on core0, (b) 10.10.5.5 on wan0, (c) 192.0.2.9 on core0, (d) 203.0.113.4 on wan0.
Answer
(a) accept; (b) drop, an internal (and private) address from the Internet; (c) drop, the route back to 192.0.2.9 is via dmz0; (d) accept. Loose mode would accept (a), (c) and (d), and drop (b) only with a bogon filter.
Exercise 8: Read a traceroute
lab-session$ traceroute -n 203.0.113.80
1 10.10.0.1 0.4 ms
2 * * *
3 * * *
4 203.0.113.80 12.0 msIs the destination reachable? What do lines 2 and 3 mean?
Answer
Yes, it answers at hop 4. Routers 2 and 3 forward traffic but don't send time-exceeded messages (or those are filtered), so their addresses stay hidden. It isn't packet loss.
Exercise 9: Who was behind the NAT?
NAT log excerpt (public address 203.0.113.7):
14:05:01 10.10.0.21:51010 -> 203.0.113.7:40220 to 198.51.100.80:443
14:05:01 10.10.0.37:52011 -> 203.0.113.7:40221 to 198.51.100.80:443
14:05:02 10.10.0.21:51011 -> 203.0.113.7:40222 to 192.0.2.25:22An abuse report says "203.0.113.7:40221 at 14:05:01 UTC". Which host? What if the report gave no port?
Answer
10.10.0.37. Without the port, the two connections at 14:05:01 can't be told apart (both to the same destination), so you would have to name two hosts or ask for the port. This is why NAT logs and abuse reports need ports and exact times.
Exercise 10: Sequence numbers
A client with ISN 7000 sends a SYN, then 300 bytes, then a FIN; the server's ISN is 1200 and it sends 50 bytes before its own FIN. Give the seq and ack of the client's FIN and of the last ACK.
Answer
The client's data occupies 7001–7300, so its FIN has seq 7301 and, after receiving the server's 50 bytes (1201–1250), ack 1251. The server's FIN has seq 1251; the client's last ACK has seq 7302 and ack 1252.
Exercise 11: Flood or flash crowd?
Two traffic spikes on a web server, each 5,000 SYNs per second. In spike A, 97 % of handshakes complete and the sources are 3,000 known ISP ranges. In spike B, 0.2 % complete and the sources are uniformly spread over the whole IPv4 space. Which is the attack, and which control helps?
Answer
B: almost no completed handshakes and random sources are spoofed SYNs. SYN cookies (or a SYN proxy) keep the server answering real clients; upstream filtering helps if the link fills. A is a legitimate flash crowd: scale out, cache, and don't block it.
Exercise 12: Amplification arithmetic
A reflector answers a 64-byte request with a 3,200-byte response. An attacker can send 50 Mbit/s of spoofed requests to 1,000 such reflectors. What factor, and what traffic reaches the victim?
Answer
Factor 3200 / 64 = 50. The victim receives about 50 × 50 Mbit/s = 2.5 Gbit/s, regardless of how the requests are spread across the reflectors. BCP 38 at the attacker's network would stop it at the source; rate limiting at the reflectors limits each one's share.
Exercise 13: Decode a DNS header
A response starts be ef 81 80 00 01 00 01 00 00 00 00. What does it say? Then: an attacker races a resolver that uses a fixed source port. How many forged responses give a 50 % chance in one race?
Answer
ID 0xbeef; flags 0x8180 = QR (response), RD, RA, rcode 0 (NOERROR); 1 question, 1 answer, no authority or additional records. With a fixed port only the 16-bit ID must be guessed: 32,768 forged responses (half of 65,536) for a 50 % chance in one race; with port randomisation about 2 billion (half of 65,536 × 64,512). DNSSEC validation makes the guess useless altogether.
Exercise 14: Two DHCP offers
A client's capture shows two OFFERs for its DISCOVER: from 10.10.0.2 (router 10.10.0.1, DNS 10.10.0.53, lease 1 day) and from 10.10.0.150 (router 10.10.0.150, DNS 10.10.0.150, lease 2 minutes), the second arriving first. What do you conclude, and which switch feature prevents it?
Answer
10.10.0.150 is a rogue DHCP server trying to become the client's gateway and resolver; the short lease keeps clients renewing with it. The client takes the first offer, so it is affected. DHCP snooping (server messages only from trusted ports) prevents it; find the port of 10.10.0.150's MAC and disconnect it.
Exercise 15: Protocol triage
A flow summary from a lab network shows connections to TCP 23, 21, 143, 445 (from the Internet), 3389 (from the Internet), 993, 22 and 587. Rank the top three problems and give the fix for each.
Answer
- 445 and 3389 reachable from the Internet: SMB and RDP are common initial-access routes; block at the perimeter, RDP only via VPN or a gateway with MFA.
- 23 (Telnet) and 21 (FTP): cleartext credentials; replace with SSH and SFTP.
- 143 (IMAP without implicit TLS): check that STARTTLS is required before login, or move clients to 993.
22, 587 and 993 are fine if configured well (keys, required TLS).
Exercise 16: What does the ClientHello say?
A ClientHello has record version 0x0301, legacy_version 0x0303, supported_versions 0x0304, 0x0303, SNI files.lab.test, ALPN http/1.1, and its JA4 begins t13d. Which TLS versions does the client support, where is it going, and what would openssl s_client -connect files.lab.test:443 -servername files.lab.test -verify_return_error tell you that the ClientHello can't?
Answer
TLS 1.3 and 1.2 (only supported_versions counts), to files.lab.test (SNI), speaking HTTP/1.1. The ClientHello says nothing about the server: s_client shows which certificate the server presents, whether it verifies against your CA and the name, and which version and suite were actually negotiated.
Exercise 17: Write the filters
Write (a) a Wireshark display filter for DNS responses other than NOERROR, (b) a BPF capture filter for TCP SYNs to port 445 from outside 10.10.0.0/24, (c) a display filter for HTTP requests that carry a cookie, (d) a display filter excluding all traffic of 10.10.0.10.
Answer
(a) dns.flags.response == 1 && dns.flags.rcode != 0; (b) 'tcp dst port 445 and tcp[tcpflags] & (tcp-syn|tcp-ack) == tcp-syn and not src net 10.10.0.0/24'; (c) http.request && http.cookie; (d) !(ip.addr == 10.10.0.10) (in Wireshark 3.6 and later ip.addr != 10.10.0.10 means the same).
Exercise 18: Read the scan and the sockets
On a lab server, nmap -sT -p 22,80,5432,9229 10.10.0.10 (from the admin network, within scope) reports 22 open, 80 open, 5432 filtered, 9229 open. ss -tln on the server shows 0.0.0.0:22, 0.0.0.0:80, 0.0.0.0:5432, 0.0.0.0:9229. Explain the difference for 5432 and say what to do about 9229.
Answer
PostgreSQL listens on all interfaces (ss), but a firewall drops the probe (filtered): the network layer protects it, the bind address doesn't. Bind it to the address it needs as a second layer. Port 9229 is typically the Node.js inspector, which gives code execution to anyone who reaches it: stop it or bind it to 127.0.0.1, and find out why it was running.
The check below runs the same comparison on the two views:
nmap = {22: "open", 80: "open", 5432: "filtered", 9229: "open"}
listening = {22: "0.0.0.0", 80: "0.0.0.0", 5432: "0.0.0.0", 9229: "0.0.0.0"}
approved = {22, 80}
for port in sorted(listening):
state = nmap.get(port, "not scanned")
if port not in approved and state == "open":
verdict = "FINDING: reachable and not approved"
elif port not in approved:
verdict = "listens on all interfaces, filtered by the network: bind it narrower"
else:
verdict = "approved"
print(f"{port:>5} bind {listening[port]:<8} scan {state:<9} {verdict}") 22 bind 0.0.0.0 scan open approved
80 bind 0.0.0.0 scan open approved
5432 bind 0.0.0.0 scan filtered listens on all interfaces, filtered by the network: bind it narrower
9229 bind 0.0.0.0 scan open FINDING: reachable and not approved
Practice problems for this course, with tests in 21 languages: Parse an IPv4 Address, Subnet Address Range, Is the Address in the Network?.
Test yourself
Which source MAC is impossible in a valid frame?
- 02:00:00:0a:0a:05
- 01:00:5e:00:00:fb
- 00:1b:21:aa:bb:cc
- 0a:0b:0c:0d:0e:0f
Which address is in 192.0.2.32/27?
- 192.0.2.31
- 192.0.2.62
- 192.0.2.64
- 192.0.2.96
A reflector sends 3,200 bytes for a 64-byte request. What is the amplification factor?
- 5
- 32
- 50
- 3136
Which tool output shows that a firewall, not the bind address, is protecting a port?
- ss shows 127.0.0.1:5432 and Nmap shows closed
- ss shows 0.0.0.0:5432 and Nmap shows filtered
- ss shows nothing and Nmap shows open
- Both show open
Which protocol pair in a flow summary is the most urgent finding?
- 22 and 993 from admin hosts
- 445 and 3389 reachable from the Internet
- 587 from mail clients
- 443 to a web server