Cross-source coverage
T1098.004 / ATT&CK
Account Manipulation: SSH Authorized Keys
16 rules across 5 sources.
From MITRE ATT&CK 19.2
Adversaries may modify the SSH authorized_keys file to maintain persistence on a victim host. Linux distributions, macOS, and ESXi hypervisors commonly use key-based authentication to secure the authentication process of SSH sessions for remote management. The authorized_keys file in SSH specifies the SSH keys that can be used for logging into the user account for which the file is configured. This file is usually found in the user's home directory under <user-home>/.ssh/authorized_keys (or, on ESXi, /etc/ssh/keys-<username>/authorized_keys). Users may edit the system’s SSH config file to modify the directives PubkeyAuthentication and RSAAuthentication to the value yes to ensure public key and RSA authentication are enabled, as well as modify the directive PermitRootLogin to the value yes to enable root authentication via SSH. The SSH config file is usually located under /etc/ssh/sshd_config.
Adversaries may modify SSH authorized_keys files directly with scripts or shell commands to add their own adversary-supplied public keys. In cloud environments, adversaries may be able to modify the SSH authorized_keys file of a particular virtual machine via the command line interface or rest API. For example, by using the Google Cloud CLI’s “add-metadata” command an adversary may add SSH keys to a user account. Similarly, in Azure, an adversary may update the authorized_keys file of a virtual machine via a PATCH request to the API. This ensures that an adversary possessing the corresponding private key may log in as an existing user via SSH. It may also lead to privilege escalation where the virtual machine or instance has distinct permissions from the requesting user.
Where authorized_keys files are modified via cloud APIs or command line interfaces, an adversary may achieve privilege escalation on the target virtual machine if they add a key to a higher-privileged user.
SSH keys can also be added to accounts on network devices, such as with the ip ssh pubkey-chain Network Device CLI command.
- Tactics
- Persistence · Privilege Escalation
- Platforms
- ESXi · IaaS · Linux · macOS · Network Devices
- Telemetry
-
auditd:SYSCALLmacos:unifiedlogmacos:authgcp:auditesxi:shellnetworkdevice:cli
How MITRE says to detect it DET0126
Detection Strategy for SSH Key Injection in Authorized Keys
Linux Analytic 0350
Adversary attempts to gain persistence by modifying ~/.ssh/authorized_keys via shell, text editor, echo or redirected output.
auditd:SYSCALLwrite | PATH=/home/*/.ssh/authorized_keysauditd:SYSCALLexecve
macOS Analytic 0351
Insertion of public keys into authorized_keys using bash/zsh or editor tools, correlated with suspicious process ancestry.
macos:unifiedlogprocess: exec + filewrite: ~/.ssh/authorized_keysmacos:auth~/.ssh/authorized_keys
IaaS Analytic 0352
Abuse of cloud metadata APIs or CLI to push SSH public keys to authorized_keys of virtual machines.
gcp:auditcompute.instances.setMetadata
ESXi Analytic 0353
Direct modification of /etc/ssh/keys-<user>/authorized_keys or enabling SSH in sshd_config to support public key auth.
esxi:shellfile write or edit
Network Devices Analytic 0354
Use of command-line like `ip ssh pubkey-chain` to bind SSH keys to privileged accounts on routers or switches.
networkdevice:cliip ssh pubkey-chain
elastic/detection-rules
9 rules| Detection | Severity | Format |
|---|---|---|
| AWS EC2 Instance Connect SSH Public Key Uploaded | High | Elastic TOML |
| Potential Redis CONFIG SET SSH Authorized Key Injection | High | Elastic TOML |
| Suspicious Echo or Printf Execution Detected via Defend for Containers | High | Elastic TOML |
| Pod or Container Creation with Suspicious Command-Line | Medium | Elastic TOML |
| SSH Authorized Key File Activity Detected via Defend for Containers | Medium | Elastic TOML |
| SSH Authorized Keys File Activity | Medium | Elastic TOML |
| Unusual Login via System User | Medium | Elastic TOML |
| Potential Persistence via File Modification | Low | Elastic TOML |
| SSH Key Generated via ssh-keygen | Low | Elastic TOML |
splunk/security_content
4 rules| Detection | Severity | Format |
|---|---|---|
| Linux Auditd Possible Access Or Modification Of Sshd Config File | Undefined | SPL |
| Linux Possible Access Or Modification Of sshd Config File | Undefined | SPL |
| Linux Possible Ssh Key File Creation | Undefined | SPL |
| Linux SSH Authorized Keys Modification | Undefined | SPL |
chainguard-dev/osquery-defense-kit
1 rule| Detection | Severity | Format |
|---|---|---|
| Find unexpected SSH authorized keys | Undefined | osquery SQL |
falcosecurity/rules
1 rule| Detection | Severity | Format |
|---|---|---|
| Adding ssh keys to authorized_keys | Medium | Falco YAML |
socfortress/Wazuh-Rules
1 rule| Detection | Severity | Format |
|---|---|---|
| Suspicious read access to SSH authorized_keys file (T1098.004) | Medium | Wazuh XML |