hashcat – 号称宇宙最强密码破解工具

简介

Hashcat是自称世界上最快的密码恢复工具。它在2015年之前拥有专有代码库,但现在作为免费软件发布。适用于Linux,OS X和Windows的版本可以使用基于CPU或基于GPU的变体。支持hashcat的散列算法有Microsoft LM哈希,MD4,MD5,SHA系列,Unix加密格式,MySQL和Cisco PIX等。

hashcat支持多种计算核心:

GPU
CPU
APU
DSP
FPGA
Coprocessor

GPU的驱动要求:

AMD GPUs on Linux require "RadeonOpenCompute (ROCm)" Software Platform (1.6.180 or later)
AMD GPUs on Windows require "AMD Radeon Software Crimson Edition" (15.12 or later)
Intel CPUs require "OpenCL Runtime for Intel Core and Intel Xeon Processors" (16.1.1 or later)
Intel GPUs on Linux require "OpenCL 2.0 GPU Driver Package for Linux" (2.0 or later)
Intel GPUs on Windows require "OpenCL Driver for Intel Iris and Intel HD Graphics"
NVIDIA GPUs require "NVIDIA Driver" (367.x or later)

最新版下载地址:https://github.com/hashcat/hashcat/releases

工具地址:https://hashcat.net

项目地址:https://github.com/hashcat/hashcat

安装

Mac用户

Mac 用户直接使用 brew 安装即可:

brew install hashcat

Linux用户

Linux

对于 Debain 的 Linux,比如 Kali、Ubuntu 可以直接使用 apt 进行安装:

apt install hashcat

或者下载官方二进制文件进行安装

在 https://github.com/hashcat/hashcat/releases 里下载最新版压缩包,这里以 6.2.4 版为例:

tar zxvf hashcat-6.2.4.7z

cd hashcat-6.2.4

chmod +x hashcat.bin

./hashcat.bin

WINDOWS

在 https://github.com/hashcat/hashcat/releases 里下载最新版压缩包,解压后可以看到 hashcat.exe

操作

先获取文件的hash值,可以使用在线工具:https://hashes.com/en/johntheripper/rar2john

如果使用字典破解,提前准备好字典工具:

https://contest-2010.korelogic.com/wordlists.html

https://wiki.skullsecurity.org/index.php/Passwords

基本使用思路:
1.先使用-m指定一下类型,破解md5 为-m 0其中0指的是md5 具体你要破解什么类型 请使用hashcat -h获取帮助

2.比如我们破解的是7z,先要指定一下版本,版本就是标红颜色部分,按照这个版本,我们从hashcat -h中找到

所以我的参数就是hashcat.exe -m 11600 d:\hash.txt  ,  d:\hash.txt 部分表示hash所在位置,11600表示破解的软件版本

3.接着选择攻击模式-a 3,这个3指代的是 指定掩码破解,下面有相关说明,如果你有字典就选择0 例:-a 0 D:\password.txt 后面的password.txt指的是字典位置

4:然后指定一下长度和掩码类型,长度很好理解,就是掩码类型的意思是,猜测密码是纯数字还是字母+数字之类的

--increment --increment-min 1 --increment-max 12   

min 后面的数字是最小长度为1  max 后面的数字最大长度是12

5.最后就是掩码类型,看下面的集成字符集和密码例子

6.完整的命令

hashcat.exe -m 11600 d:\hash.txt -a 3 --increment --increment-min 1 --increment-max 6 ?h?h?h?h?h?h -o d:\out.txt –-force

-m指定是11600的7z 存放hash的文本 -a 指定类型为3使用掩码进行破解
–increment –increment-min 1 –increment-max 6 最小位数为1,最大位数为6
?h表示为小写字母和数字 总共6个小写字母和数字的组合
-o 表示输出破解完成后的密码原文到 d:\out.txt
–force 无视任何错误警告

最终得到结果在out.txt当中 打开得到

