Security Record

セキュリティ全般に関する情報を発信しています

John the Ripperを使用したパスワードクラックの手順

※注意 こちらで紹介した内容を外部サーバーに対して実行した場合、場合によっては刑法にて処罰されます。 実験を行う場合は必ずローカル環境にテスト用のサーバーを構築して実行してください。

John the Ripperを使用したパスワードクラックの方法

John the Ripperはパスワードクラックツールです。
非常に多種多様なパスワードクラックに対応しています。
今回は、またMetasploitable2のパスワードをクラックしてみようと思います。

Kali Linux :192.168.28.3
Metasploitable2:192.168.28.4

Kali LinuxからMetasploitable2にtelnet接続をする

Metasploitable2への接続はHydraを使用した辞書攻撃によりすでに破られている前提となりますが、以下のユーザー名、パスワードを使用してMetasploitable2にtelnet接続をします。

login: msfadmin
password: msfadmin

┌──(root㉿kali)-[~]
└─# telnet 192.168.28.4 23
Trying 192.168.28.4...
Connected to 192.168.28.4.
Escape character is '^]'.
                _                  _       _ _        _     _      ____  
 _ __ ___   ___| |_ __ _ ___ _ __ | | ___ (_) |_ __ _| |__ | | ___|___ \ 
| '_ ` _ \ / _ \ __/ _` / __| '_ \| |/ _ \| | __/ _` | '_ \| |/ _ \ __) |
| | | | | |  __/ || (_| \__ \ |_) | | (_) | | || (_| | |_) | |  __// __/ 
|_| |_| |_|\___|\__\__,_|___/ .__/|_|\___/|_|\__\__,_|_.__/|_|\___|_____|
                            |_|                                          


Warning: Never expose this VM to an untrusted network!

Contact: msfdev[at]metasploit.com

Login with msfadmin/msfadmin to get started


metasploitable login: msfadmin
Password: 

Metasploitable2でroot権限になり/etc/passwdファイルを開く

msfadmin@metasploitable:~$ sudo su

root@metasploitable:/home/msfadmin# whoami
root

whoamiコマンドを実行するとMetasploitable2のroot権限が獲得できていることが分かります。

root@metasploitable:/home/msfadmin# cat /etc/passwd

root権限のまま、/etc/passwdcatコマンドで開きます。

root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/bin/sh
bin:x:2:2:bin:/bin:/bin/sh
sys:x:3:3:sys:/dev:/bin/sh
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/bin/sh
man:x:6:12:man:/var/cache/man:/bin/sh
lp:x:7:7:lp:/var/spool/lpd:/bin/sh
mail:x:8:8:mail:/var/mail:/bin/sh
news:x:9:9:news:/var/spool/news:/bin/sh
uucp:x:10:10:uucp:/var/spool/uucp:/bin/sh
proxy:x:13:13:proxy:/bin:/bin/sh
www-data:x:33:33:www-data:/var/www:/bin/sh
backup:x:34:34:backup:/var/backups:/bin/sh
list:x:38:38:Mailing List Manager:/var/list:/bin/sh
irc:x:39:39:ircd:/var/run/ircd:/bin/sh
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/bin/sh
nobody:x:65534:65534:nobody:/nonexistent:/bin/sh
libuuid:x:100:101::/var/lib/libuuid:/bin/sh
dhcp:x:101:102::/nonexistent:/bin/false
syslog:x:102:103::/home/syslog:/bin/false
klog:x:103:104::/home/klog:/bin/false
sshd:x:104:65534::/var/run/sshd:/usr/sbin/nologin
msfadmin:x:1000:1000:msfadmin,,,:/home/msfadmin:/bin/bash
bind:x:105:113::/var/cache/bind:/bin/false
postfix:x:106:115::/var/spool/postfix:/bin/false
ftp:x:107:65534::/home/ftp:/bin/false
postgres:x:108:117:PostgreSQL administrator,,,:/var/lib/postgresql:/bin/bash
mysql:x:109:118:MySQL Server,,,:/var/lib/mysql:/bin/false
tomcat55:x:110:65534::/usr/share/tomcat5.5:/bin/false
distccd:x:111:65534::/:/bin/false
user:x:1001:1001:just a user,111,,:/home/user:/bin/bash
service:x:1002:1002:,,,:/home/service:/bin/bash
telnetd:x:112:120::/nonexistent:/bin/false
proftpd:x:113:65534::/var/run/proftpd:/bin/false
statd:x:114:65534::/var/lib/nfs:/bin/false

上記のような内容がcatコマンド実行後に表示されるかと思います。
この内容は後ほど使用するのでクリップボードなどにコピーしておきます。

Kali Linuxでpasswd.txtファイルを作成する

┌──(root㉿kali)-[/home/kali]
└─# vim passwd.txt

vimコマンドでpasswd.txtファイルを作成して、そこに先程クリップボードにコピーしたMetasploitable2/etc/passwdの内容を貼り付けます。

Metasploitable2でroot権限になり/etc/shadowファイルを開く

root@metasploitable:/home/msfadmin# cat /etc/shadow

次にcatコマンドを実行して/etc/shadowのファイルを開きます。

root:$1$/avpfBJ1$x0z8w5UF9Iv./DR9E9Lid.:14747:0:99999:7:::
daemon:*:14684:0:99999:7:::
bin:*:14684:0:99999:7:::
sys:$1$fUX6BPOt$Miyc3UpOzQJqz4s5wFD9l0:14742:0:99999:7:::
sync:*:14684:0:99999:7:::
games:*:14684:0:99999:7:::
man:*:14684:0:99999:7:::
lp:*:14684:0:99999:7:::
mail:*:14684:0:99999:7:::
news:*:14684:0:99999:7:::
uucp:*:14684:0:99999:7:::
proxy:*:14684:0:99999:7:::
www-data:*:14684:0:99999:7:::
backup:*:14684:0:99999:7:::
list:*:14684:0:99999:7:::
irc:*:14684:0:99999:7:::
gnats:*:14684:0:99999:7:::
nobody:*:14684:0:99999:7:::
libuuid:!:14684:0:99999:7:::
dhcp:*:14684:0:99999:7:::
syslog:*:14684:0:99999:7:::
klog:$1$f2ZVMS4K$R9XkI.CmLdHhdUE3X9jqP0:14742:0:99999:7:::
sshd:*:14684:0:99999:7:::
msfadmin:$1$XN10Zj2c$Rt/zzCW3mLtUWA.ihZjA5/:14684:0:99999:7:::
bind:*:14685:0:99999:7:::
postfix:*:14685:0:99999:7:::
ftp:*:14685:0:99999:7:::
postgres:$1$Rw35ik.x$MgQgZUuO5pAoUvfJhfcYe/:14685:0:99999:7:::
mysql:!:14685:0:99999:7:::
tomcat55:*:14691:0:99999:7:::
distccd:*:14698:0:99999:7:::
user:$1$HESu9xrH$k.o3G93DGoXIiQKkPmUgZ0:14699:0:99999:7:::
service:$1$kR3ue7JZ$7GxELDupr5Ohp6cjZ3Bu//:14715:0:99999:7:::
telnetd:*:14715:0:99999:7:::
proftpd:!:14727:0:99999:7:::
statd:*:15474:0:99999:7:::

そうすると、上記のような内容が表示されるかと思います。
/etc/shadowファイルの内容も後で使用するのでクリップボードにコピーしておきます。

Kali Linuxでshadow.txtファイルを作成する

┌──(root㉿kali)-[/home/kali]
└─# vim shadow.txt  

vimでshadow.txtファイルを作成して、クリップボードにコピーしておいた/etc/shadowファイルの内容を内容を貼り付けます。

┌──(root㉿kali)-[/home/kali]
└─# unshadow passwd.txt shadow.txt > passwd.db
Created directory: /root/.john

unshadowコマンドを実行します。
その際に先程クリップボードからコピーして作成した、 passwd.txtshadow.txtを指定してpasswd.dbファイルを出力するように指定します。

┌──(root㉿kali)-[/home/kali]
└─# john passwd.db 
Warning: detected hash type "md5crypt", but the string is also recognized as "md5crypt-long"
Use the "--format=md5crypt-long" option to force loading these as that type instead
Using default input encoding: UTF-8
Loaded 7 password hashes with 7 different salts (md5crypt, crypt(3) $1$ (and variants) [MD5 128/128 SSE2 4x3])
Will run 4 OpenMP threads
Proceeding with single, rules:Single
Press 'q' or Ctrl-C to abort, almost any other key for status
user             (user)     
postgres         (postgres)     
msfadmin         (msfadmin)     
service          (service)     
Almost done: Processing the remaining buffered candidate passwords, if any.
Proceeding with wordlist:/usr/share/john/password.lst
123456789        (klog)     
batman           (sys)     
Proceeding with incremental:ASCII
6g 0:00:02:11  3/3 0.04560g/s 74957p/s 74960c/s 74960C/s klakel..klazy3
Use the "--show" option to display all of the cracked passwords reliably
Session aborted

John the Ripperjohnコマンドで実行します。
その際、unshadowコマンドで作成したpasswd.dbファイルを指定します。
実行後、ユーザー名、パスワードが取得出来ているのがわかります。

取得したユーザー名とパスワードでMetasploitable2に接続できるか確認する

┌──(root㉿kali)-[/home/kali]
└─# telnet 192.168.28.4                          
Trying 192.168.28.4...
Connected to 192.168.28.4.
Escape character is '^]'.
                _                  _       _ _        _     _      ____  
 _ __ ___   ___| |_ __ _ ___ _ __ | | ___ (_) |_ __ _| |__ | | ___|___ \ 
| '_ ` _ \ / _ \ __/ _` / __| '_ \| |/ _ \| | __/ _` | '_ \| |/ _ \ __) |
| | | | | |  __/ || (_| \__ \ |_) | | (_) | | || (_| | |_) | |  __// __/ 
|_| |_| |_|\___|\__\__,_|___/ .__/|_|\___/|_|\__\__,_|_.__/|_|\___|_____|
                            |_|                                          


