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
// 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 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
Required Tables
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.)
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.
- 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.
- 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.
- 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.
- 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'.
References (8)
- https://attack.mitre.org/techniques/T1021/004/
- https://man7.org/linux/man-pages/man1/ssh.1.html
- https://linux.die.net/man/8/sshd
- https://github.com/redcanaryco/atomic-red-team/blob/master/atomics/T1021.004/T1021.004.md
- https://www.mandiant.com/resources/blog/unc3944-sms-phishing-sim-swapping
- https://www.crowdstrike.com/blog/carbon-spider-embraces-big-game-hunting/
- https://www.kaspersky.com/blog/lazarus-threatneedle/
- https://www.cisa.gov/uscert/ncas/alerts/aa22-108a
Unlock Pro Content
Get the full detection package for T1021.004 including response playbook, investigation guide, and atomic red team tests.