Hello everyone. My name is Ron Ben Yitzhak and I'm very excited to be here today and give you my talk. You snooze, you lose. RPC Racer winning RPC end points against services. This year, this is the fourth year in a row I'm speaking here at DEF CON. I'll introduce myself first. I'm a security researcher at SafeBridge where I do vulnerability research. I also like playing music and going to concerts. This is our agenda for today. At the beginning I'll explain some basic terms regarding RPC. Then I'll expose some serious flaws in this very widely used protocol. I'll take you step by step showing how I manipulated a core component of RPC and masqueraded as a legitimate built in service to force a protected process to authenticate against an arbitrary server and disclosing the NTLM hash of the machine account. We're going to talk a lot today about the RPC protocol. So let's first understand what it is. The remote procedure call is used for inter process communication between clients and servers. The server exposes functionalities, certain actions and logics. And the client can request the server to execute them on its behalf. The server can run on the same machine as the client or on another computer on the network. Both RPC clients and servers use an interface definition language file or IDL file. It contains the properties of the RPC interface like definitions of structs, functions and most importantly the UUID. This unique identifier is used by the server when it registers to the machine and used by the client when it looks for its server. Before a client can communicate with a server, it first needs to create a binding handle. It is composed of three parts. The first part is the protocol sequence. This determines which protocol will encapsulate the RPC communication. The three most common protocols are TCP, named pipes over SMB and the advanced local procedure call or LPC for short. This protocol is used to transfer messages efficiently and securely between processes running on the same machine only. The second component is the network address which can be an IP address or computer name. And the last part is the end point. The meaning of it is different for every protocol sequence. For TCP it is the port number. For SMB it is the name of the pipe. And for LPC it is a unique string for that server. Two RPC servers cannot have the same end point. The examples in this talk are based on LPC end points because that is what most of the RPC servers in Windows use. But what I'm about to show you is relevant for other protocols as well. When an RPC server registers itself, it can either specify an end point or not. If it does, then the communication with it will be based on a well known end point. The client will have a hard coded string that it knows will match the server. If the server doesn't register with an end point, a unique string will be generated for it instead. This is called a dynamic end point. In this screen shot we can see three names. The first one starts with OLE. And although this is a unique string with a generated characters, it isn't the dynamic end point we are talking about. These end points are related to distributed com objects and are irrelevant for this talk. The second name is a well known end point that is registered by the local session manager. End points that start with LRPC are dynamic and contain generated characters. But the question is, if a dynamic end point is random, how does the client know who to communicate with? This is where the end point mapper comes in. The end point mapper or EPM maps between an interface UUID and the end points that expose it. If a server decides to use a dynamic end point, it needs to make sure it can be found by its clients. The way to do it is by registering to the end point mapper. After the registration of the server, the client will be able to establish an RPC connection using only a UUID. The EPM will connect it to the first server that registered that interface. There are two important tools the EPM works by. First, entries can be removed only if the original process unregisters or terminates. Second, the EPM will always use the first end point registered for an interface. The order cannot be modified. The EPM is managed by the DLL RPC EPM map which is loaded into the service RPC SS. Once it is loaded, it can be reached using multiple protocols. TCP, named pipes and LPC. Each one has its own known end points. The end point mapper can be queried locally or remotely using tools like RPC dump from impact. It behaves very much like a DNS server. It resolves UUID to an end point. This gave me an idea. Can an attack like DNS poisoning be applied to the EPM? Can we masquerade as a legitimate RPC server and have clients connect to us instead of the real one? We're going to create a new attack. EPM poisoning. Looking back at famous RPC experts, they usually target vulnerable coding servers to achieve remote code execution or privilege escalation. We're going to make a U-turn and target vulnerable code in RPC clients instead. The first step to achieve our goal is to figure out how to poison the EPM. Once it will forward RPC connections to us, we'll need to act like a built in legitimate service. Then send a malicious response to clients that will achieve privilege escalation. We're going to perform this attack without admin privileges. As a medium integrity process. To poison the EPM, the first thing we need to do is to register to it. We can do that with the API RPC EP register. But we don't want to just register any interface. We need to behave like a known server. And copy exactly what it does. Which means registering its interface. I was expecting another hard day of battling with error codes and diving into security mitigations. But then I just tried to register an interface that belongs to a built in service and apparently it worked. Moreover, it didn't even require admin privileges. I was shocked to discover that nothing stopped me from registering built in and known interfaces that belong to core services. I would expect that if Windows Defender, for example, has a unique identifier, then no other process will be able to register it. But that is not the case. Even though I achieved that, clients didn't connect to me. I didn't receive a connection because the original service registered an end point to its interface before me. When I tried registering an interface of a service that is turned off, its client connected to me instead. This is crazy. There are no security checks done by the EPM. It connected clients to an unknown process that isn't even running with admin privileges. EPM poisoning is possible and it doesn't even require elevation. As far as I can tell, this attack vector has never been explored before. Now, let's see how we can weaponize it. At this point, we made a proof of concepts. We know that the goal we set is possible. Now it's time to gather data and find our candidates. Our discovery proves that every RPC server that isn't launched on boots is prone to a hijack. Look at how many services there are. The next step is to gather lists of all the interfaces that aren't mapped to an end point. Like I mentioned before, dynamic end points can be retrieved from the EPM remotely or locally using win API. To be thorough, we need to also find the well-known end points. Several tools do that. Most notably, RPC view. It scans the memory of every process, locates the module RPC RT4 and passes internal structures to list the information shown here. I needed a comprehensive tool that knows how to retrieve both types of end points. So I developed RPC recon. The purpose of it is to find interfaces that can be registered right after the system boots. Before most services are launched. It is designed to be launched with a scheduled task when a user logs on. It will query the EPM and scan the memory of processes to gather a list of all the interfaces that are registered early in the boot process. After the first scan, it waits for several minutes until the late services starts. Then it performs the same retrieval again to gather a list of all the interfaces that are registered late. The last step is comparing the results. The difference shows interfaces that can be registered before the original service. Since this tool is used for gathering information and not for the attack itself, we'll execute it with admin permissions so it can scan the memory of elevated processes. And of course, this tool is now publicly available on GitHub. We'll start by executing RPC recon with the flag register. This will make it create a scheduled task that will be executed with elevated privileges when we log on. Then we'll restart to make sure most services aren't running. The tool will scan the system twice and compare the results. After the comparison is made, we'll get a list of all the interfaces that are registered late. Now we have a list of potential targets. There are many interfaces that we can hijack. My first surprise was that I can register to the EPM with any interface I want. No matter if it is critical to system functionality or belongs to a core component. I developed a generic RPC server that registers many interfaces and gathers information on the clients connecting to it. Then I started receiving connections from various processes on multiple interfaces. And when my server showed that those processes are services running as the local system account, I was sure I'm about to achieve the easiest privilege escalation ever. The most intuitive method to leverage the connection for privilege escalation is calling RPC impersonate clients and spawn a new console with our token. But it failed. I was able to get a new token but creating a new process with it resulted in the error bad impersonation level. Apparently MSRPC is broken. But not that broken. There is a policy for impersonation scenarios. It prevents medium integrity threads from impersonating a token with a higher integrity. To understand this mechanism better, let's go over the meaning of the levels. The anonymous level means the server cannot know who connected to it. The identification level is what I got. It lets the server query the client's privileges and security identifier. It is used to check if the client is allowed to access certain resources. The impersonation level is what I wished I had. It lets the server perform actions on the local machine with the client's security context. If the client is more privileged than the server, the server can use the impersonation for privilege escalation. Another idea I had is to leverage the connection for NTLM authentication. I try to use my new token to authenticate against an SMB server that belongs to me. That will usually disclose the NTLM hash. But again, the impersonation policy prevents it. To access remote resources over the network, we need the highest impersonation level, which is delegation. We hit our first obstacle in this race. Time to think what is our next move. At this point, I understood that I can't abuse the RPC connection. But maybe I can take advantage of the functionality the RPC server offers. If I masquerade as a server used for authentication, the clients will provide me with sensitive credentials. Out of all the vulnerable interfaces, I looked for ones with keywords such as credentials, identity and accounts. And ended up with these three interfaces. The vault service, Microsoft account signing assistant and the sync host service. When I launch my rogue server and use their clients, none of them connected to me. This is because of another security mechanism. One of the properties a binding handle can have is security quality of service. If the client is expecting the server to run as anti-authority system, it can specify a security identifier and that will prevent the connection to a server running as another user. This is what the RPC clients did. And this is why they didn't connect to me. For example, we can see that the RPC client of Microsoft account signing assistant create a security quality of service structure with the security identifier of the local system account. And then applies it to the binding handle. I was sure this time I will win the race. But I hit another obstacle. Let's have a short recap of our attempts. We received RPC connections from highly privileged services. But we couldn't impersonate them because of the policy that determines we can only identify who the client is. But not impersonate it. We saw that there are authentication services that are launched late. But their clients will only connect to a server that is running as a local system account. At this point, I needed to go to the pit stop and strategize. I knew the potential of EPM poisoning. I just needed to find the right way to abuse it. Then I had an idea. Another way to achieve privilege escalation is performing an action we aren't allowed to do natively. Such as writing to the system 32 directory. I thought that if I would masquerade as a file system service, another privileged service will ask me for data or file that it will then copy somewhere. Looking through my vulnerable interfaces list, I found a storage service. It is implemented in the file storage.dll and it is set to delayed start. The next step was launching my rogue server again. But this time registering only the interface of the storage service. I monitored the machine for RPC connections that happened naturally and gathered data on the clients of storage we see. The first service that connected to me was Windows updates. This is a highly privileged service in the operating system that can modify drivers and core DLL files. And it just connected to an unknown process running with low privileges. This security gap is just insane. Then I got a connection from storage service which doesn't make sense because that's who I'm pretending to be. Apparently this service uses its own RPC client to connect to itself. But since I registered the interface first, it connected to me instead. The last connection I got was from the delivery optimization service which is responsible for downloading updates and packages from alternative sources to make the distribution more efficient. Something interesting about this service is that it runs as a protected process light. This shows the impact EPM poisoning has. And the choosing storage we see is the right path forward. Even the most protected services will connect to us. The way to manipulate the process is to understand what it receives as inputs and what it is used for. Out of 36 methods that the interface exposes, only three were invoked. All of them are undocumented. So it is difficult to understand what they are used for. But two out of three return an integer back to the clients. And this is very unlikely to have a major impact. The third method on the other hand returns an undocumented structure. That has more potential. We want to understand what is the definition of the structure returned by the method gate storage device info. One way to do that is to look at functions on the client side that receive this structure. The call stack that led to the RPC call went through a DLL called app X deployment clients. When I disassembled it, I was surprised to see its public symbols contain a lot of information about the interface of storage service. It had enums, variable names, basically everything I needed. And the best part was, it revealed our struct contains a path. At this point, all I had to do is to apply this definition on the disassembly of other clients to see what they are doing with this path. After digging through the disassembly of all the clients, I found out that the delivery optimization service performs a few sanity checks on the path it receives that I was able to bypass. And then it creates a directory based on that path. We found an action we can manipulate. Our low privilege process can return a path that will be used by a highly privileged process. The delivery optimization service is running as a user and authority network service. And the easiest way to exploit this vulnerability is to create a directory in the home folder of this user. As you can see in the screen shots, it works. We returned a network share to the C drive of the local machine to bypass the security, the sanity checks and the directory hello DEF CON 33 was created. But that's not enough. Let's see what more we can do. To gain the most out of this vulnerability, we first need to understand what is this user and what it is used for. Processes running as network service have a token with a very high integrity level. The same as the local system accounts. But still, there is a difference between them. The network service is not part of the administrator's group. It means that it doesn't have right access to most of the sensitive directories, registry keys and processes on the machine. The purpose of this user is to have a few privileges locally, but to be able to authenticate to remote machines. And it does that with the machine accounts. Now let's understand what is this account. When a computer joins an active directory domain, an account is created in the NTTS database that represents this computer. This account can be easily identified by the dollar character at the end of its name. Like any domain user, it has a password , group memberships and can be used to access remote, to access resources in the domain network. The machine account is often abused in pen testing, depending on the configuration of the domain. And logged on users cannot authenticate to remote resources with those credentials. They are only used by the local system and network service accounts. That is where our vulnerability comes in. We can bypass the limitation applied on logged on users and authenticate with the machine accounts. Previously I showed you my RPC server returned a network share of the C drive to the delivery optimization service. If I return a network share of an external server, the delivery optimization service will authenticate against it with the machine account credentials and I'll be able to relay the NTLM authentication. We successfully crossed the security boundary and won the race. Time to recap our attack. As a medium integrity process, we can create a schedule task that will be executed when the current user logs in. At this point, most of the RPC servers haven't launched yet. Our first step will be to register the interface of the storage service. Then we'll trigger the delivery optimization service to send an RPC request to the storage service. It will connect to it with a dynamic end point. Which means it will query the EPM and get the end points that we registered. Then it will invoke the method get storage device info. And in return, it will receive an SMB share to a server that we launched. The final step will be the delivery optimization service authenticating to us with the machine account credentials. And us relaying this authentication. This attack is done by another new tool called RPC Racer. And it is now available. In addition to forcing the authentication of the machine account, RPC Racer is designed to launch rogue RPC interfaces. It will print information about the clients connecting to it. This is helpful for researching vulnerabilities in other servers. The vulnerability in the storage service was acknowledged by Microsoft. And a fix was released on July 8th. We execute our tool without admin privileges. As a medium integrity process. If we could relay the machine account authentication back to the computer we are running on, we would escalate our privileges. But that is not possible due to security mitigation. An MTLM authentication can't be relayed back to the computer that originated it. Therefore, we need to find another server in the domain. To understand the impact of forcing and relaying a machine account authentication, we look at the machine account of the domain controller. If we would execute our tool as a low privilege user on the domain controller, we can use authentication for an attack called ESC 8. ESC 8 is an attack that achieves privilege escalation by leveraging the Active Directory Certificate Service or ADCS. This server is part of the domain. And the certificate it generates are recognized by other computers in the network. Also, those certificates can be used for authentication against instead of plain text credentials. To be specific, ESC 8 targets the web enrollment feature of ADCS. This feature allows a user to log into a web server managed by ADCS and request to generate a certificate. What happens in ESC 8 is that the attack relays an MTLM authentication to request from the web server a certificate that represents a privileged user in the domain. Like I said before, MTLM authentication cannot be relayed back to the same computer. We want to use the privileges of the DC machine account, but we need another form of authentication. The first step to achieve that will be to relay the authentication created by RPC racer to the web server of ADCS. It will generate for us a certificate that represents the machine account of the domain controller. This is done by the tool MTLM relay X from in packets. We cannot authenticate anywhere across the domain with this certificate yet. Our next step will be to request from the domain controller a ticket granting tickets or TGT. This is a legitimate Kerberos ticket that can be used to request access to resources in the domain. This step is done by a tool called certify. Once we have the TGT of the domain controller machine account, we can use it to execute several attacks. The most common one will be to dump the password hashes of all the users in the domain. For this, we will use in packets again. But this time the tool secrets dump. Let's see how it all comes together. We'll launch a rogue SMB server with MTLM relay X and tell it to relay the authentication to the ADCS. Then we log on to the server as an unprivileged user. As you can see, we are running as a medium integrity process. At this point, the storage service is running. So, we'll execute RPC racer with the IP address of the relay server and tell it to register a schedule task that will start when we log on. Our moment to strike will be after the machine reboots. We can see that the delivery optimization service requested a path from us and that our SMB server received the authentication and relayed it to get a certificate. Then we'll use certify to request a TGT based on that certificate. Once we have a TGT of the machine account, we can dump all of the domain controller secrets. Like I said before, EPM poisoning is a real attack. And we saw just one way to abuse it. There are a lot more to get out of it. We can perform many in the middle by forwarding the request we received to the original service and filtering out calls to hide our foothold on the machine. An additional option for us is to just cause denial of service. By registering many interfaces and denying the requests, a lot of functionalities will be disabled. This is a much more sophisticated method. Instead of terminating processes or spamming them with packets, we can just register the RPC interface first. Another thing I talked about is stealing credentials. I looked at a few services that might be exploited for that. But there are probably more. We exposed some serious security issues at this talk. And there are a few lessons that should be learned from that. The first one is that the integrity of servers should be checked in every protocol. Just like SSL pinning verifies that the certificate is not only valid but uses a specific public key, the identity of RPC servers should be checked. The current design of the EPM doesn't perform this verification. Therefore, it must be done by the clients. The second point I want to leave you with is the danger of setting services to delayed start. Software developers of RPC servers should be aware of the implications of launching the programs late in the boot process. Services are often set to delayed start to make the boot process faster. But performance cannot come at the expense of security. Any stage where untrusted code can be executed should be considered unsafe. The patch to this vulnerability was released on July 8th. The fix was made to the RPC clients. Storage usage dot DLL. It improved how the binding was made. Instead of creating a simple binding handle, a security quality of service was applied to it. Now, the RPC connection will be made only if the RPC server is running as a local system account. Since the patch was made only to the RPC client of storage service, it means that there are many other clients and interfaces that are vulnerable to EPM poisoning. So, I have a, I have some suggestions to detect it. Security products can use hooking to monitor calls to RPC EP register. If a process wants to register a built in known interface to the EPM and it isn't a legitimate service, it should be detected. Another detection technique is to use event tracing for Windows or ETW. The operating system automatically generates events for many actions that occur in the machine. The provider named Microsoft Windows RPC logs a lot of useful information in this case. In these events, we can see the correlation between the process ID of RPC racer, the process ID of the delivery optimization service, and the interface of the storage service that we hijacked. We can even see the exact procedure number that was invoked, which correlates to get storage device info. These event types can be used to detect cases of EPM poisoning. An unknown process received an RPC connection on a known interface. I exploited the vulnerability I found to force the authentication of the machine accounts. But I think it could even lead to an even stronger impact. The password return to the delivery optimization service will be used as a private folder of the service where it will look for config files. This means that if we can point it to a directory with poisoned configs, that will affect the behavior of the service. One of the config files is key value LKG.dat. It contains many URLs. Regarding future work for this research, we would gain a lot more out of this vulnerability if we could change them to download payloads to the machine. Another interesting config file is dosvcstate.dat. This is a standalone registry hive used to manage jobs assigned to the delivery optimization service. There are some values that definitely catch the eye, such as CDN URL and working directory. Creating a key with certain values might result in the service downloading files to protected directories. And of course, the most prominent attack vector I suggest you to chase is to find more vulnerable RPC servers. There are so many. I just began scratching the surface. For example, Windows Security Center is set to delayed starts. And Windows Defender interacts with it. Maybe it is possible to neutralize Defender by sending it back a malicious response. To conclude this talk, I presented a serious security issue in a core component of the RPC protocol. There are no verifications on who is registering an interface that will be used by crucial services of the operating system. I showed you how to map the operating system to find vulnerable RPC servers. And RPC recon is now available for you to do it by yourself. After the target is found, I described how to analyze and exploit the clients. Here is the link to the repository of the tools. Feel free to reach out and contact me. Thank you.