【问题标题】:Change DCOM config security settings using Powershell使用 Powershell 更改 DCOM 配置安全设置
【发布时间】:2012-07-06 23:30:52
【问题描述】:

我的任务是编写 Powershell 脚本以从头开始设置服务器以将我们的一项服务作为 Web 应用程序的一部分运行,设置此服务器所需的步骤之一是更改 DCOM 配置安装的服务,特别是将帐户添加到“启动和激活”/“访问”权限,并在添加这些帐户后设置这些帐户的权限。

有没有使用 Powershell 的方法?我还没有找到一种具体的方法来实现我的目标,所以任何帮助都会很棒

【问题讨论】:

    标签: powershell dcom


    【解决方案1】:

    看起来你会使用 WMI 来做。

    像这样获取Win32_DCOMApplicationSetting的实例:

    $dcom = Get-WMIObject -Class Win32_DCOMApplicationSetting -Filter 'Description="Something"'
    

    现在您可以访问SetAccessSecurityDescriptorSetLaunchSecurityDescriptor 方法。

    发件人:http://msdn.microsoft.com/en-us/library/windows/desktop/aa384905(v=vs.85).aspx

    DCOM 应用程序

    DCOM 应用程序实例有几个安全描述符。开始 对于 Windows Vista,使用 Win32_DCOMApplicationSetting 的方法 类来获取或更改各种安全描述符。安全 描述符作为 Win32_SecurityDescriptor 的实例返回 类。

    要获取或更改配置权限,请调用 GetConfigurationSecurityDescriptor 或 SetConfigurationSecurityDescriptor 方法。

    要获取或更改访问权限,请调用 GetAccessSecurityDescriptor 或 SetAccessSecurityDescriptor 方法。

    要获取或更改启动和激活权限,请调用 GetLaunchSecurityDescriptor 或 SetLaunchSecurityDescriptor 方法。

    Windows Server 2003、Windows XP、Windows 2000、Windows NT 4.0 和 Windows Me/98/95:Win32_DCOMApplicationSetting 安全性 描述符方法不可用。

    还有一个名为 DCOMPERM 的工具,其中的源代码在 Windows SDK 中可用:http://www.microsoft.com/en-us/download/details.aspx?id=8279

    如果你搜索 DCOMPERM 编译,你可以在网上找到编译版本。

    以下是命令行选项:

    Syntax: dcomperm <option> [...] 
    Options:
    
    Modify or list the machine access permission list 
    -ma <"set" or "remove"> <Principal Name> ["permit" or "deny"] ["level:l,r"] 
    -ma list
    
    Modify or list the machine launch permission list 
    -ml <"set" or "remove"> <Principal Name> ["permit" or "deny"] ["level:l,r,ll,la,rl,ra"] 
    -ml list
    
    Modify or list the default access permission list 
    -da <"set" or "remove"> <Principal Name> ["permit" or "deny"] ["level:l,r"] 
    -da list
    
    Modify or list the default launch permission list 
    -dl <"set" or "remove"> <Principal Name> ["permit" or "deny"] ["level:l,r,ll,la,rl,ra"] 
    -dl list
    
    Modify or list the access permission list for a specific AppID 
    -aa <AppID> <"set" or "remove"> <Principal Name> ["permit" or "deny"] ["level:l,r"] 
    -aa <AppID> default 
    -aa <AppID> list
    
    Modify or list the launch permission list for a specific AppID 
    -al <AppID> <"set" or "remove"> <Principal Name> ["permit" or "deny"] ["level:l,r,ll,la,rl,ra"] 
    -al <AppID> default 
    -al <AppID> list
    
    level: 
        ll - local launch (only applies to {ml, dl, al} options) 
        rl - remote launch (only applies to {ml, dl, al} options) 
        la - local activate (only applies to {ml, dl, al} options) 
        ra - remote activate (only applies to {ml, dl, al} options) 
        l - local (local access - means launch and activate when used with {ml, dl, al} options) 
        r - remote (remote access - means launch and activate when used with {ml, dl, al} options)
    

    【讨论】:

    • 谢谢安迪,这帮了大忙!最后我混合使用了这两种方法。我使用 Win32_DCOMApplicationSetting 来获取应用程序 ID,然后使用 DComPerm 添加所需的权限。我发现有点奇怪的是,CMD 运行 DcomPerm 的问题比 Powershell 少得多,所以为了实现我所需要的,我编写了一个批处理文件,其中传入了某些变量,并从 Powershell 调用它。
    • @Vermin 我的猜测是您使用 PowerShell 遇到的问题可能与语法/命令行解析有关。也许发布你得到的错误?
    【解决方案2】:

    我和 OP 有同样的问题。安迪发布的答案非常有帮助,让我半途而废。然后我找到了某人写的Set-DCOMLaunchPermissions 来帮助他们部署SharePoint。

    我根据自己的目的调整了它们的功能,并提出了一个设置我需要的权限的解决方案。

    $user = "sql2012agent"
    $domain = "MYDOMAIN"
    $appdesc = "Microsoft SQL Server Integration Services 11.0"
    $app = get-wmiobject -query ('SELECT * FROM Win32_DCOMApplicationSetting WHERE Description = "' + $appdesc + '"') -enableallprivileges
    #$appid = "{83B33982-693D-4824-B42E-7196AE61BB05}"
    #$app = get-wmiobject -query ('SELECT * FROM Win32_DCOMApplicationSetting WHERE AppId = "' + $appid + '"') -enableallprivileges
    $sdRes = $app.GetLaunchSecurityDescriptor()
    $sd = $sdRes.Descriptor
    $trustee = ([wmiclass] 'Win32_Trustee').CreateInstance()
    $trustee.Domain = $domain
    $trustee.Name = $user
    $fullControl = 31
    $localLaunchActivate = 11
    $ace = ([wmiclass] 'Win32_ACE').CreateInstance()
    $ace.AccessMask = $localLaunchActivate
    $ace.AceFlags = 0
    $ace.AceType = 0
    $ace.Trustee = $trustee
    [System.Management.ManagementBaseObject[]] $newDACL = $sd.DACL + @($ace)
    $sd.DACL = $newDACL
    $app.SetLaunchSecurityDescriptor($sd)
    

    【讨论】:

    • 我正在尝试使用上面@Elijah W. Gagne 发布的 PS 脚本来配置 DCOM,并收到错误“在此对象上找不到属性 'DACL'。验证该属性存在并且可以设置。”错误是针对“$sd.DACL = $newDACL”行。我不是很精通PS的使用。谁能告诉我我需要做什么才能完成这项工作。非常感谢!
    • 我会一直运行到第 4 行。然后输出 $app 变量并确认它不为空(null)。如果是这样,您可能需要调整第 4 行中的 WHERE 子句。
    • 是的,我必须更改我的,因为我使用的是 12.0 版而不是 11.0 版,我发现 $app 为空。但是在将 $appdesc 更改为适合我之后,该脚本很有魅力。
    • 只有在我已经加载了组件服务 - DCOM 配置管理单元时才能进行这项工作。有没有办法以编程方式做到这一点?
    • 不要忘记在 Get-WMIObject 调用中使用 -EnableAllPrivileges 开关,否则安全描述符将为空(这可能是您收到无法找到 DACL 错误的原因)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-13
    • 1970-01-01
    • 2018-01-08
    相关资源
    最近更新 更多