Writable Sys Path +Dll Hijacking Privesc
Tip
Вчіться та практикуйте AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
Вчіться та практикуйте GCP Hacking:HackTricks Training GCP Red Team Expert (GRTE)
Вчіться та практикуйте Az Hacking:HackTricks Training Azure Red Team Expert (AzRTE)
Перегляньте повний каталог HackTricks Training для assessment tracks (ARTA/GRTA/AzRTA) і Linux Hacking Expert (LHE).
Підтримайте HackTricks
- Перевірте плани підписки!
- Приєднуйтесь до 💬 Discord group, telegram group, слідкуйте за @hacktricks_live на X/Twitter, або перегляньте сторінку LinkedIn і YouTube channel.
- Діліться hacking tricks, надсилаючи PRs до репозиторіїв github HackTricks і HackTricks Cloud.
Introduction
Якщо ви виявили, що можете писати в папку System Path (зверніть увагу, що це не спрацює, якщо ви можете писати в папку User Path), можливо, ви зможете підвищити привілеї в системі.
Щоб це зробити, ви можете зловживати Dll Hijacking, де ви будете перехоплювати бібліотеку, що завантажується службою або процесом з вищими привілеями, ніж у вас, і оскільки ця служба завантажує Dll, якої, ймовірно, навіть не існує в усій системі, вона спробує завантажити її з System Path, куди ви можете писати.
Для отримання додаткової інформації про що таке Dll Hijackig дивіться:
Privesc with Dll Hijacking
Finding a missing Dll
Перше, що вам потрібно, це ідентифікувати процес, який працює з вищими привілеями, ніж у вас, і намагається завантажити Dll з System Path, куди ви можете писати.
Пам’ятайте, що ця техніка залежить від запису Machine/System PATH, а не лише від вашого User PATH. Тому, перш ніж витрачати час на Procmon, варто перелічити записи Machine PATH і перевірити, які з них доступні для запису:
$machinePath = [Environment]::GetEnvironmentVariable("Path", "Machine") -split ';' | Where-Object { $_ }
$machinePath | ForEach-Object {
$path = $_.Trim()
if ($path) {
Write-Host "`n[*] $path"
icacls $path 2>$null
}
}
Проблема в цих випадках у тому, що, ймовірно, ці процеси вже запущені. Щоб знайти, яких Dlls не вистачає службам, тобі потрібно запустити procmon якомога швидше (до завантаження процесів). Отже, щоб знайти відсутні .dlls, зроби так:
- Create папку
C:\privesc_hijackingі додай шляхC:\privesc_hijackingдо System Path env variable. Це можна зробити manually або за допомогою PS:
# Set the folder path to create and check events for
$folderPath = "C:\privesc_hijacking"
# Create the folder if it does not exist
if (!(Test-Path $folderPath -PathType Container)) {
New-Item -ItemType Directory -Path $folderPath | Out-Null
}
# Set the folder path in the System environment variable PATH
$envPath = [Environment]::GetEnvironmentVariable("PATH", "Machine")
if ($envPath -notlike "*$folderPath*") {
$newPath = "$envPath;$folderPath"
[Environment]::SetEnvironmentVariable("PATH", $newPath, "Machine")
}
- Запустіть
procmonі перейдіть доOptions–>Enable boot loggingта натиснітьOKу prompt. - Потім перезавантажтеся. Коли computer буде restarted,
procmonпочне recording events asap. - Після того як Windows started execute
procmonзнову, він повідомить, що вже працював, і спитає, чи хочете ви store events у файл. Скажіть yes і store the events in a file. - Після того як file буде generated, close відкрите вікно
procmonі open the events file. - Додайте ці filters, і ви знайдете всі Dlls, які some proccess tried to load з writable System Path folder:
.png)
Tip
Boot logging is only required for services that start too early to observe otherwise. If you can trigger the target service/program on demand (for example, by interacting with its COM interface, restarting the service, or relaunching a scheduled task), it is usually faster to keep a normal Procmon capture with filters such as
Path contains .dll,Result is NAME NOT FOUND, andPath begins with <writable_machine_path>.
Missed Dlls
Running this in a free virtual (vmware) Windows 11 machine I got these results:
.png)
In this case the .exe are useless so ignore them, the missed DLLs where from:
| Service | Dll | CMD line |
|---|---|---|
| Task Scheduler (Schedule) | WptsExtensions.dll | C:\Windows\system32\svchost.exe -k netsvcs -p -s Schedule |
| Diagnostic Policy Service (DPS) | Unknown.DLL | C:\Windows\System32\svchost.exe -k LocalServiceNoNetwork -p -s DPS |
| ??? | SharedRes.dll | C:\Windows\system32\svchost.exe -k UnistackSvcGroup |
After finding this, I found this interesting blog post that also explains how to abuse WptsExtensions.dll for privesc. Which is what we are going to do now.
Other candidates worth triaging
WptsExtensions.dll is a good example, but it is not the only recurring phantom DLL that shows up in privileged services. Modern hunting rules and public hijack catalogs still track names such as:
| Service / Scenario | Missing DLL | Notes |
|---|---|---|
Task Scheduler (Schedule) | WptsExtensions.dll | Classic SYSTEM candidate on client systems. Good when the writable directory is in the Machine PATH and the service probes the DLL during startup. |
| NetMan on Windows Server | wlanhlp.dll / wlanapi.dll | Interesting on server editions because the service runs as SYSTEM and can be triggered on demand by a normal user in some builds, making it better than reboot-only cases. |
Connected Devices Platform Service (CDPSvc) | cdpsgshims.dll | Usually yields NT AUTHORITY\LOCAL SERVICE first. That is often still enough because the token has SeImpersonatePrivilege, so you can chain it with RoguePotato / PrintSpoofer. |
Treat these names as triage hints, not guaranteed wins: they are SKU/build dependent, and Microsoft may change the behavior between releases. The important takeaway is to look for missing DLLs in privileged services that traverse the Machine PATH, especially if the service can be re-triggered without rebooting.
Exploitation
So, to escalate privileges we are going to hijack the library WptsExtensions.dll. Having the path and the name we just need to generate the malicious dll.
You can try to use any of these examples. You could run payloads such as: get a rev shell, add a user, execute a beacon…
Warning
Note that not all the service are run with
NT AUTHORITY\SYSTEMsome are also run withNT AUTHORITY\LOCAL SERVICEwhich has less privileges and you won’t be able to create a new user abuse its permissions.
However, that user has theseImpersonateprivilege, so you can use the potato suite to escalate privileges. So, in this case a rev shell is a better option that trying to create a user.
At the moment of writing the Task Scheduler service is run with Nt AUTHORITY\SYSTEM.
Having generated the malicious Dll (in my case I used x64 rev shell and I got a shell back but defender killed it because it was from msfvenom), save it in the writable System Path with the name WptsExtensions.dll and restart the computer (or restart the service or do whatever it takes to rerun the affected service/program).
When the service is re-started, the dll should be loaded and executed (you can reuse the procmon trick to check if the library was loaded as expected).
References
- Windows DLL Hijacking (Hopefully) Clarified
- Suspicious DLL Loaded for Persistence or Privilege Escalation
Tip
Вчіться та практикуйте AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
Вчіться та практикуйте GCP Hacking:HackTricks Training GCP Red Team Expert (GRTE)
Вчіться та практикуйте Az Hacking:HackTricks Training Azure Red Team Expert (AzRTE)
Перегляньте повний каталог HackTricks Training для assessment tracks (ARTA/GRTA/AzRTA) і Linux Hacking Expert (LHE).
Підтримайте HackTricks
- Перевірте плани підписки!
- Приєднуйтесь до 💬 Discord group, telegram group, слідкуйте за @hacktricks_live на X/Twitter, або перегляньте сторінку LinkedIn і YouTube channel.
- Діліться hacking tricks, надсилаючи PRs до репозиторіїв github HackTricks і HackTricks Cloud.


