Unit 1: How Windows is organised · Lesson 2 of 5 · 18 min
Paths and environment variables
Expand %APPDATA% and friends into real paths and check where running programs were launched from.
mission
- You are
- You are the IT analyst on call at Brightwater Logistics.
- Situation
- Detection rules and malware both speak in variables like %APPDATA% and %TEMP%. IT exported m.osei's environment and the image path of every running process on WS-014.
- Goal
- Turn variables into real paths and count programs running from places users can write to.
- Hand in
- The real path behind %APPDATA% and a count of running programs launched from user folders.
Variables you will meet in every alert
Pick anything to read what it holds.
Expand a variable on the machine
Variables are expanded per user, so %APPDATA% means a different folder for every person. Always expand them in the right user's context.
echo %APPDATA% C:\Users\m.osei\AppData\Roaming echo %TEMP% C:\Users\m.osei\AppData\Local\Temp
defender tip In PowerShell the same values are $env:APPDATA and $env:TEMP.
Read the exported environment
You will often get exports rather than a live machine. The lab has m.osei's set output in ws-014/env.txt.
grep -i appdata= ws-014/env.txt APPDATA=C:\Users\m.osei\AppData\Roaming LOCALAPPDATA=C:\Users\m.osei\AppData\Local grep -i '^path=' ws-014/env.txt Path=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Users\m.osei\AppData\Local\Microsoft\WindowsApps
you should see Path lists the folders Windows searches when you type a bare program name. A user-writable folder early in Path would be a finding. Here it is last, which is normal.
Count programs running from user folders
Every running program has an image path. Real system processes come from System32. Anything from a user profile deserves a reason.
wc -l ws-014/running-paths.txt 20 ws-014/running-paths.txt grep -c System32 ws-014/running-paths.txt 12 grep Users ws-014/running-paths.txt
you should see Run the last command yourself in the lab. Count the lines and decide which ones you can explain.
defender tip On a live machine: Get-Process | Select-Object Name, Path | Where-Object Path -like 'C:\Users\*'.
Check PATH for user folders
Windows runs the first match it finds along PATH. A folder users can write to, early in PATH, lets a planted program win over a real one with the same name.
grep -i '^path=' ws-014/env.txt | grep -o 'C:.Users[^;]*'
you should see One user folder is in PATH, the WindowsApps folder that Windows adds for every user. It sits after the system folders, which is the normal order.
What a defender takes away
- 1%APPDATA%, %LOCALAPPDATA% and %TEMP% all point inside the user's own profile.
- 2Expand variables for the right user. The same text means a different folder per person.
- 3Programs running from user profiles are not always bad, but every one needs an explanation.
Questions
0 of 3 solved
Answer each one from what you find on your lab machine.