Security Architecture

Objectives: By the end of this topic, you will be able to…

  • Identify weaknesses in network and system architecture
  • Use basic tools to validate network exposures
  • Apply secure design principles
  • Propose well-founded structural improvements
  • Implement a stateful, default-deny firewall with nftables and verify its behaviour from the attacker’s side

Principles of secure architecture

Security architecture consists of applying design principles that protect systems and networks from their conception. Three principles govern access and privilege: least privilege ensures that each component, process, or user has only the permissions strictly needed; separation of privilege requires more than one independent condition before access is granted (Saltzer and Schroeder’s original example, from their 1975 paper on protection, is a lock that needs two keys), so that a single stolen credential or a single faulty check is not enough, and the related idea of compartmentalization divides critical functions among different components so that compromising one does not grant control over all; and minimal exposure reduces the attack surface by limiting exposed services, open ports, and publicly accessible code.

Three additional principles build resilience into the design: defense in depth layers multiple independent security controls so that if one fails, another stops the attacker; fail-safe defaults ensure that in the event of an error the system denies access rather than granting it; and continuous auditing maintains logs of security events and monitors for anomalous behavior so that intrusions are detected and investigated promptly.

Question

A web application lets an administrator delete user accounts after entering their password, and also requires a second administrator to approve the deletion from a separate session. Which of the principles above does the second approval implement, and which one would a single “superadmin” role that can do everything violate? If you cannot tell the two apart, re-read the definitions of separation of privilege and least privilege.


Firewalls: fundamentals and operation

A firewall is a network security system that monitors and controls incoming and outgoing traffic based on predetermined security rules.

Types of firewalls

TypeDescriptionExample
Packet Filtering (Stateless)Examines individual packets in isolation by IP, port, protocolBasic nftables rules
Stateful InspectionTracks connection state, allows return traffic for established connectionsnftables with ct state
Application Layer (L7)Inspects packet content, understands HTTP/FTP/DNSWAF, proxy firewalls
Next-Generation (NGFW)Combines traditional firewall with IPS, DPI, SSL inspectionPalo Alto, FortiGate

Firewall architectures

A Bastion Host is a single hardened system that serves as the main external contact point, minimizing the exposed perimeter to one well-defended entry. A Screened Subnet (DMZ) uses multiple firewalls to create isolated network zones for public-facing services, separating them from the internal network. A Dual-Homed Host, in the classic firewall literature, is a computer with one interface in each of two networks and IP forwarding turned off, so traffic crosses only through proxy applications running on the host itself. A two-interface host that forwards packets and filters them with rules is instead acting as a screening router.

Firewall rule design principles

Default Deny (recommended): block all traffic by default, explicitly allow only necessary traffic. More secure, requires careful planning, reduces attack surface.

Rule ordering: rules are processed sequentially top to bottom, and the first rule that reaches a terminal verdict (accept or drop) ends evaluation for that packet. Not every statement is a verdict. In nftables, counter and log record that a packet passed and then let evaluation continue to the next statement and the next rule, and limit behaves as a condition: when its rate check fails, the rest of that rule is skipped and the packet moves on. A packet that reaches the end of a chain without any terminal verdict receives the chain’s policy, which in a default-deny design is drop. Statements inside a rule also run left to right, so log ... limit rate 5/minute logs every packet and only then checks the rate, while limit rate 5/minute log ... logs at most five packets a minute.

1. Allow SSH from admin subnet to server
2. Deny SSH from all other sources
3. Allow HTTP/HTTPS from anywhere to web server
4. Allow DNS from internal network to DNS server
5. Deny all other traffic (default deny)

Linux firewall tools

nftables — modern Linux packet filtering framework, in the mainline kernel since version 3.13 (2014) and the default filtering framework on Debian since Debian 10 “buster” (2019), which Kali inherits. Organizes rules in tables → chains → rules and supports named sets, verdict maps, and rate meters in a single unified tool, driven from the command line with nft:

