T1021.004 Microsoft Sentinel · KQL

Detect SSH in Microsoft Sentinel

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.

MITRE ATT&CK

Tactic
Lateral Movement
Technique
T1021 Remote Services
Sub-technique
T1021.004 SSH
Canonical reference
https://attack.mitre.org/techniques/T1021/004/

KQL Detection Query

Microsoft Sentinel (KQL)
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

Detects SSH-based lateral movement using two patterns: suspicious SSH command-line flags indicating tunneling (port forwarding -D/-L/-R/-N), key-based auth to new targets, and disabled host key checking (StrictHostKeyChecking=no); and modification of authorized_keys files which may indicate persistence via SSH key addition. Uses DeviceProcessEvents and DeviceFileEvents from MDE.

Data Sources

Process: Process CreationCommand: Command ExecutionFile: File ModificationNetwork Traffic: Network Connection Creation

Required Tables

DeviceProcessEventsDeviceFileEventsDeviceNetworkEvents

False Positives & Tuning

  • 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.)
Download portable Sigma rule (.yml)

Other platforms for T1021.004


Testing Methodology

Validate this detection against 4 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 1SSH Lateral Movement to Remote Host

    Expected signal: Linux auditd EXECVE record for ssh binary with arguments. Syslog entry from sshd on target: 'Accepted password for testuser from <source_ip>'. Linux auditd USER_LOGIN event. Process creation for ssh child process.

  2. Test 2SSH SOCKS Proxy Tunnel Creation

    Expected signal: Linux auditd EXECVE for ssh with -D 1080 -N -f flags. Process runs in background (due to -f flag). Network connection established on source port 1080 (SOCKS listener). Syslog entry on target for SSH connection.

  3. Test 3Add Attacker SSH Public Key to authorized_keys

    Expected signal: Linux auditd OPEN event for ~/.ssh/authorized_keys with write flag. File modification timestamp change. Sysmon for Linux (if deployed): FileCreate/FileModify event for authorized_keys path.

  4. Test 4SSH Key-Based Lateral Movement with Stolen Key

    Expected signal: Linux auditd EXECVE for ssh with -i /tmp/stolen_id_rsa. OPEN event for /tmp/stolen_id_rsa (private key access). Network connection to target port 22. Syslog on target: 'Accepted publickey for root'.

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