Post 用 mixin
post モジュール向け mixin は lib/msf/core/post/ にあります。Msf::Post を継承すると Common / File などが使える土台が入り、OS 別機能は追加で include します。同梱 wiki Post-Mixins.md も参照になります。
Common
Section titled “Common”include Msf::Post::Common
hostname = cmd_exec('hostname')out = create_process('grep', args: ['-r', 'password', '/var/www'], time_out: 30)home = get_env('HOME')envs = get_envs('HOME', 'USER', 'PATH')print_status('python3 ready') if command_exists?('python3')| メソッド | 用途 |
|---|---|
cmd_exec | コマンド文字列実行(簡易) |
create_process | 実行ファイル + 引数配列(推奨寄り) |
cmd_exec_with_result | 出力と成否 |
get_env / get_envs | 環境変数 |
command_exists? | コマンド有無 |
rhost / rport / peer | 対象表示用 |
include Msf::Post::File
cd('/tmp')print_status(pwd)entries = dir('/etc')
if file?('/etc/passwd') && readable?('/etc/passwd') data = read_file('/etc/passwd') store_loot('linux.passwd', 'text/plain', session, data, 'passwd')end
write_file('/tmp/out.txt', "hello\n")append_file('/tmp/out.txt', "world\n")upload_file('/tmp/tool', '/local/path/tool')upload_and_chmodx('/tmp/run.bin', File.binread('/local/run.bin'))rm_f('/tmp/out.txt')| メソッド | 用途 |
|---|---|
pwd / cd / dir (ls) | 移動・一覧 |
exist? / file? / directory? | 種別 |
readable? / writable? / executable? | 権限 |
read_file / write_file / append_file | 読み書き |
upload_file / upload_and_chmodx | アップロード |
rm_f / rm_rf / mkdir / rename_file / copy_file | 管理 |
expand_path | $HOME / %APPDATA% 展開 |
file_remote_digestmd5 など | ハッシュ |
Process / Unix / Windows
Section titled “Process / Unix / Windows”include Msf::Post::Processget_processes.each { |p| print_line("#{p['pid']} #{p['name']}") }kill_process(pid) if has_pid?(pid)include Msf::Post::Unixprint_good('root') if is_root?get_users.each { |u| print_line(u['name']) }include Msf::Post::Windows::Registryval = registry_getvaldata('HKLM\\SOFTWARE\\...', 'ProductName')Windows は lib/msf/core/post/windows/ に Registry、Accounts、Powershell、Services、LDAP などが分かれています。必要なものだけ include します。
| やりたいこと | 組み合わせ |
|---|---|
| 1 コマンド実行して表示 | Common: cmd_exec |
| 引数付き安全め実行 | Common: create_process |
| 設定ファイル回収 | File: readable? → read_file → store_loot |
| 一時バイナリ設置 | File: write_file / upload_and_chmodx + FileDropper |
| ユーザ一覧(Linux) | Unix: get_users / is_root? |
| レジストリ値(Windows) | Windows::Registry |
| プロセス終了 | Process: pidof / kill_process |
使用上の指針
Section titled “使用上の指針”- 静的な 1 行コマンドなら
cmd_exec、引数を分けたいならcreate_process。 - パスは OS 差を
expand_pathや絶対パスで吸収する。 - Meterpreter 専用機能(Railgun など)を使うなら
SessionTypesをmeterpreterに寄せ、session.typeを確認する。 - post 全体の組み立ては Post を参照。

