密码爆破与字典生成技术
密码分析-字典生成
cewl
爬取网站并提取字符串或关键词,搜集可能的密码形成字典
常用命令:
cewl -w list.txt -d 5 -m 5 http://target.com
-w 将内容写入文件。在这种情况下,list.txt。
-m 5 聚集长度为 5 个字符或更长的字符串(单词)
-d 5 是网页爬取/蜘蛛的深度级别(默认 2)
http://target.com 是目标站点 URL
username_generator
通过现有的名称进行排列组合,比如有一个:{名} {姓}(例如:John Smith),会进行以下排列:
- {first name}: john
- {last name}: smith
- {first name}{last name}: johnsmith
- {last name}{first name}: smithjohn
- first letter of the {first name}{last name}: *jsmith*
- first letter of the {last name}{first name}: *sjohn*
- first letter of the {first name}.{last name}: *j.smith*
- first letter of the {first name}-{last name}: *j-smith*
- and so on
使用示例:
user@thm$ echo "John Smith" > users.lst
user@thm$ python3 username_generator.py -w users.lst
usage: username_generator.py [-h] -w wordlist [-u]
john
smith
j.smith
j-smith
j_smith
j+smith
jsmith
smithjohn
crunch
一个字典生成器,通过给定字符,进行排列组合生成指定长度的字符
使用示例:
user@thm$ crunch 2 2 01234abcd -o crunch.txt
Crunch will now generate the following amount of data: 243 bytes
0 MB
0 GB
0 TB
0 PB
Crunch will now generate the following number of lines: xx
crunch: 100% completed generating output
user@thm$ cat crunch.txt
00
01
02
03
04
0a
0b
0c
0d
10
.
.
.
PS:它能生成特别大的文件,比如:
crunch 8 8 0123456789abcdefABCDEF -o crunch.txt生成的文件大小为 459 GB,包含 54875873536 个单词。
crunch 还允许我们使用 -t 选项指定字符集,以组合我们选择的单词。以下是一些可以帮助创建不同组合的其他选项:
@- 小写字母,- 大写字母%- 数字字符^- 包含空格的特殊字符
比如生成一个pass开头,两个数字结尾的字符:
user@thm$ crunch 6 6 -t pass%%
Crunch will now generate the following amount of data: 700 bytes
0 MB
0 GB
0 TB
0 PB
Crunch will now generate the following number of lines: 100
pass00
pass01
pass02
pass03
CUPP
CUPP 是一个用 Python 编写的自动交互式工具,用于创建自定义词表。例如,如果您了解某个特定目标的某些详细信息,例如他们的生日、宠物名、公司名等,这个工具可以帮助您根据这些已知信息生成密码。CUPP 将根据提供的信息生成自定义词表。还支持 1337/leet 模式,将字母 a、i、e、t、o、s、g、z 替换为数字。例如,将 a 替换为 4 或 i 替换为 1。
CUPP 支持交互模式,它会询问有关目标的问题,并根据提供的答案创建自定义字典。如果没有给定字段的答案,则按 Enter 键跳过:
user@thm$ python3 cupp.py -i
___________
cupp.py! # Common
\ # User
\ ,__, # Passwords
\ (oo)____ # Profiler
(__) )\
||--|| * [ Muris Kurgas | j0rgan@remote-exploit.org ]
[ Mebus | https://github.com/Mebus/]
[+] Insert the information about the victim to make a dictionary
[+] If you don't know all the info, just hit enter when asked! ;)
> First Name:
> Surname:
> Nickname:
> Birthdate (DDMMYYYY):
> Partners) name:
> Partners) nickname:
> Partners) birthdate (DDMMYYYY):
> Child's name:
> Child's nickname:
> Child's birthdate (DDMMYYYY):
> Pet's name:
> Company name:
> Do you want to add some key words about the victim? Y/[N]:
> Do you want to add special chars at the end of words? Y/[N]:
> Do you want to add some random numbers at the end of words? Y/[N]:
> Leet mode? (i.e. leet = 1337) Y/[N]:
[+] Now making a dictionary...
[+] Sorting list and removing duplicates...
[+] Saving dictionary to .....txt, counting ..... words.
> Hyperspeed Print? (Y/n)
常见的命令:
-h,--help 显示帮助信息并退出
-i,--interactive 用户密码分析的交互式问题
-w FILENAME 使用此选项来改进现有的字典,或使用WyD.pl输出来制作一些pwnsauce
-l 从存储库下载巨大的单词列表
-a 直接从Alecto DB解析默认用户名和密码。Alecto项目使用经过合并和增强的纯化的Phenoelit和CIRT数据库
-v,--version 显示该程序的版本。
-q,--quiet 静音模式(不打印横幅)
离线攻击-字典和暴力破解
hashcat
爆破hash
使用hashcat或hash-identifier识别hash类型,识别后,可以使用hashcat进行爆破
示例:
f806fc5a2a0d5ba2471600758452799c 被识别为MD5,使用hashcat进行爆破:
user@machine$ hashcat -a 0 -m 0 f806fc5a2a0d5ba2471600758452799c /usr/share/wordlists/rockyou.txt
hashcat (v6.1.1) starting...
f806fc5a2a0d5ba2471600758452799c:rockyou
Session..........: hashcat
Status...........: Cracked
Hash.Name........: MD5
Hash.Target......: f806fc5a2a0d5ba2471600758452799c
Time.Started.....: Mon Oct 11 08:20:50 2021 (0 secs)
Time.Estimated...: Mon Oct 11 08:20:50 2021 (0 secs)
Guess.Base.......: File (/usr/share/wordlists/rockyou.txt)
Guess.Queue......: 1/1 (100.00%)
Speed.#1.........: 114.1 kH/s (0.02ms) @ Accel:1024 Loops:1 Thr:1 Vec:8
Recovered........: 1/1 (100.00%) Digests
Progress.........: 40/40 (100.00%)
Rejected.........: 0/40 (0.00%)
Restore.Point....: 0/40 (0.00%)
Restore.Sub.#1...: Salt:0 Amplifier:0-1 Iteration:0-1
Candidates.#1....: 123456 -> 123123
Started: Mon Oct 11 08:20:49 2021
Stopped: Mon Oct 11 08:20:52 2021
PS:
-a 0 将攻击模式设置为字典攻击
-m 0 设置破解 MD5 散列的哈希模式;对于其他类型,运行 hashcat -h 以获取支持的哈希列表。
f806fc5a2a0d5ba2471600758452799c 此选项可以是单个哈希,如我们的示例,也可以是包含哈希或多个哈希的文件。
/usr/share/wordlists/rockyou.txt 我们攻击的单词表/字典文件
使用 hashcat 的--show 选项来显示已破解的值,如果哈希已被破解:
user@machine$ hashcat -a 0 -m 0 F806FC5A2A0D5BA2471600758452799C /usr/share/wordlists/rockyou.txt --show
f806fc5a2a0d5ba2471600758452799c:rockyou
可见,破解的值为rockyou
暴力破解
尝试所有的字符组合,进行暴力攻击测试。
例如,hashcat 有字符集选项,可以用来生成自己的组合。字符集可以在 hashcat 的帮助选项中找到。
user@machine$ hashcat --help
? | Charset
===+=========
l | abcdefghijklmnopqrstuvwxyz
u | ABCDEFGHIJKLMNOPQRSTUVWXYZ
d | 0123456789
h | 0123456789abcdef
H | 0123456789ABCDEF
s | !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
a | ?l?u?d?s
b | 0x00 - 0xff
用法示例:
user@machine$ hashcat -a 3 ?d?d?d?d --stdout
1234
0234
2234
3234
..
..
PS:参数详解
- -a 3 设置攻击模式为暴力破解攻击
- ?d?d?d?d 表示 hashcat 使用数字。在我们的例子中,?d?d?d?d 表示从 0000 开始到 9999 结束的四位数字。
- --stdout 将结果打印到终端。
实操:
PS:> ./hashcat.exe -m 100 -a 0 8d6e34f987851aa599257d3831a1af040886842f D:\SafetyTools\FUZZ工具包\字典\rockyou.txt
hashcat (v6.2.6) starting
OpenCL API (OpenCL 2.1 AMD-APP (3584.0)) - Platform #1 [Advanced Micro Devices, Inc.]
=====================================================================================
* Device #1: AMD Radeon(TM) Graphics, 3072/6235 MB (2432 MB allocatable), 8MCU
Minimum password length supported by kernel: 0
Maximum password length supported by kernel: 256
Hashes: 1 digests; 1 unique digests, 1 unique salts
Bitmaps: 16 bits, 65536 entries, 0x0000ffff mask, 262144 bytes, 5/13 rotates
Rules: 1
Optimizers applied:
* Zero-Byte
* Early-Skip
* Not-Salted
* Not-Iterated
* Single-Hash
* Single-Salt
* Raw-Hash
ATTENTION! Pure (unoptimized) backend kernels selected.
Pure kernels can crack longer passwords, but drastically reduce performance.
If you want to switch to optimized kernels, append -O to your commandline.
See the above message to find out about the exact limits.
Watchdog: Temperature abort trigger set to 90c
Host memory required for this attack: 140 MB
Dictionary cache built:
* Filename..: D:\SafetyTools\FUZZ工具包\字典\rockyou.txt
* Passwords.: 14344391
* Bytes.....: 139921497
* Keyspace..: 14344384
* Runtime...: 4 secs
8d6e34f987851aa599257d3831a1af040886842f:sunshine
Session..........: hashcat
Status...........: Cracked
Hash.Mode........: 100 (SHA1)
Hash.Target......: 8d6e34f987851aa599257d3831a1af040886842f
Time.Started.....: Thu Apr 10 20:13:11 2025 (1 sec)
Time.Estimated...: Thu Apr 10 20:13:12 2025 (0 secs)
Kernel.Feature...: Pure Kernel
Guess.Base.......: File (D:\SafetyTools\FUZZ工具包\字典\rockyou.txt)
Guess.Queue......: 1/1 (100.00%)
Speed.#1.........: 10946.2 kH/s (8.51ms) @ Accel:512 Loops:1 Thr:64 Vec:1
Recovered........: 1/1 (100.00%) Digests (total), 1/1 (100.00%) Digests (new)
Progress.........: 262144/14344384 (1.83%)
Rejected.........: 0/262144 (0.00%)
Restore.Point....: 0/14344384 (0.00%)
Restore.Sub.#1...: Salt:0 Amplifier:0-1 Iteration:0-1
Candidate.Engine.: Device Generator
Candidates.#1....: 123456 -> rebel91
Hardware.Mon.#1..: Util: 15% Core:2000MHz Mem:1600MHz Bus:16
Started: Thu Apr 10 20:12:45 2025
Stopped: Thu Apr 10 20:13:12 2025
PS:>./hashcat.exe -m 100 -a 0 8d6e34f987851aa599257d3831a1af040886842f D:\SafetyTools\FUZZ工具包\字典\rockyou.txt --show
8d6e34f987851aa599257d3831a1af040886842f:sunshine
离线攻击-基于规则
john-内置规则
基于规则的攻击也叫混合攻击,主要是要对目标的密码策略有所了解,对于这种攻击,可以使用hashcat或john来扩展字典
通常,John the ripper 有一个包含规则集的配置文件,该文件位于/etc/john/john.conf 或/opt/john/john.conf,其中密码规则的所在的行数是696行 ~ 1240行。,该文件中规定了可用的规则:
user@machine$ cat /etc/john/john.conf|grep "List.Rules:" | cut -d"." -f3 | cut -d":" -f2 | cut -d"]" -f1 | awk NF
JumboSingle
i1
o2
i2
best64
d3ad0ne
dive
InsidePro
T0XlC
rockyou-30000
.
.
.
在这些可用的规则中,选择需要的规则以创建字典,比如选择best64规则,包含64个内置的john规则:
user@machine$ john --wordlist=/tmp/single-password-list.txt --rules=best64 --stdout | wc -l
Using default input encoding: UTF-8
Press 'q' or Ctrl-C to abort, almost any other key for status
76p 0:00:00:00 100.00% (2021-10-11 13:42) 1266p/s pordpo
76
PS:参数说明
--wordlist=用于指定单词列表或字典文件。--rules用于指定要使用的规则或规则。--stdout将输出打印到终端。|wc -l用于计算 John 产生的行数.
结果中可用看到有复杂的一组结果:Tryh@ckm3,可以查看所有的规则,以找到合适的方案
john-自定义规则
可以在 john 破解哈希值时运行时构建自己的规则,或者使用规则构建自定义的单词列表。
假设需要从一个现有的字典中创建一个自定义的单词列表,并对原始字典进行自定义修改。目标是给每个单词的开头添加特殊字符(例如:!@#$*&),并在末尾添加数字 0-9。规则格式如下:
[symbols]word[0-9] [symbols]单词[0-9]
可以将规则添加到 john.conf 文件末尾:
user@machine$ sudo vi /etc/john/john.conf
[List.Rules:THM-Password-Attacks]
Az"[0-9]" ^[!@#$]
PS:参数说明
[List.Rules:THM-Password-Attacks]指定规则名称 THM-Password-Attacks。Az代表原始单词列表/字典中的一个单词."[0-9]"在单词末尾添加一个数字(从 0 到 9)。对于两位数,可以添加"[0-9][0-9]",依此类推。^[!@#$]在每行文本的开头添加一个特殊字符。^ 表示行/单词的开始。注意,将 ^ 更改为 $ 将将特殊字符附加到行/单词的末尾。
使用规则来扩充字典:
echo "password" > /tmp/single.lst
eg:
user@machine$ john --wordlist=/tmp/single.lst --rules=THM-Password-Attacks --stdout
Using default input encoding: UTF-8
!password0
@password0
#password0
$password0

浙公网安备 33010602011771号