Print Spooler & NTLM Relaying
Description
The Print Spooler is an old service enabled by default, even with the latest Windows Desktop and Servers versions. The service became a popular attack vector when in 2018, Lee Christensen
found the PrinterBug
. The functions RpcRemoteFindFirstPrinterChangeNotification and RpcRemoteFindFirstPrinterChangeNotificationEx can be abused to force a remote machine to perform a connection to any other machine it can reach. Moreover, the reverse
connection will carry authentication information as a TGT
. Therefore, any domain user can coerce RemoteServer$
to authenticate to any machine. Microsoft's stance on the PrinterBug
was that it will not be fixed, as the issue is "by-design".
The impact of PrinterBug
is that any Domain Controller that has the Print Spooler enabled can be compromised in one of the following ways:
Relay the connection to another DC and perform DCSync (if
SMB Signing
is disabled).Force the Domain Controller to connect to a machine configured for
Unconstrained Delegation
(UD
) - this will cache the TGT in the memory of the UD server, which can be captured/exported with tools likeRubeus
andMimikatz
.Relay the connection to
Active Directory Certificate Services
to obtain a certificate for the Domain Controller. Threat agents can then use the certificate on-demand to authenticate and pretend to be the Domain Controller (e.g., DCSync).Relay the connection to configure
Resource-Based Kerberos Delegation
for the relayed machine. We can then abuse the delegation to authenticate as any Administrator to that machine.
Attack
In this attack path, we will relay the connection to another DC and perform DCSync
(i.e., the first compromise technique listed). For the attack to succeed, SMB Signing on Domain Controllers must be turned off.
To begin, we will configure NTLMRelayx
to forward any connections to DC2 and attempt to perform the DCSync attack:
Next, we need to trigger the PrinterBug
using the Kali box with NTLMRelayx
listening. To trigger the connection back, we'll use Dementor (when running from a non-domain joined machine, any authenticated user credentials are required, and in this case, we assumed that we had previously compromised Bob):
Now, switching back to the terminal session with NTLMRelayx
, we will see that DCSync was successful:
Prevention
Print Spooler should be disabled on all servers that are not printing servers. Domain Controllers and other core servers should never have additional roles/functionalities that open and widen the attack surface toward the core AD infrastructure.
Additionally, there is an option to prevent the abuse of the PrinterBug
while keeping the service running: when disabling the registry key RegisterSpoolerRemoteRpcEndPoint
, any incoming remote requests get blocked; this acts as if the service was disabled for remote clients. Setting the registry key to 1 enables it, while 2 disables it:
Detection
Exploiting the PrinterBug
will leave traces of network connections toward the Domain Controller; however, they are too generic to be used as a detection mechanism.
In the case of using NTLMRelayx
to perform DCSync, no event ID 4662
is generated (as mentioned in the DCSync section); however, to obtain the hashes as DC1 from DC2, there will be a successful logon event for DC1. This event originates from the IP address of the Kali machine, not the Domain Controller, as we can see below:
A suitable detection mechanism always correlates all logon attempts from core infrastructure servers to their respective IP addresses (which should be static and known).
Honeypot
It is possible to use the PrinterBug
as means of alerting on suspicious behavior in the environment. In this scenario, we would block outbound connections from our servers to ports 139
and 445
; software or physical firewalls can achieve this. Even though abuse can trigger the bug, the firewall rules will disallow the reverse connection to reach the threat agent. However, those blocked connections will act as signs of compromise for the blue team. Before enforcing anything related to this exploit, we should ensure that we have sufficient logs and knowledge of our environment to ensure that legitimate connections are allowed (for example, we must keep the mentioned ports open between DCs, so that they can replicate data).
While this may seem suitable for a honeypot to trick adversaries, we should be careful before implementing it, as currently, the bug requires the machine to connect back to us, but if a new unknown bug is discovered, which allows for some type of Remote Code Execution without the reverse connection, then this will backfire on us. Therefore, we should only consider this option if we are an extremely mature organization and can promptly act on alerts and disable the service on all devices should a new bug be discovered.
Q & A
1) What is Kerberos des-cbc-md5 key for user Administrator?
First, configure NTLMRelayx to forward connections to DC2 and attempt the DCSync attack.
To trigger the connection back, we'll use Dementor.
Returning to the terminal session with NTLMRelayx, we can see that the DCSync attack was successful.
Answer: d9b53b1f6d7c45a8
2) After performing the previous attack, connect to DC1 (172.16.18.3) as 'htb-student:HTB_@cademy_stdnt!' and make the appropriate change to the registry to prevent the PrinterBug attack. Then, restart DC1 and try the same attack again. What is the error message seen when running dementor.py?
Let’s connect to DC1 (172.16.18.3) from our Kali linux.
Let's open Registry Editior and disable the registry key RegisterSpoolerRemoteRpcEndPoint
Now let's restart DC1 and try the attack again.
Answer: [-] unhandled exception occured: SMB SessionError: STATUS_OBJECT_NAME_NOT_FOUND(The object name is not found.)
Last updated