Skip to main content
Create your own
Lesson illustration

Credential Re-use for Lateral Movement

Hello! Welcome back to our final module on post-exploitation.

In our last lesson, you learned how to establish a foothold inside a target network through pivoting. Using tools like ssh and chisel, you can now tunnel your traffic through a compromised host to reach internal-only systems. That gets you in the door.

This lesson is about what you do next: moving from that first compromised machine to other, more valuable targets within the network. This process is called lateral movement. We will focus on one of the most fundamental and effective lateral movement techniques in Windows environments: Pass-the-Hash (PtH). By the end of this lesson, you will be able to reuse credentials harvested from one machine to authenticate to another, without ever needing the original password.

1. The Theory: From Password to Hash

In many authentication systems, when you enter your password, the system hashes it and compares that hash to a stored value. The Windows NTLM authentication protocol has a characteristic that attackers can abuse: under certain conditions, you can skip the password step entirely and authenticate directly using a user's NTLM hash.

This means that if you can obtain a user's NTLM hash, you can often impersonate that user across the network.

What is Pass-the-Hash? Attacks Types and Security Best Practices

To understand Pass-the-Hash, we first need to grasp why a hash can be as good as a password. This introductory section from an article by VaaData provides an excellent overview.

Read the introduction, from the beginning down to the line '...then reuse them to move laterally within the network.' This section clearly explains that having an account's NTLM hash can be equivalent to having its password.

Where Do Hashes Live?

If you gain administrative privileges on a Windows machine, you can access these hashes from two primary locations:

  1. The SAM Database: The Security Account Manager (SAM) is a registry file (C:\Windows\System32\config\SAM) that stores the NTLM hashes for all local user accounts on that machine. Accessing it requires SYSTEM privileges.
  2. LSASS Process Memory: The Local Security Authority Subsystem Service (lsass.exe) is a critical Windows process that handles user authentication, password changes, and access token creation. It caches the credentials (including NTLM hashes) of users who are currently or have recently been logged on. This is a goldmine for an attacker, as it can contain hashes for domain users, including privileged accounts like Domain Admins, who may have logged into the machine for maintenance.

Since you have a computer science background, you can think of the SAM file as persistent, on-disk storage for local credentials, while LSASS is volatile, in-memory storage for credentials related to active sessions. Dumping credentials from LSASS is the most common technique used during a penetration test.

What is Pass-the-Hash? Attacks Types and Security Best Practices

Let's look more closely at how an attacker with administrative rights can extract these valuable hashes. The same article details the two primary sources: the SAM database and the LSASS process.

Read the section 'Windows Secrets Extraction', focusing on the two subsections: 'Extracting secrets from the SAM base' and 'Extracting hashes from LSASS'. Pay close attention to the role of the lsass.exe process, as this is the most common target in post-exploitation scenarios.

2. The Practice: Dumping Hashes with Mimikatz

The quintessential tool for extracting credentials from LSASS is Mimikatz. It's a powerful post-exploitation tool that can parse the memory of the lsass.exe process and pull out plaintext passwords, NTLM hashes, and Kerberos tickets.

Let's see how it's done. The following video provides a concise, practical demonstration.

Mimikatz: Dump Hashes & Pass-the-Hash Attacks Simplified

The video 'Mimikatz: Dump Hashes & Pass-the-Hash Attacks Simplified' by Kyser Clark is a clear, step-by-step guide. We'll start with the first part: getting Mimikatz onto a target and using it to dump hashes.

Watch from 00:40 to 08:32. The first part (until 05:10) shows transferring the tool to the target. The core part is from 05:10 to 08:32, where he runs Mimikatz, elevates its privileges (privilege::debug), and dumps credentials with sekurlsa::logonpasswords. Focus on identifying a user's NTLM hash in the output.

The key commands you saw were:

  1. privilege::debug: This command attempts to grant Mimikatz the SeDebugPrivilege, which is necessary to interact with a protected process like lsass.exe. This will only succeed if you are running as a high-integrity user (like an administrator).
  2. sekurlsa::logonpasswords: This is the magic command that instructs Mimikatz to parse the LSASS process memory and dump all available credentials.

The output will show various credential types, but for our purposes, the NTLM hash is the key piece of information we're looking for.

3. The Attack: Passing the Hash for Lateral Movement

Now that you have a user's NTLM hash, you can use it to authenticate to other machines on the network where that user has access. This is the "Pass-the-Hash" attack.

