# Environment Variable $Path Interception

It's possible to abuse `$PATH` environment variable to elevate privileges if the variable:

* contains a folder that a malicious user can write to
* that folder precedes c:\windows\system32\\

Below is an example, showing how c:\temp precedes c:\windows\system32:

![](/files/-M-6g5S7OCf5zgbpgmAF)

Let's make sure c:\temp is (M)odifiable by low privileged users:

![](/files/-M-6gtfYvAlaGui6WqmM)

Let's now drop our malicious file (calc.exe in this case) into c:\temp and call it cmd.exe:

![](/files/-M-6g9EKrA-l-PulxAeQ)

Now, the next time a high privileged user invokes cmd.exe, our malicious cmd.exe will be invoked from the c:\temp:

![](/files/-M-6gLUaw1TB79moRZ3w)

This can be very easily abused in environments where software deployment packages call powershell, cmd, cscript and other similar system binaries with `NT SYSTEM` privileges to carry out their tasks.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.ired.team/offensive-security/privilege-escalation/environment-variable-path-interception.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
