Remote Service Session Hijacking
This detection identifies adversaries commandeering existing remote service sessions to move laterally without creating new authenticated connections. Key indicators include use of tscon.exe to hijack disconnected RDP sessions (often from SYSTEM context), SSH agent socket manipulation via SSH_AUTH_SOCK environment variable abuse, SSH ControlMaster/ControlPath multiplexing attacks, and suspicious processes accessing other users' TTY devices or SSH agent sockets in /tmp. Unlike standard remote service use, session hijacking leaves minimal authentication artifacts because no new credential exchange occurs — making it a high-fidelity signal when detected.
let RDPHijack = DeviceProcessEvents
| where FileName =~ "tscon.exe"
or (FileName in~ ("cmd.exe", "powershell.exe") and ProcessCommandLine has "tscon")
| extend HijackType = "RDP_tscon"
| extend RiskDetail = strcat("tscon invoked by: ", InitiatingProcessFileName, " as ", AccountName);
let SSHAgentHijack = DeviceProcessEvents
| where ProcessCommandLine has_any ("SSH_AUTH_SOCK", "/tmp/ssh-", "ssh-agent")
and ProcessCommandLine has_any ("export", "env", "printenv", "cat /proc")
and not (FileName in~ ("sshd", "ssh-agent"))
| extend HijackType = "SSH_Agent_Hijack"
| extend RiskDetail = strcat("SSH_AUTH_SOCK access by non-ssh process: ", FileName);
let SSHControlMaster = DeviceProcessEvents
| where FileName =~ "ssh"
and ProcessCommandLine has_any ("ControlMaster", "ControlPath", "-o ControlMaster", "-S /tmp")
and not (InitiatingProcessFileName in~ ("sshd", "ansible", "fabric"))
| extend HijackType = "SSH_ControlMaster_Abuse"
| extend RiskDetail = strcat("SSH multiplexing hijack attempt from: ", InitiatingProcessFileName);
let TTYHijack = DeviceProcessEvents
| where ProcessCommandLine has_any ("/proc/", "/dev/pts/", "reptyr", "injcode")
and ProcessCommandLine matches regex @"/proc/\d+/fd"
| extend HijackType = "TTY_Hijack"
| extend RiskDetail = "Process fd hijack targeting remote session TTY";
union RDPHijack, SSHAgentHijack, SSHControlMaster, TTYHijack
| project
TimeGenerated,
DeviceName,
AccountName,
HijackType,
RiskDetail,
FileName,
ProcessCommandLine,
InitiatingProcessFileName,
InitiatingProcessCommandLine,
InitiatingProcessAccountName,
FolderPath
| order by TimeGenerated desc Data Sources
Required Tables
False Positives
- Legitimate IT administrators using tscon.exe for authorized session management or helpdesk reconnection workflows
- Ansible, Fabric, or other automation tools that legitimately use SSH ControlMaster for connection multiplexing to improve performance
- SSH agent forwarding used by developers or DevOps engineers for legitimate key forwarding across jump hosts
References (7)
- https://attack.mitre.org/techniques/T1563/
- https://attack.mitre.org/techniques/T1563/001/
- https://attack.mitre.org/techniques/T1563/002/
- https://medium.com/@networksecurity/rdp-hijacking-how-to-hijack-rds-and-remote-mstsc-sessions-transparently-2d941099b086
- https://doublepulsar.com/rdp-hijacking-how-to-hijack-rds-and-remote-mstsc-sessions-transparently-2d941099b086
- https://www.netspi.com/blog/technical/network-penetration-testing/hijacking-ssh-sessions-with-screen-and-command-injection/
- https://xorl.wordpress.com/2022/02/09/ssh-session-hijacking/
Unlock Pro Content
Get the full detection package for T1563 including response playbook, investigation guide, and atomic red team tests.