| name | detecting-port-scanning-with-fail2ban |
| description | Configures Fail2ban with custom filters and actions to detect port scanning activity, SSH brute force attempts, and network reconnaissance, automatically banning offending IP addresses and alerting security teams to suspicious network probing. . Use when working with detecting port scanning with fail2ban. |
| domain | cybersecurity |
| tags | ["network-security","fail2ban","port-scanning","intrusion-prevention","automated-defense"] |
| subdomain | network-security |
| version | 1.0 |
| author | oyi77 |
| license | Apache-2.0 |
| nist_csf | ["PR.IR-01","DE.CM-01","ID.AM-03","PR.DS-02"] |
Detecting Port Scanning With Fail2Ban
Overview
Cybersecurity skill for detecting port scanning with fail2ban. Follows industry best practices and security standards.
When to Use
Trigger phrases:
-
"detecting port scanning with fail2ban"
-
"Configures Fail2ban with custom filters and actions to detect port scanning acti"
-
Automatically blocking IP addresses that perform port scans against internet-facing servers
-
Defending SSH, HTTP, FTP, and other services against brute force attacks with automated IP banning
-
Creating custom detection filters for organization-specific attack patterns in log files
-
Reducing noise from automated scanning bots before traffic reaches IDS/IPS for deeper analysis
-
Implementing defense-in-depth by adding host-based automated response to network monitoring
Do not use as the sole network security control, for protecting against distributed attacks from many source IPs, or as a replacement for proper firewall rules and network segmentation.
When NOT to Use
- When you lack proper authorization for testing
- For production systems without change management
- When the task requires legal or compliance expertise beyond technical scope
Prerequisites
- Fail2ban 0.11+ installed (
fail2ban-client --version)
- Root/sudo access for iptables/nftables manipulation
- Services logging connection attempts to parseable log files (syslog, auth.log, access.log)
- iptables or nftables installed and operational as the host firewall
- Optional: SMTP server for email notifications on ban events
Workflow
import re
IOC_PATTERNS = {
"ip": r"\b(?:\d{1,3}\.){3}\d{1,3}\b",
"domain": r"\b[a-z0-9-]+\.[a-z]{2,}\b",
"hash_md5": r"\b[a-f0-9]{32}\b",
"hash_sha256": r"\b[a-f0-9]{64}\b",
}
def extract_iocs(text: ) -> :
{k: re.findall(v, text) k, v IOC_PATTERNS.items()}