T1098.004

SSH Authorized Keys

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.

Microsoft Sentinel / Defender
kusto
let AuthorizedKeysPaths = dynamic([
  ".ssh/authorized_keys",
  ".ssh/authorized_keys2",
  "/etc/ssh/keys-",
  "authorized_keys"
]);
let SuspiciousParents = dynamic([
  "curl", "wget", "python", "python3", "perl", "ruby",
  "nc", "ncat", "netcat", "bash", "sh", "dash", "zsh"
]);
// File write events to authorized_keys
let FileWriteEvents = DeviceFileEvents
| where TimeGenerated > ago(24h)
| where ActionType in ("FileCreated", "FileModified")
| where FolderPath has_any (AuthorizedKeysPaths) or FileName =~ "authorized_keys" or FileName =~ "authorized_keys2"
| extend EventType = "FileWrite"
| project TimeGenerated, DeviceName, AccountName, ActionType, FolderPath, FileName,
          InitiatingProcessFileName, InitiatingProcessCommandLine, InitiatingProcessParentFileName,
          SHA256, EventType;
// Process events writing to authorized_keys via shell commands
let ProcessWriteEvents = DeviceProcessEvents
| where TimeGenerated > ago(24h)
| where ProcessCommandLine has_any (AuthorizedKeysPaths)
| where ProcessCommandLine has_any ("echo", "tee", "cat", "cp", "mv", "printf", "ssh-keygen", "dd", ">", ">>", "write", "install")
| extend EventType = "ProcessWrite"
| project TimeGenerated, DeviceName, AccountName, ActionType = ActionType,
          FolderPath = "", FileName = FileName,
          InitiatingProcessFileName, InitiatingProcessCommandLine = InitiatingProcessCommandLine,
          InitiatingProcessParentFileName,
          SHA256 = SHA256, EventType;
union FileWriteEvents, ProcessWriteEvents
| extend IsRootSSHDir = FolderPath has "/root/.ssh" or ProcessCommandLine has "/root/.ssh"
| extend IsEtcSSHKeys = FolderPath has "/etc/ssh/keys" or ProcessCommandLine has "/etc/ssh/keys"
| extend IsRedirectAppend = ProcessCommandLine has ">>" or ProcessCommandLine has "tee -a" or ProcessCommandLine has "tee --append"
| extend IsSshKeygen = ProcessCommandLine has "ssh-keygen" or InitiatingProcessFileName has "ssh-keygen"
| extend IsCurlWget = InitiatingProcessFileName has_any ("curl", "wget") or ProcessCommandLine has_any ("curl", "wget")
| extend SuspicionScore = toint(IsRootSSHDir) + toint(IsEtcSSHKeys) + toint(IsRedirectAppend) + toint(IsSshKeygen) + toint(IsCurlWget)
| project TimeGenerated, DeviceName, AccountName, EventType, ActionType,
          FolderPath, FileName, InitiatingProcessFileName, InitiatingProcessCommandLine,
          InitiatingProcessParentFileName, SHA256,
          IsRootSSHDir, IsEtcSSHKeys, IsRedirectAppend, IsSshKeygen, IsCurlWget, SuspicionScore
| sort by TimeGenerated desc
high severity high confidence

Data Sources

File: File Modification File: File Creation Process: Process Creation Command: Command Execution Microsoft Defender for Endpoint

Required Tables

DeviceFileEvents DeviceProcessEvents

False Positives

  • 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

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