【KALI LINUX】 John the Ripper ~パスワードクラッカー~


今日は「John the Ripper」というツールをご紹介したいと思います。

John the Ripperはオープンソースのパスワードクラッカーで、複数のアルゴリズムを使ってパスワードをブルートフォースすることができます。様々な種類のドキュメントやアーカイブのパスワードを解除したり、様々なリソースのシンプルなユーザーパスワードを解除することができます。Johnの欠点は、ハッシュをクラックすることしかできないことです。つまり、暗号化されたファイルを直接扱うことはできません。例えばオフィス文書を開き、そこにパスワードを入力するようなことはできません。

以下の例では、JohnがすでにインストールされているKali Linuxを使って説明します。インストールは以下のコマンドで行えます。

# sudo apt install john -y

例として、暗号化されたアーカイブのパスワードをクラックする方法を見てみましょう。

ハッシュ値の抽出

まず、問題のファイルのハッシュを計算(抽出)する必要があります。zip2johnと呼ばれる補助ユーティリティーを使います。

ここで、アーカイブがあるフォルダに移動します。

# cd (ファイルパス)

zip2johnを実行し、結果(抽出したハッシュ)をTest.txtという同じフォルダに保存します。

# zip2john Test.zip > Text.txt

異なるファイル形式からハッシュを抽出する場合は、補助ユーティリティの名称が変わります。いくつか例を挙げてみましょう。

rarファイルからハッシュを抽出する場合。

# rar2john Test.rar > Text.txt

7zアーカイブからハッシュを抽出する場合。

# 7z2john.pl '/mnt/disk_d/Arch/from_kali.7z'

MS Word 2019ファイルからハッシュを抽出する場合。

# office2john.py '/mnt/disk_d/Share/Secret.docx' 2>/dev/null

Wi-Fiハッキングのためのハンドシェイクからハッシュを抽出する場合。

# wpapcap2john ~/RT-725140.pcap

キャプチャしたネットワークトラフィックからVNCハンドシェイクのハッシュを抽出する場合。

# vncpcap2john '/home/mial/VNC.pcapng'

この抽出したText.txtファイルに対して、johnコマンドで解析を進めます。

ランニング

最も頻繁に使われるオプションとしては、--mask(パスワードを生成するためのマスク)と--wordlist(辞書ファイルの指定)が挙げられます。

辞書ファイルを用いた解析を行うには、辞書が必要です。Kali Linuxにはseclistsと呼ばれるパッケージが用意されているのでインストールします。

# sudo apt install seclists -y

/usr/share/seclists/ 配下にファイルが展開されます。

辞書攻撃を行うには、次のようなコマンドを実行します。
john --wordlist=(辞書ファイル)

辞書として、/usr/share/seclists/Passwords/rockyou.txtファイルを使う場合、コマンドは以下のようになります。

john --wordlist=/usr/share/seclists/Passwords/rockyou.txt Text.txt

実行結果の例は以下となり、pass123がパスワードであることが分かります。

# sudo john --wordlist=/usr/share/seclists/Passwords/rockyou.txt Text.txt
Using default input encoding: UTF-8
Loaded 1 password hash (PKZIP [32/64])
Will run 8 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
pass123          (secure_1605054835063.zip/zippy/flag.txt)
1g 0:00:00:00 DONE (2024-07-26 21:44) 8.333g/s 136533p/s 136533c/s 136533C/s 123456..christal
Use the "--show" option to display all of the cracked passwords reliably
Session completed.

マスク攻撃を行うには、次のような形式のコマンドを使用します。

./john --mask=(マスクハッシュ)

例えば、こんな感じです。

./john --mask='?d?d?d?d?d?d' Text.txt

マスク別にパスワードを把握するためのちょっとしたメモをご紹介します。

Static Characters.
Ranges in the syntax [aouei] or [a-z]. Or both, [0-9abcdef] is the same as [0-9a-f].
Fillers that are just an abbreviated form for ranges, such as ?l, which is 100% equivalent to [a-z].
?l is lowercase ASCII letters
?u are ASCII uppercase letters.
?d are numbers
?s are special characters (all printable ASCII characters except those included in ?l, ?u, or ?d)
?a is full "printable" ASCII. Note that for formats that are not case-sensitive (e.g., LM), this designation includes only lowercase characters, which significantly reduces the key space (the number of possible password candidates), but still covers all possible variants available for a given hash type.
?B is all 8-bit (0x80-0xff)
?b is all (0x01-0xff) (the NULL character is currently not supported by the kernel).
?h are lowercase hexadecimal digits (0-9, a-f)
?H are upper case HEX digits (0-9, A-F)
?L are lowercase, non-ASCII letters
?U are uppercase letters, non-ASCII
?D are "numbers", non-ASCII
?S is for non-ASCII "special characters"
?A is all valid characters in the current code page (including ASCII). Note that for formats that do not recognize case (e.g. LM), this includes only lowercase characters, which greatly reduces the number of password candidates without compromising cracking.
Fillers that are user-defined, so we can, for example, set the value to ?1 and assign it a value, such as [?u?l]. In Hashcat, this is called "user-defined character sets".
?1 .. ?9 is a user-defined placeholder 1 . 9
Fillers for hybrid mask mode:
?w is in Hybrid Mask Mode denotes the source word created by the parent mode.
?W is like ?w except that the source word is case-sensitive (so PassWord becomes PASSWORD).

今回は、John the Ripperの用途の一つをざっと見てみましたが、決してそれだけではありません。

LinuxでJohnを使えない場合は、開発者が気を利かせて、WindowsやMacOSで使える可能性を加えてくれましたが、これはお勧めできません。興味のある方は、インターネット上にたくさんのガイドや記事があります。

以上、ここから先は誠意を持って対応してください この記事がどなたかのお役に立てれば幸いです。

出典:Брутфорс - John the Ripper

出典:John The Ripper