Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/post/multi/gather/run_console_rc_file.rb
19721 views
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
class MetasploitModule < Msf::Post
7
8
def initialize(info = {})
9
super(
10
update_info(
11
info,
12
'Name' => 'Multi Gather Run Console Resource File',
13
'Description' => %q{
14
This module will read console commands from a resource file and
15
execute the commands in the specified Meterpreter session.
16
},
17
'License' => MSF_LICENSE,
18
'Author' => [ 'Carlos Perez <carlos_perez[at]darkoperator.com>'],
19
'Platform' => [ 'win' ],
20
'SessionTypes' => [ 'meterpreter' ],
21
'Notes' => {
22
'Stability' => [CRASH_SAFE],
23
'SideEffects' => [],
24
'Reliability' => []
25
}
26
)
27
)
28
register_options(
29
[
30
OptString.new('RESOURCE', [true, 'Full path to resource file to read commands from.', nil]),
31
]
32
)
33
end
34
35
def run
36
if !::File.exist?(datastore['RESOURCE'])
37
raise 'Resource File does not exist!'
38
end
39
40
hostname = sysinfo.nil? ? cmd_exec('hostname') : sysinfo['Computer']
41
print_status("Running module against #{hostname} (#{session.session_host})")
42
43
::File.open(datastore['RESOURCE'], 'rb').each_line do |cmd|
44
next if cmd.strip.empty?
45
next if cmd.start_with?('#')
46
47
begin
48
print_status "Running command #{cmd.chomp}"
49
session.console.run_single(cmd.chomp)
50
rescue StandardError => e
51
print_status("Error Running Command #{cmd.chomp}: #{e.class} #{e}")
52
end
53
end
54
end
55
end
56
57