Scanner
Msf::Auxiliary::Scanner は多ホスト走査とスレッド実行を提供します。実装は lib/msf/core/auxiliary/scanner.rb です。
include
Section titled “include”include Msf::Auxiliary::Scanner追加される主なオプションです。
| オプション | 意味 |
|---|---|
RHOSTS | 対象レンジ |
THREADS | 並列数 |
ShowProgress | 進捗表示 |
ShowProgressPercent | 進捗割合 |
実装するメソッド
Section titled “実装するメソッド”def run_host(ip) # ip ごとに呼ばれるend通常の run は mixin が持ち、内部で host ごとに replicant を回します。「1 インスタンスだけ」と思わない方が正確です。
class MetasploitModule < Msf::Auxiliary include Msf::Exploit::Remote::Tcp include Msf::Auxiliary::Scanner include Msf::Auxiliary::Report
def initialize(info = {}) super( update_info( info, 'Name' => 'Example TCP Banner Scanner', 'Description' => 'Grab a banner', 'Author' => ['you'], 'License' => MSF_LICENSE ) ) register_options([Opt::RPORT(21)]) end
def run_host(ip) connect banner = sock.get_once(1024, 5).to_s print_good("#{ip}:#{rport} #{banner.strip}") unless banner.empty? report_service(host: ip, port: rport, name: 'ftp', info: banner.strip) rescue Rex::ConnectionError vprint_error("#{ip}:#{rport} unreachable") ensure disconnect endenduse auxiliary/scanner/http/http_versionset RHOSTS 10.10.11.1-50set THREADS 8runrunとrun_hostを自分で二重定義しない。- 共有状態(クラス変数など)はスレッド間で危険。host 固有の状態はローカル変数へ。
- 致命的エラーで全体を止めたいときは mixin の
fail_with(..., abort: true)系を確認する。

