CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/post/multi/gather/run_console_rc_file.rb
Views: 1904
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
)
22
)
23
register_options(
24
[
25
26
OptString.new('RESOURCE', [true, 'Full path to resource file to read commands from.', nil]),
27
28
]
29
)
30
end
31
32
# Run Method for when run command is issued
33
def run
34
print_status("Running module against #{sysinfo['Computer']}")
35
if !::File.exist?(datastore['RESOURCE'])
36
raise 'Resource File does not exist!'
37
else
38
::File.open(datastore['RESOURCE'], 'rb').each_line do |cmd|
39
next if cmd.strip.empty?
40
next if cmd[0, 1] == '#'
41
42
begin
43
print_status "Running command #{cmd.chomp}"
44
session.console.run_single(cmd.chomp)
45
rescue ::Exception => e
46
print_status("Error Running Command #{cmd.chomp}: #{e.class} #{e}")
47
end
48
end
49
end
50
end
51
end
52
53