Files
metasploit-gs/modules/post/multi/manage/multi_post.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

100 lines
2.9 KiB
Ruby
Raw Normal View History

##
2017-07-24 06:26:21 -07:00
# This module requires Metasploit: https://metasploit.com/download
2013-10-15 13:50:46 -05:00
# Current source: https://github.com/rapid7/metasploit-framework
##
2016-03-08 14:02:44 +01:00
class MetasploitModule < Msf::Post
2013-09-05 13:41:25 -05:00
include Msf::Post::File
2023-02-08 13:47:34 +00:00
def initialize(info = {})
super(
update_info(
info,
'Name' => 'Multi Manage Post Module Macro Execution',
'Description' => %q{
This module will execute a list of modules given in a macro file in the format
of <module> <opt=val,opt=val> against the select session checking for compatibility
of the module against the sessions and validation of the options provided.
},
2023-02-08 13:47:34 +00:00
'License' => MSF_LICENSE,
'Author' => [ '<carlos_perez[at]darkoperator.com>'],
'Platform' => %w[linux osx solaris unix win],
'SessionTypes' => [ 'meterpreter', 'shell' ]
)
)
register_options(
[
2011-11-03 22:28:08 +00:00
OptString.new('MACRO', [true, 'File with Post Modules and Options to run in the session', nil])
2023-02-08 13:47:34 +00:00
]
)
end
# Run Method for when run command is issued
def run
# syinfo is only on meterpreter sessions
2023-02-08 13:47:34 +00:00
print_status("Running module against #{sysinfo['Computer']}") if !sysinfo.nil?
macro = datastore['MACRO']
entries = []
2023-02-08 13:47:34 +00:00
if !::File.exist?(macro)
print_error 'Resource File does not exist!'
return
else
2023-02-08 13:47:34 +00:00
::File.open(datastore['MACRO'], 'rb').each_line do |line|
# Empty line
2023-02-08 13:47:34 +00:00
next if line.strip.empty?
# Comment
2023-02-08 13:47:34 +00:00
next if line[0, 1] == '#'
entries << line.chomp
end
end
if entries
entries.each do |l|
2023-02-08 13:47:34 +00:00
values = l.split(' ')
post_mod = values[0]
if values.length == 2
2023-02-08 13:47:34 +00:00
mod_opts = values[1].split(',')
end
print_line("Loading #{post_mod}")
# Make sure we can handle post module names with or without post in the start
2023-02-08 13:47:34 +00:00
if post_mod =~ %r{^post/}
post_mod.gsub!(%r{^post/}, '')
end
2011-11-03 22:28:08 +00:00
m = framework.post.create(post_mod)
2011-11-20 12:53:25 +11:00
# Check if a post module was actually initiated
if m.nil?
print_error("Post module #{post_mod} could not be initialized!")
next
end
# Set the current session
2011-11-03 22:28:08 +00:00
s = datastore['SESSION']
if m.session_compatible?(s.to_i)
print_line("Running Against #{s}")
m.datastore['SESSION'] = s
if mod_opts
mod_opts.each do |o|
2023-02-08 13:47:34 +00:00
opt_pair = o.split('=', 2)
print_line("\tSetting Option #{opt_pair[0]} to #{opt_pair[1]}")
m.datastore[opt_pair[0]] = opt_pair[1]
end
end
m.options.validate(m.datastore)
m.run_simple(
2023-02-08 13:47:34 +00:00
'LocalInput' => user_input,
'LocalOutput' => user_output
)
else
print_error("Session #{s} is not compatible with #{post_mod}")
end
end
2023-02-08 13:47:34 +00:00
else
print_error('Resource file was empty!')
end
end
2011-11-20 12:53:25 +11:00
end