Day #6 — Log Analysis Basics: Linux Auth Log (SSH Brute-Force Simulation)

🎯 Objective Simulate an SSH brute-force attack and detect it using Linux authentication logs. Learn to spot multiple failed login attempts, identify attacker IP(s), targeted user accounts, and create simple detection rules/alerts.

Overview The attacker (Kali) runs a password-guessing tool (hydra) against an Ubuntu SSH server; the defender examines /var/log/auth.log (or /var/log/secure on RHEL/CentOS) to extract indicators (SRC IP, username list, timestamps) and recommend mitigations.

Safety note (read aloud) Do this only in an isolated lab environment. Never brute-force systems you do not own or have written permission to test.


Lab Setup

Systems

  • Attacker: Kali Linux (or any Linux with hydra)

  • Target: Ubuntu Server (or Debian) with openssh-server

  • Logging: rsyslog (default on Ubuntu)

Files to inspect

  • Ubuntu/Debian: /var/log/auth.log

  • RHEL/CentOS: /var/log/secure

Required packages (target machine)

sudo apt update
sudo apt install openssh-server rsyslog -y   # Ubuntu/Debian
sudo systemctl enable --now ssh

Install hydra (attacker machine)


Lab Simulation — Step-by-Step

A. Prepare the victim (Ubuntu)

  1. Ensure SSH is installed and running:

  2. (Optional but recommended) Harden SSH so you don’t expose it later:

    • Edit /etc/ssh/sshd_config:

      • PermitRootLogin no

      • PasswordAuthentication yes (for lab purposes only; set back later)

    • Restart ssh:

  3. Confirm logging is working:

B. Attacker: Run a controlled brute-force with hydra

Replace 10.0.2.20 and targetuser with your lab target details.

  1. Quick test against a single username (password list passwords.txt):

  2. Test multiple usernames (user list users.txt):

  3. Low-and-slow attack (reduce threads, add delay):

Record the attacker IP (from the Kali VM network) — e.g., 10.0.2.10.


C. Observe & collect evidence (defender)

  1. Live monitor:

    Look for lines like:

  2. Quick grep for attacker IP:

  3. Extract representative log lines — pick 3–6 lines showing repeated failures from same SRC with timestamps and usernames.


Log Analysis — Commands & Heuristics

Count failed attempts per IP (how noisy)

Interpretation: top result = most attempts → likely attacker.

Count unique usernames attempted per IP (target diversity)

Rate-based alert: alert if >20 failures in last 200 lines

User-focused view (who's being targeted)

This shows which usernames are being tried most often (e.g., root, admin).


What to capture as evidence (deliverables)

  1. 2–5 auth.log excerpts that prove the brute-force (same SRC, repeated Failed password, timestamps). Example:

  2. Hydra output (screenshot or hydra.txt) showing attempted usernames/passwords.

  3. Short summary (one paragraph): attacker IP, time window, usernames targeted, heuristic used (e.g., >20 failures in 5 minutes), and immediate action taken.

  4. Optional: output from the Python parser or awk counts.


Detection Heuristics (simple & practical)

  • High attempt rate: same IP generating > X failed logins within Y minutes (example: >20 failures in 5 minutes).

  • User diversity: single IP trying many different usernames (e.g., >5 unique usernames).

  • Sequential port change: if attempts come from many ephemeral source ports in quick succession — typical of automated tools.

  • Invalid user: many invalid user entries implies brute-force against non-existent accounts.

Choose thresholds that match your lab (conservative for noisy environments, tighter for low-noise servers).


Immediate Mitigations (commands)

  1. Block the attacker IP with ufw or iptables:

  2. Enable SSH rate-limiting with UFW:

  3. Install & configure fail2ban:

  4. Disable password auth and use key-based auth (after you finish the lab):

    • In /etc/ssh/sshd_config: PasswordAuthentication no then sudo systemctl restart ssh.

Last updated