Detect SSH in Splunk
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/
SPL Detection Query
index=linux_audit OR index=syslog OR index=osquery (sourcetype="linux_audit" OR sourcetype="syslog" OR sourcetype="osquery:results")
(
sourcetype="linux_audit" type=EXECVE
(a0="ssh" OR a0="scp" OR a0="sftp")
| eval CommandLine=mvjoin(mvappend(a0,a1,a2,a3,a4,a5,a6,a7,a8,a9), " ")
| eval IsTunnel=if(match(CommandLine, "\s-[DLRNnN]\s"), 1, 0)
| eval NoHostCheck=if(match(CommandLine, "StrictHostKeyChecking.?no"), 1, 0)
| eval IsKeyAuth=if(match(CommandLine, "\s-i\s"), 1, 0)
| eval RiskScore=IsTunnel + NoHostCheck + IsKeyAuth
| where RiskScore > 0
| table _time, host, auid, CommandLine, IsTunnel, NoHostCheck, IsKeyAuth, RiskScore
)
OR
(
sourcetype="syslog" ("sshd" OR "OpenSSH")
("Accepted" OR "Failed" OR "Invalid")
| rex field=_raw "sshd\[\d+\]: (?P<AuthResult>\w+) (?P<AuthMethod>\w+) for (?P<TargetUser>\S+) from (?P<SourceIP>\S+) port (?P<Port>\d+)"
| eval AuthSuccess=if(AuthResult=="Accepted", 1, 0)
| eval AuthFailed=if(AuthResult=="Failed" OR AuthResult=="Invalid", 1, 0)
| stats sum(AuthSuccess) as Successes, sum(AuthFailed) as Failures, dc(TargetUser) as UniqueUsers by SourceIP, host
| where Failures >= 5 OR (Failures >= 3 AND Successes >= 1)
| eval RiskScore=Failures + (Successes * 5) + (UniqueUsers * 2)
| sort - RiskScore
) Detects SSH lateral movement via two SPL searches: Linux auditd (EXECVE events for ssh/scp/sftp with suspicious flags including tunneling, no host check, and key-based auth) and SSH daemon logs in syslog for authentication patterns including brute force (5+ failures) and successful auth following failures. Risk score calculation prioritizes multi-vector detections.
Data Sources
Required Sourcetypes
False Positives & Tuning
- System administrators using SSH tunnels for legitimate remote administration
- Automated deployment tools (Ansible, Fabric) using SSH with key-based auth
- CI/CD pipelines using SSH for deployment to multiple servers
- Bastion host configurations that establish SSH connections to internal hosts
- Developers using SSH port forwarding for local development
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.