Cybersecurity guides, explanations and reader checklists on whilenetworking.com

Defensive Technique: Analyzing Syslog Entries to Identify Brute Force Attacks Against SSH and RDP Services

In the landscape of modern network defense, log analysis remains one of the most effective yet underutilized tools for incident response. While firewalls…

In the landscape of modern network defense, log analysis remains one of the most effective yet underutilized tools for incident response. While firewalls provide perimeter protection and intrusion detection systems (IDS) offer real-time alerting, syslog entries serve as the historical record of system interactions. For IT students and junior engineers, mastering the art of parsing these logs is essential for identifying stealthy brute force attacks targeting SSH (Secure Shell) and RDP (Remote Desktop Protocol). These protocols are frequent targets because they allow remote access; if an attacker gains a foothold here, they can pivot through the entire network. This guide provides a practical, hands-on approach to detecting these attacks using standard Unix/Linux utilities, focusing on authorized lab environments to ensure safety while building critical defensive skills.

Understanding the Threat Vector: Why SSH and RDP Are Targets

SSH is the standard protocol for secure remote administration of servers, while RDP is the Microsoft standard for accessing Windows desktops and servers. Both protocols rely on authentication mechanisms that are vulnerable to brute force attacks. In a brute force scenario, an automated script attempts thousands of username/password combinations per minute against a target port (port 22 for SSH, port 3389 for RDP).

The attacker’s goal is simple: find one valid credential pair. Once successful, they gain full control. The signature of such an attack in system logs is not a single failed login, but a rapid succession of failures from a single source IP address or a small cluster of IPs within a short timeframe. Recognizing this pattern early allows administrators to block the attacker before a breach occurs.

Prerequisites and Safe Lab Setup

Before analyzing logs, you must understand how to generate them safely. Attempting to brute force a production server is unethical and illegal. Therefore, this guide assumes a controlled lab environment using virtual machines or isolated containers.

Required Environment:
* Target System: A Linux distribution (e.g., Ubuntu 22.04 LTS) or Windows Server with SSH/RDP enabled.
* Log Collector: Ensure the rsyslog service is running on the target. For Linux, verify it is active with systemctl status rsyslog.
* Attack Simulator: A separate machine (or a second VM) to simulate the attack. Tools like hydra or custom Python scripts can be used, but for this exercise, we will simulate the traffic manually to focus on log analysis.

Safety First: Never run these commands on your primary workstation or production network. Isolate your lab using a virtual switch that prevents external access. If you are unsure about your local network configuration, assume it is connected to the internet and treat the target as if it were public-facing.

Step-by-Step: Identifying SSH Brute Force Patterns in Syslog

Once the environment is isolated, let us generate some sample attack traffic. From your simulator machine, attempt to log in to the target using a non-existent user multiple times. You can simulate this by opening three terminal windows and running ssh invalid_user@target_ip repeatedly for 30 seconds.

On the target system, examine the authentication logs. On Debian/Ubuntu systems, these are typically located at /var/log/auth.log. On RHEL/CentOS/Fedora, they are found in /var/log/secure.

Open the log file using a text editor like nano or vim:

sudo nano /var/log/auth.log

Look for lines containing “Failed password”. A legitimate user might fail once or twice due to a typo. An attacker, however, generates a flood of failures. Search for the pattern using grep:

grep "Failed password" /var/log/auth.log | grep -oE 'user=[^ ]+' | sort | uniq -c | sort -rn

Expected Illustrative Output:

      45 user=invalid_user
       2 user=admin
       1 user=root

This output clearly indicates that invalid_user is being targeted with 45 attempts in the captured timeframe. The high count from a single username suggests an automated tool is scanning for specific accounts. If you see hundreds of lines from different usernames but only a few from one IP, it might be a password spray attack. If you see thousands of failures from one IP against many users, it is a classic SSH brute force.

Detecting RDP Brute Force Attempts via Syslog