nft add rule inet filter input tcp dport 22 accept
nft list ruleset

iptables — the older, widely-documented utility nftables replaces. Still present on many systems; the iptables-nft shim translates iptables commands to nftables internally. ufw (installed but disabled by default on Ubuntu) and firewalld (the default on RHEL and its derivatives, using nftables as its default backend) are higher-level managers that generate rules for you, and you will meet them on production servers.

Question

Before continuing, predict the effect of this nftables rule placed above an accept rule for port 22: tcp dport 22 log prefix "SSH: ". Does SSH still work? Now predict the effect of tcp dport 22 log prefix "SSH: " drop. If your two answers are the same, re-read the paragraph on terminal verdicts.


Connection tracking and netfilter hooks

A stateless filter judges every packet alone, which forces an uncomfortable choice: to let a server’s replies back in, you have to allow inbound traffic from any source port to every high port, and an attacker can forge packets that look exactly like replies. A stateful firewall avoids this by remembering connections. In Linux this memory is the connection tracking subsystem (conntrack), which records every flow it sees (source, destination, ports, protocol) and labels each packet with a state before your rules look at it.

Four states matter in practice. A packet is new when it starts a flow conntrack has not seen, such as a TCP SYN. It is established when it belongs to a flow that has already seen traffic in both directions, which covers every reply and every later packet of an accepted connection. It is related when it opens a new flow that belongs to an existing one, the most common case being an ICMP error (“port unreachable”, “fragmentation needed”) generated in response to an established connection. It is invalid when conntrack cannot fit it into any sensible flow: a TCP segment whose flag combination no legitimate stack sends, an unsolicited SYN-ACK, or a malformed header. This is why stateful rulesets almost always begin with two rules, one that drops ct state invalid and one that accepts ct state established,related. After those two lines, every remaining rule only has to decide which new connections are allowed, and replies are handled automatically. A default-deny policy on inbound traffic then no longer breaks the host’s own outbound connections, because their replies arrive as established.

chain input {
    type filter hook input priority 0; policy drop;
    ct state invalid drop
    ct state established,related accept
    tcp dport 443 accept          # the only new connection this host accepts
}

The second idea you need is where in the kernel a rule runs. Netfilter offers hooks at fixed points in the packet’s path, and an nftables chain attaches to exactly one of them. A packet addressed to the firewall host itself (an SSH session to the firewall, a ping to its interface) passes the input hook. A packet that arrives on one interface and leaves by another, because the host is routing it towards a different machine, passes the forward hook and never touches input. Packets the host generates itself pass output. A firewall that protects only itself needs an input policy; a firewall that protects a network behind it needs a forward policy, and the two are independent. If no chain is attached to a hook, netfilter accepts the packet at that point, so a gateway with a strict input chain and no forward chain protects itself and nothing behind it.

A Linux host only routes between its interfaces at all when IP forwarding is enabled (the net.ipv4.ip_forward kernel setting, off by default on most distributions). A filtering gateway is therefore the combination of two independent decisions: forwarding turned on, so packets can cross, and a forward chain with a default-drop policy, so only the permitted ones do. Turning on forwarding without the chain gives you a router, not a firewall.

Question

A server’s input chain has policy drop and accepts only new connections to TCP 443. From that server, you run a package update that downloads from the internet. Before reading on, decide which conntrack state the download’s reply packets carry and which rule accepts them. Then decide what would happen to the update if someone deleted the ct state established,related accept line. If you are unsure, re-read the paragraph defining the four states.


Rate limiting and firewall logging

Some traffic is legitimate in small amounts and hostile in large ones, and a firewall can only tell the two apart by counting. nftables does this with the limit expression, which implements a token bucket: the bucket refills at the stated rate (for example 3/minute), holds at most burst tokens, and each matching packet spends one. limit rate 3/minute burst 5 packets therefore allows an initial run of about five packets and then roughly one every twenty seconds. Adding over inverts the condition, so limit rate over 3/minute matches only the excess packets, which is the form you use when the rule’s verdict is drop.

