Skip to content
BoKSA

16: Firewalls and Intrusion Detection Systems

16: Firewalls and Intrusion Detection Systems

Course: Networking - Security Advanced · Updated: October 2026 Literature: K&R chapter 8: operational security: firewalls and intrusion detection systems; NF chapter 7 (Network Intrusion Detection and Analysis) Related labs: Lab: Introduction Snort, Lab: Snort

Learning objectives

After studying this article you can:

  • explain what a firewall does, and the differences between stateless packet filters, stateful filters and application gateways / next-generation firewalls
  • read and write firewall rules (ACLs, nftables)
  • explain what an IDS and an IPS are, and the difference between NIDS and HIDS
  • explain the detection methods: signature-based, protocol/anomaly-based and behavioural
  • write simple Snort/Suricata rules, and explain the role of Zeek
  • know the difference between commercial and "roll-your-own" IDS solutions, and name examples

1. Firewalls

A firewall isolates an organisation's internal network from the Internet. It lets some packets through and blocks others.

Its three goals:

  1. All traffic from outside to inside, and the other way round, passes through the firewall.
  2. Only authorised traffic, as defined by the local security policy, is allowed.
  3. The firewall itself must be immune to attacks.

1.1 Stateless packet filters

These decide per packet, based on header fields:

  • source/destination IP address
  • TCP/UDP source/destination port
  • ICMP message type
  • TCP flags (SYN, ACK, ...)

Example access control list (ACL):

Action Source address Dest. address Protocol Source port Dest. port Flag bit
allow 222.22/16 outside 222.22/16 TCP > 1023 443 any
allow outside 222.22/16 222.22/16 TCP 443 > 1023 ACK
allow 222.22/16 outside 222.22/16 UDP > 1023 53 —
allow outside 222.22/16 222.22/16 UDP 53 > 1023 —
deny all all all all all all

Rules are checked from top to bottom, and the first match wins. The last rule is default deny.

Problem: a stateless filter doesn't remember anything. It will accept a packet with the ACK flag set that doesn't belong to any connection (used in ACK scans).

1.2 Stateful packet filters

A stateful filter tracks every TCP connection (SYN, established, FIN) and every UDP "flow":

  • It only allows packets that belong to a known, established connection.
  • Connections are removed after FIN or after a timeout.
  • Rules become much simpler: "allow outgoing HTTPS connections, and allow replies to them automatically".

Example with nftables (Linux, the successor to iptables):

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
table inet filter {
  chain input {
    type filter hook input priority 0; policy drop;     # default deny
    ct state established,related accept                 # replies to our own connections
    ct state invalid drop
    iif lo accept
    tcp dport 22 ip saddr 10.0.0.0/24 accept             # SSH only from the management network
    tcp dport { 80, 443 } accept                         # web server
    icmp type echo-request limit rate 5/second accept    # limited ping
  }
}

1.3 Application gateways and next-generation firewalls

  • An application gateway (proxy) filters at the application layer. For example, a web proxy that allows only certain users and websites, or an e-mail gateway that scans for malware. All traffic goes through the proxy, which opens its own connection to the server.
  • Next-Generation Firewalls (NGFW) (Palo Alto, Fortinet, Check Point, Cisco) combine a stateful firewall with:
  • application identification (deep packet inspection: "this is Teams", "this is BitTorrent", regardless of the port)
  • user identification (integration with Active Directory)
  • an integrated IPS, URL filtering, malware sandboxing
  • TLS inspection (see article 13)
  • Web Application Firewalls (WAF) protect web applications against SQL injection, XSS and so on (e.g. ModSecurity/Coraza, Cloudflare WAF).
  • Cloud firewalls: security groups, network ACLs, Azure Firewall, and Firewall-as-a-Service in SASE (see article 14).
  • Host firewalls: Windows Defender Firewall, nftables/ufw, macOS. They are important for Zero Trust and micro-segmentation.

1.4 Limitations of firewalls

  • IP spoofing: a firewall can't tell whether a source address is real.
  • Firewalls don't see inside encrypted traffic unless they do TLS inspection.
  • Insider threats and traffic that never passes the firewall (e.g. between two hosts in the same VLAN, or over a 4G/5G hotspot) are invisible to it.
  • Tunnelling: attackers hide traffic in allowed protocols (DNS, HTTPS).
  • A firewall is only as good as its rules. Rule sprawl and "temporary" exceptions build up over time.

1.5 The DMZ

1
   Internet ── [external firewall] ── DMZ (web server, mail gateway, VPN) ── [internal firewall] ── internal LAN

Servers that must be reachable from the Internet sit in a separate zone. If one is compromised, the internal network is still protected.

