【问题标题】:wmi SetSecurityDescriptorwmi 设置安全描述符
【发布时间】:2017-05-04 15:28:39
【问题描述】:

尝试通过 wmi 使用 sddl 授予对 systemroot 的访问权限,但出现参数无效的错误。 这是我的功能:

function GrantSysRoot
{
    Param (
        [string]$strcomputer
    )  
    $sec =  Get-WmiObject -Class Win32_LogicalFileSecuritySetting -Filter "Path='C:\\Windows'" -ComputerName $strcomputer
    $converter = New-Object System.Management.ManagementClass Win32_SecurityDescriptorHelper
    $sddl = $converter.Win32SDToSDDL($sec.GetSecurityDescriptor().Descriptor)
    $newSDDL = $sddl.SDDL += "(" + $SRSDDL + ")"
    $Win32descriptor = $converter.SDDLToWin32SD($newSDDL)
    $result = $sec.SetSecurityDescriptor($Win32descriptor)

    if ($result.ReturnValue -eq 0) {
        LogWrite "Success SystemRoot setting rights"
    } 
    else {
        LogWrite "An error occured with SystemRoot rights settings"
    }
}

SetSecurityDescriptor 方法返回无效参数错误。有什么想法吗?

【问题讨论】:

  • 什么是$SRSDDL?它只在您的代码中提到过一次,从未定义过......
  • $SRSDDL 定义为简单的 sddl,例如 (A;;0x1200a9;;;$sid)。
  • 请将其放在您的代码示例中,与您脚本中的位置相同。

标签: powershell security wmi access-rights


【解决方案1】:

已解决,我们必须使用属性“描述符”

$result = $sec.SetSecurityDescriptor($Win32descriptor.Descriptor)

【讨论】:

    【解决方案2】:

    我认为你犯了一个小错误。在您的代码中,我看不到使用 $SRSDDL 定义的任何内容,但您正在附加数据并存储在 $newSDDL 中。请您重新验证一下。

    function GrantSysRoot
    {
    Param (
    [string]$strcomputer
     )  
     $sec =  Get-WmiObject -Class Win32_LogicalFileSecuritySetting -Filter "Path='C:\\Windows'" -ComputerName $strcomputer
     $converter = new-object system.management.ManagementClass Win32_SecurityDescriptorHelper
     $sddl = $converter.Win32SDToSDDL($sec.GetSecurityDescriptor().Descriptor)
     $newSDDL = $sddl.SDDL += "(" + $SDDL + ")"
     $Win32descriptor = $converter.SDDLToWin32SD($newSDDL)
     $result = $sec.SetSecurityDescriptor($Win32descriptor)
     if ($result.ReturnValue -eq 0){LogWrite "Success SystemRoot setting rights"
        } else {LogWrite "An error occured with SystemRoot rights settings"}
    

    【讨论】:

    • $SRSDDL 定义为“A;;0x1200a9;;;$sid”
    • 好的。在选择 win32SDToSDDL 之后,您也可以分享 $sddl 的示例输出吗?
    • ReturnValue : 0 SDDL : O:S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464G:S-1-5-80-956008885-3418522649-1831 2271478464D:PAI(A;;FA;;;S-1-5-80-956008885-3418522649-1831038044-1853292631-227147 8464)(A;CIIO;GA;;;S-1-5-80-956008885-3418522649 -1831038044-1853292631-2271478464)(A;;0x1301bf;;;SY)(A;OICIIO;GA;;;SY)(A;;0x1301bf;;;BA)(A;OICIIO;GA;;;BA)( A;;0x1200a9;;;BU)(A;OICIIO;GXGR;;;BU)(A;OICIIO ;GA;;;CO)'
    • @altynos:很高兴为您提供帮助。那么请接受答案:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-04-20
    • 1970-01-01
    • 2011-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多