Detect SSH Authorized Keys in Sumo Logic CSE
Adversaries may modify the SSH authorized_keys file to maintain persistence on a victim host. The authorized_keys file specifies SSH keys permitted for logging into a user account, typically found at <user-home>/.ssh/authorized_keys. Adversaries add their own public keys to this file, enabling passwordless SSH access using the corresponding private key. This technique is used by multiple threat actors including Earth Lusca, TeamTNT, and Salt Typhoon, as well as malware families like Skidmap, XCSSET, and Bundlore.
MITRE ATT&CK
- Tactic
- Persistence Privilege Escalation
- Technique
- T1098 Account Manipulation
- Sub-technique
- T1098.004 SSH Authorized Keys
- Canonical reference
- https://attack.mitre.org/techniques/T1098/004/
Sumo Detection Query
_sourceCategory=*linux* OR _sourceCategory=*syslog* OR _sourceCategory=*auditd*
| where _raw matches /authorized_keys/
| parse regex "(?P<proc_name>[a-zA-Z0-9_-]+)\[(?P<pid>\d+)\]" nodrop
| parse regex "(?:user|uid)[=: ]+(?P<username>[a-zA-Z0-9_.@-]+)" nodrop
| parse regex "(?:cmd|command|exe|comm)[=: ]+\"?(?P<command>[^\"\n]+)\"?" nodrop
| parse regex "(?:path|name)[=: ]+\"?(?P<file_path>[^\"\n ]+authorized_keys[^\"\n ]*)\"?" nodrop
| if (_raw matches /\/root\/.ssh/, 1, 0) as IsRootSSHDir
| if (_raw matches /\/etc\/ssh\/keys-/, 1, 0) as IsEtcSSHKeys
| if (_raw matches />>|tee -a|tee --append/, 1, 0) as IsAppendRedirect
| if (_raw matches /ssh-keygen/, 1, 0) as IsSshKeygen
| if (_raw matches /curl|wget/, 1, 0) as IsCurlWget
| if (_raw matches /echo.*authorized_keys|printf.*authorized_keys/, 1, 0) as IsEchoWrite
| (IsRootSSHDir + IsEtcSSHKeys + IsAppendRedirect + IsSshKeygen + IsCurlWget + IsEchoWrite) as SuspicionScore
| where SuspicionScore > 0
| fields _messageTime, _sourceHost, username, proc_name, pid, command, file_path, IsRootSSHDir, IsEtcSSHKeys, IsAppendRedirect, IsSshKeygen, IsCurlWget, IsEchoWrite, SuspicionScore
| sort by _messageTime desc Detects SSH authorized_keys modification in Sumo Logic by searching Linux syslog and auditd source categories for raw messages referencing authorized_keys. Uses multi-pass regex parsing to extract username, process name, PID, command, and file path fields. Computes a six-factor suspicion score covering root SSH directory access, /etc/ssh/keys- paths, append redirect operators, ssh-keygen invocation, curl/wget downloaders, and echo/printf writes. Only alerts when at least one risk factor is present.
Data Sources
Required Tables
False Positives & Tuning
- Infrastructure-as-code tooling (Terraform remote-exec provisioners, Pulumi local commands, cloud-init scripts) that write SSH public keys to authorized_keys as part of VM provisioning at scale
- SSH bastion host initialization scripts that pre-populate authorized_keys from a central key management service (HashiCorp Vault SSH secrets engine, AWS Systems Manager, CyberArk) on startup
- Developers using ssh-copy-id, Visual Studio Code Remote SSH, or JetBrains Gateway to add their workstation public key to development servers or Kubernetes nodes for IDE-based remote development
Other platforms for T1098.004
Testing Methodology
Validate this detection against 5 adversary techniques from Atomic Red Team. Each test below lists the behaviour to exercise and the telemetry you should expect to see. Executable commands and cleanup steps are available with Pro.
- Test 1Append Adversary SSH Key to Root authorized_keys
Expected signal: auditd SYSCALL records for open()/write() on /root/.ssh/authorized_keys if auditd watch is configured. syslog entries from auditd. DeviceFileEvents (if MDE for Linux deployed): FileCreated or FileModified event for FileName=authorized_keys with FolderPath=/root/.ssh. DeviceProcessEvents: Process Create for ssh-keygen and echo/bash with ProcessCommandLine containing 'authorized_keys'. Shell history entry in /root/.bash_history.
- Test 2Add SSH Key via curl Download
Expected signal: DeviceProcessEvents: Process Create for curl with ProcessCommandLine containing 'authorized_keys'. DeviceNetworkEvents: Network connection from curl to 127.0.0.1:18080 (Sysmon Event ID 3 if Sysmon for Linux). DeviceFileEvents: FileModified on authorized_keys with InitiatingProcessFileName=bash or sh. Shell history entries for curl and python3 commands.
- Test 3Modify SSH Config to Enable Root Login and Key Auth
Expected signal: auditd SYSCALL records for open()/write() on /etc/ssh/sshd_config if auditd watch is configured. DeviceFileEvents (if MDE for Linux): FileModified for FileName=sshd_config in FolderPath=/etc/ssh. DeviceProcessEvents: Process Create for sed with ProcessCommandLine containing 'sshd_config' and 'PermitRootLogin'. Shell history entries for sed and grep commands.
- Test 4Add SSH Key to Non-Root User Account
Expected signal: DeviceFileEvents: FileCreated or FileModified for FileName=authorized_keys under /home/<user>/.ssh/. DeviceProcessEvents: Process Create for useradd, ssh-keygen, cat with relevant command lines. auditd records for file operations on the authorized_keys path. Shell history for all commands executed.
- Test 5Simulate ESXi authorized_keys Modification
Expected signal: DeviceFileEvents: FileCreated for FileName=authorized_keys with FolderPath containing /etc/ssh/keys-. DeviceProcessEvents: Process Create for ssh-keygen and cat with ProcessCommandLine containing the ESXi key path. On actual ESXi systems, ESXCLI audit logs and /var/log/auth.log entries would also be generated.
References (13)
- https://attack.mitre.org/techniques/T1098/004/
- https://www.ssh.com/ssh/authorized_keys/
- https://www.venafi.com/blog/growing-abuse-ssh-keys-commodity-malware-campaigns-now-equipped-ssh-capabilities
- https://www.cybereason.com/blog/new-pervasive-worm-exploiting-linux-exim-server-vulnerability
- https://cloud.google.com/sdk/gcloud/reference/compute/instances/add-metadata
- https://about.gitlab.com/blog/2020/02/12/plundering-gcp-escalating-privileges-in-google-cloud-platform/
- https://docs.microsoft.com/en-us/rest/api/compute/virtual-machines/update
- https://knowledge.broadcom.com/external/article/313767/allowing-ssh-access-to-vmware-vsphere-es.html
- https://www.trendmicro.com/en_us/research/22/a/earth-lusca-employs-sophisticated-infrastructure-varied-tools-and-techniques.html
- https://www.trendmicro.com/en_us/research/19/f/skidmap-linux-malware-uses-rootkit-capabilities-to-hide-cryptocurrency-mining-payload.html
- https://blog.aquasec.com/teamtnt-activities-summary-and-a-deep-dive-into-a-recent-campaign
- https://www.cisco.com/c/en/us/td/docs/ios-xml/ios/security/d1/sec-d1-cr-book/sec-cr-i3.html#wp1254331478
- https://github.com/redcanaryco/atomic-red-team/blob/master/atomics/T1098.004/T1098.004.md
Unlock Pro Content
Get the full detection package for T1098.004 including response playbook, investigation guide, and atomic red team tests.