Skip to content
Threat Feed
high advisory

Privilege Escalation via Rogue Windir Environment Variable

A privilege escalation attempt is detected through modification of the Windows directory (Windir) environment variable, a technique often combined with other vulnerabilities to elevate privileges by redirecting system processes.

The Windows directory (Windir) environment variable can be manipulated to achieve privilege escalation. This technique involves modifying the registry values associated with Windir or SystemRoot to point to a non-standard location. Attackers can leverage this to redirect legitimate Windows processes to malicious content under their control, effectively escalating their privileges. This is often combined with other vulnerabilities to gain elevated access. This activity is typically detected via registry modification events. Defenders should monitor registry changes to the Windir and SystemRoot variables, especially in user-writable contexts.

Attack Chain

  1. An attacker gains initial access to the system, potentially through phishing or exploiting a software vulnerability.
  2. The attacker identifies a user-writable registry key associated with the current user’s environment variables (e.g., HKCU\Environment).
  3. The attacker modifies the Windir or SystemRoot registry value using tools like reg.exe or PowerShell. The registry value is changed to a path controlled by the attacker.
  4. A legitimate Windows process, such as a system utility or application, attempts to access a file or execute a command using the %Windir% or %SystemRoot% environment variable.
  5. Due to the modified environment variable, the process is redirected to a malicious file or command located in the attacker-controlled path.
  6. The malicious file or command executes with the privileges of the legitimate Windows process.
  7. The attacker gains elevated privileges on the system.
  8. The attacker performs malicious activities such as installing malware, accessing sensitive data, or moving laterally within the network.

Impact

Successful exploitation leads to privilege escalation, allowing attackers to execute commands with elevated privileges. This can enable attackers to install malware, access sensitive data, or move laterally within the network. The impact is significant, as it allows an attacker to bypass security controls and gain complete control of the affected system. The number of victims can vary depending on the scope of the attack, but any system where the Windir or SystemRoot variable is tampered with is vulnerable.

Recommendation

  • Enable Sysmon registry event logging to detect modifications to the Windir and SystemRoot registry keys.
  • Deploy the “Privilege Escalation via Rogue Windir Environment Variable” Sigma rule to your SIEM and tune for your environment to detect this activity.
  • Monitor process creation events for unusual processes executing from non-standard Windir locations to identify potential exploitation attempts.
  • Implement the “Detect Suspicious Windir Registry Modification” Sigma rule to identify potentially malicious modifications.

Detection coverage 2

Detect Suspicious Windir Registry Modification

high

Detects suspicious modifications to the Windir or SystemRoot registry values, indicating a potential privilege escalation attempt.

sigma tactics: privilege_escalation techniques: T1068 sources: registry_set, windows

Detect Process Execution from Modified Windir

medium

Detects process execution from a directory specified in a modified Windir or SystemRoot environment variable.

sigma tactics: execution, privilege_escalation techniques: T1059.001, T1068 sources: process_creation, windows

Detection queries are available on the platform. Get full rules →