ロード・トゥ・ザ・ホワイトハッカー

ホワイトハッカーはじめました

どこからはじめるMetasploit

さて、どうしたらMetasploit使いになれるのか。

 

この辺りの本を読んでみても、若干情報が古いのか、イマイチ理解が進まない。

 

本家サイトでは、有料版のGUIの解説がメインで、Metasploit Frameworkについて記述は少ない。

docs.rapid7.com

 

 

Kaliのツール紹介ページにある、動画風デモを見ていると、流れがつかめて、とても分かりやすかった。

tools.kali.org

  

上記にリンクがあり、ここにたどり着く。必要な情報が網羅されている感じです。

www.offensive-security.com

 

まずは、この辺りで一通りMetasploitに馴染んでみることにする。

 

 

 動画風デモのコマンド詳細

 Metasploit Framework | Penetration Testing Tools (kali.org)

の動画風デモで使用されている各コマンドを調査。

 

msfconsole

コンソールを開くときに、DB接続のために、msfdb initをその前に叩く。

msfdb init & msfconsole
 

Usage: msfconsole [options]

Common options:

-E, --environment : ENVIRONMENT Set Rails environment, defaults to RAIL_ENV environment variable or 'production'

Database options:

-M, --migration-path : DIRECTORY Specify a directory containing additional DB migrations
-n, --no-database : Disable database support
-y, --yaml : PATH Specify a YAML file containing database settings

Framework options:

-c : FILE Load the specified configuration file
-v, -V, --version : Show version

Module options:

--defer-module-loads : Defer module loading unless explicitly asked
-m, --module-path : DIRECTORY Load an additional module path

Console options:

-a, --ask : Ask before exiting Metasploit or accept 'exit -y'
-H, --history-file : FILE Save command history to the specified file
-l, --logger : STRING Specify a logger to use (Flatfile, StdoutWithoutTimestamps, TimestampColorlessFlatfile, Stderr, Stdout)
-L, --real-readline : Use the system Readline library instead of RbReadline
-o, --output : FILE Output to the specified file
-p, --plugin : PLUGIN Load a plugin on startup
-q, --quiet : Do not print the banner on startup
-r, --resource F: ILE Execute the specified resource file (- for stdin)
-x, --execute-command : COMMAND Execute the specified console commands (use ; for multiples)
-h, --help : Show this message

 

 workspace -a msftest  

ワークスペースの追加 

【その他オプション】

(ブランク) : List workspaces
-v : List workspaces verbosely
[name] : Switch workspace
-a [name] : Add workspace(s)
-d [name] : Delete workspace(s)
-D : Delete all workspaces
-r : Rename workspace
-h : Show this help information

 

clear 

コンソールのクリア

【その他オプション】

-T : TERM use this instead of $TERM
-V : print curses-version
-x : do not try to clear scrollback

 

db_nmap -F 192.168.0.1-10

nmapで取得した結果をdbに格納する。

Usage: db_nmap [--save | [--help | -h]] [nmap options]

  

hosts

dbに格納されたホストの情報の一覧表示。

Usage: hosts [ options ] [addr1 addr2 ...]

【その他オプション】

-a,--add : Add the hosts instead of searching
-d,--delete : Delete the hosts instead of searching
-c <col1,col2> : Only show the given columns (see list below)
-C <col1,col2> : Only show the given columns until the next restart (see list below)
-h,--help : Show this help information
-u,--up : Only show hosts which are up
-o <file> : Send output to a file in csv format
-O <column> : Order rows by specified column number
-R,--rhosts : Set RHOSTS from the results of the search
-S,--search : Search string to filter by
-i,--info : Change the info of a host
-n,--name : Change the name of a host
-m,--comment : Change the comment of a host
-t,--tag : Add or specify a tag to a range of hosts

 

services

dbに格納されたサービスの利用状況の一覧表示。

 

Usage: services [-h] [-u] [-a] [-r <proto>] [-p <port1,port2>] [-s <name1,name2>] [-o <filename>] [addr1 addr2 ...]

【その他オプション】

-a,--add : Add the services instead of searching
-d,--delete : Delete the services instead of searching
-c <col1,col2> : Only show the given columns
-h,--help : Show this help information
-s <name> : Name of the service to add
-p <port> : Search for a list of ports
-r <protocol> : Protocol type of the service being added [tcp|udp]
-u,--up : Only show services which are up
-o <file> : Send output to a file in csv format
-O <column> : Order rows by specified column number
-R,--rhosts : Set RHOSTS from the results of the search
-S,--search : Search string to filter by
-U,--update : Update data for existing service

 

use auxiliary/scanner/ssh/ssh_version

使用するモジュールを指定する。

 

Usage: use <name|term|index>

Interact with a module by name or search term/index.
If a module name is not found, it will be treated as a search term.
An index from the previous search results can be selected if desired.

 

【モジュールの種類】 
  • auxiliary - ポートスキャンやバージョン検出、ネットワークトラフィックの解析など、攻撃者の様々な作業を補助するモジュール。
  • exploit - 脆弱性を利用して、バッファオーバーフローを起こしたり認証を迂回して、ペイロードの実行をできるようにするコード。
  • payload - リモート接続の確立や meterpreter セッションの開始、シェルコマンドの実行など、exploit が成功した後にすぐ実行すること。
  • post - exploit とリモート接続が成功した後に、パスワードを盗取したりキーロガーを設定、あるいはファイルをダウンロードするために実行する様々なプログラム。
  • encoder - 暗号化を実行するためのプログラム。
  • nop - NOP ジェネレータ。NOP は何もしないアセンブリ言語の命令です。この命令の機械語はハードウェアのアーキテクチャによって異なります。NOP 命令は実行可能ファイルの空白を埋めるのに有用です。

Metasploit Framework - ArchWiki から引用

 

options

 各モジュールの設定オプションを表示する。

 

services -u -p 22 -R

 -RでRHOSTSに対して22番ポートを使用しているものを設定する。

 

setg threads 10

グローバル変数に値をセットする。

 

通常の変数にはsetを使用する。

 Usage: set [option] [value]

Set the given option to value. If value is omitted, print the current value.
If both are omitted, print options that are currently set.

If run from a module context, this will set the value in the module's
datastore. Use -g to operate on the global datastore.

  

run

モジュールの実行

 

モジュール選択 ⇒ RHOST設定 ⇒実行

use auxiliary/scanner/http/http_version

services -u -p 80 -R

run

 

モジュール選択 ⇒ RHOST設定 ⇒実行

use auxiliary/scanner/smb/smb_version

services -u -p 445 -R

run

services 192.168.0.6

ホストのサービスを表示

 

search xampp

xamppに関するモジュールを検索する 


Usage: search [<options>] [<keywords>:<value>]

Prepending a value with '-' will exclude any matching results.
If no options or keywords are provided, cached results are displayed.

 

【その他オプション】

-h Show this help information
-o <file> Send output to a file in csv format
-S <string> Regex pattern used to filter search results
-u Use module if there is one result

 

Keywords:

aka : Modules with a matching AKA (also-known-as) name
author : Modules written by this author
arch : Modules affecting this architecture
bid : Modules with a matching Bugtraq ID
cve : Modules with a matching CVE ID
edb : Modules with a matching Exploit-DB ID
check : Modules that support the 'check' method
date : Modules with a matching disclosure date
description : Modules with a matching description
fullname : Modules with a matching full name
mod_time : Modules with a matching modification date
name : Modules with a matching descriptive name
path : Modules with a matching path
platform : Modules affecting this platform
port : Modules with a matching port
rank : Modules with a matching rank (Can be descriptive (ex: 'good') or numeric with comparison operators (ex: 'gte400'))
ref : Modules with a matching ref
reference : Modules with a matching reference
target : Modules affecting this target
type : Modules of a specific type (exploit, payload, auxiliary, encoder, evasion, post, or nop)

 

Examples:
search cve:2009 type:exploit
search cve:2009 type:exploit platform:-linux

 

show payloads

 ペイロードの表示

 

valid parameters for the "show" command are:

all, encoders, nops, exploits, payloads, auxiliary, post, plugins, info, options