Firewalls

A firewall is a device or software that controls traffic between networks according to a rule set, usually between a trusted internal network and an untrusted network such as the internet. The default policy should be deny all, allow by exception. Types:

  1. Packet-filtering firewall: checks each packet's source and destination address, port and protocol; fast but blind to context.
  2. Stateful inspection firewall: remembers the state of connections and allows replies only to requests that were made from inside.
  3. Application-level (proxy) firewall: understands protocols such as HTTP and can inspect content; slower but more detailed.
  4. Next-generation firewall (NGFW): adds application awareness, intrusion prevention and user identity.

A DMZ (demilitarised zone) is a separate network segment for public servers such as web and mail servers, so that a breach of one does not give direct access to the internal network. Rules are checked from top to bottom and the first match decides.

IDS and IPS

An intrusion detection system (IDS) watches traffic or hosts and alerts on suspicious activity. An intrusion prevention system (IPS) sits in line with the traffic and can also block it. By position: network-based (NIDS) monitors a network segment; host-based (HIDS) monitors one computer's logs and files. By method: signature-based detection compares activity with known attack patterns (accurate for known attacks, blind to new ones); anomaly-based detection learns normal behaviour and flags deviations (can find new attacks but gives more false alarms). Snort and Suricata are common open-source tools.

VPNs

A virtual private network (VPN) creates an encrypted tunnel across a public network, so that remote users or branch offices communicate as if on a private network. It gives confidentiality, integrity and authentication. Types: remote-access VPN (a user connects to the office) and site-to-site VPN (two networks are joined). Protocols: IPsec, SSL/TLS VPN, OpenVPN and WireGuard.

Definition: Firewall. A security device or program that filters network traffic between networks according to a set of rules, allowing or blocking packets on the basis of addresses, ports, protocols and connection state.

Table 3.1: Firewall, IDS and IPS

Tool Placement Action Weakness
Firewall Network boundary Allow or block by rule Cannot see inside allowed traffic
IDS Passive on a copy of traffic Alerts Does not stop the attack
IPS In line with traffic Blocks A false positive can block good traffic
VPN Between two ends Encrypts the tunnel A stolen credential gives access

Example 3.1: Packet filtering with ordered rules

Problem: A firewall has the rules (first match wins): 1 allow TCP port 80 from anyone; 2 allow TCP port 443 from anyone; 3 allow TCP port 22 from 10.0.0.0/8 only; 4 deny everything. Decide the action for five packets: TCP/80 from 1.2.3.4; TCP/22 from 10.1.1.1; TCP/22 from 8.8.8.8; UDP/53 from 10.0.0.5; TCP/23 from 10.1.1.1.

Solution:

  1. TCP/80 from 1.2.3.4 matches rule 1: allow.
  2. TCP/22 from 10.1.1.1 is inside 10.0.0.0/8 and matches rule 3: allow.
  3. TCP/22 from 8.8.8.8 does not match rule 3 and falls to rule 4: deny.
  4. UDP/53 and TCP/23 match no allow rule and fall to rule 4: deny.

Result: Allow, allow, deny, deny, deny. The final deny-all rule makes the default safe.

import ipaddress
rules = [("allow", "tcp", 80, "0.0.0.0/0"),
         ("allow", "tcp", 443, "0.0.0.0/0"),
         ("allow", "tcp", 22, "10.0.0.0/8"),
         ("deny", "any", None, "0.0.0.0/0")]

def check(proto, port, src):
    ip = ipaddress.ip_address(src)
    for act, p, pt, net in rules:
        if (p in (proto, "any") and pt in (port, None)
                and ip in ipaddress.ip_network(net)):
            return act

for pkt in [("tcp", 80, "1.2.3.4"), ("tcp", 22, "10.1.1.1"),
            ("tcp", 22, "8.8.8.8"), ("udp", 53, "10.0.0.5"),
            ("tcp", 23, "10.1.1.1")]:
    print(pkt, "->", check(*pkt))

Output

('tcp', 80, '1.2.3.4') -> allow
('tcp', 22, '10.1.1.1') -> allow
('tcp', 22, '8.8.8.8') -> deny
('udp', 53, '10.0.0.5') -> deny
('tcp', 23, '10.1.1.1') -> deny

Common mistakes

  • Ending a rule set with allow all instead of deny all.
  • Placing public servers inside the internal network.
  • Treating an IDS as if it blocked attacks.
  • Trusting a firewall alone and ignoring threats from inside.

Key takeaways

  • Firewall types: packet filter, stateful, proxy, NGFW; default deny.
  • IDS alerts; IPS blocks; signature versus anomaly detection.
  • VPN: encrypted tunnel; remote-access and site-to-site.
  • Rules are matched top-down; first match wins.

Practice questions

  1. Differentiate IDS and IPS.
  2. What is a DMZ?
  3. Name two VPN protocols.

Answers to the practice questions

  1. An IDS only detects and alerts; an IPS is in line and can block the traffic.
  2. A separate network segment for public servers, isolating them from the internal network.
  3. IPsec and OpenVPN (also WireGuard, SSL VPN).

Sources

  • Official BCA syllabus Computer Security, course code 25BCA406DS02, Unit III