了解 John the Ripper 的基本模式

Kali LinuxBeginner
立即练习

引言

John the Ripper (JtR) 是一个强大且广泛使用的开源密码安全审计和密码恢复工具。系统管理员可以使用它来测试其系统上密码的强度,安全专业人员也可以用它来恢复丢失的密码。理解其不同的操作模式是有效使用它的关键。

在本实验中,你将亲身体验 John the Ripper 的基本破解模式。你将学习如何使用它的帮助选项并探索其默认行为。然后,你将深入了解其四种主要模式:Single Crack(单模式)、Wordlist(字典模式)、Incremental(增量模式)和 External mode(外部模式),学习每种模式的目的和基本用法。

探索 John the Ripper 帮助选项

在此步骤中,你将开始探索 John the Ripper 的内置帮助文档。帮助菜单是一个重要的资源,它提供了关于该工具语法、命令行选项和可用模式的快速参考。

要查看主帮助页面,只需运行 john 命令并带上 --help 标志。这将显示最常用选项及其描述的摘要。

在你的终端中执行以下命令:

john --help

你将看到一个详细的输出,列出了各种选项。请注意指定不同破解模式的标志,例如 --single--wordlist--incremental

John the Ripper 1.9.0-jumbo-1 [linux-gnu 64-bit x86_64 AVX2 AC]
Copyright (c) 1996-2019 by Solar Designer and others
Homepage: http://www.openwall.com/john/

Usage: john [OPTIONS] [PASSWORD-FILES]

