Why credential reset alone does not equal containment
- SSH keys the attacker planted on other internal hosts
- RDP sessions or cached credentials on Windows machines the attacker touched
- Service account tokens or API keys harvested from config files, environment variables, or memory
- New local user accounts created on adjacent systems
- Modified
authorized_keysfiles on servers that trust the compromised host
Auditing SSH keys and trust relationships on Linux hosts
authorized_keys file across your infrastructure. On each server:
BASH
# Find all authorized_keys files, including for service accounts
find / -name 'authorized_keys' -type f 2>/dev/null- Keys added to root's
authorized_keys(/root/.ssh/authorized_keys) - Keys added to service accounts that normally do not accept interactive SSH (like
www-data,mysql,backup) - Keys with unusual comments or no comment at all (legitimate keys typically have a user@host comment)
journalctl:
BASH
# Review SSH authentication events from the past 7 days
journalctl -u sshd --since '7 days ago' | grep -i 'accepted\\|failed'/var/log/auth.log (Debian/Ubuntu) or /var/log/secure (CentOS/RHEL). Look for accepted logins from internal IPs that should not be initiating SSH connections to that host. A database server accepting SSH from a web server might be normal for your setup, or it might be lateral movement. You need your baseline to tell the difference.
Do not forget ~/.ssh/known_hosts on the compromised machine. This file reveals which hosts the attacker (or the attacker's tools) connected to from that machine. New entries added around the time of compromise deserve investigation.
Checking RDP logs and cached credentials on Windows
- 4624 with Logon Type 10: successful RDP logon
- 4625 with Logon Type 10: failed RDP logon attempt
- 4648: logon attempted using explicit credentials (often indicates credential reuse or pass-the-hash)
POWERSHELL
# List successful RDP logons (Type 10) from the past 7 days
Get-WinEvent -FilterHashtable @{LogName='Security'; Id=4624; StartTime=(Get-Date).AddDays(-7)} |
Where-Object { $_.Properties[8].Value -eq 10 } |
Select-Object TimeCreated, @{N='SourceIP';E={_.Properties[18].Value}}, @{N='Account';E={_.Properties[5].Value}}CachedLogonsCount registry value). An attacker with local admin on one machine can extract these cached hashes and use them to authenticate to other systems. Resetting the originally compromised password does not invalidate cached hashes already sitting on other machines the attacker visited.
If your environment uses Active Directory, also check for:
- New computer accounts or user accounts created during the compromise window
- Group membership changes (especially additions to Domain Admins, Enterprise Admins, or local Administrators groups)
- Kerberos ticket-granting ticket (TGT) requests from unusual hosts
Service accounts and API keys: the forgotten credentials
- Database connection strings in application config files (
.env,wp-config.php,settings.py,appsettings.json) - API keys and tokens stored in environment variables or config management
- SMTP credentials used by the application to send email
- Backup system credentials (rsync keys, S3 access keys, FTP passwords)
- Control panel API tokens (cPanel, Plesk, or cloud provider API keys)
Building a lateral movement checklist that fits your environment
- Map the blast radius. From the compromised host, list every system it could reach: SSH keys, stored credentials, network access. This is your list of hosts to investigate.
- Check authentication logs on every host in the blast radius. Look for logons from the compromised host or using the compromised account during the compromise window. On Linux, check SSH logs. On Windows, check Security Event Log for RDP and explicit credential logons.
-
Audit key material and stored credentials. Compare
authorized_keysfiles against known good state. Check for new local accounts. Identify every credential stored on the compromised host and rotate all of them. -
Look for persistence mechanisms. New cron jobs, systemd services, scheduled tasks, startup scripts, modified shell profiles (
.bashrc,.profile). An attacker who moved laterally typically plants persistence on the new host too. -
Verify the timeline. Correlate filesystem timestamps (
staton Linux,$MFTanalysis on Windows) with log entries. If you find a new SSH key on a second server and the creation timestamp falls within the compromise window, that server was touched.
