John密码爆破工具使用

爆破hash

基本语法

john [options] [file path]

  • john : 调用 John the Ripper 程序
  • [options] :指定您想要使用的选项
  • [file path] : 包含您要破解的hash值的文件;如果它在同一目录下,您不需要指定路径,只需文件名即可。

自动爆破

john --wordlist=[path to wordlist] [path to file]

  • --wordlist= :指定使用单词列表模式,从提供的路径中读取您提供的文件
  • [path to wordlist] : 你所使用的单词列表的路径,如前一个任务所述

示例用法:

john --wordlist=/usr/share/wordlists/rockyou.txt hash_to_crack.txt

指定类型爆破

注:识别hash可以使用 hash-identifier 工具

得知具体类型后使用指定类型进行爆破

john --format=[format] --wordlist=[path to wordlist] [path to file]
  • --format= :这是告诉 John 你正在给它一个特定格式的hash值,并使用以下格式来破解它的标志
  • [format] : hash的格式

示例用法:

john --format=raw-md5 --wordlist=/usr/share/wordlists/rockyou.txt hash_to_crack.txt

注:如果处理的是标准哈希类型,例如上面示例中的 md5,必须用 raw- 作为前缀来告诉 John 你只处理标准哈希类型,判断是否需要添加前缀,可以使用 john --list=formats 列出 John 的所有格式,然后手动检查或使用类似 john --list=formats | grep -iF "md5" 的命令 grep 来搜索hash类型。

爆破Windows身份验证hash

一般使用 NT/LM 进行加密的

示例用法:

john --format=nt --wordlist=/usr/share/wordlists/rockyou.txt ./ntlm.txt

破解 /etc/shadow 中的哈希值

破解 /etc/shadow 密码,必须将其与 /etc/passwd 文件结合。可以使用 John 工具套件中内置的一个工具: unshadow

unshadow 的基本语法如下:

unshadow [path to passwd] [path to shadow]
  • unshadow : 调用 unshadow 工具
  • [path to passwd] :包含获取的 /etc/passwd 文件副本的文件
  • [path to shadow] :包含获取的 /etc/shadow 文件副本的文件

示例用法:

unshadow local_passwd local_shadow > unshadowed.txt

爆破

eg:

john --wordlist=/usr/share/wordlists/rockyou.txt --format=sha512crypt unshadowed.txt

注:在某些情况下,需要指定格式,如:--format=sha512crypt

案例:

┌──(root㉿kali)-[/home/kali/下载/John-the-Ripper-The-Basics/Task06]
└─# unshadow local_passwd local_shadow > unshadow.txt

┌──(root㉿kali)-[/home/kali/下载/John-the-Ripper-The-Basics/Task06]
└─# cat unshadow.txt
root:$6$Ha.d5nGupBm29pYr$yugXSk24ZljLTAZZagtGwpSQhb3F2DOJtnHrvk7HI2ma4GsuioHp8sm3LJiRJpKfIf7lZQ29qgtH17Q/JDpYM/:0:0::/root:/bin/bash

┌──(root㉿kali)-[/home/kali/下载/John-the-Ripper-The-Basics/Task06]
└─# john --wordlist=/usr/share/wordlists/rockyou.txt unshadow.txt
Using default input encoding: UTF-8
Loaded 1 password hash (sha512crypt, crypt(3) $6$ [SHA512 128/128 AVX 2x])
Cost 1 (iteration count) is 5000 for all loaded hashes
Will run 4 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
1234             (root)
1g 0:00:00:00 DONE (2025-03-10 23:24) 1.449g/s 1855p/s 1855c/s 1855C/s kucing..poohbear1
Use the "--show" option to display all of the cracked passwords reliably
Session completed.

单次破解模式

原理:提供一个单词或其他信息,john通过变更信息进行猜测

eg:markus -> Markus1, Markus2, Markus3 (etc.)

格式:

john --single --format=[format] [path to file]
  • --single : 这个标志让 John 知道你想使用单次哈希破解模式
  • --format=[format] : 始终,正确识别格式至关重要。

案例:破解名为“Mike”的用户的密码

注:如果在单次破解模式下破解hash值,需要更改提供给 John 的文件格式,以便它理解从哪些数据创建单词列表。

可以通过在哈希值前加上属于该hash值的用户名来实现这一点。

因此本例中,需要将更改文件名为 hashes.txt

内容从 1efee03cdcb96d90ad48ccc7b8666033 变更为 mike:1efee03cdcb96d90ad48ccc7b8666033

┌──(root㉿kali)-[/home/kali/下载/John-the-Ripper-The-Basics/Task07]
└─# cat hash07.txt
7bf6d9bb82bed1302f331fc6b816aada

┌──(root㉿kali)-[/home/kali/下载/John-the-Ripper-The-Basics/Task07]
└─# vim ./hashes.txt

┌──(root㉿kali)-[/home/kali/下载/John-the-Ripper-The-Basics/Task07]                                          # 拼接信息
└─# cat hashes.txt
Joker:7bf6d9bb82bed1302f331fc6b816aada

