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
|
2022-09-23 17:41:20 +10:00
|
|
|
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,
|
2022-09-12 13:50:32 +10:00
|
|
|
'Name' => 'Windows Gather Applied Patches',
|
2021-09-10 12:53:39 +01:00
|
|
|
'Description' => %q{
|
2022-09-12 13:50:32 +10:00
|
|
|
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
|
|
|
],
|
2022-09-12 13:50:32 +10: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
|
2022-09-12 13:50:32 +10:00
|
|
|
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
|
|
|
|
|
|
2022-09-12 13:50:32 +10:00
|
|
|
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
|
2022-09-12 13:50:32 +10:00
|
|
|
objects = session.extapi.wmi.query('SELECT HotFixID, InstalledOn FROM Win32_QuickFixEngineering')
|
2019-02-02 15:33:48 +00:00
|
|
|
rescue RuntimeError
|
2022-09-12 13:50:32 +10:00
|
|
|
fail_with(Failure::BadConfig, 'Known bug in WMI query, try migrating to another process')
|
2019-02-02 15:33:48 +00:00
|
|
|
end
|
|
|
|
|
|
2022-09-12 13:50:32 +10:00
|
|
|
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
|
|
|
|
|
|
2022-09-12 13:50:32 +10:00
|
|
|
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
|
|
|
|
2022-09-12 13:50:32 +10:00
|
|
|
results = Rex::Text::Table.new(
|
|
|
|
|
'Header' => 'Installed Patches',
|
|
|
|
|
'Indent' => 2,
|
|
|
|
|
'Columns' =>
|
|
|
|
|
[
|
|
|
|
|
'HotFix ID',
|
|
|
|
|
'Install Date'
|
|
|
|
|
]
|
|
|
|
|
)
|
2020-08-31 17:38:02 -07:00
|
|
|
|
2022-09-12 13:50:32 +10:00
|
|
|
objects[:values].compact.each do |k|
|
|
|
|
|
results << k
|
2014-05-24 23:37:17 -04:00
|
|
|
end
|
2022-09-12 13:50:32 +10:00
|
|
|
|
|
|
|
|
if results.rows.empty?
|
2022-09-15 17:44:25 -05:00
|
|
|
print_status("No patches were found to be installed on #{hostname} (#{session.session_host})")
|
2022-09-12 13:50:32 +10:00
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
print_line
|
|
|
|
|
print_line(results.to_s)
|
|
|
|
|
|
2022-09-15 17:44:25 -05:00
|
|
|
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
|