Learning Man's Blog

Active Directory Recon 初步学习

字数统计: 2.9k阅读时长: 12 min
2019/06/15

0x00 Tools

0x01 用户组成员

常见的 SID 列表:well-known-security-identifiers-in-windows-operating-systems

具有默认权限提升的用户组成员:

Default Security Group SID/RID Windows Server 2012 R2 Windows Server 2012 Windows Server 2008 R2 Windows Server 2008
Account Operators S-1-5-32-548 Yes Yes Yes Yes
Administrators S-1-5-32-544 Yes Yes Yes Yes
Allowed RODC Password Replication Group S-1-5-21-<domain>-571 Yes Yes Yes Yes
Backup Operators S-1-5-32-551 Yes Yes Yes Yes
Certificate Service DCOM Access S-1-5-32-<domain>-574 Yes Yes Yes Yes
Cert Publishers S-1-5-<domain>-517 Yes Yes Yes Yes
Distributed COM Users S-1-5-32-562 Yes Yes Yes Yes
DnsAdmins S-1-5-21-<domain>-1102 Yes Yes Yes Yes
Domain Admins S-1-5-<domain>-512 Yes Yes Yes Yes
Enterprise Admins S-1-5-21-<root_domain>-519 Yes Yes Yes Yes
Event Log Readers S-1-5-32-573 Yes Yes Yes Yes
Group Policy Creators Owners S-1-5-<domain>-520 Yes Yes Yes Yes
Hyper-V Administrators S-1-5-32-578 Yes Yes
Pre–Windows 2000 Compatible Access S-1-5-32-554 Yes Yes Yes Yes
Print Operators S-1-5-32-550 Yes Yes Yes Yes
Protected Users S-1-5-21-<domain>-525 Yes
Remote Desktop Users S-1-5-32-555 Yes Yes Yes Yes
Schema Admins S-1-5--518 Yes Yes Yes Yes
Server Operators S-1-5-32-549 Yes Yes Yes Yes
WinRMRemoteWMIUsers_ S-1-5-21-<domain>-1000 Yes Yes

0x02 Active Directory Groups with Privileged Rights on Computers

大多数组织使用组策略将 Active Directory 组添加到计算机上的本地组中(通常为管理员组)

使用PowerView,我们可以轻松发现在工作站和服务器上具有管理权限的AD组(这是非常典型的用例)

GPO: “Add Server Admins to Local Administrator Group”
Local Group: Administrators
AD Group: Server Admins (SID is shown in the example)

-w694

GPO: “Add Workstation Admins to Local Administrator Group”
Local Group: Administrators
AD Group: Workstation Admins (SID is shown in the example)

-w736

0x03 ACLs

与文件系统相似,Active Directory objects 也具有权限系统

这些权限被称为 Access Control Lists (ACLs),通过一种名为 Security Descriptor Definition Language (SDDL) 隐晦的格式设置对象的权限

SDDL 在 DACL 和 SACL 中使用 ACE 链表作为安全描述符字符串的一部分

D:PAI(D;OICI;FA;;;BG)(A;OICI;FA;;;BA)(A;OICIIO;FA;;;CO)(A;OICI;FA;;;SY)(A;OICI;FA;;;BU)

每条 ACE 对应的语法

ace_type;ace_flags;rights;object_guid;inherit_object_guid;account_sid;(resource_attribute)

具体的各个参数值可在通过此页面查询,在页面最下方官方也给出一些简单的例子方便理解

AdminSDHolder

在 AD ACLs 中,有一个被系统容器成为AdminSDHolder的对象,它的存在只有一个目的:成为域中具有高级权限的对象(及其成员)的权限模板对象

Security Descriptor propagator (SDProp)

SDProp Protected Objects (Windows Server 2008 & Windows Server 2008 R2):

  • Account Operators
  • Administrator
  • Administrators
  • Backup Operators
  • Domain Admins
  • Domain Controllers
  • Enterprise Admins
  • Krbtgt
  • Print Operators
  • Read-only Domain Controllers
  • Replicator
  • Schema Admins
  • Server Operators

每隔 60 分钟,PDC模拟器会运行一个进程来列举这些受保护的对象及其成员,并标记在AdminSDHolder中配置的权限(并将 admin 属性设置为 1),由此来确保特权用户组、账号得到保护


保持 AD 对象的自定义权限是非常困难的,以下就是一个例子

-w1280

这个 OU 委托中存在一个很严重的问题,具有完全控制权限的 Domain Computers 被授权给了此 OU 所有的对象及继承它的对象

-w1356


攻击者对以下 ACLs 中提供特权操作的权限最感兴趣:

  • Replicating Directory Changes All
  • Replicating Directory Changes (DS-Replication-Get-Changes)
  • GenericAll: GenericAll = Full Control
  • GenericWrite: Provides write access to all properties.
  • WriteDACL: Provides the ability to modify security on an object which can lead to Full Control of the object.
  • Self: Provides the ability to perform validated writes.
  • WriteOwner:: Provides the ability to take ownership of an object. The owner of an object can gain full control rights on the object.
  • WriteProperty: Typically paired with specific attribute/property information.
  • CreateChild: Provides the ability to create an object of a specified type (or “All”).
  • DeleteChild: Provides the ability to delete an object of a specified type (or “All”).
  • Extended Right: This is an interesting one because if provides additional rights beyond the obvious.

