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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

95 lines
2.6 KiB
Ruby
Raw Normal View History

2014-05-24 23:37:17 -04:00
##
2017-07-24 06:26:21 -07:00
# This module requires Metasploit: https://metasploit.com/download
2014-05-24 23:37:17 -04:00
# Current source: https://github.com/rapid7/metasploit-framework
##
2016-03-08 14:02:44 +01:00
class MetasploitModule < Msf::Post
2014-05-24 23:37:17 -04:00
include Msf::Post::Common
include Msf::Post::Windows::ExtAPI
2014-05-24 23:37:17 -04:00
2021-09-10 12:53:39 +01:00
def initialize(info = {})
super(
update_info(
info,
'Name' => 'Windows Gather Applied Patches',
2021-09-10 12:53:39 +01:00
'Description' => %q{
This module enumerates patches applied to a Windows system using the
WMI query: SELECT HotFixID, InstalledOn FROM Win32_QuickFixEngineering.
2014-05-24 23:37:17 -04:00
},
2021-09-10 12:53:39 +01:00
'License' => MSF_LICENSE,
'Platform' => ['win'],
'SessionTypes' => ['meterpreter'],
'Author' => [
2014-05-24 23:37:17 -04:00
'zeroSteiner', # Original idea
'mubix' # Post module
2014-09-16 16:17:22 -05:00
],
2021-09-10 12:53:39 +01:00
'References' => [
2014-09-16 16:17:22 -05:00
['URL', 'http://msdn.microsoft.com/en-us/library/aa394391(v=vs.85).aspx']
2021-10-06 13:43:31 +01:00
],
'Notes' => {
'Stability' => [CRASH_SAFE],
'Reliability' => [],
'SideEffects' => []
},
2021-10-06 13:43:31 +01:00
'Compat' => {
'Meterpreter' => {
'Commands' => %w[
extapi_wmi_query
]
}
}
2021-09-10 12:53:39 +01:00
)
)
2014-05-24 23:37:17 -04:00
end
def run
unless session.commands.include?(Rex::Post::Meterpreter::Extensions::Extapi::COMMAND_ID_EXTAPI_WMI_QUERY)
fail_with(Failure::NoTarget, 'Session does not support Meterpreter ExtAPI WMI queries')
2014-05-24 23:37:17 -04:00
end
hostname = sysinfo.nil? ? cmd_exec('hostname') : sysinfo['Computer']
print_status("Running module against #{hostname} (#{session.session_host})")
2019-02-02 15:33:48 +00:00
begin
objects = session.extapi.wmi.query('SELECT HotFixID, InstalledOn FROM Win32_QuickFixEngineering')
2019-02-02 15:33:48 +00:00
rescue RuntimeError
fail_with(Failure::BadConfig, 'Known bug in WMI query, try migrating to another process')
2019-02-02 15:33:48 +00:00
end
if objects.nil?
print_error('Could not retrieve patch information. WMI query returned no data.')
return
2019-02-02 15:33:48 +00:00
end
if objects[:values].blank?
print_status('Found no patches installed')
2020-01-14 20:49:39 -05:00
return
2014-05-25 19:36:40 -05:00
end
2019-02-02 15:33:48 +00:00
results = Rex::Text::Table.new(
'Header' => 'Installed Patches',
'Indent' => 2,
'Columns' =>
[
'HotFix ID',
'Install Date'
]
)
objects[:values].compact.each do |k|
results << k
2014-05-24 23:37:17 -04:00
end
if results.rows.empty?
print_status("No patches were found to be installed on #{hostname} (#{session.session_host})")
return
end
print_line
print_line(results.to_s)
loot_file = store_loot('enum_patches', 'text/plain', session, results.to_csv)
print_status("Patch list saved to #{loot_file}")
2014-05-24 23:37:17 -04:00
end
end