Warning: Never expose this VM to an untrusted network!

Contact: msfdev[at]metasploit.com

Login with msfadmin/msfadmin to get started


metasploitable login: user
Password: (user)
Linux metasploitable 2.6.24-16-server #1 SMP Thu Apr 10 13:58:00 UTC 2008 i686

The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

To access official Ubuntu documentation, please visit:
http://help.ubuntu.com/
user@metasploitable:~$ exit
logout
Connection closed by foreign host.

無事に接続出来たことが分かります。

他のユーザー名でもログイン出来るか確認する

┌──(root㉿kali)-[/home/kali]
└─# telnet 192.168.28.4 23  
Trying 192.168.28.4...
Connected to 192.168.28.4.
Escape character is '^]'.
                _                  _       _ _        _     _      ____  
 _ __ ___   ___| |_ __ _ ___ _ __ | | ___ (_) |_ __ _| |__ | | ___|___ \ 
| '_ ` _ \ / _ \ __/ _` / __| '_ \| |/ _ \| | __/ _` | '_ \| |/ _ \ __) |
| | | | | |  __/ || (_| \__ \ |_) | | (_) | | || (_| | |_) | |  __// __/ 
|_| |_| |_|\___|\__\__,_|___/ .__/|_|\___/|_|\__\__,_|_.__/|_|\___|_____|
                            |_|                                          


Warning: Never expose this VM to an untrusted network!

Contact: msfdev[at]metasploit.com

Login with msfadmin/msfadmin to get started


metasploitable login: postgres
Password: 
Linux metasploitable 2.6.24-16-server #1 SMP Thu Apr 10 13:58:00 UTC 2008 i686

The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

To access official Ubuntu documentation, please visit:
http://help.ubuntu.com/
postgres@metasploitable:~$ 

Hydraの辞書攻撃の際には取得出来なかったpostgresユーザーでも問題なくtelnetで接続できました。

そもそも/etc/shadowとは何なのか?

元々、パスワードは /etc/passwdファイルに記述されていましたが、/etc/passwdファイルはシステムのユーザであれば誰でも読み取りができてしまうという問題がありました。

そこで、パスワードを/etc/shadowファイルに格納し、/etc/passwdファイルにはパスワードを記述しないという形をとるようになったようです。

/etc/shadowファイルはroot権限以外は読みとることができないようになっており、一般ユーザでは参照できないように設定されているようです。

参考