2. Intrusion Detection and Prevention Systems

Firewalls mainly look at headers. An IDS goes further, with deep packet inspection (looking at the content) and correlation across multiple packets, to detect attacks such as:

  • port scans and network mapping
  • exploits for known vulnerabilities, worms and malware traffic
  • DoS attacks (e.g. floods)
  • policy violations (e.g. Telnet in use, or an unknown TLS certificate)
IDS (Intrusion Detection System) IPS (Intrusion Prevention System)
Placement Passive, receives a copy of the traffic (SPAN/mirror port or a network TAP) Inline: all traffic passes through it
Action Alert (log, send to SIEM) Block malicious traffic in real time
Risk Doesn't stop an attack itself False positives block legitimate traffic, and it can become a bottleneck
NIDS (Network-based) HIDS (Host-based)
Monitors Network traffic on a segment Activity on a single host: logs, file integrity, processes
Examples Snort, Suricata, Zeek Wazuh, OSSEC, and EDR (Microsoft Defender for Endpoint, CrowdStrike, SentinelOne)

2.1 Detection methods

Method How it works Strengths Weaknesses
Signature-based Compares traffic with a database of known attack patterns (signatures/rules) Accurate for known attacks, few false positives, easy to understand Doesn't detect new (zero-day) attacks. Signatures must be kept up to date. Evasion is possible by changing the attack slightly.
Protocol analysis / protocol awareness Reassembles streams and checks whether protocols follow the standard ("normal traffic") Detects abnormal protocol use and evasion through fragmentation More complex
Anomaly-based / behavioural Builds a baseline of normal traffic and alerts on deviations (e.g. sudden large uploads at night, or new connections to a country) Can detect unknown attacks Many false positives, and the baseline needs time to learn

Modern systems combine all three, increasingly with machine learning (NDR: Network Detection and Response, e.g. Vectra, Darktrace, ExtraHop, Corelight) and threat intelligence (lists of known malicious IPs, domains and TLS fingerprints).

3. Snort, Suricata and Zeek

3.1 Snort

  • An open-source NIDS/IPS, created in 1998 by Martin Roesch, now owned by Cisco (Talos).
  • Snort 3 (generally available since 2021) is the current version. It is a complete rewrite with multithreading, configuration in Lua (snort.lua in place of snort.conf), and better performance. The 2017 lab used Snort 2, which is now legacy.
  • Rules: the community ruleset (free), and the Talos subscriber ruleset (free with a 30-day delay for registered users, or paid for immediate updates).

3.2 Snort rule syntax

1
action  protocol  src_ip  src_port  direction  dst_ip  dst_port  (options)

Examples (Snort 3 syntax; the ICMP, ping-flood and SYN-scan rules also work in Snort 2 and Suricata):

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# Alert on any ICMP traffic to our network
alert icmp any any -> $HOME_NET any (msg:"ICMP detected"; sid:1000001; rev:1; classtype:icmp-event;)

# Detect a ping flood: more than 20 ICMP echo requests in 3 seconds from one source
alert icmp any any -> $HOME_NET any (msg:"Possible ping flood"; itype:8;
    detection_filter:track by_src, count 20, seconds 3; sid:1000002; rev:1;)

# Detect an attempt to read /etc/passwd over HTTP
alert http any any -> $HOME_NET any (msg:"Attempt to retrieve /etc/passwd";
    http_uri; content:"/etc/passwd"; nocase; sid:1000003; rev:1; classtype:web-application-attack;)

# Detect a SYN port scan: many SYNs from one source
alert tcp any any -> $HOME_NET any (msg:"Possible SYN port scan"; flags:S;
    detection_filter:track by_src, count 30, seconds 5; sid:1000004; rev:1;)
Part Meaning
alert / log / pass / drop / reject Action (drop/reject only in inline IPS mode)
msg Text in the alert
content Byte pattern to search for in the payload
flags, itype, flow Header conditions
detection_filter / threshold Rate-based detection
sid Unique rule ID (≥ 1,000,000 for your own local rules)
rev Revision number
classtype Category (used for priority)

Running Snort 3:

1
2
snort -c /usr/local/etc/snort/snort.lua -R /usr/local/etc/rules/local.rules -i eth0 -A alert_fast
snort -c snort.lua -r capture.pcap -A alert_fast     # analyse a saved capture

3.3 Suricata

  • An open-source IDS/IPS from the Open Information Security Foundation (OISF), first released in 2010.
  • Multithreaded from the start, with strong performance.
  • Largely compatible with Snort rules, and it also has its own keywords.
  • Produces rich EVE JSON logs: alerts, plus metadata about HTTP, DNS, TLS (including JA3/JA4 fingerprints), file extraction and flows. Ideal for a SIEM.
  • Popular rulesets: Emerging Threats Open (free) and ET Pro (Proofpoint).
  • Current version: Suricata 8 (2025). Parts of it are written in Rust for memory safety.