While RDP logs are often stored in Event Viewer on Windows, Linux machines acting as jump hosts or gateways will still capture these attempts in their syslog if they forward the events. However, if you are analyzing a Windows target directly, the event log path is Applications and Services Logs > Security.

In a Linux environment forwarding RDP logs (common in hybrid setups), look for messages related to the RDP service or generic authentication failures that might include the destination port 3389. If your syslog is configured correctly with rsyslog rules, you might see entries similar to:

Oct 24 10:15:02 server sshd[1234]: Connection closed by authenticating user admin 192.168.1.5 port 22 [preauth]

Note that while sshd handles SSH, RDP connections to a Linux machine (via Xrdp) often write to the same auth log or require specific plugins like libnss-pam-rdp.

For Windows Event Logs, use PowerShell to query for failed logins:

Get-WinEvent -FilterHashtable @{LogName='Security'; Id=4625} | Select-Object TimeCreated, Message | Format-Table

Event ID 4625 specifically denotes an account failure. Filtering by this ID and grouping by the SourceNetworkAddress field will reveal IPs conducting RDP brute force attempts.

Incident Response: Blocking the Offender

Identifying the attack is only half the battle; stopping it requires immediate action. Once you have identified a malicious IP address from your log analysis, do not wait for the next failed attempt.

Action Plan:
1. Isolate the Host: If the target is critical, disconnect it from the network to prevent lateral movement if credentials were compromised.
2. Block at the Perimeter: Add the offending IP to your firewall allow/deny list. For Linux using ufw (Uncomplicated Firewall), run:
bash
sudo ufw deny from <Malicious_IP> to any port ssh
sudo ufw reload

3. Fail2Ban Integration: Ideally, your infrastructure should use a tool like Fail2Ban. This daemon automatically scans logs and bans IPs that trigger certain conditions (e.g., 6 failed attempts in 10 minutes). Verify its status with:
bash
sudo systemctl status fail2ban

Hardening Your SSH and RDP Configuration

Prevention is better than detection. After analyzing logs, you should harden your systems to reduce the attack surface.

  • Disable Root Login: Edit /etc/ssh/sshd_config and set PermitRootLogin no. Force users to create standard accounts with sudo privileges.
  • Change Default Ports: Changing the default port from 22 to a non-standard number (e.g., 2244) reduces noise from automated bots, though it does not stop determined attackers. Update both the config file and your firewall rules accordingly.
  • Use Key-Based Authentication: Disable password authentication (PasswordAuthentication no) in favor of SSH keys. This renders brute force attacks ineffective since they cannot guess passwords.
  • Limit RDP Access: On Windows, use Network Level Authentication (NLA) and restrict RDP access via Group Policy to specific subnets or IP ranges.

Student Practice Task: The Log Forensics Challenge

To solidify these skills, try the following exercise in your lab environment:
1. Set up two VMs: Victim-Server and Attacker-Box.
2. Configure rsyslog on Victim-Server to forward logs to a central collector or simply inspect local files.
3. Write a simple Python script on Attacker-Box that attempts to SSH into Victim-Server using a list of random usernames.
4. Run the script and observe the logs on Victim-Server.
5. Use grep and awk to extract the attacking IP, count the attempts, and generate a report showing the timeline of the attack.

This exercise mimics real-world incident response where engineers must sift through noise to find the signal.

Conclusion

Analyzing syslog entries is a fundamental defensive technique that empowers IT professionals to detect and mitigate brute force attacks against critical services like SSH and RDP. By understanding the specific log formats, utilizing command-line tools for pattern recognition, and implementing hardening measures, you can significantly enhance your organization’s security posture. Remember, however, that technology alone is not a silver bullet. Regular log review, automated monitoring with tools like SIEM (Security Information and Event Management), and continuous education on emerging threats are vital components of a robust cybersecurity strategy. Always operate within legal boundaries and authorized lab environments when practicing these techniques.

Educational-use notice: This tutorial is for learning and controlled lab use only. Test carefully, use backups, and obtain authorization before making changes. Do not run unfamiliar commands on production systems. We accept no responsibility for misuse, damage, data loss, or production issues.