-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathConvertFrom-SDDL.ps1
executable file
·168 lines (126 loc) · 10.9 KB
/
ConvertFrom-SDDL.ps1
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
filter ConvertFrom-SDDL
{
<#
.SYNOPSIS
Convert a raw security descriptor from SDDL form to a parsed security descriptor.
Author: Matthew Graeber (@mattifestation)
.DESCRIPTION
ConvertFrom-SDDL generates a parsed security descriptor based upon any string in raw security descriptor definition language (SDDL) form. ConvertFrom-SDDL will parse the SDDL regardless of the type of object the security descriptor represents.
.PARAMETER RawSDDL
Specifies the security descriptor in raw SDDL form.
.EXAMPLE
ConvertFrom-SDDL -RawSDDL 'D:PAI(A;;0xd01f01ff;;;SY)(A;;0xd01f01ff;;;BA)(A;;0x80120089;;;NS)'
.EXAMPLE
'O:BAG:SYD:(D;;0xf0007;;;AN)(D;;0xf0007;;;BG)(A;;0xf0005;;;SY)(A;;0x5;;;BA)', 'O:BAG:SYD:PAI(D;OICI;FA;;;BG)(A;OICI;FA;;;BA)(A;OICIIO;FA;;;CO)(A;OICI;FA;;;SY)' | ConvertFrom-SDDL
.INPUTS
System.String
ConvertFrom-SDDL accepts SDDL strings from the pipeline
.OUTPUTS
System.Management.Automation.PSObject
.LINK
http://www.exploit-monday.com
#>
Param (
[Parameter( Position = 0, Mandatory = $True, ValueFromPipeline = $True )]
[ValidateNotNullOrEmpty()]
[String[]]
$RawSDDL
)
Set-StrictMode -Version 2
# Get reference to sealed RawSecurityDescriptor class
$RawSecurityDescriptor = [Int].Assembly.GetTypes() | ? { $_.FullName -eq 'System.Security.AccessControl.RawSecurityDescriptor' }
# Create an instance of the RawSecurityDescriptor class based upon the provided raw SDDL
try
{
$Sddl = [Activator]::CreateInstance($RawSecurityDescriptor, [Object[]] @($RawSDDL))
}
catch [Management.Automation.MethodInvocationException]
{
throw $Error[0]
}
if ($Sddl.Group -eq $null)
{
$Group = $null
}
else
{
$SID = $Sddl.Group
$Group = $SID.Translate([Security.Principal.NTAccount]).Value
}
if ($Sddl.Owner -eq $null)
{
$Owner = $null
}
else
{
$SID = $Sddl.Owner
$Owner = $SID.Translate([Security.Principal.NTAccount]).Value
}
$ObjectProperties = @{
Group = $Group
Owner = $Owner
}
if ($Sddl.DiscretionaryAcl -eq $null)
{
$Dacl = $null
}
else
{
$DaclArray = New-Object PSObject[](0)
$ValueTable = @{}
$EnumValueStrings = [Enum]::GetNames([System.Security.AccessControl.CryptoKeyRights])
$CryptoEnumValues = $EnumValueStrings | % {
$EnumValue = [Security.AccessControl.CryptoKeyRights] $_
if (-not $ValueTable.ContainsKey($EnumValue.value__))
{
$EnumValue
}
$ValueTable[$EnumValue.value__] = 1
}
$EnumValueStrings = [Enum]::GetNames([System.Security.AccessControl.FileSystemRights])
$FileEnumValues = $EnumValueStrings | % {
$EnumValue = [Security.AccessControl.FileSystemRights] $_
if (-not $ValueTable.ContainsKey($EnumValue.value__))
{
$EnumValue
}
$ValueTable[$EnumValue.value__] = 1
}
$EnumValues = $CryptoEnumValues + $FileEnumValues
foreach ($DaclEntry in $Sddl.DiscretionaryAcl)
{
$SID = $DaclEntry.SecurityIdentifier
$Account = $SID.Translate([Security.Principal.NTAccount]).Value
$Values = New-Object String[](0)
# Resolve access mask
foreach ($Value in $EnumValues)
{
if (($DaclEntry.Accessmask -band $Value) -eq $Value)
{
$Values += $Value.ToString()
}
}
$Access = "$($Values -join ',')"
$DaclTable = @{
Rights = $Access
IdentityReference = $Account
IsInherited = $DaclEntry.IsInherited
InheritanceFlags = $DaclEntry.InheritanceFlags
PropagationFlags = $DaclEntry.PropagationFlags
}
if ($DaclEntry.AceType.ToString().Contains('Allowed'))
{
$DaclTable['AccessControlType'] = [Security.AccessControl.AccessControlType]::Allow
}
else
{
$DaclTable['AccessControlType'] = [Security.AccessControl.AccessControlType]::Deny
}
$DaclArray += New-Object PSObject -Property $DaclTable
}
$Dacl = $DaclArray
}
$ObjectProperties['Access'] = $Dacl
$SecurityDescriptor = New-Object PSObject -Property $ObjectProperties
Write-Output $SecurityDescriptor
}