Detecting a Silent Root‑Kit After Brute‑Force Logins
Brute‑force attempts are a daily nuisance. Most of the time they’re harmless – a bot scanning for weak passwords. But when a successful login slips through, it can be the first step toward a silent root‑kit. The goal of this post is to show how to use journalctl as a hunting tool, how to spot the tell‑tale signs of a stealthy compromise, and what to do once you find something.
Why journalctl?
Systemd’s journal stores every system event in a binary format that preserves timestamps, user IDs, and the exact command that produced the log line. Unlike plain text logs, the journal is immutable (unless you explicitly truncate it), and it can be queried with powerful filters. That makes it a first‑line detective for root‑kit activity that tries to hide in plain sight.
1. Baseline: What a Normal Login Looks Like
Before hunting, you need a reference. A typical successful SSH login appears in the journal as:
$ journalctl -u sshd --since "2026-12-04 00:00" | grep "Accepted password"
Typical output:
Aug 12 14:23:01 server sshd[1234]: Accepted password for user1 from 203.0.113.45 port 54321 ssh2
Notice the fields:
- timestamp – the exact moment of the event
- service –
sshd - action –
Accepted password - user –
user1 - source IP –
203.0.113.45
A silent root‑kit will often try to mimic this pattern, but subtle differences can betray it.
2. Hunting for Anomalies
2.1. Unusual Source IPs
If you’re running a firewall that blocks known bad IPs, the journal should only contain whitelisted addresses. A quick filter:
$ journalctl -u sshd --since "2026-12-04 00:00" | grep "Accepted" | awk '{print $11}' | sort | uniq -c | sort -nr
If you see a high count for an IP that isn’t in your allowed list, that’s a red flag.
2.2. Logins at Odd Hours
Root‑kits often operate when admins are asleep. Use a time‑based filter:
$ journalctl -u sshd --since "2026-12-04 00:00" | grep "Accepted" | awk '$3 ~ /[0-2]/'
Any logins between 00:00 and 02:59 that aren’t part of a scheduled job are suspicious.
2.3. Failed Logins Followed by Success
A brute‑force attack typically generates many failures before a success. Compare the failure count to the success count:
$ journalctl -u sshd --since "2026-12-04 00:00" | grep "Failed password" | wc -l
$ journalctl -u sshd --since "2026-12-04 00:00" | grep "Accepted password" | wc -l
If the ratio is >10:1, investigate the successful logins.
2.4. Unexpected Authentication Methods
Root‑kits sometimes use key‑based logins to avoid password checks. Look for Accepted publickey entries that are not part of your normal key rotation:
$ journalctl -u sshd --since "2026-12-04 00:00" | grep "Accepted publickey" | awk '{print $11}'
Cross‑reference the IPs with your known key‑owners.
3. Deep Dive: Inspecting the Session
Once you spot a suspicious login, you need to know what the attacker did.
3.1. Identify the Process Tree
Use systemd-cgtop or ps to see the process hierarchy that started from the SSH session:
$ systemctl status sshd@$(systemctl show -p MainPID sshd | cut -d= -f2)
Alternatively, find the session ID:
$ loginctl list-sessions | grep $(who -u | awk '$1=="user1"{print $2}')
Then inspect the session’s cgroup:
$ systemd-cgtop -p $(loginctl show-session <id> -p PID)
A root‑kit will often spawn a hidden process that detaches from the terminal. Look for processes with no controlling terminal (TTY= empty) and no parent in the SSH session tree.
3.2. Check for Hidden Files
Root‑kits hide files under /var/lib/ or /etc/ with names that look innocuous. Use journalctl to see file creation events:
$ journalctl -u systemd-udevd --since "2026-12-04 00:00" | grep "created" | grep -E '\/var\/lib\/|\/etc\/'
If you find a file with a timestamp matching the suspicious login, flag it.
3.3. Verify System Integrity
Run rpm -Va (RHEL/CentOS) or dpkg -V (Debian/Ubuntu) to spot altered binaries. A root‑kit may replace sshd or sudo with a compromised version. Compare the checksums with a known good snapshot or a trusted mirror.
4. Practical Example
Assume you have a Debian 12 server. You notice a login from 198.51.100.23 at 01:12. Here’s a step‑by‑step hunt:
Locate the login:
$ journalctl -u sshd --since "2026-12-04 00:00" | grep "Accepted password for" | grep "198.51.100.23"Output:
Dec 04 01:12:07 server sshd[4321]: Accepted password for admin from 198.51.100.23 port 58912 ssh2Check the session:
$ loginctl list-sessions | grep admin 3 admin 1 2026-12-04 01:12:07$ systemctl status sshd@3Look for a process tree where the parent is
sshdbut children include a binary like/usr/bin/ssh-agentthat isn’t part of the normal session.Search for hidden files:
$ journalctl -u systemd-udevd --since "2026-12-04 00:00" | grep "created" | grep "/var/lib/" Dec 04 01:12:15 server systemd-udevd[123]: Created /var/lib/ssh/authorized_keysThe file name looks legitimate, but the timestamp matches the login. Inspect the file:
$ ls -l /var/lib/ssh/authorized_keys -rw-r--r-- 1 root root 123 Dec 04 01:12 /var/lib/ssh/authorized_keysThe size is suspiciously small for a legitimate key. Open it:
$ cat /var/lib/ssh/authorized_keys ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC...The key is not in your known list. Flag it.
Validate binaries:
$ dpkg -V sudoIf
sudoshows a mismatch, you’ve found a compromised binary.Take action:
- Remove the suspicious key.
- Replace the binary from a trusted source.
- Force a password reset for the compromised account.
- Review firewall rules and block the offending IP.
5. Trade‑offs and Caveats
| Approach | Benefit | Drawback |
|---|---|---|
| Journal filtering | Fast, no extra tools | Requires root to read all entries |
| Time‑based alerts | Simple to script | False positives during maintenance |
| Process tree inspection | Precise detection of hidden processes | Requires manual analysis |
| Integrity checks | Detects binary tampering | Can be slow on large systems |
- Retention policy: If you purge the journal too aggressively, you lose the evidence. Keep at least 7 days of logs for forensic purposes.
- Encrypted logs: Some distros encrypt the journal. Ensure your monitoring tools can read it.
- Root‑kit stealth: Advanced kits may tamper with the journal itself. In that case, use an external log aggregator (e.g., rsyslog forwarding to a separate server) to preserve integrity.
6. Automation Tips
- Fail2Ban + journalctl: Configure Fail2Ban to read from the journal (
journalbackend). It will block IPs that trigger multiple failures. - Auditd: Use
auditctlto watch for file creations in/var/lib/and/etc/. Combine withjournalctlfor a single view. - Prometheus + node_exporter: Export
systemdmetrics and alert on unusual session counts.
7. When to Escalate
If you confirm a root‑kit:
- Isolate the host (disable network interfaces).
- Preserve the disk image for forensic analysis.
- Reinstall the OS from a known good image.
- Review all accounts and keys.
- Harden SSH: disable password auth, enforce key‑based auth, use
sshd_configoptions likePermitRootLogin noandAllowUsers.
journalctl is more than a log viewer; it’s a detective’s notebook. By establishing a clear baseline, filtering for anomalies, and inspecting the session context, you can catch a silent root‑kit before it spreads. The key is to integrate these checks into your routine: run the filters nightly, alert on outliers, and keep the journal retention policy generous enough for post‑incident analysis.
See also
- Application-Level Firewalls
- Fix the “no route to host” error when nftables blocks traffic from a bridge.
- Fixing a Broken HTTPS on a 1‑GB VPS: Certbot, Nginx, and File Permissions
- Using systemd‑journald Filters to Stop Spurious SSH Login Alerts
- Diagnosing a DNS cache miss after a systemd‑resolved restart
- Using journalctl to hunt for rogue SSH key injections