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_devices.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::Windows::Registry78def initialize(info = {})9super(10update_info(11info,12'Name' => 'Windows Gather Hardware Enumeration',13'Description' => %q{14Enumerate PCI hardware information from the registry. Please note this script15will run through registry subkeys such as: 'PCI', 'ACPI', 'ACPI_HAL', 'FDC', 'HID',16'HTREE', 'IDE', 'ISAPNP', 'LEGACY'', LPTENUM', 'PCIIDE', 'SCSI', 'STORAGE', 'SW',17and 'USB'; it will take time to finish. It is recommended to run this module as a18background job.19},20'License' => MSF_LICENSE,21'Author' => [ 'Brandon Perry <bperry.volatile[at]gmail.com>' ],22'Platform' => [ 'win' ],23'SessionTypes' => [ 'meterpreter' ]24)25)26end2728def list29tbl = Rex::Text::Table.new(30'Header' => 'Device Information',31'Indent' => 1,32'Columns' =>33[34'Device Description',35'Driver Version',36'Class',37'Manufacturer',38'Extra',39]40)4142keys = [43'HKLM\\SYSTEM\\ControlSet001\\Enum\\PCI\\',44'HKLM\\SYSTEM\\ControlSet001\\Enum\\ACPI\\',45'HKLM\\SYSTEM\\ControlSet001\\Enum\\ACPI_HAL\\',46'HKLM\\SYSTEM\\ControlSet001\\Enum\\FDC\\',47'HKLM\\SYSTEM\\ControlSet001\\Enum\\HID\\',48'HKLM\\SYSTEM\\ControlSet001\\Enum\\HTREE\\',49'HKLM\\SYSTEM\\ControlSet001\\Enum\\IDE\\',50'HKLM\\SYSTEM\\ControlSet001\\Enum\\ISAPNP\\',51'HKLM\\SYSTEM\\ControlSet001\\Enum\\LEGACY\\',52'HKLM\\SYSTEM\\ControlSet001\\Enum\\LPTENUM\\',53'HKLM\\SYSTEM\\ControlSet001\\Enum\\PCIIDE\\',54'HKLM\\SYSTEM\\ControlSet001\\Enum\\Root\\',55'HKLM\\SYSTEM\\ControlSet001\\Enum\\SCSI\\',56'HKLM\\SYSTEM\\ControlSet001\\Enum\\STORAGE\\',57'HKLM\\SYSTEM\\ControlSet001\\Enum\\SW\\',58'HKLM\\SYSTEM\\ControlSet001\\Enum\\USB\\',59]6061keys.each do |key|62devices = registry_enumkeys(key)6364t = []6566while (!devices.nil? && !devices.empty?)671.upto(3) do68t << framework.threads.spawn("Module(#{refname})", false, devices.shift) do |device|69next if device.nil?7071vprint_status("Enumerating #{device}")7273infos = registry_enumkeys(key + '\\' + device)74next if infos.nil?7576infos.each do |info|77next if info.nil?7879info_key = key + '\\' + device + '\\' + info8081desc = registry_getvaldata(info_key, 'DeviceDesc')82mfg = registry_getvaldata(info_key, 'Mfg')83device_class = registry_getvaldata(info_key, 'Class')84driver_guid = registry_getvaldata(info_key, 'Driver')85extra = ''8687if key =~ (/USB/) || key =~ (/LPTENUM/)88extra = registry_getvaldata(info_key, 'LocationInformation')89end9091if key =~ (/SCSI/) || key =~ (/\\IDE/) || key =~ (/ACPI\\/)92extra = registry_getvaldata(info_key, 'FriendlyName')93end9495desc = desc.split(';')[1] if desc =~ /^@/96mfg = mfg.split(';')[1] if mfg =~ /^@/9798desc = '' if desc.nil?99mfg = '' if mfg.nil?100device_class = '' if device_class.nil?101driver_guid = '' if driver_guid.nil?102extra = '' if extra.nil?103104next if desc.empty? && mfg.empty?105106driver_version = ''107108if (!driver_guid.nil? || !driver_guid.empty?) && (driver_guid =~ /\\/)109k = 'HKLM\\SYSTEM\\CurrentControlSet\\Control\\Class\\' + driver_guid110d = registry_getvaldata(k, 'DriverVersion')111driver_version << d if !d.nil?112end113114done = false115116tbl.rows.each do |row|117next unless (row[0] == desc) &&118(row[1] == driver_version) &&119(row[2] == device_class) &&120(row[3] == mfg) &&121(row[4] == extra)122123done = true124break125end126127tbl << [desc, driver_version, device_class, mfg, extra] if !done128end129end130t.map(&:join)131end132end133end134135results = tbl.to_s136vprint_line("\n" + results)137138path = store_loot('host.hardware', 'text/plain', session, results, 'hardware.txt', 'Host Hardware')139print_good("Results saved in: #{path}")140end141142def run143print_status("Enumerating hardware on #{sysinfo['Computer']}")144begin145list146rescue ::Exception => e147if e.to_s =~ /execution expired/i148print_error('Sorry, execution expired. Module could not finish running.')149else150print_error("An unexpected error has occurred: #{e}:\n#{e.backtrace}")151end152end153end154end155156157