This playbook is for responding to security incidents on Linux systems, covering common attack vectors and remediation steps.
Incident: SSH Brute-Force Attack Detected
What Broke: An unauthenticated user repeatedly failed to log in via SSH, overwhelming the sshd daemon and potentially consuming system resources or masking other malicious activity.
Common Causes and Fixes:
-
Excessive Failed Logins: The most common cause is automated brute-force tools like Hydra or John the Ripper attempting to guess passwords.
- Diagnosis: Check
auth.log(orsecureon RHEL/CentOS) for a high volume of "Failed password" or "Invalid user" messages from a single IP address or a range of IPs.sudo grep "Failed password" /var/log/auth.log | awk '{print $(NF-3)}' | sort | uniq -c | sort -nr | head - Fix: Block the offending IP addresses at the firewall.
This prevents further connection attempts from the attacker’s source IP, immediately stopping the brute-force.sudo ufw deny from <offending_ip_address> to any # Or for iptables: sudo iptables -A INPUT -s <offending_ip_address> -j DROP
- Diagnosis: Check
-
Weak SSH Configuration: Default SSH configurations can be too permissive, allowing password authentication for many users.
- Diagnosis: Review
/etc/ssh/sshd_config. Look forPasswordAuthentication yesandPermitRootLogin yes. - Fix: Disable password authentication and disallow root login.
This forces the use of SSH keys (more secure) and prevents direct root access, significantly hardening the system against brute-force attacks.sudo sed -i 's/#PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config sudo sed -i 's/#PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config sudo systemctl restart sshd
- Diagnosis: Review
-
Unnecessary User Accounts: A large number of user accounts, especially those with weak passwords, increase the attack surface.
- Diagnosis: List all user accounts.
Identify accounts that are no longer needed or are default system accounts that might have been compromised.cut -d: -f1 /etc/passwd - Fix: Remove or disable unused user accounts.
Reducing the number of valid targets makes brute-force attempts less likely to succeed.sudo userdel <username> # Or to disable temporarily: sudo usermod -L <username>
- Diagnosis: List all user accounts.
-
Compromised Credentials: An attacker may have obtained valid credentials through phishing or other means.
- Diagnosis: If a legitimate user’s account shows brute-force activity, their credentials may be compromised. Check for successful logins from unusual IPs before the brute-force started.
- Fix: Force a password reset for the affected user(s) and investigate how their credentials were leaked.
This immediately invalidates the compromised credential, stopping unauthorized access.sudo passwd <username>
-
SSH Port Obfuscation (Security by Obscurity, but helps): Running SSH on a non-standard port can reduce the noise from automated scanners.
- Diagnosis: Check the
Portdirective in/etc/ssh/sshd_config. It’s likely set to22. - Fix: Change the SSH port to a high, unused port (e.g., 2222) and update firewall rules accordingly.
This hides the SSH service from basic port scanners, reducing the volume of automated attacks.sudo sed -i 's/#Port 22/Port 2222/' /etc/ssh/sshd_config sudo systemctl restart sshd # If using ufw: sudo ufw allow 2222/tcp sudo ufw delete allow 22/tcp
- Diagnosis: Check the
-
Intrusion Detection/Prevention System (IDS/IPS) Misconfiguration: If you have an IDS/IPS, it might not be configured to detect or block SSH brute-force attempts effectively.
- Diagnosis: Review the IDS/IPS logs and configuration for SSH-specific rules. Ensure it’s monitoring
auth.logor similar and has rules for excessive failed logins. - Fix: Enable or tune SSH brute-force detection rules in your IDS/IPS. For example, in Fail2ban:
Fail2ban monitors log files for specific patterns (like repeated failed logins) and automatically updates firewall rules to block offending IPs for a set duration.sudo apt install fail2ban # or yum install fail2ban # Configure jail.local # [sshd] # enabled = true # port = ssh # filter = sshd # logpath = /var/log/auth.log # maxretry = 3 # bantime = 3600 sudo systemctl restart fail2ban
- Diagnosis: Review the IDS/IPS logs and configuration for SSH-specific rules. Ensure it’s monitoring
The next error you’ll likely encounter after fixing SSH brute-force is a "Permission denied (publickey,password)." error if you haven’t configured SSH key authentication correctly for yourself.