3.4 Zeek (formerly Bro)

  • It is not a signature IDS but a network security monitor. It turns traffic into detailed logs per protocol: conn.log, dns.log, http.log, ssl.log, files.log, x509.log, ...
  • It has its own scripting language, for detection logic and policies.
  • It is indispensable for threat hunting and network forensics (see article 17).
  • It is often used together with Suricata, e.g. in Security Onion or Corelight.

3.5 Commercial vs roll-your-own

As the NF book puts it, there are commercial products and "roll-your-own" solutions:

Commercial Open source / roll-your-own
Cisco Secure Firewall (Firepower, built on Snort), Palo Alto Networks, Fortinet FortiGate IPS, Trellix (formerly McAfee/FireEye), Check Point Snort, Suricata, Zeek
NDR: Vectra AI, Darktrace, ExtraHop, Corelight (commercial Zeek) Distributions: Security Onion, SELKS (Stamus), pfSense/OPNsense with Suricata/Snort plug-ins

4. Summary

  • Firewalls enforce a policy: stateless (per packet), stateful (per connection), or NGFW/application gateways (per application and user). Always end with default deny.
  • An IDS detects and alerts, and an IPS blocks inline. A NIDS looks at the network, a HIDS/EDR looks at the host.
  • Detection is signature-based (known attacks), protocol-based or anomaly/behaviour-based (unknown attacks, more false positives).
  • Snort 3 and Suricata use rules. Zeek produces rich logs for analysis. Together they are the basis of many security operations centres (SOCs).

References

Videos

Articles

Standards and guidelines

  • NIST SP 800-41 Rev. 1: Guidelines on Firewalls and Firewall Policy
  • NIST SP 800-94: Guide to Intrusion Detection and Prevention Systems (IDPS)

Tools


Cyber Security

Why it matters

Firewalls and IDS are core components of defence in depth:

  • Prevention (firewall): reduce the attack surface. Most automated Internet attacks hit only exposed services.
  • Detection (IDS/NDR/EDR): no prevention is perfect. The dwell time (how long an attacker goes unnoticed) decides how much damage is done. With good detection, attacks are stopped before data is stolen or ransomware is deployed.
  • Evidence: IDS alerts and NSM logs are often the first and most important source in an investigation (see article 17).

They also have weak points:

  • Misconfigured firewalls (rules that allow too much, such as "any any", forgotten test rules, management interfaces exposed to the Internet) are among the most common audit findings.
  • The firewall itself is a target: edge devices from Fortinet, Palo Alto (CVE-2024-3400), Cisco ASA (ArcaneDoor, 2024) and SonicWall have been attacked by state actors and ransomware groups (see article 14).
  • Alert fatigue: an IDS that produces thousands of alerts a day gets ignored. The Target breach (2013) was actually detected, but the alerts weren't acted on.
  • Evasion: attackers use encryption, fragmentation, slow scans, or "living off the land" (legitimate tools and cloud services) to stay under the radar.
  • Encrypted traffic limits what signature-based IDS can see. Metadata (JA4 fingerprints, certificate data, flow behaviour) is becoming more important.

How to make it safe

  1. Default deny inbound and outbound (egress filtering). Allow only what you need. Blocking outbound traffic stops much malware C2 and data exfiltration.
  2. Review rules regularly: remove unused rules, document the owner and reason for every rule, and use change management. Tools such as nmap and firewall analysers help check the actual exposure.
  3. Keep firewall and IDS firmware and rules up to date: automatic rule updates (Talos, ET), and fast patching of the devices themselves.
  4. Never expose management interfaces to the Internet, and use MFA for administrators.
  5. Place sensors carefully: at the Internet edge, and internally between segments (east-west traffic), and in the cloud (VPC traffic mirroring).
  6. Tune the IDS for your environment: disable irrelevant rules, set HOME_NET and EXTERNAL_NET correctly, and use thresholds to reduce noise. Each alert should lead to an action.
  7. Send alerts and logs to a SIEM, correlate them with other sources (EDR, authentication logs), and use playbooks for response (SOAR).
  8. Combine network detection (Suricata/Zeek/NDR) with endpoint detection (EDR). Each sees what the other misses.
  9. Test your detection: run attacks in a lab (or a purple-team exercise) and check that they are detected, e.g. with Atomic Red Team or by replaying PCAPs from malware-traffic-analysis.net.
  10. Use IPS mode carefully: start in detection mode, check for false positives, and only then block.

Extra references