Skip to content

Artifact Analysis: Linux SSH Artifacts

1. Persistence via authorized_keys (Inbound Access)

Section titled “1. Persistence via authorized_keys (Inbound Access)”

The authorized_keys file contains the public keys that are permitted to authenticate to a specific user account without requiring a password.

  • Artifact Location: /home/<user>/.ssh/authorized_keys and /root/.ssh/authorized_keys

Threat actors frequently append their own public keys to this file. It is the most common, robust, and native persistence mechanism on Linux systems. Even if administrators rotate the user’s password, the attacker retains seamless access.

Analysts must parse these files across all user profiles, looking for specific anomalies:

  1. Unknown or Suspicious Keys: Keys that do not align with corporate IT management infrastructure.
  2. Comment Fields: SSH keys often terminate with a user-generated or auto-generated comment (e.g., user@hostname). Finding comments like root@kali, kali@kali, or unrecognizable external hostnames is a high-fidelity indicator of compromise. Attackers may attempt to blend in by using deceptive comments like backup-admin.
  3. Forced Commands (Stealth Backdoor): Attackers can prepend execution options to a key. If a key starts with command="/usr/bin/perl /tmp/backdoor.pl", the specified command executes automatically as soon as the attacker authenticates with that key, providing a highly stealthy, interactive shell without spawning a standard TTY.
  4. Timestamp Anomalies: Compare the modification time (mtime) of the authorized_keys file with the suspected intrusion window.

2. Lateral Movement Tracking via known_hosts (Outbound)

Section titled “2. Lateral Movement Tracking via known_hosts (Outbound)”

The known_hosts file acts as an automated address book. It stores the cryptographic fingerprints of remote servers that the user has connected to from the current machine.

  • Artifact Location: /home/<user>/.ssh/known_hosts

This artifact is vital for mapping the attacker’s lateral movement. If an analyst is triaging “Patient Zero” and discovers the IP addresses of internal database servers or domain controllers within the root user’s known_hosts file, it confirms the attacker successfully pivoted to those critical assets.

3. Credential Theft: Private Keys (id_rsa / id_ed25519)

Section titled “3. Credential Theft: Private Keys (id_rsa / id_ed25519)”

These files represent the digital identity of the compromised user.

  • Artifact Location: /home/<user>/.ssh/id_rsa, id_ed25519, id_ecdsa

If an attacker gains read access to this directory, they will invariably exfiltrate these private keys. Consequently, the attacker inherits the user’s digital identity and can seamlessly authenticate to any internal server that trusts these keys (often the exact servers listed in the known_hosts file). If evidence suggests the .ssh directory was accessed (correlate with Linux Shell History), all associated keys must be revoked immediately across the entire infrastructure.

4. Server Configuration Tampering (sshd_config)

Section titled “4. Server Configuration Tampering (sshd_config)”

Adversaries occasionally modify the SSH daemon configuration to lower security postures or establish hidden backdoors.

  • Artifact Location: /etc/ssh/sshd_config

Analysts must verify the integrity of this file against a known-good baseline, looking for:

  • PermitRootLogin yes: Enabling direct root logins, which are typically disabled by default.
  • PasswordAuthentication yes: Re-enabled to facilitate brute-force or lateral movement using dumped clear-text credentials.
  • AuthorizedKeysFile: Attackers may change this directive to point to a hidden file (e.g., /tmp/.hidden_keys), bypassing standard audits of the ~/.ssh/ directory.

To accelerate the investigation of a mounted forensic image, DFIR teams should utilize automated scripts to audit all SSH artifacts concurrently.

audit_linux_ssh.sh
#!/bin/bash
TARGET_DIR="/mnt/analysis"
echo "[+] Extracting all authorized_keys..."
find $TARGET_DIR/home $TARGET_DIR/root -type f -name "authorized_keys" -exec echo -e "\n=== {} ===" \; -exec cat {} \;
echo "[+] Checking for forced commands in authorized_keys..."
find $TARGET_DIR/home $TARGET_DIR/root -type f -name "authorized_keys" -exec grep "command=" {} +
echo "[+] Auditing sshd_config anomalies..."
grep -E "^PermitRootLogin|^PasswordAuthentication|^AuthorizedKeysFile" $TARGET_DIR/etc/ssh/sshd_config