Hashcat 是一款密码爆破神器,信息安全必备工具之一,特此收藏此文章记录总结

2024-12-24 17:32:08

Hashcat 是一款密码爆破神器,信息安全必备工具之一,特此收藏此文章记录总结,以备不时之需,同时也可能帮助到看到本本文的网友。

简介

Hashcat 是世界上最快的密码破解程序,是一个支持多平台、多算法的开源的分布式工具。

官方:https://hashcat.net/hashcat/

Github:https://github.com/hashcat/hashcat

安装

Windows

https://github.com/hashcat/hashcat/releases 下载最新版压缩包,解压根据自己的平台运行 hashcat64.exe 或者 hashcat32.exe

常用参数

-m 破解 hash 类型

指定要破解的 hash 类型,后面跟 hash 类型对应的数字

-a 破解模式

指定要使用的破解模式,其值参考后面对参数:

- [ Attack Modes ] -

  # | Mode
 ===+======
  0 | Straight                # 直接字典破解
  1 | Combination             # 组合破解
  3 | Brute-force             # 掩码暴力破解
  6 | Hybrid Wordlist + Mask  # 字典+掩码破解
  7 | Hybrid Mask + Wordlist  # 掩码+字典破解

–increment

启用增量破解模式,让 hashcat 在指定的密码长度范围内执行破解

–increment-min

密码最小长度,后面直接等于一个整数即可,配置 increment 模式一起使用

–increment-max

密码最大长度,后面直接等于一个整数即可,配置 increment 模式一起使用

–force

忽略破解过程中的警告信息

–remove

删除已被破解成功的 hash

–username

忽略 hash 文件中的指定的用户名,在破解 Linux 系统用户密码 hash 会用到

–potfile-disable

不在 potfile 中记录破解成功的 hash

-I

--opencl-info 显示有关检测到的 OpenCL 平台 / 设备的信息,如果有一块好的显卡的话破解速度会快很多。

-o

--outfile 指定破解成功后的 hash 及所对应的明文密码的存放位置

-O

--optimized-kernel-enable 启用优化的内核(限制密码长度)

-d

--opencl-devices 指定 opencl 的设备,我这里支持的设备列表如下:


Code


* Device #1: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz, skipped.
* Device #2: Intel(R) UHD Graphics 630, 384/1536 MB allocatable, 24MCU
* Device #3: AMD Radeon Pro 555X Compute Engine, 1024/4096 MB allocatable, 12MCU

-D

--opencl-device-types 指定 opencl 的设备类型,Hashcat 支持如下设备类型:


bash


1 | CPU2 | GPU3 | FPGA, DSP, Co-Processor

一般常用 -D 2 指定 GPU 破解

掩码破解

掩码规则


bash


 ? | Charset===+=========
 l | abcdefghijklmnopqrstuvwxyz          # 小写字母 a-z
 u | ABCDEFGHIJKLMNOPQRSTUVWXYZ          # 大写字母 A-Z
 d | 0123456789                          # 数字 0-9
 h | 0123456789abcdef                    # 数字 + abcdef
 H | 0123456789ABCDEF                    # 数字 + ABCDEF
 s |  !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~   # 特殊字符    
 a | ?l?u?d?s                            # 键盘上所有可见的字符
 b | 0x00 - 0xff                         # 可能是用来匹配像空格这种密码的

自定义掩码规则


bash


--custom-charset1 [chars]等价于 -1
--custom-charset2 [chars]等价于 -2
--custom-charset3 [chars]等价于 -3
--custom-charset4 [chars]等价于 -4

在掩码中用 ?1、?2、?3、?4 来表示

一些案例:


bash


--custom-charset1 abcd123456!@-+

此时?1 就表示 abcd123456!@-+


bash


--custom-charset2 ?l?d

此时?2 就表示 ?l?d 即 ?h 数字 + 小写字母:


bash


-3 abcdef -4 123456

此时 ?3?3?3?3?4?4?4?4 就表示为前四位可能是 abcdef,后四位可能是 123456

字典破解


Code


1q2w3e4r`的MD5值为`5416d7cd6ef195a0f7622a9c56b55e84


bash


hashcat -a 0 -m 0 '5416d7cd6ef195a0f7622a9c56b55e84' hashpass.txt -o success.txt

删除已破解密码

有时候破解的时候会出现如下提示:


Code


INFO: All hashes found in potfile! Use --show to display them.

这表明在之前该密码已经被我们破解成功了,Hashcat 故不再显示出来,可以在后面添加参数 --show 来显示密码:


