ARTICLE DETAIL

资讯详情

深耕网站建设与运营推广的一线实战洞察。

PowerSploit 域信息收集:Get-DomainGPOComputerLocalGroupMapping 详解——通过 GPO 关联推算计算机本地组成员

PowerSploit 域信息收集:Get-DomainGPOComputerLocalGroupMapping 详解——通过 GPO 关联推算计算机本地组成员 PowerSploit 域信息收集Get-DomainGPOComputerLocalGroupMapping 详解——通过 GPO 关联推算计算机本地组成员【免费下载链接】PowerSploitPowerSploit - A PowerShell Post-Exploitation Framework项目地址: https://gitcode.com/gh_mirrors/po/PowerSploit导读Get-DomainGPOComputerLocalGroupMapping是 PowerSploit 的 Recon 模块PowerView中用于反向 GPO 关联的侦察函数给定一台计算机或一个 OU它通过解析该计算机所属 OU、站点上链接的组策略对象GPO中的本地组成员配置推断出哪些域用户/域组拥有这台机器指定本地组如 Administrators、Remote Desktop Users的成员资格。读完本文你将掌握该函数在 Active Directory 内网信息收集中的定位、两种参数集ComputerIdentity / OUIdentity的完整用法、全部参数语义以及其从 LDAP 查询到 GptTmpl.inf / Groups.xml 解析的底层调用链能够直接用它在渗透测试与安全审计中定位通过 GPO 下发本地管理员 / RDP 权限的高价值目标。函数定位与 Get-DomainGPOUserLocalGroupMapping 互为逆操作在 PowerView 的 GPO 关联侦察体系中存在一对互补函数Get-DomainGPOUserLocalGroupMapping给定用户/组枚举哪些机器上该主体拥有指定本地组权限Get-DomainGPOComputerLocalGroupMapping给定计算机反推哪些用户/组在该机器的指定本地组中。从源码注释Recon/PowerView.ps1可以明确看到作者的定位描述This function is the inverse of Get-DomainGPOUserLocalGroupMapping。在 Recon/README.md 中前者被概括为enumerates the machines where a specific domain user/group is a member of a specific local group, all through GPO correlation二者共同覆盖了 GPO 本地组成员关系的双向枚举。在 PowerView 中该函数还常与Find-GPOLocation别名指向Get-DomainGPOUserLocalGroupMapping配合使用形成先找人有权限的机器再查机器上谁有权限的完整权限面测绘闭环。模块导出清单见 Recon/Recon.psd1函数作者为 harmj0y遵循 BSD 3-Clause 许可。函数语法与参数集源码Recon/PowerView.ps1声明了[CmdletBinding(DefaultParameterSetName ComputerIdentity)]即默认参数集为 ComputerIdentity包含两套互斥参数### ComputerIdentity默认参数集 Get-DomainGPOComputerLocalGroupMapping [-ComputerIdentity] String [-LocalGroup String] [-Domain String] [-SearchBase String] [-Server String] [-SearchScope String] [-ResultPageSize Int32] [-ServerTimeLimit Int32] [-Tombstone] [-Credential PSCredential] ### OUIdentity Get-DomainGPOComputerLocalGroupMapping -OUIdentity String [-LocalGroup String] [-Domain String] [-SearchBase String] [-Server String] [-SearchScope String] [-ResultPageSize Int32] [-ServerTimeLimit Int32] [-Tombstone] [-Credential PSCredential]两个参数集共享全部可选参数区别仅在于定位作用域的方式-ComputerIdentity按计算机身份定位默认位置参数支持管道输入-OUIdentity按 OU 身份定位命名参数不接受管道输入。参数详解继承自原文档并补充源码约束-ComputerIdentity指定要查询 GPO 本地组映射的计算机支持四种身份格式SamAccountName如WINDOWS10$DistinguishedName如CNWINDOWS10,CNComputers,DCtestlab,DClocalSID如S-1-5-21-890171859-3433809279-3366196753-1124GUID如4f16b6bc-7010-4cbf-b628-f3cfe20f6994DNS 主机名如windows10.testlab.local。Type: String Parameter Sets: ComputerIdentity Aliases: ComputerName, Computer, DistinguishedName, SamAccountName, Name Required: True Position: 1 Default value: None Accept pipeline input: True (ByPropertyName, ByValue) Accept wildcard characters: False注意源码中该参数还定义了ValueFromPipeline $True与ValueFromPipelineByPropertyName $True因此你可以把Get-DomainComputer的输出直接管道进来。若指定身份在域中找不到对应计算机对象函数会抛出异常[Get-DomainGPOComputerLocalGroupMapping] Computer Identity not found. Try a fully qualified host name.Recon/PowerView.ps1提示使用完全限定域名。-OUIdentity指定要查询的 OU支持 OU 名如TestOU、DistinguishedName如OUTestOU,DCtestlab,DClocal或 GUID如8a9ba22a-8977-47e6-84ce-8c26af4e1e6a。Type: String Parameter Sets: OUIdentity Aliases: OU Required: True Position: Named Default value: None Accept pipeline input: False Accept wildcard characters: False当使用-OUIdentity时函数会针对该 OU 的 gplink 枚举其链接的所有 GPO 并解析本地组配置适合在尚未确定具体主机、但已知某 OU 下发的策略时批量测绘。-LocalGroup要检查的本地组合法取值由源码中的[ValidateSet(Administrators, S-1-5-32-544, RDP, Remote Desktop Users, S-1-5-32-555)]约束Recon/PowerView.ps1取值含义对应 SIDAdministrators默认本地管理员组S-1-5-32-544S-1-5-32-544本地管理员组SID 形式S-1-5-32-544RDP远程桌面用户组S-1-5-32-555Remote Desktop Users远程桌面用户组全称S-1-5-32-555S-1-5-32-555远程桌面用户组SID 形式S-1-5-32-555Type: String Parameter Sets: (All) Required: False Position: Named Default value: Administrators Accept pipeline input: False Accept wildcard characters: False原文档提到或自定义本地 SID——如果 GPO 中配置的是其他本地组在Get-DomainGPOLocalGroup解析层仍可处理但传入本函数的取值受 ValidateSet 限制请以实际测试环境为准。-Domain指定要枚举 GPO 的域默认使用当前域。[ValidateNotNullOrEmpty()]约束不允许为空字符串。Type: String Parameter Sets: (All) Required: False Position: Named Default value: None Accept pipeline input: False Accept wildcard characters: False-SearchBase指定 LDAP 搜索基ADSPath 别名源码中与-Server、-SearchScope等一起作为公共参数透传给下游的Get-DomainComputer、Get-DomainOU、Get-DomainSite等依赖函数见 BEGIN 块中的$CommonArguments组装逻辑Recon/PowerView.ps1。Type: String Parameter Sets: (All) Aliases: ADSPath Required: False Position: Named Default value: None Accept pipeline input: False Accept wildcard characters: False-Server指定要绑定的 Active Directory 服务器域控制器别名DomainController。Type: String Parameter Sets: (All) Aliases: DomainController Required: False Position: Named Default value: None Accept pipeline input: False Accept wildcard characters: False-SearchScope指定搜索范围[ValidateSet(Base, OneLevel, Subtree)]限定默认Subtree。Type: String Parameter Sets: (All) Required: False Position: Named Default value: Subtree Accept pipeline input: False Accept wildcard characters: False-ResultPageSize设置 LDAP 搜索器对象的 PageSize源码约束[ValidateRange(1, 10000)]默认 200。该值直接影响大域环境下单次 LDAP 分页返回的记录条数。Type: Int32 Parameter Sets: (All) Required: False Position: Named Default value: 200 Accept pipeline input: False Accept wildcard characters: False-ServerTimeLimit指定服务器端搜索的最大耗时秒。原文档注释写默认 120 秒但参数默认值实际为 0源码中$ServerTimeLimit未赋初值见 Recon/PowerView.ps1取值范围[ValidateRange(1, 10000)]。传 0 时表示不额外设置服务端时间上限实际超时行为取决于 LDAP 服务器默认策略。Type: Int32 Parameter Sets: (All) Required: False Position: Named Default value: 0 Accept pipeline input: False Accept wildcard characters: False-Tombstone开关参数指定搜索器同时返回已删除tombstoned的对象默认False。开启后需要具备相应权限才能读取回收站对象。Type: SwitchParameter Parameter Sets: (All) Required: False Position: Named Default value: False Accept pipeline input: False Accept wildcard characters: False-Credential指定连接目标域所用的备用凭据类型为[Management.Automation.PSCredential]带CredentialAttribute()默认值为[Management.Automation.PSCredential]::Empty即使用当前会话身份。配合ConvertTo-SecureString构造明文密码的用法见下文示例 3。Type: PSCredential Parameter Sets: (All) Required: False Position: Named Default value: [Management.Automation.PSCredential]::Empty Accept pipeline input: False Accept wildcard characters: False工作原理从计算机身份到 GPO 成员的五步调用链根据源码 PROCESS 块Recon/PowerView.ps1和文档 DESCRIPTION整个流程可拆解为以下阶段解析计算机对象通过Get-DomainComputer CommonArguments -Identity $ComputerIdentity -Properties distinguishedname,dnshostname获取计算机的 DN 与 DNS 主机名只请求两个必要属性以减小 LDAP 结果集。从 DN 提取 OU 并枚举 GPO取distinguishedname中首个OU之后的部分作为 OU 路径用Get-DomainOU -SearchBase $OUName -LDAPFilter (gplink*)查询所有带 gplink 的 OU再用正则(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-...(\}){0,1}从 gplink 属性中抽取所有 GPO GUIDRecon/PowerView.ps1。解析站点并枚举站点级 GPO调用Get-NetComputerSiteName -ComputerName $Computer.dnshostname获取计算机所在 AD 站点站点解析失败结果匹配Error时跳过成功后用Get-DomainSite -Identity $ComputerSite -LDAPFilter (gplink*)同样抽取站点链接的 GPO GUIDRecon/PowerView.ps1。解析 GPO 本地组设置将 OU 级与站点级 GPO GUID 合并后管道给Get-DomainGPOLocalGroup并按GPOName去重排序。Get-DomainGPOLocalGroupRecon/PowerView.ps1内部对每个 GPO 尝试解析两条策略载体受限组Restricted GroupsGPO 的 SYSVOL 路径下MACHINE\Microsoft\Windows NT\SecEdit\GptTmpl.inf由Get-GptTmpl解析取Group Membership节组策略首选项GPPMACHINE\Preferences\Groups\Groups.xml由Get-GroupsXML解析。对于受限组中的组名字段Get-DomainGPOLocalGroup会尝试映射内置 SIDAdministrators→S-1-5-32-544、Remote Desktop→S-1-5-32-555、Guests→S-1-5-32-546其余通过ConvertTo-SID解析为域 SID成员字段则按需通过ConvertTo-SID解析Recon/PowerView.ps1。成员反查与结果组装对每条 GPO 组成员记录优先取GroupMembers否则取GroupSID逐个调用Get-DomainObject反查完整 AD 对象通过samaccounttype是否命中268435456 / 268435457 / 536870912 / 536870913判断对象是否为组最后组装输出对象Recon/PowerView.ps1。输出对象PowerView.GPOComputerLocalGroupMember原文档 OUTPUTS 声明为PowerView.GGPOComputerLocalGroupMember文档中的笔误而源码实际构造时写入的类型名为PowerView.GPOComputerLocalGroupMemberRecon/PowerView.ps1函数声明处的[OutputType(PowerView.GGPOComputerLocalGroupMember)]同样存在双 G 笔误。以源码实际对象为准每个结果包含以下属性属性含义ComputerName计算机的 DNS 主机名dnshostnameObjectName域对象用户/组的 samAccountNameObjectDN域对象的 DistinguishedNameObjectSID域对象的 SID来自 GPO 配置的成员 SIDIsGroup布尔值表示该成员是否为组依据 samaccounttype 判定GPODisplayNameGPO 的显示名称GPOGuidGPO 的 GUID即 GPONameGPOPathGPO 的 SYSVOL 文件系统路径gpcfilesyspathGPOType策略载体类型RestrictedGroups或GroupPolicyPreferences实战示例示例 1查找 WINDOWS3 的本地管理员默认行为Get-DomainGPOComputerLocalGroupMapping -ComputerName WINDOWS3.testlab.local未指定-LocalGroup时默认检查AdministratorsS-1-5-32-544返回通过 GPO 关联获得的、对 WINDOWS3 拥有本地管理员权限的用户/组。示例 2跨域查找 WINDOWS4 的 RDP 权限Get-DomainGPOComputerLocalGroupMapping -Domain dev.testlab.local -ComputerName WINDOWS4.dev.testlab.local -LocalGroup RDP指定dev.testlab.local域并改用RDPS-1-5-32-555本地组找出通过 GPO 获得 WINDOWS4 远程桌面权限的域对象。示例 3使用备用凭据$SecPassword ConvertTo-SecureString Password123! -AsPlainText -Force $Cred New-Object System.Management.Automation.PSCredential(TESTLAB\dfm.a, $SecPassword) Get-DomainGPOComputerLocalGroupMapping -Credential $Cred -ComputerIdentity SQL.testlab.local先用ConvertTo-SecureString将明文口令转为 SecureString再构造PSCredential传入-Credential以TESTLAB\dfm.a身份查询 SQL.testlab.local 的本地管理员 GPO 映射。示例 4与 Get-DomainComputer 管道配合源码支持Get-DomainComputer -Identity WINDOWS10$ | Get-DomainGPOComputerLocalGroupMapping -LocalGroup Remote Desktop Users由于-ComputerIdentity支持ValueFromPipeline与ValueFromPipelineByPropertyName可以直接将计算机对象管道输入批量审计多台主机的 RDP 权限来源。依赖与使用前提函数声明的 Required Dependencies 为Get-DomainComputer、Get-DomainOU、Get-NetComputerSiteName、Get-DomainSite、Get-DomainGPOLocalGroup实际执行时还间接依赖Get-DomainObject、Get-DomainGPO、Get-GptTmpl、Get-GroupsXML、ConvertTo-SID、ConvertFrom-SID。这些依赖全部位于 Recon/PowerView.ps1 单文件内导入 PowerView 即全部可用。适用前提与限制以当前仓库代码为准需要能解析目标计算机的站点名依赖Get-NetComputerSiteName底层调用计算机名解析目标主机的 DNS 记录需可解析GPO 仅能解析两类本地组配置载体GptTmpl.inf受限组与Groups.xmlGPP其他 GPO 设置如脚本、注册表策略不参与本地组成员判断结果的完备性取决于目标 OU/站点上 GPO 的实际链接情况GPO 继承、阻断Block Inheritance与强制Enforced链接会对实际生效策略产生影响本函数不做继承链模拟只做链接即候选的静态关联该函数属于内网后渗透Post-Exploitation侦察工具仅应在已获授权的测试环境中使用。如需反向查询指定用户/组找机器可参考姊妹函数文档 Get-DomainGPOUserLocalGroupMappingPowerView 的其余域信息收集能力域用户、域组、ACL、Kerberoast 等可查阅 Recon 模块文档目录 及 Recon/README.md模块测试用例位于 Tests/Recon.tests.ps1。【免费下载链接】PowerSploitPowerSploit - A PowerShell Post-Exploitation Framework项目地址: https://gitcode.com/gh_mirrors/po/PowerSploit创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表