Firewalls, IDS, and IPS — How Network Detection Actually Works
Stateful vs next-generation firewalls, intrusion detection and prevention systems, WAF architecture, firewall rule design, detection signatures, and tuning detection to catch real attacks without drowning in false positives.
Network security controls are the oldest and most widely deployed layer of defence. They are also widely misunderstood: a firewall that allows all outbound traffic, an IDS generating 50,000 alerts per day that nobody reviews, and a WAF in detection-only mode are security theatre, not security. Understanding how these controls actually work — and how to configure them to be effective — is foundational defensive knowledge.
The offensive modules showed you what attackers do when they encounter these controls: use allowed protocols (HTTPS for C2), live off the land with signed binaries to evade IDS signatures, and pivot through segments with no east-west inspection. This module teaches you how defenders close those gaps.
Firewall Evolution — From Packet Filter to NGFW
| Generation | Inspects | What it catches | What it misses |
|---|---|---|---|
| Packet filter (Gen 1) | IP, port, protocol per packet header | Blocked IPs and ports | Application-layer attacks, stateful evasion, tunneled protocols |
| Stateful inspection (Gen 2) | Connection state table — tracks TCP handshakes | Port scan evasion, SYN flood (limited), invalid state packets | Application-layer content, encrypted traffic, C2 over allowed ports |
| Application-layer NGFW (Gen 3) | Full payload up to Layer 7; TLS break-and-inspect | Application-aware policies, known malware signatures, DLP, user identity | Zero-day exploits, traffic not decrypted, evasion via allowed apps |
| Cloud-native NGFW | All above plus cloud context (instance metadata, IAM identity) | Cloud-specific attacks, east-west in VPCs | Performance at scale; insider threats using legitimate access |
Modern enterprise deployments use Next-Generation Firewalls (NGFWs) from vendors like Palo Alto Networks, Fortinet, and Check Point. They combine stateful inspection, application identification, user identity lookup, IPS, URL filtering, and TLS inspection in a single platform.
# Key NGFW capabilities: 1. APPLICATION IDENTIFICATION (App-ID) Identifies application regardless of port — blocks Tor even on port 443 Allows "allow HTTPS to CDNs" without "allow everything on port 443" 2. USER IDENTITY (User-ID) Maps IP addresses to Active Directory users Policy: "sales-team can access Salesforce, not GitHub" Audit: "user jsmith accessed external RDP at 2am" 3. TLS INSPECTION (SSL Decryption) NGFW acts as MiTM: decrypts, inspects, re-encrypts Catches: malware C2 over HTTPS, data exfiltration, malicious downloads Privacy trade-off: all employee traffic decryptable by IT Exempt: banking, healthcare (certificate pinning breaks these) 4. POLICY EXAMPLE: Rule: allow app=ssl dest-zone=untrust user=domain\hr-team Profiles: antivirus=strict, ips=strict, url-filter=block-gambling Logging: full session log to SIEM
Firewall Rule Design — Getting It Right
Firewall rules accumulate over time and become unmanageable without discipline. The principles below keep rule sets effective and auditable:
# Firewall rule design principles (iptables examples) # 1. DEFAULT DENY — most important rule (at the bottom) iptables -P INPUT DROP iptables -P FORWARD DROP iptables -P OUTPUT DROP # catches malware beaconing # 2. ALLOW ESTABLISHED CONNECTIONS first (performance) iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT # 3. SPECIFIC ALLOWS — most specific first # Web server — allow inbound HTTPS from anywhere iptables -A INPUT -p tcp --dport 443 -j ACCEPT # SSH — allow only from management network iptables -A INPUT -p tcp --dport 22 -s 10.0.50.0/24 -j ACCEPT # Database — allow only from app servers iptables -A INPUT -p tcp --dport 5432 -s 10.0.1.0/24 -j ACCEPT # 4. LOG BEFORE DROP — critical for incident response iptables -A INPUT -m limit --limit 5/min -j LOG --log-prefix "FIREWALL_DROP: " iptables -A INPUT -j DROP # 5. AUDIT — find overly broad rules (AWS example) aws ec2 describe-security-groups | jq '.SecurityGroups[] | select(.IpPermissions[].IpRanges[].CidrIp == "0.0.0.0/0")' # Finds: any security group allowing unrestricted inbound access
IDS and IPS — Detection Mechanisms
| Detection method | How it works | Catches | False positives |
|---|---|---|---|
| Signature-based | Match traffic against known attack patterns (Snort/Suricata rules, YARA) | Known exploits, malware C2, scan patterns | Low for tuned rules; bypassed by obfuscation or novel variants |
| Anomaly-based | Baseline normal traffic; alert on statistical deviations | Zero-days, novel attacks, insider threats | High initially — requires extensive tuning period |
| Behaviour-based | Model expected behaviour; alert on deviation | Living-off-the-land, lateral movement, unusual data access | Medium — requires training period and model updates |
| Threat intelligence IOCs | Match IPs, domains, hashes against threat intel feeds | Known attacker infrastructure, malware hashes | Low; but indicators expire quickly — old IOCs become noisy |
# Suricata — open source network IDS/IPS # Update rules and run: suricata-update suricata -c /etc/suricata/suricata.yaml -i eth0 # IDS mode tail -f /var/log/suricata/fast.log # view alerts # Example Suricata rule: alert tcp $EXTERNAL_NET any -> $HOME_NET 22 ( msg:"ET SCAN SSH Brute Force Attempt"; flow:to_server,established; content:"SSH-"; threshold:type both, track by_src, count 5, seconds 60; classtype:attempted-admin; sid:2001219; rev:20; ) # Alerts when an external host makes 5+ SSH connections in 60 seconds # Critical IDS placement: # - Perimeter: catch external attacks (north-south) # - Between DMZ and internal: catch pivoting # - Between internal segments: catch lateral movement (east-west) # North-south detection only is insufficient — attackers inside the perimeter bypass it
Web Application Firewalls (WAF)
A Web Application Firewall inspects HTTP/HTTPS traffic for web application attack patterns. Unlike NGFWs that examine network-level traffic, WAFs understand HTTP structure — detecting SQL injection in POST bodies, XSS in cookie values, or path traversal in URL parameters.
WAF deployment models: 1. CLOUD WAF (CDN-integrated) — Cloudflare WAF, AWS WAF, Fastly No server changes; DDoS protection included; global edge Risk: attacker bypasses by targeting origin IP directly 2. REVERSE PROXY WAF — F5 Advanced WAF, Imperva, ModSecurity Sits between load balancer and application servers Full control and custom rules; operational overhead 3. RASP (Runtime Application Self-Protection) Agent inside application process; context-aware blocking Language-specific; application performance impact # ModSecurity with OWASP CRS — most common open source WAF # /etc/nginx/modsec/modsecurity.conf: SecRuleEngine On # DetectionOnly = log only SecRequestBodyAccess On Include /etc/nginx/modsec/coreruleset/crs-setup.conf Include /etc/nginx/modsec/coreruleset/rules/*.conf # Common WAF bypass techniques (from offensive modules): # Case variation: sElEcT vs SELECT # Comment insertion: SE/**/LECT # Double encoding: %2527 → %27 → ' (single quote) # Unicode variants: fullwidth SQL keywords
IDS Tuning — The False Positive Problem
An untuned IDS generating 50,000 daily alerts is useless — analysts cannot review them, alert fatigue sets in, and real attacks get missed in the noise.
IDS/IPS tuning methodology: STEP 1: MEASURE Count alerts per day by rule; identify top 10 by volume Calculate: what % of high-volume rule alerts are real attacks? STEP 2: SUPPRESS KNOWN GOOD Vulnerability scanner IPs → per-rule suppression Monitoring agents (DB health checks, uptime monitors) Known legitimate internal tools STEP 3: TUNE THRESHOLDS SSH brute force rule: fires on 3 failures → tune to 10 in 60 seconds Reduces FP from developer testing while still catching real attacks STEP 4: CONTEXTUALISE Port scan from external IP = high priority Port scan from internal vulnerability scanner = suppressed Same signature, different source/context = different action STEP 5: FEEDBACK LOOP Every false positive → document → update suppression/threshold Track FP rate weekly — should decrease over time TARGET METRICS: Total actionable alerts: < 100 per analyst per day False positive rate: < 10% for critical/high rules Mean time to triage: < 15 minutes per alert
Interview Questions — Firewalls, IDS, and IPS
Common Mistakes — Firewalls, IDS, and IPS
🎯 Key Takeaways
- ✓Next-generation firewalls inspect up to Layer 7: application identity, user identity, and payload content — not just IP and port. Policies can be "allow Salesforce for sales team, block everything else on 443".
- ✓TLS break-and-inspect decrypts HTTPS traffic at the NGFW for deep packet inspection. Without it, most modern C2 traffic is invisible to the network security layer.
- ✓Default deny drops all traffic not explicitly permitted — making security posture explicit and forcing review of every new traffic flow.
- ✓IDS detects and alerts; IPS sits inline and blocks. Start IPS in detection mode, tune aggressively to reduce false positives, then enable blocking once the FP rate is acceptable.
- ✓WAFs protect against known web application attack patterns but not business logic vulnerabilities, authenticated attacks, or novel bypasses. They are compensating controls, not permanent fixes.
- ✓IDS alert fatigue is one of the most common SOC problems. Target fewer than 100 actionable alerts per analyst per day with less than 10% false positive rate on critical rules.
- ✓East-west firewall rules between internal segments are as important as north-south perimeter rules. Lateral movement exploits the absence of east-west controls.
- ✓Egress filtering catches compromised hosts beaconing to C2. Application servers should communicate outbound only to known, required destinations.
- ✓Suricata rules are written in Snort-compatible syntax: action, protocol, source, destination, payload content, thresholds, and classification. Understanding rule structure enables custom detection logic.
- ✓Every firewall rule needs a business justification, an owner, and a review date. Orphaned rules from decommissioned systems are one of the most common security audit findings.
Discussion
0Have a better approach? Found something outdated? Share it — your knowledge helps everyone learning here.