bash


hashcat -a 0 -m 0 'cbc8f5435c87e13c5d14e6ce92358d68' hashpass.txt --show
cbc8f5435c87e13c5d14e6ce92358d68:123456@abc

Hashcat 存放已经成功破解的密码文件位置为:~/.hashcat/hashcat.potfile

如果想要直接显示破解的密码的话,可以直接删除掉该文件。

批量破解


bash


# 删除之前破解成功的记录rm ~/.hashcat/hashcat.potfile# hash.txt为要破解的密码 hashpass.txt为字典 导出破解的结果到success.txt 并从hash.txt删除掉破解成功的hashcat -a 0 -m 0 hash.txt hashpass.txt -o success.txt --remove

组合破解

多字典破解


bash


hashcat -a 1 -m 0 '5416d7cd6ef195a0f7622a9c56b55e84' hashpass1.txt hashpass1.txt

字典 + 掩码破解


bash


echo -n admin888 |openssl md5
7fef6171469e80d32c0559f88b377245

破解 admin888 的 MD5 值:


bash


hashcat -a 6 -m 0 '7fef6171469e80d32c0559f88b377245' hashpass.txt -O

掩码 + 字典破解


bash


hashcat -a 7 -m 0 '7fef6171469e80d32c0559f88b377245' 'admi?l?d?d?d' hashpass.txt  -O

破解案例

8 位 MD5 加密的数字破解

对 23323323 进行 MD5 加密:


bash


$ echo -n 23323323 |openssl md5
5a745e31dbbd93f4c86d1ef82281688b

使用 Hashcat 来进行破解:


bash


hashcat -a 3 -m 0 --force '5a745e31dbbd93f4c86d1ef82281688b' '?d?d?d?d?d?d?d?d' -O

8 位 MD5 加密的大小写字母破解


bash


$ echo -n PassWord |openssl md5
a9d402bfcde5792a8b531b3a82669585

使用 Hashcat 来进行破解:


bash


hashcat -a 3 -m 0 -1 '?l?u' --force  'a9d402bfcde5792a8b531b3a82669585' '?1?1?1?1?1?1?1?1' -O

这里面定义了个自定义规则 -1,此时 ?1 就表示 ?l?u,即大小写字母。

5-7 位 MD5 加密的大小写字母 + 数字破解

Admin88 的 MD5 值为 2792e40d60bac94b4b163b93566e65a9


bash


hashcat -a 3 -m 0 -1 '?l?u?d' --force  '2792e40d60bac94b4b163b93566e65a9' --increment --increment-min 5 --increment-max 7 '?1?1?1?1?1?1?1' -O

这里面定义了个自定义规则 -1,此时 ?1 就表示 ?l?u?d,即大小写字母 + 数字。

admin 开头 10 位 MD5 加密的大小写字母 + 数字破解

admin23323 的 MD5 值为 a9991129897a44e0d1c2855c3d7dccc4


bash


hashcat -a 3 -m 0 -1 '?l?u?d' --force  'a9991129897a44e0d1c2855c3d7dccc4' 'admin?1?1?1?1?1' -O

MySQL4.1/MySQL5

查看 MySQL 的密码:


mysql


mysql> select Password from mysql.user;
+-------------------------------------------+
| Password                                  |
+-------------------------------------------+
| *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
+-------------------------------------------+
4 rows in set (0.00 sec)

然后开始使用字典破解:


bash


hashcat -a 0 -m 300 --force '81F5E21E35407D884A6CD4A731AEBFB6AF209E1B' hashpass.txt -O

Linux /etc/shadow sha512crypt $6$, SHA512 (Unix)

查看 /etc/shadow 密码文件:


bash



