PowerShell 技能连载 - 查找服务特权

Get-Service 可以提供 Windows 服务的基础信息但是并不会列出所需要的特权。以下是一段简短的 PowerShell 函数,输入一个服务名并返回服务特权:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
function Get-ServicePrivilege
{

param
(
[Parameter(Mandatory)]
[string]
$ServiceName
)

# find the service
$Service = @(Get-Service -Name $ServiceName -ErrorAction Silent)
# bail out if there is no such service
if ($Service.Count -ne 1)
{
Write-Warning "$ServiceName unknown."
return
}

# read the service privileges from registry
$Path = 'HKLM:\SYSTEM\CurrentControlSet\Services\' + $service.Name
$Privs = Get-ItemProperty -Path $Path -Name RequiredPrivileges

# output in custom object
[PSCustomObject]@{
ServiceName = $Service.Name
DisplayName = $Service.DisplayName
Privileges = $privs.RequiredPrivileges
}
}



PS C:\> Get-ServicePrivilege spooler

ServiceName DisplayName Privileges
----------- ----------- ----------
spooler Druckwarteschlange {SeTcbPrivilege, SeImpersonatePrivilege, SeAuditPrivilege, SeChangeNotifyPrivilege...}



PS C:\> Get-ServicePrivilege XboxGipSvc

ServiceName DisplayName Privileges
----------- ----------- ----------
XboxGipSvc Xbox Accessory Management Service {SeTcbPrivilege, SeImpersonatePrivilege, SeChangeNotifyPrivilege, SeCreateGlobalPrivilege}

PowerShell 技能连载 - 查找服务特权

http://blog.vichamp.com/2019/04/24/finding-service-privileges/

作者

吴波

发布于

2019-04-24

更新于

2022-07-06

许可协议

评论