$7zip$*11600*20*128*16*6caf78e403a9dfebba3d9a0be04497fa*d51467c2d8219ba292c2014b825a2df9*e4dd5450fcb5dda295573f1fdb14ac0e4363e869:999abc

加粗部分为密码。

怎么算破解完成?

status 为Cracked
status 为Exhausted 已经跑完字典,但是没找到原密码

命令补充:

如果我只知道密码是字母,并且不知道哪些是大写哪些是小写,只知道密码在8位字母内,如何写规则?

如果您知道密码全部由字母组成,但不确定哪些字母是大写哪些是小写,并且密码长度在8位以内,您可以使用Hashcat的增量模式(Incremental Mode)来尝试所有可能的大小写组合。在Hashcat中,?l 代表小写字母,?u 代表大写字母,而?a代表所有的ASCII可打印字符(包括大小写字母、数字和特殊字符)。但在这个情况下,我们只关注大小写字母,所以将使用 ?l?u

为了覆盖所有大小写字母的组合,您可以使用类似于 ?l?u 的模式,但需要扩展到8位长度。然而,由于您不知道具体的大小写分布,您需要一个模式,它可以包含所有可能的大小写字母组合。这在Hashcat中称为自定义字符集。

首先,定义一个字符集(称为自定义字符集)来包括大小写字母:

  • -1 ?l?u:这定义了一个自定义字符集 -1,其中包含所有小写字母(?l)和所有大写字母(?u)。

接着,使用这个自定义字符集来构建密码模式:

  • -1 -1 -1 -1 -1 -1 -1 -1:这个模式中的每个 -1 都表示上面定义的字符集,也就是任意一个大小写字母。以下是一个Hashcat命令的示例,用于破解最多8位长度的由大小写字母组成的密码:

以下是一个Hashcat命令的示例,用于破解最多8位长度的由大小写字母组成的密码:

hashcat -m [hash type] -a 3 -1 ?l?u --increment [hash file] -1 -1 -1 -1 -1 -1 -1 -1

在这里:

  • -m [hash type]:指定哈希类型的选项,例如 -m 0 用于MD5哈希。
  • -a 3:指定使用暴力破解攻击模式。
  • -1 ?l?u:定义一个自定义字符集 -1,包括所有大小写字母。
  • --increment:启用增量模式,这意味着Hashcat将从较短的密码开始尝试,并逐渐增加长度直到达到8位。
  • [hash file]:您要破解的哈希文件。
  • -1 -1 -1 -1 -1 -1 -1 -1:使用自定义字符集 -1 构建的8位密码模式。

使用

常用参数

下面使常见的参数,想了解更多的参数可以 hashcat –h 查看

-a  指定要使用的破解模式,其值参考后面对参数。“-a 0”字典攻击,“-a 1” 组合攻击;“-a 3”掩码攻击。
-m  指定要破解的hash类型,如果不指定类型,则默认是MD5
-o  指定破解成功后的hash及所对应的明文密码的存放位置,可以用它把破解成功的hash写到指定的文件中
--force 忽略破解过程中的警告信息,跑单条hash可能需要加上此选项
--show  显示已经破解的hash及该hash所对应的明文
--increment  启用增量破解模式,你可以利用此模式让hashcat在指定的密码长度范围内执行破解过程
--increment-min  密码最小长度,后面直接等于一个整数即可,配置increment模式一起使用
--increment-max  密码最大长度,同上
--outfile-format 指定破解结果的输出格式id,默认是3
--username   忽略hash文件中的指定的用户名,在破解linux系统用户密码hash可能会用到
--remove     删除已被破解成功的hash
-r       使用自定义破解规则

攻击模式

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

输出格式

1 = hash[:salt]
2 = plain
3 = hash[:salt]:plain
4 = hex_plain
5 = hash[:salt]:hex_plain
6 = plain:hex_plain
7 = hash[:salt]:plain:hex_plain
8 = crackpos
9 = hash[:salt]:crackpos
10 = plain:crackpos
11 = hash[:salt]:plain:crackpos
12 = hex_plain:crackpos
13 = hash[:salt]:hex_plain:crackpos
14 = plain:hex_plain:crackpos
15 = hash[:salt]:plain:hex_plain:crackpos