root@kali-linux:~# cat /etc/shadowroot:$6$4ojiBMDPrehqrLkX$d2T7Cn8LKkLk4SDXgCh1IEqjhnsUekXaNUXSxiZIwUTndSqyd.9sEcu80sX9DuEHGmHOeoMev2O0ACYtjMett1:18201:0:99999:7:::
daemon:*:18024:0:99999:7:::
bin:*:18024:0:99999:7:::
sys:*:18024:0:99999:7:::
sync:*:18024:0:99999:7:::
games:*:18024:0:99999:7:::
man:*:18024:0:99999:7:::
lp:*:18024:0:99999:7:::
mail:*:18024:0:99999:7:::
news:*:18024:0:99999:7:::
uucp:*:18024:0:99999:7:::
proxy:*:18024:0:99999:7:::
www-data:*:18024:0:99999:7:::
backup:*:18024:0:99999:7:::
list:*:18024:0:99999:7:::
irc:*:18024:0:99999:7:::
gnats:*:18024:0:99999:7:::
nobody:*:18024:0:99999:7:::
_apt:*:18024:0:99999:7:::
systemd-timesync:*:18024:0:99999:7:::
systemd-network:*:18024:0:99999:7:::
systemd-resolve:*:18024:0:99999:7:::
mysql:!:18024:0:99999:7:::
ntp:*:18024:0:99999:7:::
messagebus:*:18024:0:99999:7:::
arpwatch:!:18024:0:99999:7:::
Debian-exim:!:18024:0:99999:7:::
uuidd:*:18024:0:99999:7:::
redsocks:!:18024:0:99999:7:::
tss:*:18024:0:99999:7:::
rwhod:*:18024:0:99999:7:::
iodine:*:18024:0:99999:7:::
miredo:*:18024:0:99999:7:::
dnsmasq:*:18024:0:99999:7:::
postgres:*:18024:0:99999:7:::
usbmux:*:18024:0:99999:7:::
rtkit:*:18024:0:99999:7:::
stunnel4:!:18024:0:99999:7:::
sshd:*:18024:0:99999:7:::
Debian-snmp:!:18024:0:99999:7:::
sslh:!:18024:0:99999:7:::
pulse:*:18024:0:99999:7:::
speech-dispatcher:!:18024:0:99999:7:::
avahi:*:18024:0:99999:7:::
saned:*:18024:0:99999:7:::
inetsim:*:18024:0:99999:7:::
colord:*:18024:0:99999:7:::
geoclue:*:18024:0:99999:7:::
king-phisher:*:18024:0:99999:7:::
Debian-gdm:*:18024:0:99999:7:::
dradis:*:18024:0:99999:7:::
beef-xss:*:18024:0:99999:7:::
systemd-coredump:!!:18082::::::

可以看到 root 是有密码的,前面使用的是 $6 表面 hash 的加密方式为:sha512crypt $6$, SHA512 (Unix)。


bash


# 掩码破解root密码 不在potfile中记录破解成功的hash 指定设备2(核显)来跑密码 并开启优化hashcat -a 3 -m 1800 --force  '$6$4ojiBMDPrehqrLkX$d2T7Cn8LKkLk4SDXgCh1IEqjhnsUekXaNUXSxiZIwUTndSqyd.9sEcu80sX9DuEHGmHOeoMev2O0ACYtjMett1' '?l?l?l?l' -O -d 2 --potfile-disable# 掩码破解root密码 忽略用户名 不在potfile中记录破解成功的hash 指定设备2(核显)来跑密码 并开启优化hashcat -a 3 -m 1800 --force  'root:$6$4ojiBMDPrehqrLkX$d2T7Cn8LKkLk4SDXgCh1IEqjhnsUekXaNUXSxiZIwUTndSqyd.9sEcu80sX9DuEHGmHOeoMev2O0ACYtjMett1' '?l?l?l?l' -O -d 2 --username --potfile-disable

macOS 下自带的 CPU 和独显无法破解,这里国光本人手动切换了 -d 2 用核显才成功跑出来:

字典破解 Windows LM Hash


bash


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

字典破解 Windows NTLM Hash


bash


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

分布破解

参数类型说明国光的理解示例
–brain-server
Enable brain server启用主服务器
-z, –brain-client
Enable brain client, activates -S启用分布式客户端
–brain-client-featuresNumDefine brain client features, see below定义客户端功能–brain-client-features=3
–brain-hostStrBrain server host (IP or domain)主服务器的 IP 或者域–brain-host=127.0.0.1
–brain-portPortBrain server port主服务器端口–brain-port=13743
–brain-passwordStrBrain server authentication password主服务器的认证密码–brain-password=e8acfc7280c48009
–brain-sessionHexOverrides automatically calculated brain session自动覆盖已经计算的主会话–brain-session=0x2ae611db
–brain-session-whitelistHexAllow given sessions only, separated with commas仅允许给定的对话,以逗号分隔–brain-session-whitelist=0x2ae611db

客户端功能


bash


- [ Brain Client Features ] -  # | Features
 ===+========
  1 | Send hashed passwords                       # 发送已破解的密码
  2 | Send attack positions                       # 发送已破解的位置
  3 | Send hashed passwords and attack positions  # 发送已破解的密码和已破解的位置


上一条:hashcat的使用方法 技术分享
下一条:Hashcat使用教程之破解模式参数设置(超详细干货,值得收藏)