>> ABSTRACT

In the previous case study, we observed how an attacker exploited an undefended system. This section focuses on Hardening. Intrusion Detection Systems (IDS) like Snort provide visibility, while Intrusion Prevention Systems (IPS) like Fail2ban actively block malicious actors.

1. Snort: The Network IDS

Snort is the de-facto standard for open-source IDS. It operates by packet sniffing and logging traffic that matches predefined signatures.

// CUSTOM_RULE: ICMP_Tunneling_Detection

A rule designed to detect large ICMP packets, often indicative of data exfiltration or tunneling attempts.

alert icmp $EXTERNAL_NET any -> $HOME_NET any (msg:"Possible ICMP Tunneling Detected"; dsize:>1000; sid:1000001; rev:1;)
Snort Configuration File
FIG 2.41: Custom ICMP Alert Rule

// CUSTOM_RULE: SSH_Brute_Force

While Snort can detect the volume of traffic, it works best when paired with a log analyzer. This rule flags excessive connection attempts.

alert tcp $EXTERNAL_NET any -> $HOME_NET 22 (msg:"SSH Brute Force Attempt"; flags:S; threshold:type both, track by_src, count 5, seconds 60; sid:1000002; rev:1;)

2. Fail2ban: The Host IPS

Fail2ban scans log files (e.g., `/var/log/auth.log`) and bans IPs that show malicious signs like too many password failures. It updates firewall rules (iptables) to reject new connections from those IP addresses.

// JAIL_CONFIGURATION: sshd

[sshd] enabled = true port = ssh filter = sshd logpath = /var/log/auth.log maxretry = 3 bantime = 3600
Fail2ban Jail Config
FIG 2.27: fail2ban SSH Jail Configuration

// JAIL_CONFIGURATION: vsftpd

[vsftpd] enabled = true port = ftp logpath = /var/log/vsftpd.log maxretry = 5 bantime = 86400 # 24 Hours ban

3. Conclusion

By combining Snort's deep packet inspection with Fail2ban's active response capabilities, we create a robust defense-in-depth architecture. Snort provides the visibility needed to understand "what" is happening, while Fail2ban ensures that "action" is taken to stop it.

NEXT CHAPTER >> VALIDATING SECURITY

Testing the Walls:
Offensive Validation (Metasploit) ↗