The classic use is against online password guessing, where an attacker submits guesses to a live login service rather than cracking a stolen hash offline (the offline case, and why slow key-derivation functions defeat it, is in class 06). Every online guess on SSH costs at least one new TCP connection, so limiting new connections per unit of time caps the guessing rate. It slows an attacker from thousands of guesses a minute to a handful, but it cannot distinguish a correct guess from a wrong one and does nothing against an attacker who stays under the limit. A source allowlist, which refuses the connection outright, is a stronger network control, and host controls such as key-only authentication are stronger still. In practice you layer all of them.

Firewall logging has the same volume problem in reverse. A log statement writes a line to the kernel log for every packet it sees, so a single fast port scan against a rule that logs every drop can produce thousands of lines in seconds, burying the events you care about and filling the disk. A well-built ruleset therefore puts a limit in front of log and adds a counter to the rule, so the log keeps a representative sample while the counter keeps the exact total.

Example

Work through this on paper before continuing, ignoring TCP retransmissions for now. A rule reads tcp dport 22 ct state new limit rate over 3/minute burst 5 packets drop, and a password-guessing tool sends 16 SYN packets (each starting a new SSH connection) in the first second, then one SYN every second after that. How many of the first 16 SYNs are dropped? Roughly how many SYNs in the next minute get through? Write your two numbers down and check them against the token-bucket description above: the bucket starts with about 5 tokens, so about 5 of the first 16 pass and about 11 are dropped, and after that the bucket refills at one token every 20 seconds, so about 3 a minute pass. Then consider what a client does when its SYN is dropped, and why a real tool’s count would differ.


How a scanner reads a filtered host

Class 03 introduced -sS and the three port states open, closed and filtered; the three-way handshake underneath them is covered in class 15. Against a firewall, two more scan behaviours matter. A connect scan (nmap -sT) asks the operating system to open a full TCP connection to each port, needs no privileges, and is the scan an unprivileged user gets; because it completes the handshake, the target application can log it. A SYN scan sends only the first packet and needs raw-socket access, as class 03 explained.

A NULL scan (nmap -sN) sends TCP segments with no flags set at all, and its relatives send unusual combinations (FIN alone, or FIN with PSH and URG for the “Xmas” scan). These rely on a rule in the original TCP specification, RFC 793 (now superseded by RFC 9293): a closed port that receives a segment without SYN, RST or ACK answers with a RST, while an open port silently discards it. A scanner can therefore map closed ports by their RST and infer that silent ports are open|filtered, a fourth state meaning “either open, or a filter ate the probe, and nothing here can tell which”. Some stacks, notably Windows, send RST regardless of port state, which makes these scans useless against them. The scans were attractive historically because some stateless filters only inspected SYN packets and let everything else through.

No legitimate TCP stack sends a segment with no flags, with SYN and FIN together, or with SYN and RST together, so a firewall can drop them without any risk of breaking real traffic. On Linux a stateful firewall usually does so before any explicit flag rule runs: conntrack’s TCP handler classifies those flag combinations as invalid, so a ruleset that drops ct state invalid near the top of the chain has already discarded them. Against a default-drop firewall, then, the two scans tell the attacker different things. A SYN scan reports the dropped ports as filtered; a NULL scan reports every port as open|filtered and learns nothing at all.

Question

A host sits behind a stateful firewall whose rules drop ct state invalid first and log only the packets that reach the end of the chain. You run a SYN scan and a NULL scan against it. Predict, for each scan, the port state nmap will report for a port the firewall blocks, and whether the firewall’s log will show the probes. If you cannot predict the logging half, re-read the paragraph on invalid packets in the connection-tracking section.


Network zones (segmentation)

ZoneDescription
Public zoneAccessible from the internet (public web servers)
DMZIntermediate between internal network and outside, hosts public-facing services
Internal zone (intranet)Private network with restricted access for sensitive data
Management zoneExclusive network for system administration with strict access controls

