コンテンツにスキップ

Post 用 mixin

post モジュール向け mixin は lib/msf/core/post/ にあります。Msf::Post を継承すると Common / File などが使える土台が入り、OS 別機能は追加で include します。同梱 wiki Post-Mixins.md も参照になります。

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 などハッシュ
include Msf::Post::Process
get_processes.each { |p| print_line("#{p['pid']} #{p['name']}") }
kill_process(pid) if has_pid?(pid)
include Msf::Post::Unix
print_good('root') if is_root?
get_users.each { |u| print_line(u['name']) }
include Msf::Post::Windows::Registry
val = 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
  • 静的な 1 行コマンドなら cmd_exec、引数を分けたいなら create_process。
  • パスは OS 差を expand_path や絶対パスで吸収する。
  • Meterpreter 専用機能(Railgun など)を使うなら SessionTypes を meterpreter に寄せ、session.type を確認する。
  • post 全体の組み立ては Post を参照。