मुख्य सामग्री पर जाएँ
Skillpedia
एजेंट35k · #7859

detecting-port-scanning-with-fail2ban

यह क्या करती है

यह सिस्टम आपके सर्वर को port scanning और brute-force लॉगिन कोशिशों से बचाता है। यह संदिग्ध गतिविधि पकड़ता है और उसे करने वाले IP पतों को अपने-आप ब्लॉक कर देता है, साथ ही आपकी सुरक्षा टीम को अलर्ट भी भेजता है।

कब इस्तेमाल करें

  • ✓जब आप उन IP पतों को ब्लॉक करना चाहते हैं जो आपके खुले पोर्ट स्कैन कर रहे हैं।
  • ✓SSH, FTP आदि के पासवर्ड अंदाज़े से तोड़ने की कोशिशों से बचाव के लिए।
  • ✓अपने लॉग के आधार पर कस्टम हमले पहचानने के नियम बनाने के लिए।

Skill का लिंक

https://github.com/mukul975/Anthropic-Cybersecurity-Skills/blob/main/skills/detecting-port-scanning-with-fail2ban/SKILL.md

इसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।

कैसे इस्तेमाल करें

सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।

पेस्ट करने के लिए तैयार मैसेज

इस skill से मेरी मदद करो: https://github.com/mukul975/Anthropic-Cybersecurity-Skills/blob/main/skills/detecting-port-scanning-with-fail2ban/SKILL.md इस लिंक की SKILL.md फ़ाइल पढ़ो और मेरे काम में उसके निर्देशों का पालन करो।
क्या आप चाहते हैं कि आपका AI ऐसी skills खुद ढूँढे?मुफ़्त Skillpedia MCP इंस्टॉल करें: बस एक लाइन, और हर काम से पहले यह 15,000+ skills में खोजता है।1 मिनट में इंस्टॉल करें →

AI से क्या माँगें: उदाहरण

“Fail2ban सेट करो ताकि जो IP कम समय में बहुत सारे पोर्ट खटखटाएँ, उन्हें ब्लॉक किया जाए।”

हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।

यह कैसे काम करती है

Fail2ban सर्वर की लॉग फ़ाइलों पर नज़र रखता है। कोई हमले वाला पैटर्न मिलने पर वह firewall नियमों से हमलावर के IP पते को तय समय के लिए ब्लॉक कर देता है।

तकनीकी सामग्री (मूल SKILL.md)

लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।

Detecting Port Scanning with Fail2ban

When to Use

  • 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.

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

Step 1: Install and Configure Fail2ban

# Install Fail2ban
sudo apt install -y fail2ban

# Create local configuration (never edit jail.conf directly)
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local

# Configure global defaults
sudo tee /etc/fail2ban/jail.local << 'EOF'
[DEFAULT]
# Ban duration (1 hour default, escalates for repeat offenders)
bantime = 3600
# Detection window
findtime = 600
# Max failures before ban
maxretry = 5
# Ban action using iptables
banaction = iptables-multiport
banaction_allports = iptables-allports
# Email notifications
destemail = security@example.com
sender = fail2ban@example.com
mta = sendmail
action = %(action_mwl)s

# Ignore internal networks
ignoreip = 127.0.0.1/8 ::1 10.10.0.0/16

# Use systemd journal backend where available
backend = systemd

[sshd]
enabled = true
port = ssh
filter = sshd
logpath = /var/log/auth.log
maxretry = 3
bantime = 7200
findtime = 300

[sshd-ddos]
enabled = true
port = ssh
filter = sshd-ddos
logpath = /var/log/auth.log
maxretry = 6
bantime = 3600
EOF

Step 2: Create Custom Port Scan Detection Filter

# Create iptables logging rule for dropped connections
sudo iptables -N PORTSCAN
sudo iptables -A PORTSCAN -j LOG --log-prefix "PORTSCAN_DETECTED: " --log-level 4
sudo iptables -A PORTSCAN -j DROP