Hash id对照表

因为实在是太多了,所有我就贴一部分常见的hash类型,要想了解所有的参数可到hashcat的Wiki上去看,或者直接 hashcat –h 查看hash对照表:

- [ Hash modes ] -

      # | Name                                             | Category
  ======+==================================================+======================================
    900 | MD4                                              | Raw Hash
      0 | MD5                                              | Raw Hash
   5100 | Half MD5                                         | Raw Hash
    100 | SHA1                                             | Raw Hash
   1300 | SHA2-224                                         | Raw Hash
   1400 | SHA2-256                                         | Raw Hash
  10800 | SHA2-384                                         | Raw Hash
   1700 | SHA2-512                                         | Raw Hash
  17300 | SHA3-224                                         | Raw Hash
  17400 | SHA3-256                                         | Raw Hash
  17500 | SHA3-384                                         | Raw Hash
  17600 | SHA3-512                                         | Raw Hash
     10 | md5($pass.$salt)                                 | Raw Hash, Salted and/or Iterated
     20 | md5($salt.$pass)                                 | Raw Hash, Salted and/or Iterated
     30 | md5(utf16le($pass).$salt)                        | Raw Hash, Salted and/or Iterated
     40 | md5($salt.utf16le($pass))                        | Raw Hash, Salted and/or Iterated
   3800 | md5($salt.$pass.$salt)                           | Raw Hash, Salted and/or Iterated
   3710 | md5($salt.md5($pass))                            | Raw Hash, Salted and/or Iterated
   4010 | md5($salt.md5($salt.$pass))                      | Raw Hash, Salted and/or Iterated
   4110 | md5($salt.md5($pass.$salt))                      | Raw Hash, Salted and/or Iterated
   2600 | md5(md5($pass))                                  | Raw Hash, Salted and/or Iterated
   3910 | md5(md5($pass).md5($salt))                       | Raw Hash, Salted and/or Iterated
   4300 | md5(strtoupper(md5($pass)))                      | Raw Hash, Salted and/or Iterated
   4400 | md5(sha1($pass))                                 | Raw Hash, Salted and/or Iterated
    110 | sha1($pass.$salt)                                | Raw Hash, Salted and/or Iterated
    120 | sha1($salt.$pass)                                | Raw Hash, Salted and/or Iterated
    130 | sha1(utf16le($pass).$salt)                       | Raw Hash, Salted and/or Iterated
    140 | sha1($salt.utf16le($pass))                       | Raw Hash, Salted and/or Iterated
   4500 | sha1(sha1($pass))                                | Raw Hash, Salted and/or Iterated
   4520 | sha1($salt.sha1($pass))                          | Raw Hash, Salted and/or Iterated
   4700 | sha1(md5($pass))                                 | Raw Hash, Salted and/or Iterated
   4900 | sha1($salt.$pass.$salt)                          | Raw Hash, Salted and/or Iterated
  14400 | sha1(CX)                                         | Raw Hash, Salted and/or Iterated
   1410 | sha256($pass.$salt)                              | Raw Hash, Salted and/or Iterated
   1420 | sha256($salt.$pass)                              | Raw Hash, Salted and/or Iterated
   1430 | sha256(utf16le($pass).$salt)                     | Raw Hash, Salted and/or Iterated
   1440 | sha256($salt.utf16le($pass))                     | Raw Hash, Salted and/or Iterated
   1710 | sha512($pass.$salt)                              | Raw Hash, Salted and/or Iterated
   1720 | sha512($salt.$pass)                              | Raw Hash, Salted and/or Iterated
   1730 | sha512(utf16le($pass).$salt)                     | Raw Hash, Salted and/or Iterated
   1740 | sha512($salt.utf16le($pass))                     | Raw Hash, Salted and/or Iterated
  14000 | DES (PT = $salt, key = $pass)                    | Raw Cipher, Known-Plaintext attack
  14100 | 3DES (PT = $salt, key = $pass)                   | Raw Cipher, Known-Plaintext attack
  14900 | Skip32 (PT = $salt, key = $pass)                 | Raw Cipher, Known-Plaintext attack
  15400 | ChaCha20                                         | Raw Cipher, Known-Plaintext attack
   2500 | WPA-EAPOL-PBKDF2                                 | Network Protocols
   2501 | WPA-EAPOL-PMK                                    | Network Protocols
  16800 | WPA-PMKID-PBKDF2                                 | Network Protocols
  16801 | WPA-PMKID-PMK                                    | Network Protocols
   7300 | IPMI2 RAKP HMAC-SHA1                             | Network Protocols
   7500 | Kerberos 5 AS-REQ Pre-Auth etype 23              | Network Protocols
   8300 | DNSSEC (NSEC3)                                   | Network Protocols
  10200 | CRAM-MD5                                         | Network Protocols
  11100 | PostgreSQL CRAM (MD5)                            | Network Protocols
  11200 | MySQL CRAM (SHA1)                                | Network Protocols
  16100 | TACACS+                                          | Network Protocols
  16500 | JWT (JSON Web Token)                             | Network Protocols
    121 | SMF (Simple Machines Forum) > v1.1               | Forums, CMS, E-Commerce, Frameworks
    400 | phpBB3 (MD5)                                     | Forums, CMS, E-Commerce, Frameworks
   2811 | MyBB 1.2+                                        | Forums, CMS, E-Commerce, Frameworks
   2811 | IPB2+ (Invision Power Board)                     | Forums, CMS, E-Commerce, Frameworks
   8400 | WBB3 (Woltlab Burning Board)                     | Forums, CMS, E-Commerce, Frameworks
     11 | Joomla < 2.5.18                                  | Forums, CMS, E-Commerce, Frameworks
    400 | Joomla >= 2.5.18 (MD5)                           | Forums, CMS, E-Commerce, Frameworks
    400 | WordPress (MD5)                                  | Forums, CMS, E-Commerce, Frameworks
   2612 | PHPS                                             | Forums, CMS, E-Commerce, Frameworks
   7900 | Drupal7                                          | Forums, CMS, E-Commerce, Frameworks
     21 | osCommerce                                       | Forums, CMS, E-Commerce, Frameworks
     21 | xt:Commerce                                      | Forums, CMS, E-Commerce, Frameworks
  11000 | PrestaShop                                       | Forums, CMS, E-Commerce, Frameworks
    124 | Django (SHA-1)                                   | Forums, CMS, E-Commerce, Frameworks
  10000 | Django (PBKDF2-SHA256)                           | Forums, CMS, E-Commerce, Frameworks
     12 | PostgreSQL                                       | Database Server
    131 | MSSQL (2000)                                     | Database Server
    132 | MSSQL (2005)                                     | Database Server
   1731 | MSSQL (2012, 2014)                               | Database Server
    200 | MySQL323                                         | Database Server
    300 | MySQL4.1/MySQL5                                  | Database Server
   3100 | Oracle H: Type (Oracle 7+)                       | Database Server
    112 | Oracle S: Type (Oracle 11+)                      | Database Server
  12300 | Oracle T: Type (Oracle 12+)                      | Database Server
   8000 | Sybase ASE                                       | Database Server
  15000 | FileZilla Server >= 0.9.55                       | FTP Server
  11500 | CRC32                                            | Checksums
   3000 | LM                                               | Operating Systems
   1000 | NTLM                                             | Operating Systems
    500 | md5crypt, MD5 (Unix), Cisco-IOS $1$ (MD5)        | Operating Systems
   3200 | bcrypt $2*$, Blowfish (Unix)                     | Operating Systems
   7400 | sha256crypt $5$, SHA256 (Unix)                   | Operating Systems
   1800 | sha512crypt $6$, SHA512 (Unix)                   | Operating Systems
    122 | macOS v10.4, MacOS v10.5, MacOS v10.6            | Operating Systems
   1722 | macOS v10.7                                      | Operating Systems
   7100 | macOS v10.8+ (PBKDF2-SHA512)                     | Operating Systems
  11600 | 7-Zip                                            | Archives
  12500 | RAR3-hp                                          | Archives
  13000 | RAR5                                             | Archives
  13600 | WinZip                                           | Archives
   9700 | MS Office <= 2003 $0/$1, MD5 + RC4               | Documents
   9710 | MS Office <= 2003 $0/$1, MD5 + RC4, collider #1  | Documents
   9720 | MS Office <= 2003 $0/$1, MD5 + RC4, collider #2  | Documents
   9800 | MS Office <= 2003 $3/$4, SHA1 + RC4              | Documents
   9810 | MS Office <= 2003 $3, SHA1 + RC4, collider #1    | Documents
   9820 | MS Office <= 2003 $3, SHA1 + RC4, collider #2    | Documents
   9400 | MS Office 2007                                   | Documents
   9500 | MS Office 2010                                   | Documents
   9600 | MS Office 2013                                   | Documents
  10400 | PDF 1.1 - 1.3 (Acrobat 2 - 4)                    | Documents
  10410 | PDF 1.1 - 1.3 (Acrobat 2 - 4), collider #1       | Documents
  10420 | PDF 1.1 - 1.3 (Acrobat 2 - 4), collider #2       | Documents
  10500 | PDF 1.4 - 1.6 (Acrobat 5 - 8)                    | Documents
  10600 | PDF 1.7 Level 3 (Acrobat 9)                      | Documents
  10700 | PDF 1.7 Level 8 (Acrobat 10 - 11)                | Documents
  99999 | Plaintext                                        | Plaintext

