Cybersecurity guides, explanations and reader checklists on whilenetworking.com

Defensive Analysis Project: Parsing Syslog Entries to Correlate Brute Force Attacks Against SSH and RDP Services Over 24 Hours

In modern network defense, the ability to correlate disparate log streams is a fundamental skill for incident responders. A brute force attack often leaves…

In modern network defense, the ability to correlate disparate log streams is a fundamental skill for incident responders. A brute force attack often leaves subtle traces in system logs that are easily missed when viewed in isolation. This guide walks you through a defensive analysis project designed to identify coordinated attempts against SSH and RDP services over a 24-hour window using standard syslog formats. By parsing these entries, you can distinguish between legitimate administrative activity and malicious automated scanning tools.

Understanding the Threat Landscape: SSH vs. RDP Log Signatures

Before diving into parsing commands, it is essential to understand how different operating systems record authentication failures. Linux-based servers typically use syslog, while Windows systems often utilize the Event Viewer but can forward logs to a central syslog daemon via agents or built-in forwarding features in newer versions.

SSH (Secure Shell) logs usually reside in /var/log/auth.log on Debian/Ubuntu systems or /var/log/secure on RHEL/CentOS/Fedora entries. A failed SSH attempt typically generates an entry containing keywords like Failed password, authentication failure, or Invalid user. These messages often include the username attempted and the source IP address.

RDP (Remote Desktop Protocol) logs on Windows are found in the Security event log, specifically Event ID 4625. This event indicates that a login attempt failed. The log entry will contain the account name, the process ID of the service handling the connection, and crucially, the source network address.

Setting Up a Safe Analysis Environment

To practice this analysis without risking production systems, you must establish a controlled lab environment or use anonymized data dumps from public repositories like the MIT Lincoln Laboratory’s Cyber Range datasets. Never attempt to parse logs from live customer networks without explicit authorization and a signed engagement letter.

Prerequisites:
* Access to a log aggregation tool (e.g., ELK Stack, Splunk Free, Graylog) or a standard Linux workstation with grep, awk, and jq installed.
* A sample dataset of syslog entries covering at least 24 hours.
* Basic familiarity with command-line interfaces.

Safety Note: All commands provided below are for educational purposes in isolated environments. Running these scripts against live internet-facing servers without prior hardening measures could expose sensitive data or trigger false positives that disrupt legitimate services.

Step-by-Step Log Parsing and Correlation Strategy

The core of this project involves writing a script or using command-line tools to filter and join log entries based on time stamps and source IP addresses. The goal is to identify IPs that generate a high volume of failed attempts within a short timeframe, indicative of automated brute force tools.

1. Extracting SSH Failure Events

First, isolate all authentication failures from the SSH logs. In a Linux environment, you can use grep to filter relevant lines.

# Example command to extract failed SSH attempts from auth.log
grep "Failed password\|Invalid user" /var/log/auth.log > ssh_failures.txt

This command creates a file containing only the lines indicating a failed login. Note that this does not include successful logins, which is often desirable for attack detection but requires careful correlation to avoid missing pivoting attackers who succeed after many failures.

2. Extracting RDP Failure Events

For Windows logs forwarded to a syslog collector, the format may vary. Assuming a standard RFC 5424 or BSD syslog format where the facility and severity are consistent:

# Example command to extract failed RDP attempts (Event ID 4625 mapped to syslog)
grep "EventID=4625\|An account failed" rdp_syslog.log > rdp_failures.txt

If your environment uses raw Event Log XML exports, you would need to use a tool like PowerShell or xmlstarlet to parse the XML and extract similar fields.

3. Correlating by Source IP and Time Window

The most critical step is correlating the two datasets. An attacker might target SSH first, then switch to RDP if the former fails, or scan both simultaneously. You need to identify source IPs appearing in both lists within a 24-hour window.

# Extract unique source IPs from SSH failures
awk '{print $NF}' ssh_failures.txt | sort -u > ssh_ips.txt

# Extract unique source IPs from RDP failures (adjust field number based on your log format)
awk '{print $10}' rdp_failures.txt | sort -u > rdp_ips.txt

# Find intersection of IPs attacking both services
comm -12 <(sort ssh_ips.txt) <(sort rdp_ips.txt) > correlated_attackers.txt

Explanation: The awk command extracts fields based on space delimiters; you must adjust the field number ($NF for last field, $10 for a specific column) depending on your specific syslog parser output. The comm -12 command finds lines common to both sorted files.

Interpreting Results and Identifying Attack Patterns

Once you have the list of correlated IPs, analyze the frequency of attempts. A legitimate administrator might log in via SSH and occasionally fail once due to a typo. However, an IP address appearing with 50+ failed SSH entries and 20+ failed RDP entries within one hour is almost certainly an automated botnet or scanning tool.

Illustrative Output Analysis:
If your correlated_attackers.txt shows the IP 192.0.2.45, review the raw logs for that IP. Look for patterns in the usernames being tried (e.g., admin, root, administrator, guest). If the usernames cycle rapidly through common lists, it confirms an automated brute force attack rather than human error.

Verification and False Positive Mitigation

Before reporting a finding as a confirmed attack, you must verify that the activity is not part of authorized penetration testing or scheduled maintenance. Check your ticketing system (e.g., Jira, ServiceNow) for active engagement logs associated with that IP range.

Common Errors and Fixes:
* Error: Log timestamps are in different time zones.
* Fix: Normalize all timestamps to UTC before parsing using dateutil or standard Unix TZ environment variables.
* Error: Missing fields in syslog entries due to truncation.
* Fix: Use a proper log parser (like Logstash) that preserves full message content rather than relying on simple grep which may miss multi-line events.
* Error: Legitimate high-volume scanning services (like vulnerability scanners) mimicking attacks.
* Fix: Cross-reference the User-Agent string or specific process names in the logs to distinguish between tools like Nessus/Nmap and actual brute force bots.

Industry Application: Hardening and Incident Response

In a professional setting, this analysis feeds directly into incident response playbooks. If correlation confirms an active attack:
1. Block the IP: Use your firewall or WAF (Web Application Firewall) to drop traffic from the offending IPs immediately.
2. Hardening: Review SSH configuration (/etc/ssh/sshd_config) to disable root login and enforce key-based authentication only. Similarly, ensure RDP is restricted via Network Level Authentication (NLA) and limited to specific subnets using Windows Firewall rules.
3. Alerting: Configure SIEM rules to trigger alerts when a single IP exceeds a threshold of failed logins (e.g., >5 per minute).

Student Practice Task

To solidify these skills, students should set up a virtual machine with two services running: an SSH server and an RDP listener (using xrdp on Linux for simulation). They should then use a tool like hydra or medusa to perform a simulated brute force attack against both services. Finally, they must capture the logs, parse them using the methods described above, and generate a report detailing the attack timeline and the specific correlation logic used to detect it. This hands-on approach bridges the gap between theoretical log analysis and real-world defensive operations.

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.