2023. 5. 10. 11:59

How to prevent a services from being stopped by administrative users.

It is almost impossible to prevent administrators from stopping services.
But there are some ways to make it difficult for them.

  1. Ignoring the stop notification

SetServiceStatus

 

SetServiceStatus function (winsvc.h) - Win32 apps

Updates the service control manager's status information for the calling service.

learn.microsoft.com

If you call this function without 'SERVICE_ACCEPT_STOP' in dwControlsAccepted member in SERVICE_STAUS structure, the service ignores the stop notification.

  1. Chaning the access control on the service
// Get an acl of the service

  ATL::CDacl dacl;
  bool result = ATL::AtlGetDacl(L"serviceName", SE_SERVICE, &dacl);


// Traverse all access masks

  for (UINT index = 0; index < count; ++index) {
    CSid aceSid;
    ACCESS_MASK mask = 0;
    BYTE type = 0;
    BYTE flags = 0;
    GUID objectType;
    GUID inheritedObjectType;
    dacl.GetAclEntry(index, &aceSid, &mask, &type, &flags, &objectType, &inheritedObjectType);

}

// Change & Set acess mask

// Remove old ace
dacl.RemoveAce(speciifcIndex);
// Remove permissions(SERVICE_CHANGE_CONFIG & SERVICE_STOP)
specificMask &= ~SERVICE_CHANGE_CONFIG; 
specificMask &= ~SERVICE_STOP;
// Add new ace
 result = dacl.AddAllowedAce(specificSid, specificMask, specificFlags);
2015. 1. 12. 11:38

Debugging windows services

using psexec

psexec –sd –i 0 "c:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\Remote Debugger\x86\msvsmon.exe" /noauth /anyuser /silent


download psexec 


How to debug Windows services with Windbg




2013. 9. 16. 17:29

Development Windows Service