Zones are only useful because the rules between them are directional. Traffic from a more trusted zone to a less trusted one (workstations browsing the web) is often permitted, while the reverse direction is denied unless a specific service needs it, and because the firewall is stateful, permitting one direction automatically admits the replies. Ingress filtering controls what enters a zone; egress filtering controls what leaves it, and it is easy to forget, even though it is what stops a compromised host from reaching an attacker’s server freely. If you have deployed to a cloud provider, you have already done this: a VPC subnet is a zone, and a security group is a stateful, default-deny rule set attached to it. The trust boundaries you drew on data-flow diagrams in class 04 are exactly the lines a firewall between zones enforces.

Within that structure, place databases, authentication servers and the management interfaces of every device in their own zones, reachable only from the specific hosts that need them. Rules between internal segments, and not only at the perimeter, are what restrict lateral movement, the step where an attacker who has compromised one host uses it to reach the next.

Question

A company’s firewall permits HTTPS from the internet to its DMZ web server and denies everything else inbound, but has no rules at all for traffic leaving the internal network. An attacker phishes one employee’s workstation. List two things the attacker can now do that egress filtering would have prevented, and one thing it would not. If you are not sure what “leaving” covers, re-read the first paragraph above.


Common architectural failures

Many breaches trace back to a small set of design failures that compound each other. Lack of segmentation places everything on a single flat network, so an attacker who compromises one host can reach all others with no friction. Unnecessary access (services or users with more permissions than their role requires) means that when one account is compromised, the damage radius is far larger than it needed to be. Exposed internal services such as databases or admin panels reachable from the internet hand attackers a direct path to the most sensitive parts of the system. Lack of monitoring lets these intrusions proceed undetected until the damage is severe. Poor default configurations, such as unchanged vendor passwords or unnecessary services left enabled, provide trivial initial footholds. Missing or misconfigured firewalls remove the fundamental traffic control layer entirely. And a single layer of defense means that defeating the perimeter firewall ends the contest, rather than being just the first obstacle in a series. Avoiding these failures is not a one-time design task: rule sets need regular audits to remove stale or overly permissive entries, intrusion detection should run alongside the firewall to catch what the rules permit, and firewall logs belong in a central store where they can be correlated with every other system’s logs.

Question

Pick two of the failures above and, for each, name the principle from the start of this class that it violates. Then decide which single failure in the list would most increase the damage of each of the others if it were also present, and justify your choice in one sentence; there is more than one defensible answer.


Hands-on lab

Requirements: 3 Kali Linux VMs — VM1: firewall/gateway (two NICs), VM2: web server, VM3: attacker

Working as a pair

You split this lab by machine. The firewall engineer drives VM1 and VM2 and owns the firewall’s rules, services and logs. The exposure tester drives VM3 and owns the attacker’s view of the network, which means the scans, the predictions and the timed attacks. Decide who takes which role before you start. You build the lab setup together; from Part 1 onward each step below is labelled with the role that performs it, and the points where you must hand something to your partner are marked Handoff.

If you each have a laptop and can connect them directly with an Ethernet cable, run VM1 and VM2 on the engineer’s laptop and VM3 on the tester’s, and in the table below attach VM1’s Adapter 1 and VM3’s Adapter 1 to Bridged Adapter on each laptop’s wired interface instead of net-external. Use a direct cable, not the classroom network, so your 10.10.0.0/24 segment does not collide with other pairs’. If you cannot connect two laptops, run all three VMs on one host and work side by side, each of you driving your own VM window; the roles and handoffs stay the same.

Lab setup

The three VMs simulate two network segments separated by a firewall. VM1 sits between them with one interface in each segment. VM2 is a server on the internal segment. VM3 is an attacker on the external segment.