┌──( D:/SafetyTools/hash-identifier-hash类型识别 )                                                                         # hash类型识别
└─ 11:05:38 # python .\hash-id.py
   #########################################################################
   #     __  __                     __           ______    _____           #
   #    /\ \/\ \                   /\ \         /\__  _\  /\  _ `\         #
   #    \ \ \_\ \     __      ____ \ \ \___     \/_/\ \/  \ \ \/\ \        #
   #     \ \  _  \  /'__`\   / ,__\ \ \  _ `\      \ \ \   \ \ \ \ \       #
   #      \ \ \ \ \/\ \_\ \_/\__, `\ \ \ \ \ \      \_\ \__ \ \ \_\ \      #
   #       \ \_\ \_\ \___ \_\/\____/  \ \_\ \_\     /\_____\ \ \____/      #
   #        \/_/\/_/\/__/\/_/\/___/    \/_/\/_/     \/_____/  \/___/  v1.2 #
   #                                                             By Zion3R #
   #                                                    www.Blackploit.com #
   #                                                   Root@Blackploit.com #
   #########################################################################
--------------------------------------------------
 HASH: 7bf6d9bb82bed1302f331fc6b816aada

Possible Hashs:
[+] MD5
[+] Domain Cached Credentials - MD4(MD4(($pass)).(strtolower($username)))

┌──(root㉿kali)-[/home/kali/下载/John-the-Ripper-The-Basics/Task07]                                            # 爆破
└─# john --single --format=raw-md5 hashes.txt
Using default input encoding: UTF-8
Loaded 1 password hash (Raw-MD5 [MD5 128/128 AVX 4x3])
Warning: no OpenMP support for this hash type, consider --fork=4
Press 'q' or Ctrl-C to abort, almost any other key for status
Warning: Only 2 candidates buffered for the current salt, minimum 12 needed for performance.
Jok3r            (Joker)
1g 0:00:00:00 DONE (2025-03-10 23:40) 100.0g/s 19600p/s 19600c/s 19600C/s j0ker..J0k3r
Use the "--show --format=Raw-MD5" options to display all of the cracked passwords reliably
Session completed.

自定义规则

创建自定义规则

自定义规则定义在 john.conf 文件中。使用包管理器安装了 John 或从源代码构建,它通常位于 /etc/john/john.conf

使用正则进行匹配修改,常用的有:

  • Az : 将单词与定义的字符附加在一起
  • A0 : 将单词与定义的字符连接在一起
  • c :按位置大写字符
  • [0-9] : 将包含数字 0-9
  • [0] :仅包括数字 0
  • [A-z] : 将包含大小写字母
  • [A-Z] : 仅包括大写字母
  • [a-z] : 仅包括小写字母

