有人知道如何使用 C# 获取远程服务上的 SACL 吗?我尝试了很多不同的方法,但基本上没有什么效果。我可以在本地计算机上获取 DACL 和 SACL,但在远程计算机上获取其中任何一个似乎都不可能。
我所做的是创建一个名为ServiceSecurity
继承自NativeObjectSecurity
并且行为很像RegistrySecurity
班级。以下是我拥有的两个构造函数:
public ServiceSecurity(string serviceName, AccessControlSections includeSections)
: base(true, ResourceType.Service, serviceName, includeSections, null, null)
{
}
public ServiceSecurity(System.Runtime.InteropServices.SafeHandle handle, AccessControlSections includeSections)
: base(true, ResourceType.Service, handle, includeSections)
{
}
第一个使用服务名称,而第二个则需要服务的句柄。显然,第一个可以很好地获取 DACL 和 SACL,因为它都是本地的,但为了获取远程计算机,我正在使用ServiceController
类来查找远程计算机上的服务。得到它后,我通过了ServiceHandle
服务的财产ServiceSecurity
我构建了一个类,此时我收到了未经授权的访问异常,这似乎不对,因为我的用户帐户是该域的域管理员,并且是目标框上的本地管理员。我也有SeSecurityPrivilege
是的,这应该允许我访问。
有人有主意吗?似乎是SafeHandle
我得到的是不对的,但是SafeHandle
属性说它没有关闭并且它是一个有效的句柄,所以我不太知道发生了什么。
这是我用来尝试检索数据的代码:
ServiceSecurity sSec = new ServiceSecurity(services[i].ServiceName, accessSections);
string outputData = sSec.GetSecurityDescriptorSddlForm(accessSections);
上述内容适用于本地权限和审核设置(DACL 和 SACL)。但它被设计为在本地机器上工作。如果我这样做:
ServiceSecurity sSec = new ServiceSecurity(services[i].ServiceHandle, accessSections);
string outputData = sSec.GetSecurityDescriptorSddlForm(accessSections);
ServiceSecurity 构造函数在本地和远程服务器上对于 SACL 均失败,如下所示,但对于 DACL 仍然有效:
System.UnauthorizedAccessException: Attempted to perform an unauthorized operation.
at System.Security.AccessControl.Win32.GetSecurityInfo(ResourceType resourceType, String name, SafeHandle handle, AccessControlSections accessControlSections, RawSecurityDescriptor& resultSd)
at System.Security.AccessControl.NativeObjectSecurity.CreateInternal(ResourceType resourceType, Boolean isContainer, String name, SafeHandle handle, AccessControlSections includeSections, Boolean createByName, ExceptionFromErrorCode exceptionFromErrorCode, Object exceptionContext)
at System.Security.AccessControl.NativeObjectSecurity..ctor(Boolean isContainer, ResourceType resourceType, SafeHandle handle, AccessControlSections includeSections)
对于 accessSections,我仅指定其中一个AccessControlSections
,无论是审核还是访问,每次我通过考试时审核似乎都会失败ServiceHandle
.
更新:
所以也许真正的问题应该是,我如何获得具有以下功能的服务的句柄:ACCESS_SYSTEM_SECURITY
权利以便我可以获得 SACL?