Internet (external)          Firewall/Gateway            Internal network
                          ┌──────────────────┐
  VM3 (attacker)          │       VM1        │                        VM2 (web server)
  10.10.0.10 ─────── eth0                      eth1 ───────────────── 10.20.0.10
  gw: 10.10.0.1           │    10.10.0.1     │                        gw: 10.20.0.1
                          │    10.20.0.1     │
                          └──────────────────┘

VirtualBox network configuration

Create two isolated internal networks — one per segment: net-external and net-internal. In VirtualBox, go to each VM’s Settings → Network:

VMAdapterAttached toName
VM1Adapter 1Internal Networknet-external
VM1Adapter 2Internal Networknet-internal
VM2Adapter 1Internal Networknet-internal
VM3Adapter 1Internal Networknet-external

Note for VMware: use custom VMnet adapters (VMnet2, VMnet3) set to host-only with DHCP disabled, one per segment.

IP configuration

On each VM, assign a static IP. ip is the Linux tool for inspecting and configuring network interfaces, addresses and routes. Identify the interface names first with ip link, then edit /etc/network/interfaces or use nmcli (NetworkManager’s command-line client):

VM1 — eth0 (external):

sudo ip addr add 10.10.0.1/24 dev eth0
sudo ip link set eth0 up

VM1 — eth1 (internal):

sudo ip addr add 10.20.0.1/24 dev eth1
sudo ip link set eth1 up

VM2 — web server:

sudo ip addr add 10.20.0.10/24 dev eth0
sudo ip link set eth0 up
sudo ip route add default via 10.20.0.1   # firewall as gateway

VM3 — attacker:

sudo ip addr add 10.10.0.10/24 dev eth0
sudo ip link set eth0 up
sudo ip route add default via 10.10.0.1  # firewall as gateway

Verify connectivity before starting

Before touching any firewall rules, confirm the base network works. ping sends ICMP echo requests to a host and reports whether replies come back:

# From VM3: firewall external interface should respond
ping -c 2 10.10.0.1
 
# From VM2: firewall internal interface should respond
ping -c 2 10.20.0.1
 
# From VM3: VM2 should NOT be directly reachable (no routing yet)
ping -c 2 10.20.0.10

IP forwarding is disabled by default on Kali, so VM3 cannot reach VM2 until Part 2 enables it. Confirm that now: ping 10.20.0.10 from VM3 should time out. If it succeeds, check that VM1’s forwarding is off; cat prints a file’s contents, and this kernel file holds the forwarding setting:

# On VM1 — should print 0
cat /proc/sys/net/ipv4/ip_forward

These IPs are used throughout the lab. Wherever you see <webserver_IP>, substitute 10.20.0.10; wherever you see <attacker_IP>, substitute 10.10.0.10; wherever you see <firewall_IP>, substitute 10.10.0.1 (from VM3’s perspective) or 10.20.0.1 (from VM2’s perspective). This topology has only three machines, so VM2 doubles as the admin host, the one machine allowed to SSH into the firewall. In Part 1’s design that role belongs to a dedicated workstation in a management zone; here it is a compromise forced by the VM count, and your report should say so.

Part 1: Network design and planning

Read the following description of a small company’s infrastructure and use it to produce a network diagram and a firewall rule plan.


Scenario: A fintech startup runs a customer-facing web application and an internal operations team. The infrastructure has four zones separated by a single firewall/gateway:

  • Internet — untrusted external network. Customers access the web app from here. Attackers originate from here too.
  • DMZ — hosts one web server running HTTP and HTTPS. It must be reachable from the internet on those ports only. It also needs to reach an internal database to serve dynamic content.
  • Internal network — hosts employee workstations (192.168.10.0/24) and a database server (192.168.10.50). The database listens on port 5432. Only the web server should be able to query it — not workstations, not the internet.
  • Management zone — a single hardened admin workstation (10.0.0.5) used for SSH access to the firewall and the web server. No other host should be able to SSH into anything.

