-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShowACL.cpp
376 lines (280 loc) · 14.9 KB
/
ShowACL.cpp
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
/** ShowACL.cpp (2023.06.16) P. Stuer **/
#include "pch.h"
#include <CppCoreCheck/Warnings.h>
#pragma warning(disable: 4710 4711 4820 ALL_CPPCORECHECK_WARNINGS)
#include "Console.h"
#include "Support.h"
#include "ShowACL.h"
#include "ShowSID.h"
extern Console _Console;
static HRESULT ShowExplicitAccess(const EXPLICIT_ACCESS_W * ea, ObjectType objectType);
static HRESULT ShowTrustee(const TRUSTEE_W * Trustee);
///<summary>
/// Shows the information in an ACL.
///</summary>
HRESULT ShowACL(const PACL acl, ObjectType objectType)
{
HRESULT hResult = S_OK;
EXPLICIT_ACCESS_W * Entries = nullptr;
ULONG EntryCount = 0;
DWORD ErrorCode = ::GetExplicitEntriesFromAclW(acl, &EntryCount, &Entries);
if (ErrorCode == ERROR_SUCCESS)
{
if (EntryCount > 0)
{
for (ULONG i = 0; i < EntryCount; i++)
{
_Console.Write(L"Entry %d\n", i + 1);
_Console.IncreaseIndent();
ShowExplicitAccess(&Entries[i], objectType);
_Console.DecreaseIndent();
}
}
else
_Console.Write(L"ACL contains no entries.\n");
LocalFree(Entries);
}
else
hResult = HRESULT_FROM_WIN32(ShowError(L"GetExplicitEntriesFromAcl() failed."));
return hResult;
}
static HRESULT ShowExplicitAccess(const EXPLICIT_ACCESS_W * ea, ObjectType objectType)
{
{
_Console.SetItalic(true);
_Console.Write(L"Trustee\n");
_Console.SetItalic(false);
_Console.IncreaseIndent();
ShowTrustee(&ea->Trustee);
_Console.DecreaseIndent();
}
{
_Console.SetItalic(true);
_Console.Write(L"Access Rights\n");
_Console.SetItalic(false);
_Console.IncreaseIndent();
LPCWSTR AccessMode = NULL;
switch (ea->grfAccessMode)
{
// DACL
case GRANT_ACCESS: AccessMode = L"Grant"; break;
case DENY_ACCESS: AccessMode = L"Deny"; break;
// SACL
case SET_AUDIT_SUCCESS: AccessMode = L"Enable audit success of"; break;
case SET_AUDIT_FAILURE: AccessMode = L"Enable audit failure of"; break;
case SET_ACCESS: AccessMode = L"Set"; break;
case REVOKE_ACCESS: AccessMode = L"Revoke"; break;
case NOT_USED_ACCESS: AccessMode = L"Unused"; break;
default: AccessMode = L"<Unknown access mode>";
}
_Console.Write(L"Specific Access Rights\n");
_Console.IncreaseIndent();
_Console.SetBullet(true);
// Access Rights for Access-Token Objects, https://msdn.microsoft.com/en-us/library/aa374905(v=vs.85).aspx
if (objectType == AccessTokenObject)
{
}
else
// Process Security and Access Rights, https://msdn.microsoft.com/en-us/library/ms684880(v=vs.85).aspx
if (objectType == ProcessObject)
{
if (ea->grfAccessPermissions & PROCESS_TERMINATE)
_Console.Write(L"%s terminate\n", AccessMode);
if (ea->grfAccessPermissions & PROCESS_CREATE_THREAD)
_Console.Write(L"%s create thread\n", AccessMode);
if (ea->grfAccessPermissions & PROCESS_SET_SESSIONID)
_Console.Write(L"%s read data\n", AccessMode);
if (ea->grfAccessPermissions & PROCESS_VM_OPERATION)
_Console.Write(L"%s address space operations\n", AccessMode);
if (ea->grfAccessPermissions & PROCESS_VM_READ)
_Console.Write(L"%s read process memory\n", AccessMode);
if (ea->grfAccessPermissions & PROCESS_VM_WRITE)
_Console.Write(L"%s write process memory\n", AccessMode);
if (ea->grfAccessPermissions & PROCESS_DUP_HANDLE)
_Console.Write(L"%s duplicate handles\n", AccessMode);
if (ea->grfAccessPermissions & PROCESS_CREATE_PROCESS)
_Console.Write(L"%s create process\n", AccessMode);
if (ea->grfAccessPermissions & PROCESS_SET_QUOTA)
_Console.Write(L"%s set quota\n", AccessMode);
if (ea->grfAccessPermissions & PROCESS_SET_INFORMATION)
_Console.Write(L"%s read data\n", AccessMode);
if (ea->grfAccessPermissions & PROCESS_QUERY_INFORMATION)
_Console.Write(L"%s query information\n", AccessMode);
if (ea->grfAccessPermissions & PROCESS_SUSPEND_RESUME)
_Console.Write(L"%s suspend/resume\n", AccessMode);
if (ea->grfAccessPermissions & PROCESS_QUERY_LIMITED_INFORMATION)
_Console.Write(L"%s query limited information\n", AccessMode);
if (ea->grfAccessPermissions & PROCESS_SET_LIMITED_INFORMATION)
_Console.Write(L"%s set limited information\n", AccessMode);
}
else
// File Security and Access Rights, https://msdn.microsoft.com/en-us/library/aa364399(v=vs.85).aspx
if ((objectType == FileObject) || (objectType == NamedPipeObject))
{
if (ea->grfAccessPermissions & FILE_READ_DATA)
_Console.Write(L"%s read data\n", AccessMode);
else
if (ea->grfAccessPermissions & FILE_LIST_DIRECTORY)
_Console.Write(L"%s list\n", AccessMode);
if (ea->grfAccessPermissions & FILE_WRITE_DATA)
_Console.Write(L"%s write data\n", AccessMode);
else
if (ea->grfAccessPermissions & FILE_ADD_FILE)
_Console.Write(L"%s add file\n", AccessMode);
if ((objectType == FileObject) && ea->grfAccessPermissions & FILE_APPEND_DATA)
_Console.Write(L"%s append data\n", AccessMode);
if ((objectType == FileObject) && ea->grfAccessPermissions & FILE_EXECUTE)
_Console.Write(L"%s execute\n", AccessMode);
if ((objectType == NamedPipeObject) && ea->grfAccessPermissions & FILE_CREATE_PIPE_INSTANCE)
_Console.Write(L"%s create instance\n", AccessMode);
}
else
if (objectType == DirectoryObject)
{
if (ea->grfAccessPermissions & FILE_ADD_SUBDIRECTORY)
_Console.Write(L"%s add subdirectory\n", AccessMode);
if (ea->grfAccessPermissions & FILE_TRAVERSE)
_Console.Write(L"%s traverse\n", AccessMode);
if (ea->grfAccessPermissions & FILE_DELETE_CHILD)
_Console.Write(L"%s delete child\n", AccessMode);
}
if ((objectType == FileObject) || (objectType == DirectoryObject))
{
if (ea->grfAccessPermissions & FILE_READ_EA)
_Console.Write(L"%s read extended attributes\n", AccessMode);
if (ea->grfAccessPermissions & FILE_WRITE_EA)
_Console.Write(L"%s write extended attributes\n", AccessMode);
if (ea->grfAccessPermissions & FILE_READ_ATTRIBUTES)
_Console.Write(L"%s read attributes\n", AccessMode);
if (ea->grfAccessPermissions & FILE_WRITE_ATTRIBUTES)
_Console.Write(L"%s write attributes\n", AccessMode);
}
_Console.SetBullet(false);
_Console.DecreaseIndent();
_Console.Write(L"Standard Access Rights\n");
_Console.IncreaseIndent();
_Console.SetBullet(true);
if (ea->grfAccessPermissions & DELETE) _Console.Write(L"%s delete access\n", AccessMode);
if (ea->grfAccessPermissions & READ_CONTROL) _Console.Write(L"%s read access to the owner, group, and DACL\n", AccessMode);
if (ea->grfAccessPermissions & WRITE_DAC) _Console.Write(L"%s write access to the DACL\n", AccessMode);
if (ea->grfAccessPermissions & WRITE_OWNER) _Console.Write(L"%s write access to the owner\n", AccessMode);
if (ea->grfAccessPermissions & SYNCHRONIZE) _Console.Write(L"%s synchronize access\n", AccessMode);
_Console.SetBullet(false);
_Console.DecreaseIndent();
_Console.Write(L"Generic Access Rights\n");
_Console.IncreaseIndent();
_Console.SetBullet(true);
if (ea->grfAccessPermissions & ACCESS_SYSTEM_SECURITY) _Console.Write(L"%s access to system access control list (SACL)\n", AccessMode);
if (ea->grfAccessPermissions & MAXIMUM_ALLOWED) _Console.Write(L"%s maximum allowed access\n", AccessMode);
if (ea->grfAccessPermissions & GENERIC_ALL) _Console.Write(L"%s generic all\n", AccessMode);
if (ea->grfAccessPermissions & GENERIC_EXECUTE) _Console.Write(L"%s generic execute\n", AccessMode);
if (ea->grfAccessPermissions & GENERIC_WRITE) _Console.Write(L"%s generic write\n", AccessMode);
if (ea->grfAccessPermissions & GENERIC_READ) _Console.Write(L"%s generic read\n", AccessMode);
_Console.SetBullet(false);
_Console.DecreaseIndent();
_Console.DecreaseIndent();
}
{
_Console.SetItalic(true);
_Console.Write(L"Inheritance\n");
_Console.SetItalic(false);
_Console.IncreaseIndent();
_Console.SetBullet(true);
if (ea->grfInheritance & INHERITED_ACE) _Console.Write(L"Inherited from parent\n");
if (ea->grfInheritance & CONTAINER_INHERIT_ACE) _Console.Write(L"Applies to child containers\n");
if (ea->grfInheritance & OBJECT_INHERIT_ACE) _Console.Write(L"Applies to child objects\n");
if (ea->grfInheritance & INHERIT_NO_PROPAGATE) _Console.Write(L"Inherited but not propagated\n");
if (ea->grfInheritance & INHERIT_ONLY) _Console.Write(L"Inherited\n");
if (ea->grfInheritance & INHERIT_ONLY_ACE) _Console.Write(L"Does not apply to this object. Will only be inherited by child objects and child containers\n"); else _Console.Write(L"Applies to this object only.\n");
if (ea->grfInheritance & NO_INHERITANCE) _Console.Write(L"Will not be inherited by child objects or child containers\n");
if (ea->grfInheritance & NO_PROPAGATE_INHERIT_ACE) _Console.Write(L"Does not propagate to child objects or child containers\n");
_Console.SetBullet(false);
_Console.DecreaseIndent();
}
return S_OK;
}
///<summary>
/// Shows the trustee defined in an ACE.
///</summary>
static HRESULT ShowTrustee(const TRUSTEE_W * Trustee)
{
switch (Trustee->TrusteeForm)
{
case TRUSTEE_IS_SID:
ShowSID((PSID)(Trustee->ptstrName));
break;
case TRUSTEE_IS_NAME:
_Console.Write(L"%s\n", Trustee->ptstrName);
break;
case TRUSTEE_IS_OBJECTS_AND_SID:
{
POBJECTS_AND_SID oas = (POBJECTS_AND_SID)Trustee->ptstrName;
ShowSID(oas->pSid);
WCHAR GuidString[256] = { '\0' };
if ((oas->ObjectsPresent & ACE_OBJECT_TYPE_PRESENT) && SUCCEEDED(GUIDToText(&oas->ObjectTypeGuid, GuidString, ARRAYSIZE(GuidString))))
{
_Console.Write(L"Object Type: %s\n", GuidString);
}
if ((oas->ObjectsPresent & ACE_INHERITED_OBJECT_TYPE_PRESENT) && SUCCEEDED(GUIDToText(&oas->InheritedObjectTypeGuid, GuidString, ARRAYSIZE(GuidString))))
{
_Console.Write(L"Inherited Object Type: %s\n", GuidString);
}
break;
}
case TRUSTEE_IS_OBJECTS_AND_NAME:
{
POBJECTS_AND_NAME_W oan = (POBJECTS_AND_NAME_W)Trustee->ptstrName;
_Console.Write(L"%s\n", Trustee->ptstrName);
if (oan->ObjectsPresent & ACE_OBJECT_TYPE_PRESENT)
{
_Console.Write(L"Object Type: %s\n", oan->ObjectTypeName);
}
if (oan->ObjectsPresent & ACE_INHERITED_OBJECT_TYPE_PRESENT)
{
_Console.Write(L"Inherited Object Type: %s\n", oan->InheritedObjectTypeName);
}
break;
}
case TRUSTEE_BAD_FORM:
{
_Console.Write(L"<Invalid>\n");
break;
}
default:
_Console.Write(L"Unknow trustee form %08X\n", Trustee->TrusteeForm);
break;
}
return S_OK;
}
///<summary>
/// Gets the description of the ACE type.
///</summary>
LPCWSTR GetACETypeDescription(BYTE aceType)
{
switch (aceType)
{
case ACCESS_ALLOWED_ACE_TYPE: return L"Access Allowed";
case ACCESS_DENIED_ACE_TYPE: return L"Access Denied";
case SYSTEM_AUDIT_ACE_TYPE: return L"System Audit";
case SYSTEM_ALARM_ACE_TYPE: return L"System Alarm";
case ACCESS_ALLOWED_COMPOUND_ACE_TYPE: return L"Access Allowed Compound";
case ACCESS_ALLOWED_OBJECT_ACE_TYPE: return L"Object-specific Access Allowed";
case ACCESS_DENIED_OBJECT_ACE_TYPE: return L"Object-specific Access Allowed";
case SYSTEM_AUDIT_OBJECT_ACE_TYPE: return L"Object-specific System Audit";
case SYSTEM_ALARM_OBJECT_ACE_TYPE: return L"Object-specific System Alarm";
case ACCESS_ALLOWED_CALLBACK_ACE_TYPE: return L"Access Allowed Callback";
case ACCESS_DENIED_CALLBACK_ACE_TYPE: return L"Access Allowed Callback";
case ACCESS_ALLOWED_CALLBACK_OBJECT_ACE_TYPE: return L"Object-specific Access Allowed Callback";
case ACCESS_DENIED_CALLBACK_OBJECT_ACE_TYPE: return L"Object-specific Access Denied Callback";
case SYSTEM_AUDIT_CALLBACK_ACE_TYPE: return L"System Audit Callback";
case SYSTEM_ALARM_CALLBACK_ACE_TYPE: return L"System Alarm Callback";
case SYSTEM_AUDIT_CALLBACK_OBJECT_ACE_TYPE: return L"Object-specific System Audit Callback";
case SYSTEM_ALARM_CALLBACK_OBJECT_ACE_TYPE: return L"Object-specific System Alarm Callback";
case SYSTEM_MANDATORY_LABEL_ACE_TYPE: return L"System Mandatory Label";
case SYSTEM_RESOURCE_ATTRIBUTE_ACE_TYPE: return L"System Resource Attribute";
case SYSTEM_SCOPED_POLICY_ID_ACE_TYPE: return L"System Scoped Policy";
case SYSTEM_PROCESS_TRUST_LABEL_ACE_TYPE: return L"System Process Trust Label";
case SYSTEM_ACCESS_FILTER_ACE_TYPE: return L"System Access Filter";
default: return L"Unknown ACE Type";
}
}