Host-Based Firewall
How a firewall running on a single device controls traffic in and out of that device, and how to configure its rules.
1What a host-based firewall is
A host-based firewall is software that runs on a single device (a laptop, desktop, or server) and allows or denies traffic into or out of that one device. A host is any single computer on a network. Most operating systems include one.
2Why add one
A network firewall protects a whole network at its edge. A host-based firewall adds an extra layer for each device, which matters when:
- the device is on a compromised network, where another device on the same network has been infected;
- the device leaves the building and joins an untrusted network such as café or hotel Wi-Fi;
- an attacker is already inside the network, past the edge firewall.
3How its rules work
A host-based firewall follows a set of rules, an ACL, just like a network-based firewall. Rules can allow or deny traffic based on source or destination port or IP address, service, protocol, or application. Rules are applied in order, and the first matching rule decides.
A host-based firewall should always block ports and services the device does not need. A laptop that never shares files has no reason to accept file-sharing connections.
4Blocking outbound traffic
A host-based firewall can also block specified types of outbound traffic. For example, blocking outbound FTP (file transfer protocol, port 21) prevents an adversary who has gained remote access to the host from using FTP to exfiltrate (copy out) a file to their own server. Outbound rules limit what an attacker can do even after getting in.
5Testing a rule set
Rule 1: ALLOW inbound TCP port 3389 from 10.10.9.0/24 Rule 2: DENY inbound ALL ALL from ALL Rule 3: DENY outbound TCP port 21 to ALL Rule 4: DENY outbound TCP port 23 to ALL Rule 5: ALLOW outbound ALL ALL to ALL
| Traffic | Result | Deciding rule |
|---|---|---|
| IT help desk remote session from 10.10.9.30 | ALLOW | Rule 1 |
| Remote desktop attempt from the café Wi-Fi | DENY | Rule 2 |
| File-sharing probe from another laptop | DENY | Rule 2 |
| FTP upload to an outside server | DENY | Rule 3 |
| Loading a website | ALLOW | Rule 5 |
A host-based firewall protects one device, wherever it is. It uses ordered ACL rules like a network firewall, should block every port and service the device does not need, and can block outbound traffic to stop data from being sent out.
6Worked examples
Remote desktop from the café
Using the rules above, the laptop is on café Wi-Fi. Someone at 192.168.0.44 tries to connect with remote desktop (inbound TCP 3389). What happens?
- 1Rule 1 allows inbound 3389 only from
10.10.9.0/24(the IT subnet).192.168.0.44is not in that range: no match. - 2Rule 2 denies all other inbound traffic: match.
Stopping the upload
An attacker gets remote access to the laptop and tries to upload a file to their server at 203.0.113.99 using FTP (outbound TCP 21). What happens, and why does this rule matter?
- 1Rules 1 and 2 are inbound: they do not apply.
- 2Rule 3 denies outbound TCP port 21 to any destination: match. The upload is blocked.
- 3Even with remote access, the attacker cannot use FTP to exfiltrate data.
Moving the allow-all
If Rule 5 (ALLOW outbound ALL ALL to ALL) were moved above Rule 3, what would happen to the FTP upload?
- 1The upload would now match the allow-all rule first.
- 2First match wins, so it would be allowed; the FTP block below it would never be reached.
Ports on a kiosk
A library kiosk only needs to load websites. Its host-based firewall currently allows all inbound traffic. What should its rules be?
- 1Inbound: deny all. The kiosk offers no services to other computers.
- 2Outbound: allow web traffic (TCP 443, and 80 if needed) and DNS lookups (port 53); deny everything else.
- 3Everything the kiosk does not need is blocked.
7Common mistakes
Network firewalls do not see traffic between devices inside the network, and do not travel with a laptop. Host firewalls cover both gaps.
Outbound rules stop malware from contacting attackers and stop data from being copied out.
Every open port is a way in. A host firewall should block every port and service the device does not need.
“Rule 3 denies outbound TCP port 21 from the laptop. If an adversary gains remote access, they cannot use FTP to exfiltrate files to their server, because the host-based firewall blocks that outbound traffic before it leaves the device.”
Quote the rule, say what traffic it matches, and explain the attack it prevents.