Additional constraints:

  • The firewall itself must not accept connections from the internet or the DMZ — only from the management zone.
  • Workstations need outbound internet access (HTTP/HTTPS) but should not accept inbound connections from any zone.
  • All inter-zone traffic not explicitly permitted is denied.

  1. Together: draw the network diagram. Include: zones, hosts with IPs, the firewall/gateway, and labeled arrows showing which traffic flows are permitted and in which direction.

  2. Together: identify the decisions the description leaves open, things it does not specify but that you have to resolve to write rules. Document each decision and justify your choice.

  3. Firewall engineer: design a firewall rule table with: Rule #, Source, Destination, Port/Protocol, Action, Justification. Apply default-deny at the end of each chain.

    Exposure tester, at the same time: from the scenario alone, list every attack path an outsider or a compromised internal host would try first: for each, the source, the target, the port, and what the attacker gains. Include at least one path that starts from a compromised DMZ web server.

  4. Handoff, rule table → tester: the tester checks every attack path against the engineer’s rule table and marks each one blocked (citing the rule number) or open. Hand the marked list back. The engineer revises the table to close any path that should not be open, or justifies in the table why it stays open. Submit both the revised table and the marked attack-path list.

Part 2: Basic nftables setup

nftables organizes rules in a three-level hierarchy: tables hold the ruleset for a given address family; chains attach to a netfilter hook (input, forward, output) and define the default policy; rules are the individual match-and-verdict statements evaluated top to bottom. You manage all of it with the nft command, which loads, lists and edits the kernel’s active ruleset.

The inet address family covers both IPv4 and IPv6 in a single table, which is the modern default.

  1. Firewall engineer: on VM1, enable IP forwarding and start the SSH server (sshd, which the ssh client on the other VMs connects to), which Kali does not run by default. tee writes its input to a file, which lets the write itself run under sudo; systemctl starts and stops system services; ss -tln lists listening TCP sockets, and grep keeps only the lines that contain a pattern, so together they confirm sshd is listening on port 22. Confirm no filtering ruleset is loaded yet: nft list ruleset should print nothing, or only empty chains with policy accept.
echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward
sudo systemctl start ssh
sudo ss -tln | grep ':22'
sudo nft list ruleset

Then start the web server on VM2:

sudo systemctl start apache2

Tell the tester the network is ready.

  1. Exposure tester: with no firewall rules loaded, measure the baseline exposure from VM3. nmap is the port scanner from class 03, and -oN saves its output to a file; curl fetches a URL and prints the response; nc -zv (netcat) attempts a TCP connection to a port and reports whether it succeeded, without sending data.
nmap -sT -p 1-1000 -oN baseline-webserver.txt <webserver_IP>
nmap -sT -p 1-1000 -oN baseline-firewall.txt <firewall_IP>
curl http://<webserver_IP>
nc -zv <firewall_IP> 22

Handoff, baseline → engineer: give the engineer both scan files. This is the exposure the ruleset must close.

  1. Firewall engineer: write the baseline ruleset to a file. nftables accepts a declarative configuration that can be loaded atomically, which is safer and more readable than issuing rules one at a time:
sudo tee /etc/nftables-lab.conf << 'EOF'
#!/usr/sbin/nft -f
 
flush ruleset
 
table inet filter {
 
    # Named set: hosts allowed to SSH into the firewall
    set admin_hosts {
        type ipv4_addr
        elements = { 10.20.0.10 }   # VM2 doubles as the admin host in this topology
    }
 
    chain input {
        type filter hook input priority 0; policy drop;
 
        iif lo accept                          # loopback always allowed
        ct state invalid counter drop          # drop malformed packets
        ct state established,related accept    # allow return traffic
 
        ip saddr @admin_hosts tcp dport 22 accept   # SSH from admin only
        counter limit rate 5/minute log prefix "NFT-INPUT-DROP: "
    }
 
    chain forward {
        type filter hook forward priority 0; policy drop;
 
        ct state established,related accept
 
        # Allow HTTP and HTTPS to the web server only
        tcp dport { 80, 443 } ip daddr <webserver_IP> accept
        counter limit rate 5/minute log prefix "NFT-FORWARD-DROP: "
    }
 
    chain output {
        type filter hook output priority 0; policy accept;
    }
}
EOF
  1. Firewall engineer: load the ruleset and verify it:
