Skip to content
This repository was archived by the owner on Jan 21, 2021. It is now read-only.

Commit 0181ff0

Browse files
committed
Removed C# enum for Test-ServiceDaclPermission
1 parent 9ffc26a commit 0181ff0

File tree

1 file changed

+42
-42
lines changed

1 file changed

+42
-42
lines changed

Privesc/PowerUp.ps1

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,6 @@
1515
#
1616
########################################################
1717

18-
Add-Type @"
19-
[System.FlagsAttribute]
20-
public enum ServiceAccessFlags : uint
21-
{
22-
CC = 1,
23-
DC = 2,
24-
LC = 4,
25-
SW = 8,
26-
RP = 16,
27-
WP = 32,
28-
DT = 64,
29-
LO = 128,
30-
CR = 256,
31-
SD = 65536,
32-
RC = 131072,
33-
WD = 262144,
34-
WO = 524288,
35-
GA = 268435456,
36-
GX = 536870912,
37-
GW = 1073741824,
38-
GR = 2147483648
39-
}
40-
"@
41-
4218
function Get-ModifiableFile {
4319
<#
4420
.SYNOPSIS
@@ -134,32 +110,52 @@ function Test-ServiceDaclPermission {
134110
#>
135111

136112
[CmdletBinding()]
137-
Param(
138-
[Parameter(Mandatory = $True)]
139-
[string]
140-
$ServiceName,
113+
Param(
114+
[Parameter(Mandatory = $True)]
115+
[string]
116+
$ServiceName,
141117

142-
[Parameter(Mandatory = $True)]
143-
[string]
144-
$Dacl
145-
)
118+
[Parameter(Mandatory = $True)]
119+
[string]
120+
$Dacl
121+
)
146122

147123
# check if sc.exe exists
148124
if (-not (Test-Path ("$env:SystemRoot\system32\sc.exe"))){
149125
Write-Warning "[!] Could not find $env:SystemRoot\system32\sc.exe"
150126
return $False
151127
}
152128

129+
$ServiceAccessFlags = @{
130+
CC = 1
131+
DC = 2
132+
LC = 4
133+
SW = 8
134+
RP = 16
135+
WP = 32
136+
DT = 64
137+
LO = 128
138+
CR = 256
139+
SD = 65536
140+
RC = 131072
141+
WD = 262144
142+
WO = 524288
143+
GA = 268435456
144+
GX = 536870912
145+
GW = 1073741824
146+
GR = 2147483648
147+
}
148+
153149
# query WMI for the service
154150
$TargetService = Get-WmiObject -Class win32_service -Filter "Name='$ServiceName'" | Where-Object {$_}
155-
151+
156152
# make sure we got a result back
157153
if (-not ($TargetService)){
158154
Write-Warning "[!] Target service '$ServiceName' not found on the machine"
159155
return $False
160156
}
161157

162-
try {
158+
# try {
163159
# retrieve DACL from sc.exe
164160
$Result = sc.exe sdshow $TargetService.Name | where {$_}
165161

@@ -181,9 +177,13 @@ function Test-ServiceDaclPermission {
181177

182178
# check if the group/user SID is included in the ACE
183179
if ($Sid -eq $Ace.SecurityIdentifier){
184-
180+
185181
# convert the AccessMask to a service DACL string
186-
$DaclString = [string]([ServiceAccessFlags] $Ace.AccessMask) -replace ', ',''
182+
$DaclString = $($ServiceAccessFlags.Keys | Foreach-Object {
183+
if (($ServiceAccessFlags[$_] -band $Ace.AccessMask) -eq $ServiceAccessFlags[$_]) {
184+
$_
185+
}
186+
}) -join ""
187187

188188
# convert the input DACL to an array
189189
$DaclArray = [array] ($Dacl -split '(.{2})' | Where-Object {$_})
@@ -201,18 +201,18 @@ function Test-ServiceDaclPermission {
201201
}
202202
}
203203
# found all permissions - success
204-
if ($MatchedPermissions-eq $DaclArray.Count){
204+
if ($MatchedPermissions -eq $DaclArray.Count){
205205
return $True
206206
}
207207
}
208208
}
209209
}
210210
return $False
211-
}
212-
catch{
213-
Write-Warning "Error: $_"
214-
return $False
215-
}
211+
# }
212+
# catch{
213+
# Write-Warning "Error: $_"
214+
# return $False
215+
# }
216216
}
217217

218218
function Invoke-ServiceStart {

0 commit comments

Comments
 (0)