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.
// 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 Data Sources
Required Tables
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.)
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.