Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/msf/ui/console/command_dispatcher/post.rb
Views: 11784
# -*- coding: binary -*-1module Msf2module Ui3module Console4module CommandDispatcher56###7#8# Recon module command dispatcher.9#10###11class Post1213include Msf::Ui::Console::ModuleCommandDispatcher14include Msf::Ui::Console::ModuleActionCommands15include Msf::Ui::Console::ModuleOptionTabCompletion16include Msf::Ui::Console::ModuleArgumentParsing1718#19# Returns the hash of commands specific to post modules.20#21def commands22super.merge({23"run" => "Launches the post exploitation module",24"rerun" => "Reloads and launches the module",25"exploit" => "This is an alias for the run command",26"rexploit" => "This is an alias for the rerun command",27}).merge( (mod ? mod.post_commands : {}) )28end2930#31#32# Returns the command dispatcher name.33#34def name35"Post"36end3738#39# This is an alias for 'rerun'40#41def cmd_rexploit(*args)42cmd_rerun(*args)43end4445#46# Reloads a post module and executes it47#48def cmd_rerun(*args)49opts = {}50if args.include?('-r') || args.include?('--reload-libs')51driver.run_single('reload_lib -a')52opts[:previously_reloaded] = true53end5455# Stop existing job and reload the module56if reload(true)57cmd_run(*args, opts: opts)58end59end6061alias cmd_rexploit cmd_rerun6263def cmd_run_help64print_module_run_or_check_usage(65command: :run,66description: 'Launches a post exploitation module.'67)68end6970#71# Executes a post module72#73def cmd_run(*args, action: nil, opts: {})74if (args.include?('-r') || args.include?('--reload-libs')) && !opts[:previously_reloaded]75driver.run_single('reload_lib -a')76end7778return false unless (args = parse_run_opts(args, action: action))79jobify = args[:jobify]8081# Always run passive modules in the background82if (mod.passive)83jobify = true84end8586begin87mod.run_simple(88'Action' => args[:action],89'Options' => args[:datastore_options],90'LocalInput' => driver.input,91'LocalOutput' => driver.output,92'RunAsJob' => jobify,93'Quiet' => args[:quiet]94)95rescue ::Timeout::Error96print_error("Post triggered a timeout exception")97rescue ::Interrupt98print_error("Post interrupted by the console user")99rescue ::Exception => e100print_error("Post failed: #{e.class} #{e}")101if (e.class.to_s != 'Msf::OptionValidateError')102print_error("Call stack:")103e.backtrace.each do |line|104break if line =~ /lib.msf.base.simple/105print_error(" #{line}")106end107end108109return false110end111112if (jobify && mod.job_id)113print_status("Post module running as background job #{mod.job_id}.")114else115print_status("Post module execution completed")116end117end118119alias cmd_exploit cmd_run120121alias cmd_exploit_tabs cmd_run_tabs122123def cmd_run_help124print_line "Usage: run [options]"125print_line126print_line "Launches a post module."127print @@module_opts_with_action_support.usage128end129130alias cmd_exploit_help cmd_run_help131132end133134end end end end135136137138