Path: blob/master/modules/post/multi/gather/run_console_rc_file.rb
19721 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Post67def initialize(info = {})8super(9update_info(10info,11'Name' => 'Multi Gather Run Console Resource File',12'Description' => %q{13This module will read console commands from a resource file and14execute the commands in the specified Meterpreter session.15},16'License' => MSF_LICENSE,17'Author' => [ 'Carlos Perez <carlos_perez[at]darkoperator.com>'],18'Platform' => [ 'win' ],19'SessionTypes' => [ 'meterpreter' ],20'Notes' => {21'Stability' => [CRASH_SAFE],22'SideEffects' => [],23'Reliability' => []24}25)26)27register_options(28[29OptString.new('RESOURCE', [true, 'Full path to resource file to read commands from.', nil]),30]31)32end3334def run35if !::File.exist?(datastore['RESOURCE'])36raise 'Resource File does not exist!'37end3839hostname = sysinfo.nil? ? cmd_exec('hostname') : sysinfo['Computer']40print_status("Running module against #{hostname} (#{session.session_host})")4142::File.open(datastore['RESOURCE'], 'rb').each_line do |cmd|43next if cmd.strip.empty?44next if cmd.start_with?('#')4546begin47print_status "Running command #{cmd.chomp}"48session.console.run_single(cmd.chomp)49rescue StandardError => e50print_status("Error Running Command #{cmd.chomp}: #{e.class} #{e}")51end52end53end54end555657