一:简介

crunch 是一种创建密码字典的工具,按照指定的规则生成密码字典,可以灵活的定制自己的字典文件。

使用 crunch 工具生成的密码可以输出到屏幕,保存到文件、或者另一个程序。

crunch 最厉害的就是知道密码的一部分细节后,可以针对性的生成字典。

二:规则

2.1 生成方式

crunch生成字典的方式:

  1. 指定生成26个字母或者数字的随机字典
  2. 指定格式生成字典
  3. 指定模板生成字典
  4. 指定字符串生成字典

2.2 参数详情

  • min:设定最小字符串长度(必选)
  • max:设定最大字符串长度(必选)
  • -o 将生成的字典保存在指定文件
  • -t 指定密码输出的格式
  • -p 指定元素组合
  • 特殊字符
    • %:代表数字
    • ^:代表特殊符号
    • @:代表小写字母
    • .:代表大写字母

三:命令

2.1 crunch

1
2
3
4
5
6
7
8
9
10
11
12
13
14
crunch   

crunch version 3.6

Crunch can create a wordlist based on criteria you specify. The output from crunch can be sent to the screen, file, or to another program.
crunch 可以基于你指定的标准创建一个单词表。crunch的输出key发送到屏幕、文件或者另一个程序。

Usage: crunch <min> <max> [options]
用法:crunch <最小> <最大> [选项]
where min and max are numbers
其中最小值和最大值是数字

Please refer to the man page for instructions and examples on how to use crunch.
有关如何使用crunch,请参考手册页的说明和实例。

2.2 生成纯数字密码

1
2
3
4
5
6
7
8
9
10
11
# 生成一个最小字符串长度为两位、最大字符串长度为四位的字典。
crunch 2 4 > number.txt

Crunch will now generate the following amount of data: 2357212 bytes
crunch 现在将生成以下数量的数据:2357212 字节
2 MB
0 GB
0 TB
0 PB
Crunch will now generate the following number of lines: 475228
crunch 现在将生成以下行数:475228

2.3 生成指定格式密码

1
2
3
4
5
6
7
8
9
10
# 生成7位数,以admin开头+2位数字的字典,保存到admin_num.txt中。
# -t:指定以某种格式开头
# %%:表示两位数字
crunch 7 7 -t admin%% > admin_num.txt
Crunch will now generate the following amount of data: 800 bytes
0 MB
0 GB
0 TB
0 PB
Crunch will now generate the following number of lines: 100
1
2
3
4
5
6
7
8
# 生成以1520003开头的手机号
crunch 11 11 -t 1520003%%%% > mobile.txt
Crunch will now generate the following amount of data: 120000 bytes
0 MB
0 GB
0 TB
0 PB
Crunch will now generate the following number of lines: 10000
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 指定的数字生成字典
crunch 6 6 0123456789 > num.txt
Crunch will now generate the following amount of data: 7000000 bytes
6 MB
0 GB
0 TB
0 PB
Crunch will now generate the following number of lines: 1000000

crunch 6 6 -f /usr/share/crunch/charset.lst numeric > num_repo.txt
Crunch will now generate the following amount of data: 7000000 bytes
6 MB
0 GB
0 TB
0 PB
Crunch will now generate the following number of lines: 1000000

2.4 依据库文件生成密码

1
2
3
4
5
6
7
8
9
10
# -f:指定库文件
crunch 6 6 -f /usr/share/crunch/charset.lst hex-lower -o repo.txt
Crunch will now generate the following amount of data: 117440512 bytes
112 MB
0 GB
0 TB
0 PB
Crunch will now generate the following number of lines: 16777216

crunch: 100% completed generating output
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 库文件
cat /usr/share/crunch/charset.lst
# charset configuration file for winrtgen v1.2 by Massimiliano Montoro (mao@oxid.it)
# Massimiliano Montoro 的 winrtgen v1.2 字符集配置文件(mao@oxid.it)
# compatible with rainbowcrack 1.1 and later by Zhu Shuanglei <shuanglei@hotmail.com>
# 兼容 Zhu Shuanglei 的 rainbowcrack 1.1 以及更高版本。


hex-lower = [0123456789abcdef]
十六进制小写
hex-upper = [0123456789ABCDEF]
十六进制大写

numeric = [0123456789]
数字的
numeric-space = [0123456789 ]
带有空格的数字

symbols14 = [!@#$%^&*()-_+=]
symbols14-space = [!@#$%^&*()-_+= ]

symbols-all = [!@#$%^&*()-_+=~`[]{}|\:;"'<>,.?/]
symbols-all-space = [!@#$%^&*()-_+=~`[]{}|\:;"'<>,.?/ ]
...

2.4 指定元素组合生成字典

1
2
3
4
5
6
7
8
# 指定生成的字典,由 ghost、99、22 三个元素组成
crunch 3 3 -p ghost 99 22 > combination.txt
Crunch will now generate approximately the following amount of data: 60 bytes
0 MB
0 GB
0 TB
0 PB
Crunch will now generate the following number of lines: 6

四:练习

  • 以26个字母为元素最小5位,最大6位的组合,重定向保存到exercise1.txt字典文件中。
    • crunch 5 6 > exericise1.txt
  • 以root字符开头,第五位、第六位为特殊符号,七八九位为123结尾的9位数字字典,重定向保存到exercise2.txt字典文件中
    • crunch 9 9 -t root^^123 > exercise3.txt
  • 指定库文件中的 hex-upper 模板生成6位的字典,使用 -o 参数,保存在 exercise4.txt 字典文件中
    • crunch 6 6 -f /usr/share/crunch/charset.lst hex-upper -o exercise4.txt
  • 生成 pdd、1611、0101 这个三个字符串的随机字典,重定向保存到 exercise5.txt 字典文件中
    • crunch 3 3 -p pdd 1611 0101 > exercise5.txt