Skip to main content

Lesson 3 of 10

Intrusion Detection & Prevention Systems

IDS (Intrusion Detection Systems) and IPS (Intrusion Prevention Systems) monitor network or host activity for malicious patterns. IDS alerts; IPS both alerts and actively blocks. Together with firewalls, they form a layered defense.

55 minBy Priygop Editorial TeamUpdated 2026Peer Reviewed & Verified

IDS vs IPS - Key Differences

  • IDS (Passive): Copies network traffic and analyzes it - does NOT modify traffic flow. Alerts on suspicious patterns. Low risk of false-positive blocking legitimate traffic. Useful for: monitoring, compliance, forensic capture
  • IPS (Inline, Active): Sits in the network path - CAN block, drop, or rate-limit traffic. Must be tuned carefully - too aggressive causes false-positive blocking of legitimate traffic. Positioned after the firewall for efficient pre-filtering
  • NIDS (Network IDS): Monitors network traffic at strategic points - typically at network boundaries, between segments
  • HIDS (Host IDS): Monitors individual system - file changes, process creation, log analysis. Examples: OSSEC, Wazuh, Tripwire (file integrity monitoring)
  • Detection methods: Signature-based (matches known attack patterns - high precision, misses zero-days), Anomaly-based (baseline normal and detect deviations - catches novel attacks, higher false-positive rate), Behavior-based (detect suspicious sequences of actions regardless of individual signatures)

Snort/Suricata Rule Writing

Snort/Suricata Rule Writing
# Snort/Suricata - Most widely used open-source IDS/IPS

# Rule structure:
# action protocol src_ip src_port -> dst_ip dst_port (options)

# Alert on SQL injection attempt
alert tcp any any -> $HTTP_SERVERS $HTTP_PORTS (
    msg:"SQL Injection Attempt - UNION SELECT";
    flow:to_server,established;
    content:"UNION"; nocase;
    content:"SELECT"; nocase; distance:1;
    pcre:"/UNION[s+]SELECT/i";
    sid:1000001; rev:1;
    classtype:web-application-attack;
    priority:1;
)

# Alert on port scan (TCP SYN to many ports)
alert tcp any any -> $HOME_NET any (
    msg:"Possible Port Scan";
    flags:S;
    detection_filter:track by_src, count 20, seconds 3;
    sid:1000002; rev:1;
)

# Alert on SSH brute force
alert tcp any any -> $HOME_NET 22 (
    msg:"SSH Brute Force Attempt";
    flow:to_server;
    detection_filter:track by_src, count 5, seconds 60;
    sid:1000003; rev:1;
)

# Alert on DNS tunneling (unusually long DNS names)
alert dns any any -> any 53 (
    msg:"Possible DNS Tunneling - Long DNS Query";
    dns.query; content:!".local";
    byte_test:1,>,50,0,relative;
    sid:1000004; rev:1;
)

Suricata in IPS Mode

Suricata in IPS Mode
# Suricata configuration for IPS mode (inline deployment)

# /etc/suricata/suricata.yaml
af-packet:
  - interface: eth0
    cluster-id: 99
    cluster-type: cluster_flow
    defrag: yes
    use-mmap: yes

# Enable rule categories
rule-files:
  - /etc/suricata/rules/emerging-exploit.rules
  - /etc/suricata/rules/emerging-web_specific_apps.rules
  - /etc/suricata/rules/botcc.rules
  - /etc/suricata/rules/custom.rules

# Start Suricata in IPS mode (NFQUEUE)
suricata -c /etc/suricata/suricata.yaml -q 0 --pidfile /run/suricata.pid

# Route traffic through Suricata (iptables NFQUEUE)
iptables -I INPUT -j NFQUEUE --queue-num 0
iptables -I OUTPUT -j NFQUEUE --queue-num 0

# Update rules (use suricata-update)
suricata-update
systemctl restart suricata

# Monitor alerts in real-time
tail -f /var/log/suricata/fast.log
# Output: [**] [1:2010935:3] ET SCAN Nmap OS Detection Probe [**]

Common Mistakes

  • Enabling all IPS rules on day one - alert mode first, tune rules to reduce false positives, then enable blocking for well-tested rule sets
  • IDS without a response process - IDS generating alerts that nobody reads is security theater. Alerts must trigger a documented investigation workflow
  • Not updating signatures regularly - signature-based IDS is only as good as its latest signature database; update daily using suricata-update or equivalent

Tip

Tip

Practice Intrusion Detection Prevention Systems in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.

Diagram
Loading diagram…

The foundational security model: Confidentiality (privacy), Integrity (trust), and Availability (uptime).

Practice Task

Note

Practice Task - (1) Write a working example of Intrusion Detection Prevention Systems from scratch without looking at notes. (2) Modify it to handle an edge case (empty input, null value, or error state). (3) Share your solution in the Priygop community for feedback.

Quick Quiz

Common Mistake

Warning

A common mistake with Intrusion Detection Prevention Systems is skipping edge case testing - empty inputs, null values, and unexpected data types. Always validate boundary conditions to write robust, production-ready cybersecurity code.

Key Takeaways

  • IDS (Intrusion Detection Systems) and IPS (Intrusion Prevention Systems) monitor network or host activity for malicious patterns.
  • IDS (Passive): Copies network traffic and analyzes it - does NOT modify traffic flow. Alerts on suspicious patterns. Low risk of false-positive blocking legitimate traffic. Useful for: monitoring, compliance, forensic capture
  • IPS (Inline, Active): Sits in the network path - CAN block, drop, or rate-limit traffic. Must be tuned carefully - too aggressive causes false-positive blocking of legitimate traffic. Positioned after the firewall for efficient pre-filtering
  • NIDS (Network IDS): Monitors network traffic at strategic points - typically at network boundaries, between segments

Hands-on Practice Tools for this Course

Test what you learn using these free in-browser developer utilities (no signup required).

All 40+ Tools

Topics in This Module

0/10 done