Removed C# enum for Test-ServiceDaclPermission

This commit is contained in:
Harmj0y 2015-12-14 21:53:42 -05:00
parent 9ffc26af70
commit 0181ff0c09
1 changed files with 42 additions and 42 deletions

View File

@ -15,30 +15,6 @@
#
########################################################
Add-Type @"
[System.FlagsAttribute]
public enum ServiceAccessFlags : uint
{
CC = 1,
DC = 2,
LC = 4,
SW = 8,
RP = 16,
WP = 32,
DT = 64,
LO = 128,
CR = 256,
SD = 65536,
RC = 131072,
WD = 262144,
WO = 524288,
GA = 268435456,
GX = 536870912,
GW = 1073741824,
GR = 2147483648
}
"@
function Get-ModifiableFile {
<#
.SYNOPSIS
@ -150,6 +126,26 @@ function Test-ServiceDaclPermission {
return $False
}
$ServiceAccessFlags = @{
CC = 1
DC = 2
LC = 4
SW = 8
RP = 16
WP = 32
DT = 64
LO = 128
CR = 256
SD = 65536
RC = 131072
WD = 262144
WO = 524288
GA = 268435456
GX = 536870912
GW = 1073741824
GR = 2147483648
}
# query WMI for the service
$TargetService = Get-WmiObject -Class win32_service -Filter "Name='$ServiceName'" | Where-Object {$_}
@ -159,7 +155,7 @@ function Test-ServiceDaclPermission {
return $False
}
try {
# try {
# retrieve DACL from sc.exe
$Result = sc.exe sdshow $TargetService.Name | where {$_}
@ -183,7 +179,11 @@ function Test-ServiceDaclPermission {
if ($Sid -eq $Ace.SecurityIdentifier){
# convert the AccessMask to a service DACL string
$DaclString = [string]([ServiceAccessFlags] $Ace.AccessMask) -replace ', ',''
$DaclString = $($ServiceAccessFlags.Keys | Foreach-Object {
if (($ServiceAccessFlags[$_] -band $Ace.AccessMask) -eq $ServiceAccessFlags[$_]) {
$_
}
}) -join ""
# convert the input DACL to an array
$DaclArray = [array] ($Dacl -split '(.{2})' | Where-Object {$_})
@ -208,11 +208,11 @@ function Test-ServiceDaclPermission {
}
}
return $False
}
catch{
Write-Warning "Error: $_"
return $False
}
# }
# catch{
# Write-Warning "Error: $_"
# return $False
# }
}
function Invoke-ServiceStart {