基底と mixin
種別が決まったら、どのクラスを継承するかと、どの mixin を include(または prepend)するかを選びます。基底は「モジュールの種類」、mixin は「どうやって話すか / どう回すか」です。
class MetasploitModule < Msf::Exploit::Remote # または Msf::Exploit::Local / Msf::Auxiliary / Msf::Postend| やりたいこと | 基底 |
|---|---|
| ネットワーク越しにペイロードを届ける | Msf::Exploit::Remote |
| 既存セッション上で local PE して新セッション | Msf::Exploit::Local |
| セッションを開かず操作・列挙 | Msf::Auxiliary |
| 既存セッション上で収集・管理 | Msf::Post |
クラス名は現行では MetasploitModule です。
mixin とは何か
Section titled “mixin とは何か”mixin は Ruby のモジュールを include して、メソッドと datastore オプションを足す仕組みです。自分で socket や HTTP クライアントを一から書かず、フレームワークの実装を借ります。
class MetasploitModule < Msf::Exploit::Remote include Msf::Exploit::Remote::HttpClient include Msf::Exploit::CmdStager include Msf::Exploit::FileDropperendこの例では次が足されます。
- HttpClient →
send_request_cgi、RHOST、RPORT、SSLなど - CmdStager →
execute_cmdstager(要execute_command) - FileDropper →
register_file_for_cleanup
選び方の順番
Section titled “選び方の順番”- 通信手段(HTTP / TCP / SSH / SMB / 既存セッション)
- 実行モデル(単発 / 多ホスト scanner / 認証ブルート)
- 配信手段(CmdStager、HttpServer、FileDropper)
- 保存(Report は HttpClient に既に含まれることが多い)
通信手段の対応表
Section titled “通信手段の対応表”| 通信 | mixin | 典型 API |
|---|---|---|
| HTTP(S) クライアント | Msf::Exploit::Remote::HttpClient | send_request_cgi |
| 素の TCP | Msf::Exploit::Remote::Tcp | connect / sock |
| SSH | Msf::Exploit::Remote::SSH | SSH 接続ヘルパー |
| SMB | Msf::Exploit::Remote::SMB::Client など | 共有・パイプ |
| 罠 HTTP サーバ | Msf::Exploit::Remote::HttpServer | ブラウザ向け配信 |
| 既存セッション | (Msf::Post 継承で Common/File など) | cmd_exec / read_file |
詳細ページ: HttpClient / Tcp / SSH / SMB / HttpServer / Post 用 mixin
実行モデルの対応表
Section titled “実行モデルの対応表”| モデル | mixin | 入口 |
|---|---|---|
| 単一ホスト | (なしでも可) | run / exploit |
| 多ホスト並列 | Msf::Auxiliary::Scanner | run_host(ip) |
| 辞書ログイン | Msf::Auxiliary::AuthBrute | 認証ループ + LoginScanner |
| check を exploit 前に自動実行 | prepend Msf::Exploit::Remote::AutoCheck | check 必須 |
組み合わせ例
Section titled “組み合わせ例”HTTP RCE exploit
Section titled “HTTP RCE exploit”class MetasploitModule < Msf::Exploit::Remote Rank = ExcellentRanking prepend Msf::Exploit::Remote::AutoCheck include Msf::Exploit::Remote::HttpClient include Msf::Exploit::CmdStager include Msf::Exploit::FileDropperendHTTP banner scanner
Section titled “HTTP banner scanner”class MetasploitModule < Msf::Auxiliary include Msf::Exploit::Remote::HttpClient include Msf::Auxiliary::Scanner include Msf::Auxiliary::ReportendLinux post gather
Section titled “Linux post gather”class MetasploitModule < Msf::Post include Msf::Post::File include Msf::Post::Unix include Msf::Auxiliary::ReportendSSH ログイン試行
Section titled “SSH ログイン試行”class MetasploitModule < Msf::Auxiliary include Msf::Exploit::Remote::SSH include Msf::Auxiliary::Scanner include Msf::Auxiliary::AuthBrute include Msf::Auxiliary::Reportendやってはいけないこと
Section titled “やってはいけないこと”- Scanner なのに
runだけ書いてrun_hostを書かない。 - HttpClient が要るのに Tcp だけで HTTP を手組みする(保守が辛い)。
- AutoCheck を
includeする(正しくはprepend)。 - mixin が既に登録する
RHOSTS/THREADSを二重登録する。
次は update_info で、msfconsole に見せるメタデータを書きます。