# Log SYN packets to closed ports (indicates scanning)
sudo iptables -A INPUT -p tcp --tcp-flags SYN,ACK,FIN,RST SYN -m state --state NEW \
  -m recent --name portscan --set
sudo iptables -A INPUT -p tcp --tcp-flags SYN,ACK,FIN,RST SYN -m state --state NEW \
  -m recent --name portscan --rcheck --seconds 10 --hitcount 20 -j PORTSCAN

# Create Fail2ban filter for port scanning
sudo tee /etc/fail2ban/filter.d/portscan.conf << 'EOF'
[Definition]
# Match iptables port scan log entries
failregex = PORTSCAN_DETECTED: .* SRC=<HOST> DST=\S+ .* DPT=\d+
ignoreregex =
datepattern = {^LN-BEG}
EOF

# Create Fail2ban filter for Nmap detection via kernel logs
sudo tee /etc/fail2ban/filter.d/nmap-scan.conf << 'EOF'
[Definition]
# Detect rapid connection attempts to multiple ports from same source
failregex = kernel: \[.*\] PORTSCAN_DETECTED: .* SRC=<HOST>
            iptables: .* PORTSCAN .* SRC=<HOST>
ignoreregex =
datepattern = {^LN-BEG}
EOF

# Create filter for HTTP scanning/probing
sudo tee /etc/fail2ban/filter.d/http-scan.conf << 'EOF'
[Definition]
# Detect scanners probing for common vulnerabilities
failregex = ^<HOST> .* "(GET|POST|HEAD) /(wp-login|wp-admin|phpmyadmin|admin|.env|xmlrpc|wp-content/uploads).*" (403|404|444)
            ^<HOST> .* "(GET|POST) /.*\.(php|asp|aspx|jsp|cgi)\?.*" (403|404)
            ^<HOST> .* "() .*" 400
            ^<HOST> .* "(GET|POST) /.*" 400
ignoreregex =
datepattern = {^LN-BEG}
EOF

Step 3: Configure Jail for Port Scanning

# Add port scan jails to jail.local
sudo tee -a /etc/fail2ban/jail.local << 'EOF'

[portscan]
enabled = true
filter = portscan
logpath = /var/log/kern.log
maxretry = 10
findtime = 60
bantime = 86400
banaction = iptables-allports
action = %(action_mwl)s

[nmap-scan]
enabled = true
filter = nmap-scan
logpath = /var/log/kern.log
maxretry = 5
findtime = 30
bantime = 86400
banaction = iptables-allports
action = %(action_mwl)s

[http-scan]
enabled = true
filter = http-scan
logpath = /var/log/nginx/access.log
maxretry = 10
findtime = 300
bantime = 3600
banaction = iptables-multiport
port = http,https


…
अक्सर पूछे जाने वाले सवाल

Fail2ban क्या है?

Fail2ban एक प्रोग्राम है जो brute-force और port scanning हमलों से सर्वर की रक्षा करता है और दुर्भावनापूर्ण IP पतों को अपने-आप ब्लॉक कर देता है।

port scan क्या है?

जब हमलावर कमज़ोर सेवाएँ ढूँढने के लिए आपके सर्वर के कई अलग-अलग पोर्ट से कनेक्ट करने की कोशिश करता है, तो उसे port scan कहते हैं।

brute-force हमला क्या है?

जब हमलावर बार-बार पासवर्ड अंदाज़े से आज़माता है, जैसे SSH में लॉगिन करने के लिए, तो उसे brute-force हमला कहते हैं।

जानकारी

लेखक का मूल विवरण

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. '

repo: mukul975/Anthropic-Cybersecurity-Skills

लोकप्रियता

GitHub स्टार
35k
रैंकिंग में स्थान
#7859
लाइसेंस
Apache-2.0
अपडेट की गई
31/8/2026

क्या यह skill काम की है?

0

लॉग इन करें वोट करने के लिए।

कमेंट

  • …

इस repository की और skills

मिलती-जुलती skills