Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/post/windows/gather/enum_patches.rb
Views: 11655
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Post6include Msf::Post::Common7include Msf::Post::Windows::ExtAPI89def initialize(info = {})10super(11update_info(12info,13'Name' => 'Windows Gather Applied Patches',14'Description' => %q{15This module enumerates patches applied to a Windows system using the16WMI query: SELECT HotFixID, InstalledOn FROM Win32_QuickFixEngineering.17},18'License' => MSF_LICENSE,19'Platform' => ['win'],20'SessionTypes' => ['meterpreter'],21'Author' => [22'zeroSteiner', # Original idea23'mubix' # Post module24],25'References' => [26['URL', 'http://msdn.microsoft.com/en-us/library/aa394391(v=vs.85).aspx']27],28'Notes' => {29'Stability' => [CRASH_SAFE],30'Reliability' => [],31'SideEffects' => []32},33'Compat' => {34'Meterpreter' => {35'Commands' => %w[36extapi_wmi_query37]38}39}40)41)42end4344def run45unless session.commands.include?(Rex::Post::Meterpreter::Extensions::Extapi::COMMAND_ID_EXTAPI_WMI_QUERY)46fail_with(Failure::NoTarget, 'Session does not support Meterpreter ExtAPI WMI queries')47end4849hostname = sysinfo.nil? ? cmd_exec('hostname') : sysinfo['Computer']50print_status("Running module against #{hostname} (#{session.session_host})")5152begin53objects = session.extapi.wmi.query('SELECT HotFixID, InstalledOn FROM Win32_QuickFixEngineering')54rescue RuntimeError55fail_with(Failure::BadConfig, 'Known bug in WMI query, try migrating to another process')56end5758if objects.nil?59print_error('Could not retrieve patch information. WMI query returned no data.')60return61end6263if objects[:values].blank?64print_status('Found no patches installed')65return66end6768results = Rex::Text::Table.new(69'Header' => 'Installed Patches',70'Indent' => 2,71'Columns' =>72[73'HotFix ID',74'Install Date'75]76)7778objects[:values].compact.each do |k|79results << k80end8182if results.rows.empty?83print_status("No patches were found to be installed on #{hostname} (#{session.session_host})")84return85end8687print_line88print_line(results.to_s)8990loot_file = store_loot('enum_patches', 'text/plain', session, results.to_csv)91print_status("Patch list saved to #{loot_file}")92end93end949596