T1021.004

SSH

Adversaries may use Valid Accounts to log into remote machines using Secure Shell (SSH). SSH allows authorized users to open remote shells on Linux, macOS, and ESXi systems. Adversaries leverage existing SSH keys or stolen passwords to pivot between systems. Notable actors using SSH for lateral movement include FIN7, Lazarus Group, Leviathan, Scattered Spider, BlackTech, and APT groups targeting cloud and ESXi environments. SSH lateral movement may also involve agent forwarding abuse, key theft, adding attacker-controlled public keys to authorized_keys files, or chaining through multiple hosts to obscure the original source.

Microsoft Sentinel / Defender
kusto
// Detect suspicious SSH lateral movement on Linux/macOS
let SuspiciousSshPatterns = dynamic([
  "ssh -o StrictHostKeyChecking=no",
  "ssh -i ",
  "ProxyJump",
  "ProxyCommand",
  "StrictHostKeyChecking=no",
  "-D ",  // SOCKS proxy
  "-L ",  // Local port forward
  "-R ",  // Reverse port forward
  "-N ",  // No command (tunnel)
  "authorized_keys"
]);
DeviceProcessEvents
| where Timestamp > ago(24h)
| where FileName in~ ("ssh", "scp", "sftp", "ssh-agent", "ssh-add")
| where ProcessCommandLine has_any (SuspiciousSshPatterns)
| extend IsTunnel = ProcessCommandLine has_any ("-D ", "-L ", "-R ", "-N ")
| extend IsNoHostCheck = ProcessCommandLine has "StrictHostKeyChecking=no"
| extend IsKeyAuth = ProcessCommandLine has "-i "
| project Timestamp, DeviceName, AccountName, FileName, ProcessCommandLine,
         InitiatingProcessFileName, InitiatingProcessCommandLine,
         IsTunnel, IsNoHostCheck, IsKeyAuth
| union (
    // Detect SSH authorized_keys modification
    DeviceFileEvents
    | where Timestamp > ago(24h)
    | where ActionType in ("FileCreated", "FileModified")
    | where FolderPath has ".ssh" and FileName =~ "authorized_keys"
    | project Timestamp, DeviceName, AccountName=InitiatingProcessAccountName,
             FileName, FolderPath, InitiatingProcessFileName
)
| sort by Timestamp desc
high severity medium confidence

Data Sources

Process: Process Creation Command: Command Execution File: File Modification Network Traffic: Network Connection Creation

Required Tables

DeviceProcessEvents DeviceFileEvents DeviceNetworkEvents

False Positives

  • System administrators using SSH tunnels for legitimate remote administration and database connectivity
  • Automated deployment tools (Ansible, Fabric, Capistrano) using SSH with key-based auth and StrictHostKeyChecking=no in provisioning scripts
  • CI/CD pipelines (Jenkins, GitLab) using SSH for deployment to multiple servers
  • Bastion host or jump server configurations that establish SSH connections to internal hosts on behalf of users
  • Developers using SSH port forwarding for local development against remote services (database tunnels, etc.)

Unlock Pro Content

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

Response PlaybookInvestigation GuideHunting QueriesAtomic Red Team TestsTuning Guidance

Related Detections