|
| 1 | +## |
| 2 | +# This module requires Metasploit: http//metasploit.com/download |
| 3 | +# Current source: https://github.com/rapid7/metasploit-framework |
| 4 | +## |
| 5 | + |
| 6 | + |
| 7 | +require 'msf/core' |
| 8 | +require 'msf/core/post/common' |
| 9 | +require 'msf/core/post/windows/extapi' |
| 10 | + |
| 11 | +class Metasploit3 < Msf::Post |
| 12 | + include Msf::Post::Common |
| 13 | + include Msf::Post::Windows::ExtAPI |
| 14 | + |
| 15 | + MSF_MODULES = { |
| 16 | + 'KB977165' => "KB977165 - Possibly vulnerable to MS10-015 kitrap0d if Windows 2K SP4 - Windows 7 (x86)", |
| 17 | + 'KB2305420' => "KB2305420 - Possibly vulnerable to MS10-092 schelevator if Vista, 7, and 2008", |
| 18 | + 'KB2592799' => "KB2592799 - Possibly vulnerable to MS11-080 afdjoinleaf if XP SP2/SP3 Win 2k3 SP2", |
| 19 | + 'KB2778930' => "KB2778930 - Possibly vulnerable to MS13-005 hwnd_broadcast, elevates from Low to Medium integrity", |
| 20 | + 'KB2850851' => "KB2850851 - Possibly vulnerable to MS13-053 schlamperei if x86 Win7 SP0/SP1", |
| 21 | + 'KB2870008' => "KB2870008 - Possibly vulnerable to MS13-081 track_popup_menu if x86 Windows 7 SP0/SP1" |
| 22 | + } |
| 23 | + |
| 24 | + def initialize(info={}) |
| 25 | + super(update_info(info, |
| 26 | + 'Name' => "Windows Gather Applied Patches", |
| 27 | + 'Description' => %q{ |
| 28 | + This module will attempt to enumerate which patches are applied to a windows system |
| 29 | + based on the result of the WMI query: SELECT HotFixID FROM Win32_QuickFixEngineering |
| 30 | + }, |
| 31 | + 'License' => MSF_LICENSE, |
| 32 | + 'Platform' => ['win'], |
| 33 | + 'SessionTypes' => ['meterpreter'], |
| 34 | + 'Author' => |
| 35 | + [ |
| 36 | + 'zeroSteiner', # Original idea |
| 37 | + 'mubix' # Post module |
| 38 | + ], |
| 39 | + 'References' => |
| 40 | + [ |
| 41 | + ['URL', 'http://msdn.microsoft.com/en-us/library/aa394391(v=vs.85).aspx'] |
| 42 | + ] |
| 43 | + )) |
| 44 | + |
| 45 | + register_options( |
| 46 | + [ |
| 47 | + OptBool.new('MSFLOCALS', [ true, 'Search for missing patchs for which there is a MSF local module', true]), |
| 48 | + OptString.new('KB', [ true, 'A comma separated list of KB patches to search for', 'KB2871997, KB2928120']) |
| 49 | + ], self.class) |
| 50 | + end |
| 51 | + |
| 52 | + # The sauce starts here |
| 53 | + def run |
| 54 | + patches = [] |
| 55 | + |
| 56 | + datastore['KB'].split(',').each do |kb| |
| 57 | + patches << kb.strip |
| 58 | + end |
| 59 | + |
| 60 | + if datastore['MSFLOCALS'] |
| 61 | + patches = patches + MSF_MODULES.keys |
| 62 | + end |
| 63 | + |
| 64 | + extapi_loaded = load_extapi |
| 65 | + if extapi_loaded |
| 66 | + begin |
| 67 | + objects = session.extapi.wmi.query("SELECT HotFixID FROM Win32_QuickFixEngineering") |
| 68 | + rescue RuntimeError |
| 69 | + print_error "Known bug in WMI query, try migrating to another process" |
| 70 | + return |
| 71 | + end |
| 72 | + kb_ids = objects[:values].map { |kb| kb[0] } |
| 73 | + print_debug(kb_ids.inspect) |
| 74 | + report_info(patches, kb_ids) |
| 75 | + else |
| 76 | + print_error "ExtAPI failed to load" |
| 77 | + end |
| 78 | + end |
| 79 | + |
| 80 | + def report_info(patches, kb_ids) |
| 81 | + patches.each do |kb| |
| 82 | + if kb_ids.include?(kb) |
| 83 | + print_status("#{kb} applied") |
| 84 | + else |
| 85 | + if MSF_MODULES.include?(kb) |
| 86 | + print_good(MSF_MODULES[kb]) |
| 87 | + else |
| 88 | + print_good("#{kb} is missing") |
| 89 | + end |
| 90 | + end |
| 91 | + end |
| 92 | + end |
| 93 | +end |
0 commit comments