sudo nft -f /etc/nftables-lab.conf
sudo nft list ruleset          # inspect the active rules
sudo nft list set inet filter admin_hosts   # verify the named set

Handoff, ruleset → tester: give the tester the ruleset (a copy of the file or a screenshot of nft list ruleset).

  1. Exposure tester: before running anything, write a prediction table with one row per probe: Probe, Target, Predicted result, Rule responsible, Observed result. Fill in the first three columns from the ruleset alone. Then rerun the four commands from step 2 (saving to after-webserver.txt and after-firewall.txt) and fill in the Observed column. Hand any row where prediction and observation disagree to the engineer, who explains it in writing.

Question

Firewall engineer: Swap the ct state established,related accept rule with the SSH accept rule, reload, and open a new SSH session from the admin host. Predict first: does anything break? Restore the order, then comment out the ct state established,related accept line entirely, reload, and from VM1 run ping -c 2 <webserver_IP>. What happens to the ping, and which hook and which policy explain it? Restore the line. Why do stateful rulesets put this rule near the top even though moving it did not break SSH?

Question

Both: The engineer adds VM3 to the admin set directly, without editing the config file: sudo nft add element inet filter admin_hosts { <attacker_IP> }, and verifies with nft list set inet filter admin_hosts. The tester then tries SSH from VM3: does it work immediately? The engineer reloads the file with sudo nft -f /etc/nftables-lab.conf and the tester tries again. What happened to the element added manually, and why?

Question

Exposure tester: Using your baseline and after scans, which ports were reachable before the ruleset was loaded, and what changed after? Why does SSH to the firewall from VM3 now fail?

Question

Firewall engineer, then exposure tester: The ruleset defines an input chain and a forward chain. What is the difference between traffic that hits each one? Engineer: predict whether VM3 could still reach the web server if you deleted the forward chain entirely, then delete it and reload. Tester: verify with curl. Engineer: restore the chain.

Part 3: Rate limiting, anti-scan rules, and attack simulation

  1. Firewall engineer: extend the ruleset with brute-force and scan protections. Edit /etc/nftables-lab.conf. Add the three flag-anomaly rules below immediately after iif lo accept and before ct state invalid counter drop, and add the SSH rate-limit rule immediately above the ip saddr @admin_hosts tcp dport 22 accept line:
        # Drop TCP packets with flag combinations no legitimate stack sends
        tcp flags & (fin|syn|rst|psh|ack|urg) == 0x0 counter drop          # NULL scan
        tcp flags & (fin|syn) == (fin|syn) counter drop                    # FIN+SYN scan
        tcp flags & (syn|rst) == (syn|rst) counter drop                    # SYN+RST scan

        # Rate-limit new SSH connections: allow a burst of 5, then 3 per minute
        tcp dport 22 ct state new \
            limit rate over 3/minute burst 5 packets \
            counter log prefix "NFT-SSH-RATELIMIT: " drop

Then add <attacker_IP> to the admin_hosts elements in the file, so the line reads elements = { 10.20.0.10, 10.10.0.10 }. For this part, treat VM3 as a host that is legitimately allowed to reach SSH (a remote administrator’s laptop, say) whose credentials an attacker is guessing. A source allowlist alone would stop Hydra outright, as you saw in Part 2; this part tests what remains when the allowlist has to admit the source.

Reload atomically:

sudo nft -f /etc/nftables-lab.conf

Question

Firewall engineer: The config file starts with flush ruleset. Introduce a deliberate syntax error somewhere in the file and try reloading. Does the flush take effect before nftables hits the error, leaving you with no rules at all? Fix the error, reload cleanly, then explain why atomic loading matters on a system that must stay protected during updates.

