Mixins for post modules live under lib/msf/core/post/. Inheriting from Msf::Post provides the foundation for Common and File functionality; include OS-specific features separately. The bundled wiki page Post-Mixins.md is another reference.
include Msf :: Post :: Common
hostname = cmd_exec ( ' hostname ' )
out = create_process ( ' grep ' , args: [ ' -r ' , ' password ' , ' /var/www ' ] , time_out: 30 )
envs = get_envs ( ' HOME ' , ' USER ' , ' PATH ' )
print_status ( ' python3 ready ' ) if command_exists? ( ' python3 ' )
Method Purpose cmd_execRun a command string (simple) create_processRun an executable with an argument array (often preferable) cmd_exec_with_resultOutput and success status get_env / get_envsEnvironment variables command_exists?Check whether a command exists rhost / rport / peerDisplay target information
if file? ( ' /etc/passwd ' ) && readable? ( ' /etc/passwd ' )
data = read_file ( ' /etc/passwd ' )
store_loot ( ' linux.passwd ' , ' text/plain ' , session , data , ' passwd ' )
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 ' ))
Method Purpose pwd / cd / dir (ls)Navigate and list exist? / file? / directory?File type readable? / writable? / executable?Permissions read_file / write_file / append_fileRead and write files upload_file / upload_and_chmodxUpload files rm_f / rm_rf / mkdir / rename_file / copy_fileManage files and directories expand_pathExpand $HOME or %APPDATA% file_remote_digestmd5 and othersHash files
include Msf :: Post :: Process
get_processes . each { | p | print_line ( " #{ p [ ' pid ' ] } #{ p [ ' name ' ] } " ) }
kill_process ( pid ) if has_pid? ( pid )
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-specific functionality is split into Registry, Accounts, Powershell, Services, LDAP, and others under lib/msf/core/post/windows/. Include only what you need.
Task Combination Run and display one command Common: cmd_exec Run with separate arguments Common: create_process Collect a configuration file File: readable? → read_file → store_loot Place a temporary binary File: write_file / upload_and_chmodx + FileDropper List users on Linux Unix: get_users / is_root? Read a Windows registry value Windows::Registry Stop a process Process: pidof / kill_process
Use cmd_exec for a static one-line command; use create_process when arguments should be separate.
Handle OS path differences with expand_path or absolute paths.
For Meterpreter-only features such as Railgun, limit SessionTypes to meterpreter and check session.type.
For the full structure of a post module, see Post .