SID History

简单地说,SID历史记录用于确保账户在从两个域A、B中迁移时,在 SID 改变后,通过将旧的 SID 映射到新的 SID 后,保证账户仍能在迁出的域A中继续访问

SID History Injection

注意,SID 历史在同一个域中的作用与 SID 同一个林的跨多个域中是相同的,这意味着 DomainA 中的常规用户可以包含 DomainA SIDs,如果其中 SID 用于特权账户或组,那么一个常规用户就可以拥有域管理员权限而不需要成为该域管理员组的成员


案例:劫权五分钟

Mimikatz 提供将 SID History 注入任意用户账户(需要 Domain Admin 或者等效的权限),如下中,攻击者创建一个用户账户bobafett,并将域中默认管理账户ADSAdministrator(RID 500)注入到账户 SID History属性中

SID: S-1-5-21-domain-500
Name: Administrator
Description: A user account for the system administrator. By default, it is the only user account that is given full control over the system.

-w495

当用户bobafett登录时,所有与之相关的 SID 都会被添加到用户 token 中,用于确定对资源的访问权限

这些 SIDs 包括

  • 用户 SID
  • 用户所在组 SID
  • SID 历史记录中的 SID

通过命令Get-ADUser可以看到虽然账户bobafett在 SIDHistory 中已经拥有了ADSAdministrator 账户 SID,但是在 MemberOf 却没有任何组成员身份

-w387

快速攻击

检测 SID 历史记录账户用于提权的最佳方法是枚举所有具有 SID 历史记录属性的用户的数据,并标记包含同一个域中的 SID 的账户

#Detect Same Domain SID History
> Import-Module ActiveDirectory
[string]$DomainSID = ((Get-ADDomain).DomainSID.Value)