Handoff, extended ruleset → tester: give the tester the updated ruleset. The tester adds rows to the prediction table for the SYN scan, the NULL scan and the brute-force run, predicting the port states nmap will report, the log prefix (if any) each attack will produce, and roughly how many passwords Hydra will manage per minute.

  1. Firewall engineer: start monitoring on VM1 before the tester attacks, and keep both views open for the whole of step 3. journalctl reads the system journal: -k restricts it to kernel messages, where nftables writes its log lines, and -f follows new lines as they arrive. tail -f follows a log file the same way.
sudo journalctl -kf | grep NFT
# or, if writing to syslog:
sudo tail -f /var/log/syslog | grep NFT

Also watch the rule hit counters update live; watch reruns a command every N seconds:

watch -n 1 'sudo nft list ruleset'

For each attack window the tester announces, note which log prefixes appeared and which counters moved, and by how much.

  1. Exposure tester: launch the attacks from VM3, one at a time. Run date, which prints the current date and time, immediately before and after each attack and record both times in your attack log, so the engineer’s log lines can be matched to your commands. Tell the engineer when each attack starts.

    Hydra is an online password-guessing tool: it opens login sessions against a network service and tries each password from a wordlist in turn. gunzip decompresses a .gz file in place; Hydra reads its wordlist as plain text, so the compressed file has to be expanded first. The -V flag prints every login attempt so you can count them.

# Stealth SYN scan and NULL scan
sudo nmap -sS -T4 <firewall_IP>
sudo nmap -sN -T4 <firewall_IP>
 
# Decompress the wordlist once (Kali ships it gzipped)
sudo gunzip /usr/share/wordlists/rockyou.txt.gz
 
# SSH brute force; -V prints each attempt. Stop it with Ctrl+C after two minutes.
hydra -V -l root -P /usr/share/wordlists/rockyou.txt ssh://<firewall_IP>
  1. Both: shadowing experiment. The engineer moves the three flag-anomaly rules below ct state invalid counter drop and reloads with sudo nft -f /etc/nftables-lab.conf; reloading recreates every rule from the file, so all counters start again from zero. The tester reruns only the NULL scan, recording start and end times. The engineer records which counter moved. Restore the original order afterward.

  2. Both, handoff, attack log + firewall observations → correlation table: join your two records into one table with these columns: Attack, Start–end time (tester), What nmap or Hydra reported (tester), Log prefixes and counters that moved (engineer), Matches prediction? (yes/no, and why). This table is the core of your report.

Question

Both, from the correlation table: How many passwords did Hydra try in the first minute, and how many new-connection attempts did the rate-limit rule log in the same window? Why are the two numbers different? Did the NULL scan produce different results from the SYN scan, both in what nmap reported and in what the firewall logged, and which counter moved for the NULL probes in the shadowing experiment? Explain the difference using connection tracking.

  1. Firewall engineer: at the end of the session, save the final ruleset:
sudo nft list ruleset | sudo tee /etc/nftables-final.conf

Submission

  • Revised firewall rule table with justifications (engineer) and the marked attack-path list (tester), from Part 1
  • Baseline and after scan files, and the prediction table with observed results (tester)
  • Final /etc/nftables-final.conf saved from VM1 (engineer)
  • Screenshots: Hydra output and live log lines from journalctl during the attacks
  • The correlation table from Part 3
  • Short report (2–3 pages): network architecture used (including the admin-host compromise), attacks attempted, how the firewall responded to each according to the correlation table, at least one rule you would add or change based on what you observed, and one paragraph from each of you on the step where your partner’s artifact changed your understanding

Key concepts

TermDefinition
FirewallSystem that monitors and controls network traffic based on rules
DMZIntermediate network zone that hosts isolated public-facing services
RBACAccess control based on roles assigned to users
DACAccess control where the owner decides who has access
nftablesModern Linux framework for packet filtering, replacing iptables
IPSIntrusion detection and prevention systems

Navigation: ← Previous | Home | Next →