注:要使用 "" 将正则式括起来

  • [List.Rules:THMRules] 用于定义规则的名称;
  • [a] : 将仅包括 `a``
  • [!£$%@] : 将包含符号 ! , £ , $ , %@

eg:

[List.Rules:PoloPassword]
cAz"[0-9] [!£$%@]"

利用以下内容:

  • c :将首字母大写
  • Az :将内容附加到单词末尾
  • [0-9] :0-9 范围内的一个数字
  • [!£$%@] : 密码后跟这些符号之一

使用

john --wordlist=[path to wordlist] --rule=PoloPassword [path to file]

破解ZIP文件-Zip2John

使用 zip2john 工具将 Zip 文件转换为 John 可以理解和尝试破解的哈希格式。主要用法如下:

zip2john [options] [zip file] > [output file]
  • [options] : 向 zip2john 传递特定的校验和选项;这通常是不必要的
  • [zip file] : 你想要获取哈希值的 Zip 文件路径
  • > :此操作将此命令的输出重定向到另一个文件
  • [output file] :这是将存储输出的文件

示例

zip2john zipfile.zip > zip_hash.txt

案例

┌──(root㉿kali)-[/home/kali/下载/John-the-Ripper-The-Basics/Task09]
└─# zip2john ./secure.zip > ziphash.txt
ver 1.0 efh 5455 efh 7875 secure.zip/zippy/flag.txt PKZIP Encr: 2b chk, TS_chk, cmplen=38, decmplen=26, crc=849AB5A6 ts=B689 cs=b689 type=0

┌──(root㉿kali)-[/home/kali/下载/John-the-Ripper-The-Basics/Task09]
└─# ls
secure.zip  ziphash.txt

┌──(root㉿kali)-[/home/kali/下载/John-the-Ripper-The-Basics/Task09]
└─# cat ziphash.txt
secure.zip/zippy/flag.txt:$pkzip$1*2*2*0*26*1a*849ab5a6*0*48*0*26*b689*964fa5a31f8cefe8e6b3456b578d66a08489def78128450ccf07c28dfa6c197fd148f696e3a2*$/pkzip$:zippy/flag.txt:secure.zip::./secure.zip

┌──(root㉿kali)-[/home/kali/下载/John-the-Ripper-The-Basics/Task09]
└─# john --wordlist=/usr/share/wordlists/rockyou.txt ziphash.txt
Using default input encoding: UTF-8
Loaded 1 password hash (PKZIP [32/64])
Will run 4 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
pass123          (secure.zip/zippy/flag.txt)
1g 0:00:00:00 DONE (2025-03-11 00:14) 100.0g/s 819200p/s 819200c/s 819200C/s 123456..whitetiger
Use the "--show" option to display all of the cracked passwords reliably
Session completed.

┌──(root㉿kali)-[/home/kali/下载/John-the-Ripper-The-Basics/Task09]
└─# unzip secure.zip
Archive:  secure.zip
[secure.zip] zippy/flag.txt password:
 extracting: zippy/flag.txt

┌──(root㉿kali)-[/home/kali/下载/John-the-Ripper-The-Basics/Task09]
└─# cd zippy

┌──(root㉿kali)-[/home/…/下载/John-the-Ripper-The-Basics/Task09/zippy]
└─# ll
总计 4
-rw-r--r-- 1 root root 26 2020年11月10日 flag.txt

┌──(root㉿kali)-[/home/…/下载/John-the-Ripper-The-Basics/Task09/zippy]
└─# cat flag.txt
THM{w3ll_d0n3_h4sh_r0y4l}

破解ZIP文件-Rar2John

使用 rar2john 工具将 RAR 文件转换为 John 可以理解的哈希格式。基本语法如下:

rar2john [rar file] > [output file]
  • rar2john :调用 rar2john 工具
  • [rar file] : 要获取哈希值的 RAR 文件路径
  • > :将此命令的输出重定向到另一个文件
  • [output file] : 这是将存储命令输出的文件

示例

rar2john rarfile.rar > rar_hash.txt

实例

┌──(root㉿kali)-[/home/kali/下载/John-the-Ripper-The-Basics/Task10]
└─# rar2john secure.rar > hash.txt

┌──(root㉿kali)-[/home/kali/下载/John-the-Ripper-The-Basics/Task10]
└─# ls
hash.txt  secure.rar

┌──(root㉿kali)-[/home/kali/下载/John-the-Ripper-The-Basics/Task10]
└─# john --wordlist=/usr/share/wordlists/rockyou.txt hash.txt
Using default input encoding: UTF-8
Loaded 1 password hash (RAR5 [PBKDF2-SHA256 128/128 AVX 4x])
Cost 1 (iteration count) is 32768 for all loaded hashes
Will run 4 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
password         (secure.rar)
1g 0:00:00:00 DONE (2025-03-11 00:19) 5.882g/s 376.4p/s 376.4c/s 376.4C/s 123456..charlie
Use the "--show" option to display all of the cracked passwords reliably
Session completed.

┌──(root㉿kali)-[/home/kali/下载/John-the-Ripper-The-Basics/Task10]
└─# ls
hash.txt  secure.rar

┌──(root㉿kali)-[/home/kali/下载/John-the-Ripper-The-Basics/Task10]
└─# unrar x secure.rar

UNRAR 6.21 freeware      Copyright (c) 1993-2023 Alexander Roshal

Enter password (will not be echoed) for secure.rar:


Extracting from secure.rar

Extracting  flag.txt                                                  OK
All OK

┌──(root㉿kali)-[/home/kali/下载/John-the-Ripper-The-Basics/Task10]
└─# ls
flag.txt  hash.txt  secure.rar

┌──(root㉿kali)-[/home/kali/下载/John-the-Ripper-The-Basics/Task10]
└─# cat flag.txt
THM{r4r_4rch1ve5_th15_t1m3}

破解ssh密钥-SSH2John

破解访问私钥的密码,得到私钥通过ssh认证

ssh2john [id_rsa private key file] > [output file]
  • ssh2john :调用 ssh2john 工具
  • [id_rsa private key file] : 想要获取哈希值的 id_rsa 文件路径
  • > : 将输出重定向到另一个文件。
  • [output file] : 存储输出的文件

示例用法

ssh2john id_rsa > id_rsa_hash.txt

实例

┌──(root㉿kali)-[/home/kali/下载/John-the-Ripper-The-Basics/Task11]
└─# ssh2john id_rsa > id_rsahash.txt

┌──(root㉿kali)-[/home/kali/下载/John-the-Ripper-The-Basics/Task11]
└─# ls
id_rsa  id_rsahash.txt

┌──(root㉿kali)-[/home/kali/下载/John-the-Ripper-The-Basics/Task11]
└─# john --wordlist=/usr/share/wordlists/rockyou.txt id_rsahash.txt
Using default input encoding: UTF-8
Loaded 1 password hash (SSH, SSH private key [RSA/DSA/EC/OPENSSH 32/64])
Cost 1 (KDF/cipher [0=MD5/AES 1=MD5/3DES 2=Bcrypt/AES]) is 0 for all loaded hashes
Cost 2 (iteration count) is 1 for all loaded hashes
Will run 4 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
mango            (id_rsa)
1g 0:00:00:00 DONE (2025-03-11 00:29) 100.0g/s 432000p/s 432000c/s 432000C/s mango..doodles
Use the "--show" option to display all of the cracked passwords reliably
Session completed.
posted @ 2025-12-04 16:29  shinianyunyan  阅读(2)  评论(0)    收藏  举报