> Get-ADUser -Filter SIDHistory -Like "*" -Properties SIDHistory | `
Where { $_.SIDHistory -Like "$DomainSID-*" }

*注意:在具有多个域的林中,建议在林中的每个域以及每个受信任的域或林中查找管理组 SID(和成员账户 SID)

攻击快速检测

Configure sub-category auditing under Account Management, “Audit User Account Management” (success) on Domain Controllers for the following event ids:

  • 4765 将 SID 历史记录添加到一个账户中
  • 4766 尝试将 SID 历史记录添加到账户的失败事件

Group Policy Permissions

组策略权限用于在在Active Directory中创建,配置和链接组策略对象(GPO)。将GPO链接到OU时,GPO中的设置将应用于该OU中的相应对象(用户/计算机)

如果在链接到该域的组策略上配置了自定义权限,并且攻击者获得对具有修改访问权限的帐户的访问权限,则该域可能会被入侵

PowerView 提供一种快速扫描所有域的 GPO 权限的方法

> Get-NetGPO | %{Get-ObjectAcl -ResolveGUIDs -Name $_.Name}

Abusing GPO Permissions

内容学习中,待丰富…

http://www.harmj0y.net/blog/redteaming/abusing-gpo-permissions/

User Rights Assignment

用户权限分配经常在计算机 GPO 中进行配置,并且定义了计算机的几个权限

域控制器通常被用于在应用于域控制器容器中的默认域控制器策略中进行用户权限分配,分析与域控制器链接的GPO,可以提供DC和域被提升权限的安全主体的有关的有用信息

  • SeTrustedCredManAccessPrivilege:访问凭据管理器作为受信任的呼叫者
  • SeNetworkLogonRight:从网络访问此计算机
  • SeTcbPrivilege:作为操作系统的一部分
  • SeMachineAccountPrivilege:将工作站添加到域
  • SeIncreaseQuotaPrivilege:调整进程的内存配额
  • SeInteractiveLogonRight:允许本地登录
  • SeRemoteInteractiveLogonRight:允许通过远程桌面服务登录
  • SeBackupPrivilege:备份文件和目录
  • SeChangeNotifyPrivilege:绕过遍历检查
  • SeSystemtimePrivilege:更改系统时间
  • SeTimeZonePrivilege:更改时区
  • SeCreatePagefilePrivilege:创建页面文件
  • SeCreateTokenPrivilege:创建一个令牌对象
  • SeCreateGlobalPrivilege:创建全局对象
  • SeCreatePermanentPrivilege:创建永久共享对象
  • SeCreateSymbolicLinkPrivilege:创建符号链接
  • SeDebugPrivilege:调试程序
  • SeDenyNetworkLogonRight:拒绝从网络访问此计算机
  • SeDenyBatchLogonRight:拒绝作为批处理作业登录
  • SeDenyServiceLogonRight:拒绝作为服务登录
  • SeDenyInteractiveLogonRight:拒绝本地登录
  • SeDenyRemoteInteractiveLogonRight:拒绝通过远程桌面服务登录
  • SeEnableDelegationPrivilege:启用计算机和用户帐户以进行授权
  • SeRemoteShutdownPrivilege:从远程系统强制关闭
  • SeAuditPrivilege:生成安全审核
  • SeImpersonatePrivilege:认证后模拟客户端
  • SeIncreaseWorkingSetPrivilege:增加一个进程工作集
  • SeIncreaseBasePriorityPrivilege:增加调度优先级
  • SeLoadDriverPrivilege:加载和卸载设备驱动程序
  • SeLockMemoryPrivilege:在内存中锁定页面
  • SeBatchLogonRight:作为批处理作业登录
  • SeServiceLogonRight:作为服务登录
  • SeSecurityPrivilege:管理审核和安全日志
  • SeRelabelPrivilege:修改对象标签
  • SeSystemEnvironmentPrivilege:修改固件环境值
  • SeManageVolumePrivilege:执行卷维护任务
  • SeProfileSingleProcessPrivilege:配置文件单进程
  • SeSystemProfilePrivilege:配置文件系统性能
  • SeUndockPrivilege:从工作站中移除电脑
  • SeAssignPrimaryTokenPrivilege:替换进程级令牌
  • SeRestorePrivilege:恢复文件和目录
  • SeShutdownPrivilege:关闭系统
  • SeSyncAgentPrivilege:同步目录服务数据
  • SeTakeOwnershipPrivilege:获取文件或其他对象的所有权

在这里有很多有趣的策略(特别是适用于域控制器的GPO):

  • Allow logon locally & Allow logon over Remote Desktop Services - 允许本地登录并允许登录远程桌面服务:提供登录权限
  • Manage auditing and security log - 管理审核和安全日志:提供查看事件日志中的所有事件(包括安全事件)并清除事件日志的功能
    • 有趣的点:Exchange Server 需要这样的权限,这意味着如果攻击者在Exchange服务器上获得系统权限,则可以清除域控制器上的安全日志
      ↳ CVE-2018-8581:https://www.anquanke.com/post/id/170199
  • Synchronize directory service data - 同步目录服务数据 :”此策略设置确定了哪些用户和组具有同步所有目录服务数据的权限,而不管对象和属性的保护。使用LDAP目录同步(dirsync)服务需要此权限。域控制器本身就具有此用户权限,因为同步过程是在域控制器上的系统帐户的上下文中运行。”
    ↳ 这意味着在域控制器上对此用户的访问权限可能能够运行DCSync
        ↳ 黄金票据:https://www.cnblogs.com/KevinGeorge/p/10463527.html
  • Enable computer and user accounts to be trusted for delegation - 允许计算机和用户帐户被委托进行授权:提供在域中的计算机和用户上配置委派的功能。
    • 有趣的点:这提供了在计算机或用户帐户上设置Kerberos委派的功能。
  • Impersonate a client after authentication - 验证后模仿一个客户端:这个看起来是一些很有趣的东西,它可以…
    ↳ msf 中的 getsystem 原理:https://www.anquanke.com/post/id/87292
  • Take ownership of files or other objects - 取得文件或其他对象的所有权:Administrators 仅有。任意用户拥有此权限后,可忽视任意对象所设置的权限而直接获取其所有权,并可进行任意修改,但可能导致暴露数据、数据报错、拒绝服务
  • Load and Unload Device Drivers - 加载或卸载设备驱动器:”设备驱动程序在高权限运行代码。具有’加载和卸载设备驱动程序’用户权限的用户可能会无意中安装伪装成设备驱动程序的恶意软件。管理员应该小心谨慎,只安装带有经过验证的数字签名的驱动程序。”

检查步骤

  • 枚举默认组(包括子组)的组成员,确定需要什么权限并删除其他不需要的权限
  • 扫描 Active Directory (特别是OU和安全组) 中的自定义委派
  • 扫描具有 SID History 的帐户(仅在从一个域到另一个域的主动迁移期间才会需要)
  • 查看域控制器、服务器和工作站的GPO中的用户权限分配
  • 查看将 AD 组添加到本地组的 GPO,并确保仍然需要这些本地组,并且权限级别是适当的

参考资料

  1. Scanning for Active Directory Privileges & Privileged Accounts : https://adsecurity.org/?p=3658
  2. Sneaky Active Directory Persistence #14: SID History : https://adsecurity.org/?p=1772
CATALOG
  1. 1. 0x00 Tools
  2. 2. 0x01 用户组成员
  3. 3. 0x02 Active Directory Groups with Privileged Rights on Computers
  4. 4. 0x03 ACLs
    1. 4.1. AdminSDHolder
      1. 4.1.1. Security Descriptor propagator (SDProp)
  5. 5. SID History
    1. 5.1. SID History Injection
      1. 5.1.1. 快速攻击
      2. 5.1.2. 攻击快速检测
  6. 6. Group Policy Permissions
    1. 6.1. Abusing GPO Permissions
  7. 7. User Rights Assignment
  8. 8. 检查步骤
  9. 9. 参考资料