掩码设置

这里列一下常见的掩码字符集:

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

下面举几个简单的例子来了解一下掩码的设置:

八位数字密码:?d?d?d?d?d?d?d?d
八位未知密码:?a?a?a?a?a?a?a?a
前四位为大写字母,后面四位为数字:?u?u?u?u?d?d?d?d
前四位为数字或者是小写字母,后四位为大写字母或者数字:?h?h?h?h?H?H?H?H
前三个字符未知,中间为admin,后三位未知:?a?a?aadmin?a?a?a
6-8位数字密码:--increment --increment-min 6 --increment-max 8 ?l?l?l?l?l?l?l?l
6-8位数字+小写字母密码:--increment --increment-min 6 --increment-max 8 ?h?h?h?h?h?h?h?h

如果我们想设置字符集为:abcd123456!@-+,那该怎么做呢。这就需要用到自定义字符集这个参数了,hashcat支持用户最多定义4组字符集:

--custom-charset1 [chars]等价于 -1
--custom-charset2 [chars]等价于 -2
--custom-charset3 [chars]等价于 -3
--custom-charset4 [chars]等价于 -4
在掩码中用?1、?2、?3、?4来表示。

再来举几个例子:

--custom-charset1 abcd123456!@-+。然后我们就可以用"?1"去表示这个字符集了
--custom-charset2 ?l?d,这里和?2就等价于?h
-1 ?d?l?u,?1就表示数字+小写字母+大写字母
-3 abcdef -4 123456 那么?3?3?3?3?4?4?4?4就表示为前四位可能是“abcdef”,后四位可能是“123456”

