-
Notifications
You must be signed in to change notification settings - Fork 2
/
descriptors.c
86 lines (66 loc) · 1.78 KB
/
descriptors.c
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
/*
* descriptors.c
*
* WinSecCheck.
*
* - thesnoom 2018
*/
#include <Windows.h>
#include <stdio.h>
#include <AclAPI.h>
#include "descriptors.h"
// Retrieve an objects Descriptor ACL.
ACL *GetObjectDacl( HANDLE hObject, SE_OBJECT_TYPE ObjectType, SECURITY_DESCRIPTOR **pDescOut )
{
if(!hObject)
{
printf("[-] PrintObjectDacl :: NULL handle passed?\n");
return NULL;
}
SECURITY_DESCRIPTOR *pSecDesc = NULL;
ACL *pDacl = NULL;
DWORD dwRet = GetSecurityInfo(hObject, ObjectType, DACL_SECURITY_INFORMATION, NULL, NULL, &pDacl, NULL, &pSecDesc);
if(dwRet != ERROR_SUCCESS)
{
printf("[-] GetSecurityInfo :: Error retrieving SECURITY_INFORMATION (%d)\n", GetLastError());
return NULL;
}
if(!IsValidAcl(pDacl))
{
printf("[-] IsValidAcl :: DACL is invalid? (%d).\n", GetLastError());
return NULL;
}
*pDescOut = pSecDesc;
return pDacl;
}
// Print out the ACL by account and permissions.
void PrintDacl( ACL *pDacl )
{
for(int i = 0; i < pDacl->AceCount; i++)
{
ACCESS_ALLOWED_ACE *pAce = NULL;
if(GetAce(pDacl, i, (PVOID *)&pAce))
{
if(pAce->Header.AceType == ACCESS_ALLOWED_ACE_TYPE)
{
char szAceUser[64] = { 0 }, szAceDom[256] = { 0 };
DWORD dwUserLen = 64, dwDomLen = 256;
SID_NAME_USE pName;
LookupAccountSidA(NULL, (SID *)&pAce->SidStart, szAceUser, &dwUserLen, szAceDom, &dwDomLen, &pName);
printf("%s\\%s -", szAceDom, szAceUser);
if(pAce->Mask & GENERIC_ALL || pAce->Mask & FILE_ALL_ACCESS)
{
printf(" F\n");
continue;
}
if(pAce->Mask & GENERIC_READ || pAce->Mask & FILE_GENERIC_READ)
printf(" R");
if(pAce->Mask & GENERIC_WRITE || pAce->Mask & FILE_GENERIC_WRITE)
printf(" W");
if(pAce->Mask & GENERIC_EXECUTE || pAce->Mask & FILE_GENERIC_EXECUTE)
printf(" X");
puts("");
}
}
}
}