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/scripts/meterpreter/multi_console_command.rb
Views: 11766
##1# WARNING: Metasploit no longer maintains or accepts meterpreter scripts.2# If you'd like to improve this script, please try to port it as a post3# module instead. Thank you.4##567#8# Meterpreter script for running multiple console commands on a meterpreter session9# Provided by Carlos Perez at carlos_perez[at]darkoperator[dot]com10# Version: 0.111#1213################## Variable Declarations ##################14@client = client1516# Setting Arguments17@@exec_opts = Rex::Parser::Arguments.new(18"-h" => [ false,"Help menu." ],19"-s" => [ false,"Hide commands output for work in background sessions"],20"-c" => [ true,"Commands to execute. The command must be enclosed in double quotes and separated by a comma."],21"-r" => [ true,"Text file with list of commands, one per line."]22)2324commands = nil25script = []26help = false27silence = false2829def usage30print_line("Console Multi Command Execution Meterpreter Script ")31print_line(@@exec_opts.usage)32raise Rex::Script::Completed33end3435@@exec_opts.parse(args) { |opt, idx, val|36case opt3738when "-c"39commands = val.split(",")40when "-r"41script = val42if not ::File.exist?(script)43raise "Command List File does not exist!"44else45commands = []46::File.open(script, "r").each_line do |line|47commands << line.chomp48end49end5051when "-h"52help = true53when "-s"54silence = true55end56}5758if args.length == 0 or help or commands.nil?59usage60end6162print_status("Running Command List ...")6364commands.each do |cmd|65next if cmd.strip.length < 166next if cmd[0,1] == "#"67begin68print_status "\tRunning command #{cmd}"69if silence70@client.console.disable_output = true71end7273@client.console.run_single(cmd)7475if silence76@client.console.disable_output = false77end7879rescue ::Exception => e80print_status("Error Running Command #{cmd}: #{e.class} #{e}")81end82end838485