例子

MD5破解

PS:我这里给一下我机子的配置,以破解MD5为例,

8位数字破解:

hashcat -a 3 --force d54d1702ad0f8326224b817c796763c9 ?d?d?d?d?d?d?d?d

密码为 4 位小写字母+数字:

hashcat -a 3 --force 4575621b0d88c303998e63fc74d165b0 -1 ?l?d ?1?1?1?1

密码为 1-4 位大写字母+数字

hashcat -a 3 --force 8fb5a3e7338ce951971d69be27fc5210 -1 ?u?d ?1?1?1?1 --increment --increment-min 1 --increment-max 4

指定特定字符集:123456abcdf!@+- 进行破解

hashcat -a 3 -1 123456abcdf!@+- 8b78ba5089b11326290bc15cf0b9a07d ?1?1?1?1?1

由于在终端里可能会把部分字符识别为特殊字符,因此需要转义一下:

hashcat -a 3 -1 123456abcdf\!\@+- 8b78ba5089b11326290bc15cf0b9a07d ?1?1?1?1?1

如果不知道目标密码的构成情况,可以直接使用 ?a 表示使用所有字符进行破解:

hashcat -a 3 19b9a36f0cab6d89cd4d3c21b2aa15be --increment --increment-min 1 --increment-max 8 ?a?a?a?a?a?a?a?a

