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/manage/multi_post.rb
Views: 11784
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Post6include Msf::Post::File78def initialize(info = {})9super(10update_info(11info,12'Name' => 'Multi Manage Post Module Macro Execution',13'Description' => %q{14This module will execute a list of modules given in a macro file in the format15of <module> <opt=val,opt=val> against the select session checking for compatibility16of the module against the sessions and validation of the options provided.17},18'License' => MSF_LICENSE,19'Author' => [ '<carlos_perez[at]darkoperator.com>'],20'Platform' => %w[linux osx solaris unix win],21'SessionTypes' => [ 'meterpreter', 'shell' ]22)23)24register_options(25[2627OptString.new('MACRO', [true, 'File with Post Modules and Options to run in the session', nil])2829]30)31end3233# Run Method for when run command is issued34def run35# syinfo is only on meterpreter sessions36print_status("Running module against #{sysinfo['Computer']}") if !sysinfo.nil?37macro = datastore['MACRO']38entries = []39if !::File.exist?(macro)40print_error 'Resource File does not exist!'41return42else43::File.open(datastore['MACRO'], 'rb').each_line do |line|44# Empty line45next if line.strip.empty?46# Comment47next if line[0, 1] == '#'4849entries << line.chomp50end51end5253if entries54entries.each do |l|55values = l.split(' ')56post_mod = values[0]57if values.length == 258mod_opts = values[1].split(',')59end60print_line("Loading #{post_mod}")61# Make sure we can handle post module names with or without post in the start62if post_mod =~ %r{^post/}63post_mod.gsub!(%r{^post/}, '')64end65m = framework.post.create(post_mod)6667# Check if a post module was actually initiated68if m.nil?69print_error("Post module #{post_mod} could not be initialized!")70next71end72# Set the current session73s = datastore['SESSION']7475if m.session_compatible?(s.to_i)76print_line("Running Against #{s}")77m.datastore['SESSION'] = s78if mod_opts79mod_opts.each do |o|80opt_pair = o.split('=', 2)81print_line("\tSetting Option #{opt_pair[0]} to #{opt_pair[1]}")82m.datastore[opt_pair[0]] = opt_pair[1]83end84end85m.options.validate(m.datastore)86m.run_simple(87'LocalInput' => user_input,88'LocalOutput' => user_output89)90else91print_error("Session #{s} is not compatible with #{post_mod}")92end93end94else95print_error('Resource file was empty!')96end97end98end99100101