微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

通过SetSecurityDescriptor设置WMI ACL

我似乎无法通过Powershell设置WMI ACL。 调用

Invoke-WmiMethod -Name "SetSecurityDescriptor" -Path "__systemsecurity=@" -ArgumentList $acl.psobject.immediateBaSEObject

返回这个exception:

Invoke-WmiMethod : Invalid method Parameter(s) At line:1 char:17. + Invoke-WmiMethod <<<< -Name "SetSecurityDescriptor" -Path "__systemsecurity=@" -ArgumentList $acl.psobject.immediateBaSEObject + CategoryInfo : InvalidOperation: (:) [Invoke-WmiMethod],ManagementException + FullyQualifiedErrorId : InvokeWMIManagementException,Microsoft.PowerShell.Commands.InvokeWmiMethod

SetSecurityDescriptor只需要__SecurityDescriptortypes的一个参数,而我在-Arguments使用的$acl对象本身就好了:

PS C:Windowssystem32> $acl | gm TypeName: System.Management.ManagementBaSEObject#__SecurityDescriptor Name MemberType DeFinition ---- ---------- ---------- ControlFlags Property System.UInt32 ControlFlags {get;set;} DACL Property System.Management.ManagementObject#__ACE[] DACL ... Group Property System.Management.ManagementObject#__ACE Group {... Owner Property System.Management.ManagementObject#__ACE Owner {... SACL Property System.Management.ManagementObject#__ACE[] SACL ... TIME_CREATED Property System.UInt64 TIME_CREATED {get;set;} __CLASS Property System.String __CLASS {get;set;} __DERIVATION Property System.String[] __DERIVATION {get;set;} __DYNASTY Property System.String __DYNASTY {get;set;} __GENUS Property system.int32 __GENUS {get;set;} __NAMESPACE Property System.String __NAMESPACE {get;set;} __PATH Property System.String __PATH {get;set;} __PROPERTY_COUNT Property system.int32 __PROPERTY_COUNT {get;set;} __RELPATH Property System.String __RELPATH {get;set;} __SERVER Property System.String __SERVER {get;set;} __SUPERCLASS Property System.String __SUPERCLASS {get;set;}

从我可以得到的文档 ,我调用Parameter Set: path重载,所以参数集似乎不会丢失所需的参数。

创buildWindows Media编码器对象时,C#程序始终会崩溃

如何从C#.net客户端列出Linux运行进程?

与本地Windows服务进行通信的“正确”方式

仅在Linux Core上运行时存储错误

Windows性能计数器从PerfMon中消失

我基本上是从同一主题的MSDN博客文章中剥离代码,而GetSecurityDescriptor使用类似的调用给出了所需的结果:

$output = Invoke-WmiMethod -Path "__systemsecurity=@" -Name GetSecurityDescriptor

SetSecurityDescriptor不断抛出exception。 我如何得到它的工作?

上下文中的代码,供参考:

# connect to SystemSecurity $invokeparams = @{Path="__systemsecurity=@"} # get SecurityDescriptor with ACL $output = Invoke-WmiMethod @invokeparams -Name GetSecurityDescriptor if ($output.ReturnValue -ne 0) { throw "GetSecurityDescriptor Failed: $($output.ReturnValue)" } # ACL object reference is in the .Descriptor property $acl = $output.Descriptor $ace = (New-Object System.Management.ManagementClass("win32_Ace")).CreateInstance() # AccessMask is WBEM_ENABLE,$WBEM_METHOD_EXECUTE,$WBEM_WRITE_PROVIDER,$WBEM_REMOTE_ACCESS $ace.AccessMask = 1 + 2 + 0x10 + 0x20 # AceFlags are $OBJECT_INHERIT_ACE_FLAG,$CONTAINER_INHERIT_ACE_FLAG $ace.AceFlags = 0x01 + 0x2 # AceType is ACCESS_ALLOWED_ACE_TYPE $ace.AceType = 0x1 # get user SID $getparams = @{Class="Win32_Account";Filter="Domain='MYDOMAIN' and Name='SERVER$'"} $win32account = Get-WmiObject @getparams # and build a new Trustee object $trustee = (New-Object System.Management.ManagementClass("win32_Trustee")).CreateInstance() $trustee.SidString = $win32account.Sid $ace.Trustee = $trustee # Add ACE to ACL $acl.DACL += $ace.psobject.immediateBaSEObject # apply new ACL $setparams = @{Name="SetSecurityDescriptor";ArgumentList=$acl.psobject.immediateBaSEObject} + $invokeParams $output = Invoke-WmiMethod @setparams if ($output.ReturnValue -ne 0) { throw "SetSecurityDescriptor Failed: $($output.ReturnValue)" }

我也已经尝试过使用.AceFlags属性,正如Steve Lee上述博客文章评论中所build议的那样 – 都是徒劳的。

.NET的SuppressKeypress如何/为什么工作?

问题与WPF C#应用程序产生两个主要的Windows

使用System.Net.WebSockets处理多个子协议

绕过Windows兼容性链接目录

如何在不创build窗口的情况下将WPF UserControl呈现给位图

在这文章中,你指的是调用是不同的,这些差异可能是重要的 – 参数是一个单一的哈希表,建立起来包括所有的参数作为名称/值对:

$invokeparams = @{Namespace=$namespace;Path="__systemsecurity=@"} $setparams = @{Name="SetSecurityDescriptor";ArgumentList=$acl.psobject.immediateBaSEObject} + $invokeParams $output = Invoke-WmiMethod @setparams

我通过改变这一行来得到这个工作

# AceFlags are $OBJECT_INHERIT_ACE_FLAG,$CONTAINER_INHERIT_ACE_FLAG $ace.AceFlags = 0x01 + 0x2

# AceFlags are $CONTAINER_INHERIT_ACE_FLAG $ace.AceFlags = 0x2

我希望我能告诉你为什么这个改变是必要的,但我不知道。 我也改变了invokeparams等于@ {Path =“__ systemsecurity = @”; Namespace =“root”},以便脚本在根级别而不是cimv2级别设置权限。 许可似乎是按预期继承的。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