T1098.004 Elastic Security · Elastic

Detect SSH Authorized Keys in Elastic Security

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/

Elastic Detection Query

Elastic Security (Elastic)
eql
any where (
  (
    event.category == "file" and
    event.type in ("creation", "change") and
    (
      file.path : ("*/.ssh/authorized_keys", "*/.ssh/authorized_keys2", "*/etc/ssh/keys-*") or
      file.name in ("authorized_keys", "authorized_keys2")
    )
  ) or
  (
    event.category == "process" and
    event.type == "start" and
    process.name in ("echo", "tee", "cat", "cp", "mv", "printf", "ssh-keygen", "dd", "install") and
    process.command_line : "*authorized_keys*"
  ) or
  (
    event.category == "process" and
    event.type == "start" and
    process.parent.name in ("curl", "wget", "python", "python3", "perl", "ruby", "nc", "ncat", "netcat", "bash", "sh", "dash", "zsh") and
    process.command_line : "*authorized_keys*"
  )
)
high severity high confidence

Detects SSH authorized_keys file modification or creation (MITRE T1098.004) using Elastic ECS fields. Covers three vectors: direct file write events to authorized_keys paths, shell utility processes (echo, tee, ssh-keygen, etc.) with authorized_keys in the command line, and processes spawned from suspicious network-capable parents (curl, wget, python) that reference authorized_keys. Designed for Elastic Security detection rules engine.

Data Sources

Elastic Endpoint Security (ECS file and process events)Auditbeat with audit module (auditd syscall events)Filebeat with system module (syslog, auth.log)Elastic Agent with Endpoint integration (logs-endpoint.events.*)

Required Tables

logs-endpoint.events.file-*logs-endpoint.events.process-*auditbeat-*

False Positives & Tuning

  • Configuration management tools (Ansible authorized_key module, Chef ssh_authorize_key resource, Puppet ssh_authorized_key type) deploying legitimate SSH public keys to managed Linux hosts as part of standard user provisioning
  • IT administrators or DevOps engineers running ssh-copy-id or manual shell scripts to add their own public keys to jump hosts, bastion servers, or shared service accounts during onboarding or access refresh
  • CI/CD pipeline automation (GitHub Actions, Jenkins, GitLab CI runners) rotating or injecting SSH deployment keys into service accounts on freshly provisioned build or deployment hosts
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