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/evasion.rb
Views: 11788
module Msf1module Ui2module Console3module CommandDispatcher4class Evasion56include Msf::Ui::Console::ModuleCommandDispatcher7include Msf::Ui::Console::ModuleOptionTabCompletion89def commands10super.update({11'run' => 'Launches the evasion module',12'rerun' => 'Reloads and launches the evasion module',13'exploit' => 'This is an alias for the run command',14'rexploit' => 'This is an alias for the rerun command',15'reload' => 'Reloads the auxiliary module',16'to_handler' => 'Creates a handler with the specified payload'17}).merge(mod ? mod.evasion_commands : {})18end1920def name21'Evasion'22end2324def cmd_run(*args, opts: {})25if (args.include?('-r') || args.include?('--reload-libs')) && !opts[:previously_reloaded]26driver.run_single('reload_lib -a')27end2829module_opts = {30'Encoder' => mod.datastore['ENCODER'],31'Payload' => mod.datastore['PAYLOAD'],32'Nop' => mod.datastore['NOP'],33'LocalInput' => driver.input,34'LocalOutput' => driver.output35}3637begin38mod.run_simple(module_opts)39rescue ::Interrupt40print_error('Evasion interrupted by the console user')41rescue ::Exception => e42print_error("Evasion failed: #{e.class} #{e}")43elog('Evasion Failed', error: e)44end45end4647alias cmd_exploit cmd_run4849def cmd_rerun(*args)50opts = {}51if args.include?('-r') || args.include?('--reload-libs')52driver.run_single('reload_lib -a')53opts[:previously_reloaded] = true54end5556if reload(true)57cmd_run(*args, opts: opts)58end59end6061alias cmd_rexploit cmd_rerun6263#64# Tab completion for the run command65#66def cmd_run_tabs(str, words)67fmt = {68'-e' => [ framework.encoders.module_refnames ],69'-f' => [ nil ],70'-h' => [ nil ],71'-j' => [ nil ],72'-J' => [ nil ],73'-n' => [ framework.nops.module_refnames ],74'-o' => [ true ],75'-p' => [ framework.payloads.module_refnames ],76'-r' => [ nil ],77'-t' => [ true ],78'-z' => [ nil ]79}80flags = tab_complete_generic(fmt, str, words)81options = tab_complete_option(active_module, str, words)82flags + options83end8485#86# Tab completion for the exploit command87#88alias cmd_exploit_tabs cmd_run_tabs8990def cmd_to_handler(*args)91if args.include?('-r') || args.include?('--reload-libs')92driver.run_single('reload_lib -a')93end9495handler = framework.modules.create('exploit/multi/handler')9697handler_opts = {98'Payload' => mod.datastore['PAYLOAD'],99'LocalInput' => driver.input,100'LocalOutput' => driver.output,101'RunAsJob' => true,102'Options' => {103'ExitOnSession' => false,104}105}106107handler.share_datastore(mod.datastore)108109replicant_handler = nil110handler.exploit_simple(handler_opts) do |yielded_replicant_handler|111replicant_handler = yielded_replicant_handler112end113114if replicant_handler.nil?115print_error('Failed to run module')116return117end118119if replicant_handler.error.nil?120job_id = handler.job_id121122print_status "Payload Handler Started as Job #{job_id}"123end124end125end126end127end128end129end130131132