Path Interception by PATH Environment Variable
Adversaries may intercept execution by placing a malicious binary in an earlier directory of the PATH environment variable than the legitimate binary. When a program calls another program without specifying its full path, the OS searches PATH entries sequentially and executes the first matching binary found. On Windows, if an adversary creates C:\evil\net.exe and the PATH includes C:\evil before C:\Windows\System32, the malicious net.exe runs instead of the legitimate one. DarkGate abused this by setting HKCU\Environment\windir to a malicious path, causing DiskCleanup scheduled tasks to execute its payload. On Linux/macOS, modifying ~/.bashrc, /etc/profile, or /etc/paths.d achieves similar results. PowerSploit and Empire include PATH interception modules for privilege escalation.
let SuspiciousPathChanges = DeviceRegistryEvents
| where Timestamp > ago(24h)
| where RegistryKey has "Environment"
| where RegistryValueName in~ ("PATH", "Path", "windir", "SystemRoot", "TEMP", "TMP")
| where not(InitiatingProcessFileName in~ ("msiexec.exe", "setup.exe", "svchost.exe", "services.exe"))
| project Timestamp, DeviceName, AccountName, RegistryKey, RegistryValueName, RegistryValueData, InitiatingProcessFileName;
SuspiciousPathChanges
| join kind=leftouter (
DeviceProcessEvents
| where Timestamp > ago(24h)
| where FolderPath !has "C:\\Windows\\"
| where FolderPath !has "C:\\Program Files"
| project DeviceId, ProcessId, FileName, FolderPath, AccountName
) on DeviceId
| project Timestamp, DeviceName, AccountName, RegistryKey, RegistryValueName, RegistryValueData, InitiatingProcessFileName
| sort by Timestamp desc Data Sources
Required Tables
False Positives
- Software installers legitimately adding their installation directory to the PATH variable
- Developer tools (Node.js, Python, Go, Rust toolchain) adding binary directories to PATH during installation
- Enterprise configuration management tools (Ansible, Chef, Puppet) modifying PATH as part of software provisioning
- Virtual environment tools (virtualenv, conda) that modify PATH to prioritize their own Python interpreter
References (4)
- https://attack.mitre.org/techniques/T1574/007/
- https://www.expressvpn.com/blog/cybersecurity-lessons-a-path-vulnerability-in-windows/
- https://github.com/redcanaryco/atomic-red-team/blob/master/atomics/T1574.007/T1574.007.md
- https://github.com/PowerShellMafia/PowerSploit/blob/master/Privesc/PowerUp.ps1
Unlock Pro Content
Get the full detection package for T1574.007 including response playbook, investigation guide, and atomic red team tests.