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

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

156 lines
4.9 KiB
Ruby
Raw Normal View History

##
2017-07-24 06:26:21 -07:00
# This module requires Metasploit: https://metasploit.com/download
2013-10-15 13:50:46 -05:00
# Current source: https://github.com/rapid7/metasploit-framework
##
2016-03-08 14:02:44 +01:00
class MetasploitModule < Msf::Post
include Msf::Post::Windows::Registry
2013-08-30 16:28:54 -05:00
2023-02-08 13:47:34 +00:00
def initialize(info = {})
super(
update_info(
info,
'Name' => 'Windows Gather Hardware Enumeration',
'Description' => %q{
Enumerate PCI hardware information from the registry. Please note this script
2023-02-08 13:47:34 +00:00
will run through registry subkeys such as: 'PCI', 'ACPI', 'ACPI_HAL', 'FDC', 'HID',
'HTREE', 'IDE', 'ISAPNP', 'LEGACY'', LPTENUM', 'PCIIDE', 'SCSI', 'STORAGE', 'SW',
and 'USB'; it will take time to finish. It is recommended to run this module as a
background job.
},
2023-02-08 13:47:34 +00:00
'License' => MSF_LICENSE,
'Author' => [ 'Brandon Perry <bperry.volatile[at]gmail.com>' ],
'Platform' => [ 'win' ],
'SessionTypes' => [ 'meterpreter' ]
)
)
end
2013-08-30 16:28:54 -05:00
def list
2016-08-10 13:30:09 -05:00
tbl = Rex::Text::Table.new(
2023-02-08 13:47:34 +00:00
'Header' => 'Device Information',
'Indent' => 1,
'Columns' =>
[
2023-02-08 13:47:34 +00:00
'Device Description',
'Driver Version',
'Class',
'Manufacturer',
'Extra',
]
)
2013-08-30 16:28:54 -05:00
keys = [
2023-02-08 13:47:34 +00:00
'HKLM\\SYSTEM\\ControlSet001\\Enum\\PCI\\',
'HKLM\\SYSTEM\\ControlSet001\\Enum\\ACPI\\',
'HKLM\\SYSTEM\\ControlSet001\\Enum\\ACPI_HAL\\',
'HKLM\\SYSTEM\\ControlSet001\\Enum\\FDC\\',
'HKLM\\SYSTEM\\ControlSet001\\Enum\\HID\\',
'HKLM\\SYSTEM\\ControlSet001\\Enum\\HTREE\\',
'HKLM\\SYSTEM\\ControlSet001\\Enum\\IDE\\',
'HKLM\\SYSTEM\\ControlSet001\\Enum\\ISAPNP\\',
'HKLM\\SYSTEM\\ControlSet001\\Enum\\LEGACY\\',
'HKLM\\SYSTEM\\ControlSet001\\Enum\\LPTENUM\\',
'HKLM\\SYSTEM\\ControlSet001\\Enum\\PCIIDE\\',
'HKLM\\SYSTEM\\ControlSet001\\Enum\\Root\\',
'HKLM\\SYSTEM\\ControlSet001\\Enum\\SCSI\\',
'HKLM\\SYSTEM\\ControlSet001\\Enum\\STORAGE\\',
'HKLM\\SYSTEM\\ControlSet001\\Enum\\SW\\',
'HKLM\\SYSTEM\\ControlSet001\\Enum\\USB\\',
]
2013-08-30 16:28:54 -05:00
keys.each do |key|
devices = registry_enumkeys(key)
2013-08-30 16:28:54 -05:00
t = []
2013-08-30 16:28:54 -05:00
2023-02-08 13:47:34 +00:00
while (!devices.nil? && !devices.empty?)
1.upto(3) do
2023-02-08 13:47:34 +00:00
t << framework.threads.spawn("Module(#{refname})", false, devices.shift) do |device|
next if device.nil?
2023-02-08 13:47:34 +00:00
vprint_status("Enumerating #{device}")
2013-08-30 16:28:54 -05:00
2023-02-08 13:47:34 +00:00
infos = registry_enumkeys(key + '\\' + device)
next if infos.nil?
2013-08-30 16:28:54 -05:00
infos.each do |info|
next if info.nil?
2013-08-30 16:28:54 -05:00
2023-02-08 13:47:34 +00:00
info_key = key + '\\' + device + '\\' + info
2013-08-30 16:28:54 -05:00
2023-02-08 13:47:34 +00:00
desc = registry_getvaldata(info_key, 'DeviceDesc')
mfg = registry_getvaldata(info_key, 'Mfg')
device_class = registry_getvaldata(info_key, 'Class')
driver_guid = registry_getvaldata(info_key, 'Driver')
extra = ''
2013-08-30 16:28:54 -05:00
2023-02-08 13:47:34 +00:00
if key =~ (/USB/) || key =~ (/LPTENUM/)
extra = registry_getvaldata(info_key, 'LocationInformation')
end
2013-08-30 16:28:54 -05:00
2023-02-08 13:47:34 +00:00
if key =~ (/SCSI/) || key =~ (/\\IDE/) || key =~ (/ACPI\\/)
extra = registry_getvaldata(info_key, 'FriendlyName')
end
2013-08-30 16:28:54 -05:00
desc = desc.split(';')[1] if desc =~ /^@/
mfg = mfg.split(';')[1] if mfg =~ /^@/
2013-08-30 16:28:54 -05:00
2023-02-08 13:47:34 +00:00
desc = '' if desc.nil?
mfg = '' if mfg.nil?
device_class = '' if device_class.nil?
2023-02-08 13:47:34 +00:00
driver_guid = '' if driver_guid.nil?
extra = '' if extra.nil?
2013-08-30 16:28:54 -05:00
2023-02-08 13:47:34 +00:00
next if desc.empty? && mfg.empty?
2013-08-30 16:28:54 -05:00
2023-02-08 13:47:34 +00:00
driver_version = ''
2013-08-30 16:28:54 -05:00
2023-02-08 13:47:34 +00:00
if (!driver_guid.nil? || !driver_guid.empty?) && (driver_guid =~ /\\/)
k = 'HKLM\\SYSTEM\\CurrentControlSet\\Control\\Class\\' + driver_guid
d = registry_getvaldata(k, 'DriverVersion')
driver_version << d if !d.nil?
end
2013-08-30 16:28:54 -05:00
done = false
2013-08-30 16:28:54 -05:00
tbl.rows.each do |row|
2023-02-08 13:47:34 +00:00
next unless (row[0] == desc) &&
(row[1] == driver_version) &&
(row[2] == device_class) &&
(row[3] == mfg) &&
(row[4] == extra)
done = true
break
end
2013-08-30 16:28:54 -05:00
2023-02-08 13:47:34 +00:00
tbl << [desc, driver_version, device_class, mfg, extra] if !done
end
end
2023-02-08 13:47:34 +00:00
t.map(&:join)
end
end
end
2013-08-30 16:28:54 -05:00
results = tbl.to_s
vprint_line("\n" + results)
2013-08-30 16:28:54 -05:00
2023-02-08 13:47:34 +00:00
path = store_loot('host.hardware', 'text/plain', session, results, 'hardware.txt', 'Host Hardware')
2017-07-19 13:02:49 +01:00
print_good("Results saved in: #{path}")
end
2013-08-30 16:28:54 -05:00
def run
print_status("Enumerating hardware on #{sysinfo['Computer']}")
begin
list
rescue ::Exception => e
if e.to_s =~ /execution expired/i
2023-02-08 13:47:34 +00:00
print_error('Sorry, execution expired. Module could not finish running.')
else
2023-02-08 13:47:34 +00:00
print_error("An unexpected error has occurred: #{e}:\n#{e.backtrace}")
end
end
end
end