一:John 概述

开膛手约翰(John the Ripper)是一个快速的密码破解程序。

其主要目的是检测弱 Unix 密码。

二:John 破解 Linux 密码

2.1 相关文件

Linux 系统中存放账号、密码的两个重要文件 /etc/passwd 与 /etc/shadow

1
2
3
4
5
6
7
8
9
cat /etc/passwd		# 查看存放账户的文件内容
cat /etc/passwd | head -1
root:x:0:0:root:/root:/usr/bin/zsh # 被":"划分为7个字段
用户名:密码:用户ID(UID):用户组ID(GID):描述信息:主目录:默认shell

cat /etc/shadow # 查看存放账户密码的文件内容
cat /etc/shadow | head -1 # 被":"划分为9个字段
root:$y$j9T$yRBeGeHrNuu/yNBeAEqn40$.ljB8e37.pNGJXOVLiDDJUTTCcA..R8rXJcUmFCuBcB:19321:0:99999:7:::
用户名:加密密码:最后一次修改时间:最小修改时间间隔:密码有效期:密码需要变更前的警告天数:密码过期后的宽限时间:账号失效时间:保留字段

2.2 破解密码

1
2
# 将账户文件与密码文件合成一个文件
unshadow /etc/passwd /etc/shadow > shadow
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 使用 john 破解账户 ssh 密码
john --format=crypt shadow

Using default input encoding: UTF-8
使用默认输入编码:UTF-8
Loaded 3 password hashes with 3 different salts (crypt, generic crypt(3) [?/64])
用3种不同的盐加载3个密码散列(crypt, generic crypt(3) [?/64])
Cost 1 (algorithm [1:descrypt 2:md5crypt 3:sunmd5 4:bcrypt 5:sha256crypt 6:sha512crypt]) is 0 for all loaded hashes
对于所有加载的哈希,成本1(算法[1:descrypt 2:md5crypt 3:sunmd5 4:bcrypt 5:sha256crypt 6:sha512crypt])为0
Cost 2 (algorithm specific iterations) is 1 for all loaded hashes
对于所有加载的哈希,成本2(特定于算法的迭代)为1
Proceeding with single, rules:Single
单一进程,规则:单一
Press 'q' or Ctrl-C to abort, almost any other key for status
按 'q' 或者 Ctrl-C 终止,几乎任何其他状态键
root (root)
root (ghost)
Almost done: Processing the remaining buffered candidate passwords, if any.
基本完成:处理剩余的缓存候选密码(如果有)
Proceeding with wordlist:/usr/share/john/password.lst
继续处理单词列表:/usr/share/john/password.lst
123456 (test)
3g 0:00:00:18 DONE 2/3 (2022-11-27 01:26) 0.1648g/s 82.08p/s 82.19c/s 82.19C/s 123456..pepper
Use the "--show" option to display all of the cracked passwords reliably
使用 "--show" 选项可靠地显示所有破解的密码
Session completed.
会话完成。