In the realm of defensive security, log analysis remains one of the most critical skills for incident responders. Attackers often rely on automated scripts to perform brute force attacks against remote access services like SSH (port 22) and RDP (port 3389). While these attempts may fail due to strong passwords or account lockout policies, they generate a distinct signature in system logs. This exercise guides IT students and junior engineers through the process of parsing syslog files to identify, correlate, and quantify these brute force attempts over a specific timeframe. By mastering this workflow, practitioners can strengthen their incident response capabilities and validate the effectiveness of existing security controls.
Understanding the Data Source: Syslog Architecture
Before diving into commands, it is essential to understand where the data resides. In Linux environments, syslog messages are typically aggregated in /var/log/auth.log (Debian/Ubuntu) or /var/log/secure (RHEL/CentOS/Fedora). Windows systems utilize the Event Viewer, storing authentication events in the Security log under Event ID 4625 for failed logons.
For this exercise, we will focus on a Linux-based server where both SSH and an RDP gateway (such as OpenSSH with X11 forwarding or a dedicated VNC/RDP bridge) are running. The goal is to isolate entries indicating authentication failures within a 24-hour window. It is important to note that log formats can vary slightly depending on the system version and kernel configuration. Always verify your specific distribution’s documentation before executing commands in production environments.
Step-by-Step Log Parsing with Standard Utilities
The most accessible method for parsing logs involves using standard Unix utilities like grep, awk, and date. This approach requires no additional software installation, making it ideal for initial assessments or restricted lab environments.
Identifying Failed Authentication Attempts
To find failed login attempts, we search for specific keywords such as “Failed password”, “authentication failure”, or “Invalid user”. The following command filters the auth log for failures occurring between January 1st and January 2nd (representing a 24-hour period):
grep -E "Failed password|Invalid user" /var/log/auth.log | grep -E "Jan 0[1-9]|Jan 1[0-9]" > /tmp/failed_ssh_attempts.txt
Explanation of the command:
* grep -E: Enables extended regular expressions for flexible pattern matching.
* /var/log/auth.log: The target file containing authentication events.
* > /tmp/...: Redirects the output to a temporary file for further analysis.
Isolating RDP-Related Failures in Hybrid Environments
On Linux servers hosting RDP services, log entries might differ slightly from standard Windows events. However, many RDP gateways implemented on Linux still report failures via the SSH subsystem or specific application logs. If your environment uses a tool like xrdp, you might also check /var/log/xrdp.log.
grep -i "error|fail" /var/log/xrdp.log | grep -E "Jan 0[1-9]|Jan 1[0-9]" > /tmp/failed_rdp_attempts.txt
Correlating Data and Quantifying the Attack Surface
Finding raw logs is only the first step. The true value lies in correlation: determining how many attempts targeted SSH versus RDP and identifying if they originated from the same IP addresses. This helps distinguish between a single attacker probing multiple vectors or distinct automated bots.
Generating a Summary Report
We can use awk to count occurrences and group them by source IP address. This provides a high-level view of the attack intensity.
cat /tmp/failed_ssh_attempts.txt /tmp/failed_rdp_attempts.txt | awk '{print $1, $2}' | sort | uniq -c | sort -rn | head -n 10 > /correlation_summary.txt
Expected Output Structure:
The resulting file will display counts followed by IP addresses. An illustrative output might look like this:
45 192.168.1.105 # High volume of attempts from one source
12 10.0.0.55 # Moderate activity
3 203.0.113.50 # Low activity, possibly a scan
Note: The first column represents the count of failed attempts, and subsequent columns represent the source IP address. This format allows immediate identification of malicious actors targeting your infrastructure.
Advanced Analysis with Python (Optional)
For larger datasets or more complex correlation needs, Python offers better readability and flexibility. If available on the system, a simple script can parse timestamps and aggregate data more robustly.
from collections import Counter
import re
# Load failed attempts
with open('/tmp/failed_ssh_attempts.txt') as f:
ssh_lines = f.readlines()
# Simple IP extraction regex (adjust based on actual log format)
ip_pattern = r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}'
ssh_ips = re.findall(ip_pattern, ' '.join(ssh_lines))
ssh_counts = Counter(ssh_ips)
print(f"Total unique SSH source IPs: {len(ssh_counts)}")
for ip, count in ssh_counts.most_common(5):
print(f"IP: {ip}, Attempts: {count}")
Verification and Common Pitfalls
When performing log forensics, accuracy is paramount. Misinterpreting logs can lead to false positives or missed detections. Below are common errors practitioners encounter and how to fix them.
Common Mistake 1: Ignoring Timezone Discrepancies
Syslog timestamps are often in UTC, while local system time may differ. Correlating a 24-hour period based purely on string matching (e.g., “Jan 01”) can miss entries if the server clock is skewed or if daylight saving time changes occur.
Fix: Always convert logs to UTC for analysis or ensure your analysis script normalizes timestamps before filtering. Use date -u commands to verify system time alignment.
Common Mistake 2: Overlooking Log Rotation
Syslog files are often rotated (e.g., from /var/log/auth.log to /var/log/auth.log.1) based on size or age. If your analysis script only reads the current active log file, you will miss historical data that has been archived.
Fix: Modify your search commands to include rotated logs:
grep -r "Failed password" /var/log/auth.log* > /tmp/all_failed_attempts.txt
Common Mistake 3: False Positives from Service Restarts
System updates or service restarts can generate log entries that mimic authentication failures. For example, a failed bind attempt during an SSH daemon restart might look like a brute force entry.
Fix: Cross-reference timestamps with system event logs (/var/log/syslog) to confirm whether the “failure” corresponds to a legitimate user login attempt or a service initialization error.
Student Practice Task and Industry Application
To solidify these skills, students should set up a controlled lab environment using virtual machines (e.g., VirtualBox or VMware). In this scenario:
1. Deploy two vulnerable Linux VMs acting as targets.
2. Configure one to simulate an attacker by running a script that attempts SSH and RDP logins every 5 seconds for 24 hours using invalid credentials.
3. Deploy a monitoring VM to collect logs from the targets.
4. Perform the parsing, correlation, and reporting exercises described above.
Industry Application: In a real-world enterprise setting, this exercise translates directly to SOC (Security Operations Center) workflows. Security analysts use similar techniques to detect lateral movement attempts or credential stuffing attacks. The ability to quickly aggregate logs from multiple sources allows teams to contain threats before they escalate into full breaches. Regularly practicing these exercises ensures that engineers remain proficient in defensive security methodologies.
Conclusion
Parsing syslog files to correlate brute force attempts against SSH and RDP ports is a fundamental skill for any cybersecurity professional. By utilizing standard command-line tools or scripting languages, practitioners can effectively quantify attack vectors and identify persistent threats. However, it is crucial to remember that log analysis is just one layer of defense; it must be combined with hardening measures like fail2ban, intrusion detection systems (IDS), and regular patching. Always operate within authorized lab environments when testing these procedures, and consult official vendor documentation for specific log formats and retention policies applicable to your jurisdiction.
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.

