T1098.004 Splunk · SPL

Detect SSH Authorized Keys in Splunk

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/

SPL Detection Query

Splunk (SPL)
spl
index=syslog sourcetype=syslog OR sourcetype=linux_secure OR sourcetype="linux:syslog"
| eval raw_msg=_raw
// Match file writes to authorized_keys via auditd or syslog
| where match(raw_msg, "authorized_keys") OR match(raw_msg, "authorized_keys2")
| rex field=raw_msg "(?i)(?P<proc_name>[a-zA-Z0-9_\-]+)\[(?P<pid>\d+)\]"
| rex field=raw_msg "(?i)(user|uid)[=:\s]+(?P<username>[a-zA-Z0-9_\-\.]+)"
| rex field=raw_msg "(?i)(cmd|command|exe)[=:\s]+(?P<command>[^\n]+)"
| eval IsRootSSHDir=if(match(raw_msg, "/root/\.ssh"), 1, 0)
| eval IsEtcSSHKeys=if(match(raw_msg, "/etc/ssh/keys-"), 1, 0)
| eval IsAppendRedirect=if(match(raw_msg, ">>|tee\s+-a|tee\s+--append"), 1, 0)
| eval IsSshKeygen=if(match(raw_msg, "ssh-keygen"), 1, 0)
| eval IsCurlWget=if(match(raw_msg, "curl|wget"), 1, 0)
| eval IsEchoWrite=if(match(raw_msg, "echo.+authorized_keys|printf.+authorized_keys"), 1, 0)
| eval SuspicionScore=IsRootSSHDir + IsEtcSSHKeys + IsAppendRedirect + IsSshKeygen + IsCurlWget + IsEchoWrite
| where SuspicionScore > 0
| table _time, host, username, proc_name, pid, raw_msg, IsRootSSHDir, IsEtcSSHKeys, IsAppendRedirect, IsSshKeygen, IsCurlWget, IsEchoWrite, SuspicionScore
| sort - _time

| appendcols
    [search index=syslog sourcetype="XmlWinEventLog:Microsoft-Windows-Sysmon/Operational" EventCode=11
     file_path="*authorized_keys*"
    | eval IsRootSSHDir=if(match(TargetFilename, "/root/\.ssh"), 1, 0)
    | eval IsEtcSSHKeys=if(match(TargetFilename, "/etc/ssh/keys-"), 1, 0)
    | eval IsSshKeygen=if(match(Image, "ssh-keygen"), 1, 0)
    | table _time, host, User, Image, TargetFilename, CommandLine, IsRootSSHDir, IsEtcSSHKeys, IsSshKeygen]
high severity medium confidence

Detects SSH authorized_keys modifications on Linux/macOS hosts using syslog and auditd data. Parses syslog messages referencing authorized_keys paths and evaluates suspicious indicators: writes to root's .ssh directory, ESXi /etc/ssh/keys- paths, append redirections (>>), ssh-keygen invocations, and curl/wget involvement. Assigns a suspicion score to prioritize alerts. Also includes a secondary sub-search for Sysmon for Linux (Event ID 11 File Create) if deployed.

Data Sources

File: File ModificationFile: File CreationProcess: Process CreationLinux auditdLinux syslog

Required Sourcetypes

sysloglinux_securelinux:syslog

False Positives & Tuning

  • Legitimate system administrators adding their own SSH public keys to authorized remote servers during provisioning or key rotation
  • Configuration management tools (Ansible, Chef, Puppet, Terraform) that deploy authorized_keys as part of infrastructure-as-code workflows
  • Automated CI/CD pipelines that configure SSH keys for deployment accounts on build or staging servers
  • Cloud-init or user-data scripts that populate authorized_keys during virtual machine boot and initial provisioning
Download portable Sigma rule (.yml)

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.

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

Unlock Pro Content

Get the full detection package for T1098.004 including response playbook, investigation guide, and atomic red team tests.

Response PlaybookInvestigation GuideHunting QueriesAtomic Red Team TestsTuning Guidance

Related Detections