The image below illustrates a typical workflow. An attacker uses Mimikatz to generate a new command prompt that has the authentication context of a privileged user, then uses that new shell to access another machine.

Pass-the-Hash Attack Demonstration with Mimikatz and PsExec
This diagram illustrates a common Pass-the-Hash workflow. On the left, Mimikatz's `sekurlsa::pth` module creates a new command prompt under the context of the 'administrador' user by providing their NTLM hash. From this new privileged shell, the attacker can use tools like PsExec to connect to other machines (e.g., 10.0.0.10), achieving lateral movement.

While using Mimikatz's pth module is one way to do this, a more common and flexible method is to use specialized tools that can authenticate with a hash directly. Tools from the Impacket suite (like psexec.py, wmiexec.py) and other tools like Evil-WinRM are perfect for this. They allow you to specify the hash on the command line to gain a shell on a remote system.

Let's return to the video to see this in action.

Mimikatz: Dump Hashes & Pass-the-Hash Attacks Simplified

Let's continue with the Kyser Clark video. Now that he has the NTLM hash, he will use it with two different tools to gain access to another machine.

Watch from 08:32 to 11:40. This section demonstrates two classic PtH attacks: Against WinRM (port 5985) using evil-winrm with the -H [hash] flag. Against SMB (port 445) using impacket-wmiexec with the -hashes [hash] flag. Notice how he uses the same hash to authenticate to different administrative services on the target.

This demonstrates the core loop of lateral movement: compromise > dump credentials > reuse credentials > repeat.

To round out your understanding, the following resource provides a text-based "cheat sheet" of various commands used for Pass-the-Hash.

Pass the hash

The 'Pass the hash' guide from The Hacker Recipes serves as an excellent quick reference for various tools that support this technique. It reinforces what you saw in the video with clear command-line syntax.

Quickly review the 'Theory' and 'Practice' sections. Notice the pattern in the Impacket and NetExec commands: a flag like -hashes or -H is used to provide the NTLM hash instead of a password.

Test your understanding!

You have compromised a Windows host and used Mimikatz to dump the following NTLM hash for the user CORP\DomainAdmin: aad3b435b51404eeaad3b435b51404ee.

Your nmap scan of another server, 10.1.1.20, shows that port 445 (SMB) is open. You suspect the DomainAdmin account has administrator rights on this server as well.

Which Impacket command would you use to get a shell on 10.1.1.20?

Show answer

One of the best options would be impacket-psexec.py or impacket-wmiexec.py. The syntax would be:

impacket-psexec.py -hashes :aad3b435b51404eeaad3b435b51404ee CORP/DomainAdmin@10.1.1.20

Or using wmiexec:

impacket-wmiexec.py -hashes :aad3b435b51404eeaad3b435b51404ee CORP/DomainAdmin@10.1.1.20

Both tools use the -hashes flag to perform a Pass-the-Hash attack over SMB. The leading colon : is used as a separator for the LM hash and NTLM hash (LMhash:NThash). Since the LM hash is legacy and almost never used, it is left blank.

Conclusion

Today you've learned a critical post-exploitation skill: lateral movement using Pass-the-Hash. This technique is a staple of penetration testing in Windows environments and is essential for moving from an initial foothold to controlling key assets within a network.

Key Takeaways:

  • Lateral Movement is the process of moving from a compromised host to other hosts within the same network.
  • Pass-the-Hash (PtH) is an attack that leverages a user's NTLM hash to authenticate to a remote service, bypassing the need for a plaintext password.
  • LSASS (lsass.exe) is the primary target for credential dumping on a live system, as it caches credentials for logged-on users.
  • Mimikatz is the go-to tool for dumping credentials from LSASS memory using the sekurlsa::logonpasswords command.
  • Tools like Impacket (psexec.py, wmiexec.py) and Evil-WinRM allow you to use a captured hash to authenticate and gain a shell on a remote machine.

Next Lesson Preview:

Pass-the-Hash is incredibly powerful, but it's just one method of lateral movement. In our next lesson, we will explore another common scenario: reusing compromised credentials found in plaintext (e.g., in configuration files or scripts) and using a technique known as Pass-the-Hash to move laterally in a different way, this time by passing password hashes for Kerberos authentication. This will set the stage for you to understand how to move towards a domain controller, the ultimate prize in an Active Directory environment.

Can't find a good explanation? Sign up and we'll make it for you

Sign up