コンテンツにスキップ

基底と mixin

種別が決まったら、どのクラスを継承するかと、どの mixin を include(または prepend)するかを選びます。基底は「モジュールの種類」、mixin は「どうやって話すか / どう回すか」です。

class MetasploitModule < Msf::Exploit::Remote
# または Msf::Exploit::Local / Msf::Auxiliary / Msf::Post
end
やりたいこと基底
ネットワーク越しにペイロードを届けるMsf::Exploit::Remote
既存セッション上で local PE して新セッションMsf::Exploit::Local
セッションを開かず操作・列挙Msf::Auxiliary
既存セッション上で収集・管理Msf::Post

クラス名は現行では MetasploitModule です。

mixin は Ruby のモジュールを include して、メソッドと datastore オプションを足す仕組みです。自分で socket や HTTP クライアントを一から書かず、フレームワークの実装を借ります。

class MetasploitModule < Msf::Exploit::Remote
include Msf::Exploit::Remote::HttpClient
include Msf::Exploit::CmdStager
include Msf::Exploit::FileDropper
end

この例では次が足されます。

  • HttpClient → send_request_cgi、RHOST、RPORT、SSL など
  • CmdStager → execute_cmdstager(要 execute_command)
  • FileDropper → register_file_for_cleanup
  1. 通信手段(HTTP / TCP / SSH / SMB / 既存セッション)
  2. 実行モデル(単発 / 多ホスト scanner / 認証ブルート)
  3. 配信手段(CmdStager、HttpServer、FileDropper)
  4. 保存(Report は HttpClient に既に含まれることが多い)
通信mixin典型 API
HTTP(S) クライアントMsf::Exploit::Remote::HttpClientsend_request_cgi
素の TCPMsf::Exploit::Remote::Tcpconnect / sock
SSHMsf::Exploit::Remote::SSHSSH 接続ヘルパー
SMBMsf::Exploit::Remote::SMB::Client など共有・パイプ
罠 HTTP サーバMsf::Exploit::Remote::HttpServerブラウザ向け配信
既存セッション(Msf::Post 継承で Common/File など)cmd_exec / read_file

詳細ページ: HttpClient / Tcp / SSH / SMB / HttpServer / Post 用 mixin

モデルmixin入口
単一ホスト(なしでも可)run / exploit
多ホスト並列Msf::Auxiliary::Scannerrun_host(ip)
辞書ログインMsf::Auxiliary::AuthBrute認証ループ + LoginScanner
check を exploit 前に自動実行prepend Msf::Exploit::Remote::AutoCheckcheck 必須
class MetasploitModule < Msf::Exploit::Remote
Rank = ExcellentRanking
prepend Msf::Exploit::Remote::AutoCheck
include Msf::Exploit::Remote::HttpClient
include Msf::Exploit::CmdStager
include Msf::Exploit::FileDropper
end
class MetasploitModule < Msf::Auxiliary
include Msf::Exploit::Remote::HttpClient
include Msf::Auxiliary::Scanner
include Msf::Auxiliary::Report
end
class MetasploitModule < Msf::Post
include Msf::Post::File
include Msf::Post::Unix
include Msf::Auxiliary::Report
end
class MetasploitModule < Msf::Auxiliary
include Msf::Exploit::Remote::SSH
include Msf::Auxiliary::Scanner
include Msf::Auxiliary::AuthBrute
include Msf::Auxiliary::Report
end
  • Scanner なのに run だけ書いて run_host を書かない。
  • HttpClient が要るのに Tcp だけで HTTP を手組みする(保守が辛い)。
  • AutoCheck を include する(正しくは prepend)。
  • mixin が既に登録する RHOSTS / THREADS を二重登録する。

次は update_info で、msfconsole に見せるメタデータを書きます。