/
run_console_rc_file.rb
51 lines (45 loc) · 1.43 KB
/
run_console_rc_file.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
class MetasploitModule < Msf::Post
def initialize(info = {})
super(
update_info(
info,
'Name' => 'Multi Gather Run Console Resource File',
'Description' => %q{
This module will read console commands from a resource file and
execute the commands in the specified Meterpreter session.
},
'License' => MSF_LICENSE,
'Author' => [ 'Carlos Perez <carlos_perez[at]darkoperator.com>'],
'Platform' => [ 'win' ],
'SessionTypes' => [ 'meterpreter' ]
)
)
register_options(
[
OptString.new('RESOURCE', [true, 'Full path to resource file to read commands from.', nil]),
]
)
end
# Run Method for when run command is issued
def run
print_status("Running module against #{sysinfo['Computer']}")
if !::File.exist?(datastore['RESOURCE'])
raise 'Resource File does not exist!'
else
::File.open(datastore['RESOURCE'], 'rb').each_line do |cmd|
next if cmd.strip.empty?
next if cmd[0, 1] == '#'
begin
print_status "Running command #{cmd.chomp}"
session.console.run_single(cmd.chomp)
rescue ::Exception => e
print_status("Error Running Command #{cmd.chomp}: #{e.class} #{e}")
end
end
end
end
end