1
- package main
1
+ package gosddl
2
2
3
3
import (
4
- "encoding/json"
5
- "flag"
6
4
"fmt"
7
- "github.com/gorilla/mux"
8
5
"log"
9
- "net/http"
10
6
"strings"
11
7
)
12
8
@@ -19,7 +15,7 @@ type entryACLInternal struct {
19
15
InheritObjectGuid string `json:"InheritObjectGuid"`
20
16
}
21
17
22
- type permissons struct {
18
+ type Permissons struct {
23
19
Owner string `json:"owner"`
24
20
Primary string `json:"primary"`
25
21
Dacl []entryACLInternal `json:"dacl"`
@@ -28,191 +24,8 @@ type permissons struct {
28
24
SaclInger []string `json:"saclInheritFlags"`
29
25
}
30
26
31
- var sddlRights = map [string ]string {
32
- // Generic access rights
33
- "GA" : "GENERIC_ALL" ,
34
- "GR" : "GENERIC_READ" ,
35
- "GW" : "GENERIC_WRITE" ,
36
- "GX" : "GENERIC_EXECUTE" ,
37
- // Standard access rights
38
- "RC" : "READ_CONTROL" ,
39
- "SD" : "DELETE" ,
40
- "WD" : "WRITE_DAC" ,
41
- "WO" : "WRITE_OWNER" ,
42
- // Directory service object access rights
43
- "RP" : "ADS_RIGHT_DS_READ_PROP" ,
44
- "WP" : "ADS_RIGHT_DS_WRITE_PROP" ,
45
- "CC" : "ADS_RIGHT_DS_CREATE_CHILD" ,
46
- "DC" : "ADS_RIGHT_DS_DELETE_CHILD" ,
47
- "LC" : "ADS_RIGHT_ACTRL_DS_LIST" ,
48
- "SW" : "ADS_RIGHT_DS_SELF" ,
49
- "LO" : "ADS_RIGHT_DS_LIST_OBJECT" ,
50
- "DT" : "ADS_RIGHT_DS_DELETE_TREE" ,
51
- "CR" : "ADS_RIGHT_DS_CONTROL_ACCESS" ,
52
- // File access rights
53
- "FA" : "FILE_ALL_ACCESS" ,
54
- "FR" : "FILE_GENERIC_READ" ,
55
- "FW" : "FILE_GENERIC_WRITE" ,
56
- "FX" : "FILE_GENERIC_EXECUTE" ,
57
- // Registry key access rights
58
- "KA" : "KEY_ALL_ACCESS" ,
59
- "KR" : "KEY_READ" ,
60
- "KW" : "KEY_WRITE" ,
61
- "KX" : "KEY_EXECUTE" ,
62
- // Mandatory label rights
63
- "NR" : "SYSTEM_MANDATORY_LABEL_NO_READ_UP" ,
64
- "NW" : "SYSTEM_MANDATORY_LABEL_NO_WRITE_UP" ,
65
- "NX" : "SYSTEM_MANDATORY_LABEL_NO_EXECUTE" ,
66
- }
67
-
68
- var sddlInheritanceFlags = map [string ]string {
69
- "P" : "DDL_PROTECTED" ,
70
- "AI" : "SDDL_AUTO_INHERITED" ,
71
- "AR" : "SDDL_AUTO_INHERIT_REQ" ,
72
- }
73
-
74
- var sddlAceType = map [string ]string {
75
- "D" : "ACCESS DENIED" ,
76
- "OA" : "OBJECT ACCESS ALLOWED" ,
77
- "OD" : "OBJECT ACCESS DENIED" ,
78
- "AU" : "SYSTEM AUDIT" ,
79
- "OU" : "OBJECT SYSTEM AUDIT" ,
80
- "OL" : "OBJECT SYSTEM ALARM" ,
81
- "A" : "ACCESS ALLOWED" ,
82
- }
83
-
84
- var sddlAceFlags = map [string ]string {
85
- "CI" : "CONTAINER INHERIT" ,
86
- "OI" : "OBJECT INHERIT" ,
87
- "NP" : "NO PROPAGATE" ,
88
- "IO" : "INHERITANCE ONLY" ,
89
- "ID" : "ACE IS INHERITED" ,
90
- "SA" : "SUCCESSFUL ACCESS AUDIT" ,
91
- "FA" : "FAILED ACCESS AUDIT" ,
92
- }
93
-
94
- var sddlSidsRep = map [string ]string {
95
- "O" : "Owner" ,
96
- "AO" : "Account operators" ,
97
- "PA" : "Group Policy administrators" ,
98
- "RU" : "Alias to allow previous Windows 2000" ,
99
- "IU" : "Interactively logged-on user" ,
100
- "AN" : "Anonymous logon" ,
101
- "LA" : "Local administrator" ,
102
- "AU" : "Authenticated users" ,
103
- "LG" : "Local guest" ,
104
- "BA" : "Built-in administrators" ,
105
- "LS" : "Local service account" ,
106
- "BG" : "Built-in guests" ,
107
- "SY" : "Local system" ,
108
- "BO" : "Backup operators" ,
109
- "NU" : "Network logon user" ,
110
- "BU" : "Built-in users" ,
111
- "NO" : "Network configuration operators" ,
112
- "CA" : "Certificate server administrators" ,
113
- "NS" : "Network service account" ,
114
- "CG" : "Creator group" ,
115
- "PO" : "Printer operators" ,
116
- "CO" : "Creator owner" ,
117
- "PS" : "Personal self" ,
118
- "DA" : "Domain administrators" ,
119
- "PU" : "Power users" ,
120
- "DC" : "Domain computers" ,
121
- "RS" : "RAS servers group" ,
122
- "DD" : "Domain controllers" ,
123
- "RD" : "Terminal server users" ,
124
- "DG" : "Domain guests" ,
125
- "RE" : "Replicator" ,
126
- "DU" : "Domain users" ,
127
- "RC" : "Restricted code" ,
128
- "EA" : "Enterprise administrators" ,
129
- "SA" : "Schema administrators" ,
130
- "ED" : "Enterprise domain controllers" ,
131
- "SO" : "Server operators" ,
132
- "WD" : "Everyone" ,
133
- "SU" : "Service logon user" ,
134
- }
135
-
136
- var sddlWellKnownSidsRep = map [string ]string {
137
- "S-1-0" : "Null Authority" ,
138
- "S-1-0-0" : "Nobody" ,
139
- "S-1-1" : "World Authority" ,
140
- "S-1-1-0" : "Everyone" ,
141
- "S-1-2" : "Local Authority" ,
142
- "S-1-2-0" : "Local " ,
143
- "S-1-2-1" : "Console Logon " ,
144
- "S-1-3" : "Creator Authority" ,
145
- "S-1-3-0" : "Creator Owner" ,
146
- "S-1-3-1" : "Creator Group" ,
147
- "S-1-3-2" : "Creator Owner Server" ,
148
- "S-1-3-3" : "Creator Group Server" ,
149
- "S-1-3-4" : "Owner Rights " ,
150
- "S-1-4" : "Non-unique Authority" ,
151
- "S-1-5" : "NT Authority" ,
152
- "S-1-5-1" : "Dialup" ,
153
- "S-1-5-2" : "Network" ,
154
- "S-1-5-3" : "Batch" ,
155
- "S-1-5-4" : "Interactive" ,
156
- "S-1-5-6" : "Service" ,
157
- "S-1-5-7" : "Anonymous" ,
158
- "S-1-5-8" : "Proxy" ,
159
- "S-1-5-9" : "Enterprise Domain Controllers" ,
160
- "S-1-5-10" : "Principal Self" ,
161
- "S-1-5-11" : "Authenticated Users" ,
162
- "S-1-5-12" : "Restricted Code" ,
163
- "S-1-5-13" : "Terminal Server Users" ,
164
- "S-1-5-14" : "Remote Interactive Logon " ,
165
- "S-1-5-15" : "This Organization " ,
166
- "S-1-5-17" : "This Organization " ,
167
- "S-1-5-18" : "Local System" ,
168
- "S-1-5-19" : "NT Authority" ,
169
- "S-1-5-20" : "NT Authority" ,
170
- "S-1-5-32-544" : "Administrators" ,
171
- "S-1-5-32-545" : "Users" ,
172
- "S-1-5-32-546" : "Guests" ,
173
- "S-1-5-32-547" : "Power Users" ,
174
- "S-1-5-32-548" : "Account Operators" ,
175
- "S-1-5-32-549" : "Server Operators" ,
176
- "S-1-5-32-550" : "Print Operators" ,
177
- "S-1-5-32-551" : "Backup Operators" ,
178
- "S-1-5-32-552" : "Replicators" ,
179
- "S-1-5-64-10" : "NTLM Authentication " ,
180
- "S-1-5-64-14" : "SChannel Authentication " ,
181
- "S-1-5-64-21" : "Digest Authentication " ,
182
- "S-1-5-80" : "NT Service " ,
183
- "S-1-5-80-0" : "All Services " ,
184
- "S-1-5-83-0" : "NT VIRTUAL MACHINE\\ Virtual Machines" ,
185
- "S-1-16-0" : "Untrusted Mandatory Level " ,
186
- "S-1-16-4096" : "Low Mandatory Level " ,
187
- "S-1-16-8192" : "Medium Mandatory Level " ,
188
- "S-1-16-8448" : "Medium Plus Mandatory Level " ,
189
- "S-1-16-12288" : "High Mandatory Level " ,
190
- "S-1-16-16384" : "System Mandatory Level " ,
191
- "S-1-16-20480" : "Protected Process Mandatory Level " ,
192
- "S-1-16-28672" : "Secure Process Mandatory Level " ,
193
- "S-1-5-32-554" : "BUILTIN\\ Pre-Windows 2000 Compatible Access" ,
194
- "S-1-5-32-555" : "BUILTIN\\ Remote Desktop Users" ,
195
- "S-1-5-32-556" : "BUILTIN\\ Network Configuration Operators" ,
196
- "S-1-5-32-557" : "BUILTIN\\ Incoming Forest Trust Builders" ,
197
- "S-1-5-32-558" : "BUILTIN\\ Performance Monitor Users" ,
198
- "S-1-5-32-559" : "BUILTIN\\ Performance Log Users" ,
199
- "S-1-5-32-560" : "BUILTIN\\ Windows Authorization Access Group" ,
200
- "S-1-5-32-561" : "BUILTIN\\ Terminal Server License Servers" ,
201
- "S-1-5-32-562" : "BUILTIN\\ Distributed COM Users" ,
202
- "S-1-5-32-569" : "BUILTIN\\ Cryptographic Operators" ,
203
- "S-1-5-32-573" : "BUILTIN\\ Event Log Readers " ,
204
- "S-1-5-32-574" : "BUILTIN\\ Certificate Service DCOM Access " ,
205
- "S-1-5-32-575" : "BUILTIN\\ RDS Remote Access Servers" ,
206
- "S-1-5-32-576" : "BUILTIN\\ RDS Endpoint Servers" ,
207
- "S-1-5-32-577" : "BUILTIN\\ RDS Management Servers" ,
208
- "S-1-5-32-578" : "BUILTIN\\ Hyper-V Administrators" ,
209
- "S-1-5-32-579" : "BUILTIN\\ Access Control Assistance Operators" ,
210
- "S-1-5-32-580" : "BUILTIN\\ Remote Management Users" ,
211
- "S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464" : "Trusted Installer" ,
212
- }
213
-
27
+ // replace identification account: sid/wellkhownsid/usersid
214
28
func sidReplace (str string ) string {
215
- // replace identification account: sid/wellkhownsid/usersid
216
29
if len (str ) > 2 {
217
30
if x , ok := sddlWellKnownSidsRep [str ]; ok {
218
31
return x
@@ -225,8 +38,8 @@ func sidReplace(str string) string {
225
38
}
226
39
}
227
40
41
+ // Chunk string with 2 letters, add to array and then resolve
228
42
func replacer (maps map [string ]string , str string ) []string {
229
- // Chunk string with 2 letters, add to array and then resolve
230
43
var temp , result []string
231
44
if len (str ) > 2 {
232
45
for j := 0 ; j < len (str )- 1 ; j = j + 2 {
@@ -245,13 +58,9 @@ func replacer(maps map[string]string, str string) []string {
245
58
return result
246
59
}
247
60
248
- func GetInfo (w http.ResponseWriter , r * http.Request ) {
249
- json .NewEncoder (w ).Encode ("Hello" )
250
- }
251
-
61
+ // Base format ACL: (ace_type;ace_flags;rights;object_guid;inherit_object_guid;account_sid)
62
+ // Convert values from string to struct with replace strings
252
63
func splitBodyACL (str string ) entryACLInternal {
253
- // Base format ACL: (ace_type;ace_flags;rights;object_guid;inherit_object_guid;account_sid)
254
- // Convert values from string to struct with replace strings
255
64
temp := strings .Split (str , ";" )
256
65
return entryACLInternal {
257
66
AceType : replacer (sddlAceType , temp [0 ])[0 ],
@@ -274,7 +83,7 @@ func splitBody(body string) []entryACLInternal {
274
83
return entryACLInternalArr
275
84
}
276
85
277
- func (p * permissons ) parseBody (body string ) ([]string , []entryACLInternal ) {
86
+ func (p * Permissons ) parseBody (body string ) ([]string , []entryACLInternal ) {
278
87
var inheritFlagArr []string
279
88
var entryACLInternalArr []entryACLInternal
280
89
if strings .Index (body , "(" ) != 0 {
@@ -292,7 +101,7 @@ func (p *permissons) parseBody(body string) ([]string, []entryACLInternal) {
292
101
return inheritFlagArr , entryACLInternalArr
293
102
}
294
103
295
- func (p * permissons ) parseSDDL (sddrArr []string ) {
104
+ func (p * Permissons ) parseSDDL (sddrArr []string ) {
296
105
for _ , y := range sddrArr {
297
106
sddlSplit := strings .Split (y , ":" )
298
107
letter := sddlSplit [0 ]
@@ -313,8 +122,8 @@ func (p *permissons) parseSDDL(sddrArr []string) {
313
122
314
123
}
315
124
316
- func ( p * permissons ) sliceSDDL ( indecs [] int , str string ) {
317
- // create slice objects from str to array of strings
125
+ // create slice objects from str to array of strings
126
+ func ( p * Permissons ) sliceSDDL ( indecs [] int , str string ) {
318
127
var sddlArr []string
319
128
for i := 0 ; i < len (indecs )- 1 ; i ++ {
320
129
sl := str [indecs [i ]:indecs [i + 1 ]]
@@ -323,7 +132,7 @@ func (p *permissons) sliceSDDL(indecs []int, str string) {
323
132
p .parseSDDL (sddlArr )
324
133
}
325
134
326
- func (p * permissons ) findIndex (str string ) {
135
+ func (p * Permissons ) FindGroupIndex (str string ) {
327
136
groups := []string {"O:" , "G:" , "D:" , "S:" }
328
137
var result []int
329
138
for _ , i := range groups {
@@ -334,41 +143,3 @@ func (p *permissons) findIndex(str string) {
334
143
result = append (result , len (str ))
335
144
p .sliceSDDL (result , str )
336
145
}
337
-
338
- func Decode (w http.ResponseWriter , r * http.Request ) {
339
- params := mux .Vars (r )
340
- if params ["sddl" ] != "" {
341
- sddl := params ["sddl" ]
342
- var permisson permissons
343
- permisson .findIndex (sddl )
344
- json .NewEncoder (w ).Encode (permisson )
345
- return
346
- }
347
-
348
- }
349
-
350
- func api (port string ) {
351
- port = ":" + port
352
- router := mux .NewRouter ()
353
- router .HandleFunc ("/sddl" , GetInfo ).Methods ("GET" )
354
- router .HandleFunc ("/sddl/{sddl}" , Decode ).Methods ("GET" )
355
- log .Fatal (http .ListenAndServe (port , router ))
356
- }
357
-
358
- func main () {
359
- apiPtr := flag .Bool ("api" , false , "a bool" )
360
- apiPortPtr := flag .String ("port" , "8000" , "Default port 8000" )
361
- flag .Parse ()
362
- if * apiPtr {
363
- fmt .Println ("API Interface started on port" , * apiPortPtr )
364
- api (* apiPortPtr )
365
- } else if flag .Args () != nil {
366
- var permisson permissons
367
- permisson .findIndex (flag .Args ()[0 ])
368
- b , err := json .Marshal (permisson )
369
- if err != nil {
370
- log .Fatal (err )
371
- }
372
- fmt .Println (string (b ))
373
- }
374
- }
0 commit comments