使用字典破解

hashcat -a 0 e10adc3949ba59abbe56e057f20f883e password.txt

使用字典批量破解

hashcat -a 0 hash.txt password.txt

字典组合破解

hashcat -a 1 77b3e6926e7295494dd3be91c6934899 pwd1.txt pwd2.txt

RAR破解

首先获取 rar 文件的 hash 值,我们可以使用另一款哈希破解工具 John 提供的 rar2john 工具将 rar 文件里的 hash 提取出来。

rar2john 下载地址:http://openwall.info/wiki/_media/john/johntheripper-v1.8.0.12-jumbo-1-bleeding-e6214ceab-2018-02-07-win-x64.7z

解压保存,然后CD进入目录执行,获取 rar 文件 hash:

rar2john.exe 1.rar

hashcat 支持 RAR3-hp 和 RAR5:

对于 RAR5,示例如下:

hashcat -a 3 -m 13000 --force '$rar5$16$b06f5f2d4c973d6235e1a88b8d5dd594$15$a520dddcc53dd4e3930b8489b013f273$8$733969e5bda903e4' ?d?d?d?d?d?d

对于 RAR3-hp:

hashcat -a 3 -m 12500 --force '$RAR3$*0*5ba3dd697a8706fa*919ad1d7a1c42bae4a8d462c8537c9cb' ?d?d?d?d

RAR3-hp 哈希头为 $RAR3$*0*,而不是 $RAR3$*1*,中间的数值是0(-hp)而不是1(-p),-p 尚未得到支持,只支持 -hp

关于 RAR 参数 -p 和 -hp 的区别:
-p:只对 RAR 文件加密,里面的目录和文件名没加密;
-hp:对目录中的文件名和子目录都进行加密处理

ZIP 压缩密码

和 rar 破解过程一样,我们需要先提取 zip 文件的哈希值,这里可以使用 zip2john 进行获取,zip2john.exe 在上面下载的 rar2john.exe 的同级目录下:

zip2john.exe 1.zip

然后执行:

hashcat -a 3 -m 13600 '$zip2$*0*3*0*18b1a7e7ad39cb3624e54622849b23c7*5b99*3*5deee7*a418cee1a98710adce9a*$/zip2$' --force ?d?d?d?d?d?d

这里 ZIP 的加密算法使用的 AES256。

其他

  • Hashcat 在有时破解的时候会提示 All hashes found in potfile!,这表明该 hash 已经被破解出来过了,可以使用 hashcat [哈希值] –show 查看已破解出来的明文密码。
  • 如果想再次破解已经破解过的密码,删除 ~/.hashcat/hashcat.potfile 文件里的对应记录即可。
  • 在使用GPU模式进行破解时,可以使用 -O 参数自动进行优化
  • 在实际破解过程中,可以先使用 top 字典进行破解,不行再试试社工字典,比如姓名+生日的组合字典

Hashcat 参数优化:

 --gpu-accel 160    可以让GPU发挥最大性能

 --gpu-loops 1024   可以让GPU发挥最大性能

 --segment-size 512 可以提高大字典破解的速度