Skip to content

Massively improve windows' vm fingerprinting module#18140

Closed
jvoisin wants to merge 8 commits intorapid7:masterfrom
jvoisin:improve_vm_detection
Closed

Massively improve windows' vm fingerprinting module#18140
jvoisin wants to merge 8 commits intorapid7:masterfrom
jvoisin:improve_vm_detection

Conversation

@jvoisin
Copy link
Copy Markdown
Contributor

@jvoisin jvoisin commented Jun 24, 2023

@cdelafuente-r7 cdelafuente-r7 self-assigned this Jun 26, 2023
Copy link
Copy Markdown
Contributor

@cdelafuente-r7 cdelafuente-r7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jvoisin for improving this module. I left some comments and suggestions for you to review when you get a chance.

return true if registry_getvaldata('HKLM\HARDWARE\DESCRIPTION\System\BIOS', 'SystemManufacturer') =~ /vmware/i
return true if registry_getvaldata('HKLM\HARDWARE\DEVICEMAP\Scsi\Scsi Port 0\Scsi Bus 0\Target Id 0\Logical Unit Id 0', 'Identifier') =~ /vmware/i
return true if registry_getvaldata('HKLM\HARDWARE\DEVICEMAP\Scsi\Scsi Port 1\Scsi Bus 0\Target Id 0\Logical Unit Id 0', 'Identifier') =~ /vmware/i
return true if registry_getvaldata('HKLM\SYSTEM\ControlSet001\Control\Class\{4D36E968-E325-11CE-BFC1-08002BE10318}\0000', 'DriverDesc') =~ /cl_vmx_svga/i
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked this with Windows 11 on VMware Fusion 12.2.5 and the value of the is registry key is VMware SVGA 3D. Should this value also be checked?

return true if registry_getvaldata('HKLM\HARDWARE\DEVICEMAP\Scsi\Scsi Port 0\Scsi Bus 0\Target Id 0\Logical Unit Id 0', 'Identifier') =~ /vmware/i
return true if registry_getvaldata('HKLM\HARDWARE\DEVICEMAP\Scsi\Scsi Port 1\Scsi Bus 0\Target Id 0\Logical Unit Id 0', 'Identifier') =~ /vmware/i
return true if registry_getvaldata('HKLM\SYSTEM\ControlSet001\Control\Class\{4D36E968-E325-11CE-BFC1-08002BE10318}\0000', 'DriverDesc') =~ /cl_vmx_svga/i
return true if registry_getvaldata('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall', 'DisplayName') =~ /vmware tools/i
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This registry key looks weird to me. HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall usually includes sub-keys for each installed software. VMware Tools seems to be in HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{1FF5D624-5515-4343-837A-E54C101573E6} on my environment.

module supports detection of JoeSandbox, Hyper-V, VMWare, Virtual PC,
VirtualBox, Xen, MicrosoftSandbox, Parallels, Bochs and QEMU.
},
'License' => MSF_LICENSE,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


%w[HKLM\HARDWARE\ACPI\DSDT HKLM\HARDWARE\ACPI\FADT HKLM\HARDWARE\ACPI\RSDT].each do |key|
srvvals = registry_enumkeys(key)
return true if srvvals && srvvals.include?('BOCHS_')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand it correctly, this check is now exclusively for bochs emulation software. It has been removed from qemu detection logic. Is there a specific reason for this?

According to the documentation, qemu also uses some bochs components.

QEMU uses the PC BIOS from the Seabios project and the Plex86/Bochs LGPL VGA BIOS.

include Msf::Post::Windows::Process
include Msf::Post::Windows::Registry
include Msf::Post::Windows::UserProfiles
include Msf::Post::Windows::WMIC
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This mixin brings the SMB* options to authenticate. Since it is a local connection, they should not be used. I would recommend deregistering these options:

      deregister_options('SMBUser', 'SMBPass', 'SMBDomain')

key_path = 'HKLM\HARDWARE\DESCRIPTION\System\CentralProcessor\0'
return true if registry_getvaldata(key_path, 'ProcessorNameString') =~ /qemu/i

return true if registry_getvaldata('HKLM\HARDWARE\DESCRIPTION\System', 'SystemBiosVersion') =~ /qemu/i
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HKLM\HARDWARE\DESCRIPTION\System\SystemBiosVersion is a Multi String value and this call returns an array of characters:

[4] pry(#<Msf::Modules::Post__Windows__Gather__Checkvm::MetasploitModule>)> registry_getvaldata('HKLM\HARDWARE\DESCRIPTION\System', 'SystemBiosVersion')
=> ["I",
 "N",
 "T",
 "E",
 "L",
 " ",
 " ",
 "-",
...

So, this regex won't work. Maybe this would be enough to fix it (not tested):

Suggested change
return true if registry_getvaldata('HKLM\HARDWARE\DESCRIPTION\System', 'SystemBiosVersion') =~ /qemu/i
return true if registry_getvaldata('HKLM\HARDWARE\DESCRIPTION\System', 'SystemBiosVersion').join =~ /qemu/i

I also noticed this issue in many times in this file and they should also be fixed.

jvoisin and others added 6 commits June 27, 2023 16:15
Co-authored-by: Christophe De La Fuente <56716719+cdelafuente-r7@users.noreply.github.com>
Co-authored-by: Christophe De La Fuente <56716719+cdelafuente-r7@users.noreply.github.com>
Co-authored-by: Christophe De La Fuente <56716719+cdelafuente-r7@users.noreply.github.com>
Co-authored-by: Christophe De La Fuente <56716719+cdelafuente-r7@users.noreply.github.com>
Co-authored-by: Christophe De La Fuente <56716719+cdelafuente-r7@users.noreply.github.com>
Co-authored-by: Christophe De La Fuente <56716719+cdelafuente-r7@users.noreply.github.com>
Comment on lines +50 to +52
def get_computer_model
wmic_query('computersystem get model')
end
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def get_computer_model
wmic_query('computersystem get model')
end
def get_computer_model
@get_computer_model ||= wmic_query('computersystem get model')
end

This prevents us from executing the command multiple times- same for the other data retrieval methods below.

@jvoisin
Copy link
Copy Markdown
Contributor Author

jvoisin commented Jul 8, 2023

I'll re-open smaller PR.

@jvoisin jvoisin closed this Jul 8, 2023
@jvoisin
Copy link
Copy Markdown
Contributor Author

jvoisin commented Jul 11, 2023

Superseeded by #18179

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants