コンテンツにスキップ

Msf::Auxiliary::Scanner は多ホスト走査とスレッド実行を提供します。実装は lib/msf/core/auxiliary/scanner.rb です。

include Msf::Auxiliary::Scanner

追加される主なオプションです。

オプション意味
RHOSTS対象レンジ
THREADS並列数
ShowProgress進捗表示
ShowProgressPercent進捗割合
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
end
end
use auxiliary/scanner/http/http_version
set RHOSTS 10.10.11.1-50
set THREADS 8
run
  • run と run_host を自分で二重定義しない。
  • 共有状態(クラス変数など)はスレッド間で危険。host 固有の状態はローカル変数へ。
  • 致命的エラーで全体を止めたいときは mixin の fail_with(..., abort: true) 系を確認する。