2011-08-09 16:49:12 +00:00
|
|
|
#
|
|
|
|
# List physical drives and logical volumes on the remote system
|
|
|
|
#
|
|
|
|
# R. Wesley McGrew wesley@mcgrewsecurity.com
|
|
|
|
# http://mcgrewsecurity.com
|
|
|
|
# Mississippi State University National Forensics Training Center
|
|
|
|
# http://msu-nftc.org
|
|
|
|
|
|
|
|
class Metasploit3 < Msf::Post
|
2011-11-20 01:53:25 +00:00
|
|
|
|
2011-08-09 16:49:12 +00:00
|
|
|
def initialize(info={})
|
|
|
|
super( update_info( info,
|
2011-10-15 19:41:40 +00:00
|
|
|
'Name' => 'Windows Gather Physical Drives and Logical Volumes',
|
2011-08-09 16:49:12 +00:00
|
|
|
'Description' => %q{This module will list physical drives and logical volumes},
|
|
|
|
'License' => MSF_LICENSE,
|
2012-10-23 18:33:01 +00:00
|
|
|
'Platform' => ['win'],
|
2011-08-09 16:49:12 +00:00
|
|
|
'SessionTypes' => ['meterpreter'],
|
2011-11-06 22:02:26 +00:00
|
|
|
'Author' => ['Wesley McGrew <wesley[at]mcgrewsecurity.com>']
|
2011-08-09 16:49:12 +00:00
|
|
|
))
|
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
OptInt.new('MAXDRIVES',[false,'Maximum physical drive number',10])
|
|
|
|
], self.class)
|
|
|
|
end
|
|
|
|
|
|
|
|
def print_device(devname)
|
|
|
|
ioctl_disk_get_drive_geometry_ex = 0x000700A0
|
|
|
|
ioctl_disk_get_partition_info = 0x00074004
|
|
|
|
removable = 0x0b
|
|
|
|
fixed = 0x0c
|
|
|
|
invalid_handle_value = 0xFFFFFFFF
|
|
|
|
result = client.railgun.kernel32.CreateFileA(devname, "GENERIC_READ",
|
|
|
|
0x3, nil, "OPEN_EXISTING", 'FILE_ATTRIBUTE_READONLY', 0)
|
|
|
|
handle = result['return']
|
|
|
|
if result['return'] != invalid_handle_value
|
|
|
|
driveinfo = ""
|
|
|
|
ioctl = client.railgun.kernel32.DeviceIoControl(handle,ioctl_disk_get_drive_geometry_ex,
|
|
|
|
"",0,200,200,4,"")
|
2011-08-09 19:21:33 +00:00
|
|
|
if ioctl['GetLastError'] == 6
|
2011-08-09 16:49:12 +00:00
|
|
|
ioctl = client.railgun.kernel32.DeviceIoControl(handle,ioctl_disk_get_drive_geometry_ex,
|
|
|
|
"",0,200,200,4,"")
|
|
|
|
end
|
|
|
|
geometry = ioctl['lpOutBuffer']
|
|
|
|
if geometry[8] == removable
|
|
|
|
type = "Removable"
|
|
|
|
elsif geometry[8] == fixed
|
|
|
|
type = "Fixed"
|
|
|
|
else
|
|
|
|
type = ""
|
|
|
|
end
|
2011-11-06 22:02:26 +00:00
|
|
|
|
2011-08-09 16:49:12 +00:00
|
|
|
size = geometry[24,31].unpack('Q')
|
|
|
|
if size.to_s == "4702111234474983745"
|
|
|
|
size = 'N/A'
|
|
|
|
end
|
2011-11-06 22:02:26 +00:00
|
|
|
|
2011-08-09 16:49:12 +00:00
|
|
|
print_line("%-25s%12s%15i" % [devname,type,size[0]])
|
|
|
|
client.railgun.kernel32.CloseHandle(handle)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def run
|
|
|
|
print_line("Device Name: Type: Size (bytes):")
|
|
|
|
print_line("------------ ----- -------------")
|
|
|
|
print_line("<Physical Drives:>")
|
|
|
|
max_physical = datastore['MAXDRIVES']
|
|
|
|
(0..max_physical).each do |i|
|
|
|
|
devname = "\\\\.\\PhysicalDrive#{i}"
|
|
|
|
print_device(devname)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Props to Rob Fuller (mubix at room362.com) for logical drive enumeration code:
|
|
|
|
bitmask = client.railgun.kernel32.GetLogicalDrives()["return"]
|
|
|
|
drives = []
|
|
|
|
letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
|
|
(0..25).each do |i|
|
|
|
|
test = letters[i,1]
|
|
|
|
rem = bitmask % (2**(i+1))
|
|
|
|
if rem > 0
|
|
|
|
drives << test
|
|
|
|
bitmask = bitmask - rem
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
print_line ("<Logical Drives:>")
|
|
|
|
drives.each do |i|
|
|
|
|
devname = "\\\\.\\#{i}:"
|
|
|
|
print_device(devname)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|