--single                   "single crack" mode
--wordlist=FILE --stdin    wordlist mode, read words from FILE or stdin
--rules                    enable word mangling rules for wordlist mode
--incremental[=MODE]       "incremental" mode [using section MODE]
--external=MODE            external mode or word filter
--stdout[=LENGTH]          just output candidate passwords [cut at LENGTH]
--restore[=NAME]           restore an interrupted session [called NAME]
--session=NAME             new session [called NAME]
--status[=NAME]            print status of a session [called NAME]
--show[=LEFT]              show cracked passwords [if =LEFT, then uncracked]
--test[=TIME]              run tests and benchmarks for TIME seconds each
--users=[-]LOGIN|UID[,..]  [don't] load this (these) user(s) only
--groups=[-]GID[,..]       load users of this (these) group(s) only
... (output truncated) ...

此命令为你提供了 John the Ripper 功能的扎实概述。在接下来的步骤中,我们将实际探索其中一些模式。

识别 John the Ripper 的默认破解模式

在此步骤中,你将了解 John the Ripper 的默认运行方式。当你对密码文件运行 john 而不指定模式时,它不会只选择一种方法。相反,它会以默认顺序智能地循环使用其最有效的模式:首先是“single”(单模式),然后是“wordlist”(字典模式),最后是“incremental”(增量模式)。这在速度和彻底性之间取得了良好的平衡。

我们的设置脚本已在你的当前目录(~/project)中创建了一个名为 mypasswd.txt 的文件。该文件包含一个用户条目和一个简单的哈希密码。

让我们在不带任何模式标志的情况下对该文件运行 John the Ripper,以观察其默认行为。

john mypasswd.txt

John 将开始破解过程。你将看到它工作时的状态更新。由于密码很简单,它应该会很快被破解。

Using default input encoding: UTF-8
Loaded 1 password hash (descrypt, traditional crypt(3) [DES 128/128 SSE2-16])
Cost 1 (algorithm [1:descrypt]...[3:DES]) is 50400 for all loaded hashes
Will run 4 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
password         (testuser)
1g 0:00:00:00 DONE (2023-10-27 10:30) 100.0g/s 12000p/s 12000c/s 12000C/s rolez..pimpin
Use the "--show" option to display all of the cracked passwords reliably
Session completed

如你所见,John 成功破解了用户 testuser 的密码(password)。它还贴心地建议使用 --show 选项稍后查看破解的密码。

要确认破解的密码,你可以使用 --show 选项:

john --show mypasswd.txt

这将显示给定文件中所有成功破解的密码。

testuser:password:1001:1001::/home/testuser:/bin/sh

1 password hash cracked, 0 left

这证实了默认模式顺序是成功的。

区分 Single Crack 和 Wordlist 模式

在此步骤中,你将了解两种最基本的破解模式:“single crack”(单模式)和“wordlist”(字典模式)。

首先,重要的是要知道 John the Ripper 将破解的密码存储在名为 john.pot 的文件中,该文件位于 ~/.john/ 目录中。要对已破解的密码重新运行破解会话,我们必须先删除此文件。现在就来做这件事。

rm ~/.john/john.pot

Single Crack 模式

Single crack 模式是一种快速有效的模式,它根据用户账户本身的信息(如用户名或 GECOS 字段数据)生成密码候选。它会对这些候选密码应用常见的变异(如添加数字或符号)。

让我们使用 --single 标志显式地以 single crack 模式运行 John。

john --single mypasswd.txt

输出将与默认运行类似,因为这是 John 尝试的第一种模式。它对用户名变体密码非常有效。

Wordlist 模式

Wordlist 模式是最流行的密码破解技术之一。它使用预编译的单词列表(字典或 wordlist)并尝试将每个单词作为密码。John 自带一个默认的 wordlist,通常位于 /usr/share/john/password.lst

让我们先再次删除 pot 文件以重置会话。

rm ~/.john/john.pot

现在,使用 --wordlist 标志显式指向其默认 wordlist,以 wordlist 模式运行 John。

john --wordlist=/usr/share/john/password.lst mypasswd.txt

你将看到 John 加载 wordlist 并尝试破解哈希。由于“password”是一个非常常见的密码,它包含在默认列表中,并且几乎会立即被找到。

Using default input encoding: UTF-8
Loaded 1 password hash (descrypt, traditional crypt(3) [DES 128/128 SSE2-16])
Cost 1 (algorithm [1:descrypt]...[3:DES]) is 50400 for all loaded hashes
Will run 4 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
password         (testuser)
1g 0:00:00:00 DONE (2023-10-27 10:35) 100.0g/s 12000p/s 12000c/s 12000C/s passwo..pascal
Use the "--show" option to display all of the cracked passwords reliably
Session completed

这演示了如何指示 John 在其攻击中使用特定的字典文件。

理解 Incremental 模式基础

在此步骤中,你将探索“incremental”(增量)模式。此模式本质上是一种暴力破解(brute-force)攻击。它系统地尝试所有可能的字符组合,直到达到特定长度。虽然它是最全面的模式,但对于复杂度中等的密码来说,它也可能非常耗时。

Incremental 模式的行为在 john.conf 文件中定义,该文件指定了字符集(例如,Alnum 表示字母数字,All 表示所有字符)和长度限制。

首先,让我们通过再次删除 john.pot 文件来重置破解会话。

rm ~/.john/john.pot

现在,让我们以 incremental 模式运行 John。我们将指定 Digits 字符集,它告诉 John 尝试所有可能的数字组合。我们为此使用 --incremental 标志。

john --incremental=Digits mypasswd.txt

你将看到 John 开始尝试诸如“0”、“1”、“2”、“00”、“01”等组合。由于我们的密码是“password”(全部是字母),此攻击将不会成功。你可以在几秒钟后按 Ctrl+C 停止它。

现在,让我们尝试一个更合适的字符集。我们将使用默认的 incremental 模式,它通常从常见的字符集(如小写字母)开始。

再重置一次会话:

rm ~/.john/john.pot

运行不指定字符集的命令:

john --incremental mypasswd.txt

这次,John 将使用其预定义的字符集序列。由于“password”由小写字母组成,LowerAlpha 字符集最终会找到它。

Using default input encoding: UTF-8
Loaded 1 password hash (descrypt, traditional crypt(3) [DES 128/128 SSE2-16])
Cost 1 (algorithm [1:descrypt]...[3:DES]) is 50400 for all loaded hashes
Will run 4 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
password         (testuser)
1g 0:00:00:00 DONE (2023-10-27 10:40) 100.0g/s 12000p/s 12000c/s 12000C/s passwo..pascal
Session completed

当其他更快的模式失败时,Incremental 模式是你最后的手段。

了解 External 模式功能

在此步骤中,你将了解“external”(外部)模式。这是 John 中最先进、最灵活的模式。它允许你直接在 john.conf 配置文件中使用类似 C 的脚本语言来定义自定义密码生成逻辑。这对于创建其他模式无法处理的高度定向攻击非常强大。

虽然编写外部脚本是一个高级主题,但你可以轻松使用 John 附带的预定义外部模式。首先,让我们列出在 /etc/john/john.conf 中定义的可用外部模式。

grep '^\[' /etc/john/john.conf | grep 'External:'

此命令会过滤配置文件,显示外部模式部分的名称。

[External:Compiler]
[External:Double]
[External:Hybrid]
[External:Keyboard]
[External:LanManager]
[External:Shift]
[External:Status]
[External:Wordlist]

你可以看到几个内置的外部函数。让我们尝试使用 Wordlist 外部模式。此模式本质上模仿了标准的 wordlist 模式,但它作为外部脚本实现,使其成为一个很好的示例。

首先,一如既往,重置会话。

rm ~/.john/john.pot

现在,使用 --external 标志运行 John,并指定 Wordlist 模式。

john --external=Wordlist mypasswd.txt

输出将与你运行标准 wordlist 模式时非常相似,因为底层逻辑是相同的:它使用默认的 wordlist 来查找密码。

Using default input encoding: UTF-8
Loaded 1 password hash (descrypt, traditional crypt(3) [DES 128/128 SSE2-16])
Cost 1 (algorithm [1:descrypt]...[3:DES]) is 50400 for all loaded hashes
Will run 4 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
password         (testuser)
1g 0:00:00:00 DONE (2023-10-27 10:45) 100.0g/s 12000p/s 12000c/s 12000C/s passwo..pascal
Session completed

External 模式为生成密码候选解锁了近乎无限的可能性,使其成为需要实现自定义破解逻辑的专家用户的工具。

总结

在此次实验中,你已成功探索了 John the Ripper 的基本破解模式。你学会了如何使用其帮助选项,并观察了其默认行为,该行为会智能地组合多种模式以提高效率。

你获得了以下方面的实践经验:

  • Single Crack Mode(单模式破解):一种快速模式,利用用户特定信息来猜测密码。
  • Wordlist Mode(字典模式):一种常用的技术,使用单词字典。
  • Incremental Mode(增量模式):一种全面的暴力破解模式,尝试所有字符组合。
  • External Mode(外部模式):一种高级的可脚本化模式,用于创建自定义密码生成规则。

理解这些核心模式是掌握 John the Ripper 以进行密码安全审计和恢复任务的第一步。你现在已具备选择适合不同场景的模式的基础知识。