1 00:00:00,000 --> 00:00:01,180 Hello everyone. 2 00:00:01,180 --> 00:00:06,960 My name is Ron Ben Yitzhak and I'm very excited to be here today and give you my talk. 3 00:00:06,960 --> 00:00:08,280 You snooze, you lose. 4 00:00:08,280 --> 00:00:12,360 RPC Racer winning RPC end points against services. 5 00:00:12,640 --> 00:00:18,080 This year, this is the fourth year in a row I'm speaking here at DEF CON. 6 00:00:24,590 --> 00:00:26,790 I'll introduce myself first. 7 00:00:26,790 --> 00:00:31,570 I'm a security researcher at SafeBridge where I do vulnerability research. 8 00:00:31,570 --> 00:00:35,390 I also like playing music and going to concerts. 9 00:00:36,250 --> 00:00:38,670 This is our agenda for today. 10 00:00:38,670 --> 00:00:43,110 At the beginning I'll explain some basic terms regarding RPC. 11 00:00:43,130 --> 00:00:49,170 Then I'll expose some serious flaws in this very widely used protocol. 12 00:00:49,170 --> 00:01:07,810 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. 13 00:01:08,870 --> 00:01:13,110 We're going to talk a lot today about the RPC protocol. 14 00:01:13,110 --> 00:01:16,490 So let's first understand what it is. 15 00:01:16,570 --> 00:01:23,470 The remote procedure call is used for inter process communication between clients and servers. 16 00:01:23,470 --> 00:01:28,570 The server exposes functionalities, certain actions and logics. 17 00:01:28,570 --> 00:01:33,230 And the client can request the server to execute them on its behalf. 18 00:01:33,290 --> 00:01:39,450 The server can run on the same machine as the client or on another computer on the network. 19 00:01:40,510 --> 00:01:47,890 Both RPC clients and servers use an interface definition language file or IDL file. 20 00:01:47,890 --> 00:01:58,130 It contains the properties of the RPC interface like definitions of structs, functions and most importantly the UUID. 21 00:01:58,130 --> 00:02:06,950 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. 22 00:02:07,950 --> 00:02:14,270 Before a client can communicate with a server, it first needs to create a binding handle. 23 00:02:14,270 --> 00:02:16,730 It is composed of three parts. 24 00:02:16,810 --> 00:02:19,730 The first part is the protocol sequence. 25 00:02:19,730 --> 00:02:24,690 This determines which protocol will encapsulate the RPC communication. 26 00:02:24,770 --> 00:02:35,470 The three most common protocols are TCP, named pipes over SMB and the advanced local procedure call or LPC for short. 27 00:02:35,470 --> 00:02:44,150 This protocol is used to transfer messages efficiently and securely between processes running on the same machine only. 28 00:02:45,410 --> 00:02:51,730 The second component is the network address which can be an IP address or computer name. 29 00:02:52,250 --> 00:02:55,170 And the last part is the end point. 30 00:02:55,190 --> 00:02:59,050 The meaning of it is different for every protocol sequence. 31 00:02:59,050 --> 00:03:01,310 For TCP it is the port number. 32 00:03:01,310 --> 00:03:03,910 For SMB it is the name of the pipe. 33 00:03:03,910 --> 00:03:08,030 And for LPC it is a unique string for that server. 34 00:03:08,090 --> 00:03:11,850 Two RPC servers cannot have the same end point. 35 00:03:12,330 --> 00:03:20,150 The examples in this talk are based on LPC end points because that is what most of the RPC servers in Windows use. 36 00:03:20,290 --> 00:03:24,630 But what I'm about to show you is relevant for other protocols as well. 37 00:03:26,030 --> 00:03:32,630 When an RPC server registers itself, it can either specify an end point or not. 38 00:03:32,750 --> 00:03:38,510 If it does, then the communication with it will be based on a well known end point. 39 00:03:38,510 --> 00:03:43,850 The client will have a hard coded string that it knows will match the server. 40 00:03:43,950 --> 00:03:50,210 If the server doesn't register with an end point, a unique string will be generated for it instead. 41 00:03:50,210 --> 00:03:52,810 This is called a dynamic end point. 42 00:03:52,810 --> 00:03:55,670 In this screen shot we can see three names. 43 00:03:56,670 --> 00:03:59,790 The first one starts with OLE. 44 00:03:59,830 --> 00:04:06,890 And although this is a unique string with a generated characters, it isn't the dynamic end point we are talking about. 45 00:04:06,890 --> 00:04:12,710 These end points are related to distributed com objects and are irrelevant for this talk. 46 00:04:13,330 --> 00:04:19,190 The second name is a well known end point that is registered by the local session manager. 47 00:04:20,590 --> 00:04:26,530 End points that start with LRPC are dynamic and contain generated characters. 48 00:04:27,010 --> 00:04:34,490 But the question is, if a dynamic end point is random, how does the client know who to communicate with? 49 00:04:34,490 --> 00:04:37,550 This is where the end point mapper comes in. 50 00:04:38,770 --> 00:04:46,850 The end point mapper or EPM maps between an interface UUID and the end points that expose it. 51 00:04:47,050 --> 00:04:54,890 If a server decides to use a dynamic end point, it needs to make sure it can be found by its clients. 52 00:04:54,890 --> 00:04:58,730 The way to do it is by registering to the end point mapper. 53 00:05:00,270 --> 00:05:08,330 After the registration of the server, the client will be able to establish an RPC connection using only a UUID. 54 00:05:08,670 --> 00:05:13,730 The EPM will connect it to the first server that registered that interface. 55 00:05:13,730 --> 00:05:17,230 There are two important tools the EPM works by. 56 00:05:17,230 --> 00:05:24,770 First, entries can be removed only if the original process unregisters or terminates. 57 00:05:24,810 --> 00:05:30,570 Second, the EPM will always use the first end point registered for an interface. 58 00:05:30,570 --> 00:05:32,970 The order cannot be modified. 59 00:05:33,750 --> 00:05:41,050 The EPM is managed by the DLL RPC EPM map which is loaded into the service RPC SS. 60 00:05:41,050 --> 00:05:45,230 Once it is loaded, it can be reached using multiple protocols. 61 00:05:45,230 --> 00:05:48,310 TCP, named pipes and LPC. 62 00:05:48,310 --> 00:05:51,350 Each one has its own known end points. 63 00:05:52,350 --> 00:05:58,810 The end point mapper can be queried locally or remotely using tools like RPC dump from impact. 64 00:05:59,070 --> 00:06:03,270 It behaves very much like a DNS server. 65 00:06:03,270 --> 00:06:06,470 It resolves UUID to an end point. 66 00:06:06,710 --> 00:06:08,730 This gave me an idea. 67 00:06:08,830 --> 00:06:12,870 Can an attack like DNS poisoning be applied to the EPM? 68 00:06:13,730 --> 00:06:21,530 Can we masquerade as a legitimate RPC server and have clients connect to us instead of the real one? 69 00:06:21,610 --> 00:06:24,130 We're going to create a new attack. 70 00:06:24,130 --> 00:06:25,870 EPM poisoning. 71 00:06:27,550 --> 00:06:38,050 Looking back at famous RPC experts, they usually target vulnerable coding servers to achieve remote code execution or privilege escalation. 72 00:06:38,470 --> 00:06:45,510 We're going to make a U-turn and target vulnerable code in RPC clients instead. 73 00:06:46,610 --> 00:06:51,690 The first step to achieve our goal is to figure out how to poison the EPM. 74 00:06:51,790 --> 00:06:58,670 Once it will forward RPC connections to us, we'll need to act like a built in legitimate service. 75 00:06:58,670 --> 00:07:04,130 Then send a malicious response to clients that will achieve privilege escalation. 76 00:07:04,330 --> 00:07:08,350 We're going to perform this attack without admin privileges. 77 00:07:08,350 --> 00:07:10,790 As a medium integrity process. 78 00:07:11,650 --> 00:07:17,170 To poison the EPM, the first thing we need to do is to register to it. 79 00:07:17,170 --> 00:07:21,170 We can do that with the API RPC EP register. 80 00:07:21,230 --> 00:07:25,670 But we don't want to just register any interface. 81 00:07:25,670 --> 00:07:28,550 We need to behave like a known server. 82 00:07:28,550 --> 00:07:31,470 And copy exactly what it does. 83 00:07:31,470 --> 00:07:35,030 Which means registering its interface. 84 00:07:35,550 --> 00:07:43,010 I was expecting another hard day of battling with error codes and diving into security mitigations. 85 00:07:43,010 --> 00:07:52,370 But then I just tried to register an interface that belongs to a built in service and apparently it worked. 86 00:07:52,370 --> 00:07:56,550 Moreover, it didn't even require admin privileges. 87 00:07:57,690 --> 00:08:07,510 I was shocked to discover that nothing stopped me from registering built in and known interfaces that belong to core services. 88 00:08:07,730 --> 00:08:16,770 I would expect that if Windows Defender, for example, has a unique identifier, then no other process will be able to register it. 89 00:08:16,770 --> 00:08:18,850 But that is not the case. 90 00:08:19,250 --> 00:08:23,130 Even though I achieved that, clients didn't connect to me. 91 00:08:23,830 --> 00:08:31,470 I didn't receive a connection because the original service registered an end point to its interface before me. 92 00:08:31,470 --> 00:08:39,250 When I tried registering an interface of a service that is turned off, its client connected to me instead. 93 00:08:39,570 --> 00:08:41,550 This is crazy. 94 00:08:41,550 --> 00:08:44,910 There are no security checks done by the EPM. 95 00:08:44,910 --> 00:08:51,130 It connected clients to an unknown process that isn't even running with admin privileges. 96 00:08:52,870 --> 00:08:58,070 EPM poisoning is possible and it doesn't even require elevation. 97 00:08:58,190 --> 00:09:03,250 As far as I can tell, this attack vector has never been explored before. 98 00:09:03,250 --> 00:09:07,050 Now, let's see how we can weaponize it. 99 00:09:08,430 --> 00:09:11,590 At this point, we made a proof of concepts. 100 00:09:11,590 --> 00:09:14,230 We know that the goal we set is possible. 101 00:09:14,370 --> 00:09:17,830 Now it's time to gather data and find our candidates. 102 00:09:17,990 --> 00:09:25,530 Our discovery proves that every RPC server that isn't launched on boots is prone to a hijack. 103 00:09:25,710 --> 00:09:28,510 Look at how many services there are. 104 00:09:28,650 --> 00:09:34,530 The next step is to gather lists of all the interfaces that aren't mapped to an end point. 105 00:09:36,190 --> 00:09:44,210 Like I mentioned before, dynamic end points can be retrieved from the EPM remotely or locally using win API. 106 00:09:44,590 --> 00:09:49,250 To be thorough, we need to also find the well-known end points. 107 00:09:49,250 --> 00:09:51,010 Several tools do that. 108 00:09:51,010 --> 00:09:53,470 Most notably, RPC view. 109 00:09:53,590 --> 00:10:02,990 It scans the memory of every process, locates the module RPC RT4 and passes internal structures to list the information shown here. 110 00:10:04,690 --> 00:10:10,430 I needed a comprehensive tool that knows how to retrieve both types of end points. 111 00:10:10,430 --> 00:10:13,190 So I developed RPC recon. 112 00:10:13,190 --> 00:10:19,570 The purpose of it is to find interfaces that can be registered right after the system boots. 113 00:10:19,570 --> 00:10:22,250 Before most services are launched. 114 00:10:23,810 --> 00:10:28,090 It is designed to be launched with a scheduled task when a user logs on. 115 00:10:28,090 --> 00:10:37,570 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. 116 00:10:38,510 --> 00:10:44,210 After the first scan, it waits for several minutes until the late services starts. 117 00:10:44,250 --> 00:10:51,110 Then it performs the same retrieval again to gather a list of all the interfaces that are registered late. 118 00:10:52,250 --> 00:10:55,270 The last step is comparing the results. 119 00:10:55,470 --> 00:11:00,870 The difference shows interfaces that can be registered before the original service. 120 00:11:01,090 --> 00:11:11,270 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. 121 00:11:11,790 --> 00:11:15,570 And of course, this tool is now publicly available on GitHub. 122 00:11:18,170 --> 00:11:22,470 We'll start by executing RPC recon with the flag register. 123 00:11:22,490 --> 00:11:28,330 This will make it create a scheduled task that will be executed with elevated privileges when we log on. 124 00:11:28,410 --> 00:11:32,230 Then we'll restart to make sure most services aren't running. 125 00:11:34,850 --> 00:11:38,610 The tool will scan the system twice and compare the results. 126 00:11:38,670 --> 00:11:44,390 After the comparison is made, we'll get a list of all the interfaces that are registered late. 127 00:11:45,690 --> 00:11:48,530 Now we have a list of potential targets. 128 00:11:48,530 --> 00:11:51,730 There are many interfaces that we can hijack. 129 00:11:55,280 --> 00:12:01,420 My first surprise was that I can register to the EPM with any interface I want. 130 00:12:01,420 --> 00:12:07,040 No matter if it is critical to system functionality or belongs to a core component. 131 00:12:07,200 --> 00:12:16,080 I developed a generic RPC server that registers many interfaces and gathers information on the clients connecting to it. 132 00:12:17,000 --> 00:12:24,260 Then I started receiving connections from various processes on multiple interfaces. 133 00:12:25,340 --> 00:12:37,720 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. 134 00:12:38,820 --> 00:12:48,920 The most intuitive method to leverage the connection for privilege escalation is calling RPC impersonate clients and spawn a new console with our token. 135 00:12:48,920 --> 00:12:51,500 But it failed. 136 00:12:51,620 --> 00:12:59,260 I was able to get a new token but creating a new process with it resulted in the error bad impersonation level. 137 00:12:59,720 --> 00:13:02,520 Apparently MSRPC is broken. 138 00:13:02,520 --> 00:13:05,060 But not that broken. 139 00:13:05,240 --> 00:13:08,300 There is a policy for impersonation scenarios. 140 00:13:08,300 --> 00:13:14,180 It prevents medium integrity threads from impersonating a token with a higher integrity. 141 00:13:14,420 --> 00:13:19,220 To understand this mechanism better, let's go over the meaning of the levels. 142 00:13:20,060 --> 00:13:25,380 The anonymous level means the server cannot know who connected to it. 143 00:13:25,380 --> 00:13:28,300 The identification level is what I got. 144 00:13:28,300 --> 00:13:32,840 It lets the server query the client's privileges and security identifier. 145 00:13:33,060 --> 00:13:37,540 It is used to check if the client is allowed to access certain resources. 146 00:13:37,920 --> 00:13:41,380 The impersonation level is what I wished I had. 147 00:13:41,380 --> 00:13:46,940 It lets the server perform actions on the local machine with the client's security context. 148 00:13:47,140 --> 00:13:54,160 If the client is more privileged than the server, the server can use the impersonation for privilege escalation. 149 00:13:55,920 --> 00:14:01,720 Another idea I had is to leverage the connection for NTLM authentication. 150 00:14:01,780 --> 00:14:07,880 I try to use my new token to authenticate against an SMB server that belongs to me. 151 00:14:08,020 --> 00:14:11,700 That will usually disclose the NTLM hash. 152 00:14:11,700 --> 00:14:14,760 But again, the impersonation policy prevents it. 153 00:14:14,760 --> 00:14:21,700 To access remote resources over the network, we need the highest impersonation level, which is delegation. 154 00:14:23,220 --> 00:14:26,580 We hit our first obstacle in this race. 155 00:14:26,580 --> 00:14:29,120 Time to think what is our next move. 156 00:14:34,850 --> 00:14:39,110 At this point, I understood that I can't abuse the RPC connection. 157 00:14:39,350 --> 00:14:45,390 But maybe I can take advantage of the functionality the RPC server offers. 158 00:14:45,450 --> 00:14:52,210 If I masquerade as a server used for authentication, the clients will provide me with sensitive credentials. 159 00:14:52,330 --> 00:15:00,370 Out of all the vulnerable interfaces, I looked for ones with keywords such as credentials, identity and accounts. 160 00:15:00,370 --> 00:15:03,110 And ended up with these three interfaces. 161 00:15:03,630 --> 00:15:09,470 The vault service, Microsoft account signing assistant and the sync host service. 162 00:15:09,630 --> 00:15:14,830 When I launch my rogue server and use their clients, none of them connected to me. 163 00:15:14,830 --> 00:15:17,850 This is because of another security mechanism. 164 00:15:18,910 --> 00:15:24,690 One of the properties a binding handle can have is security quality of service. 165 00:15:24,710 --> 00:15:37,150 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. 166 00:15:37,350 --> 00:15:39,690 This is what the RPC clients did. 167 00:15:39,690 --> 00:15:42,070 And this is why they didn't connect to me. 168 00:15:43,290 --> 00:15:54,970 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. 169 00:15:54,970 --> 00:15:57,970 And then applies it to the binding handle. 170 00:15:59,190 --> 00:16:03,490 I was sure this time I will win the race. 171 00:16:03,490 --> 00:16:05,930 But I hit another obstacle. 172 00:16:07,810 --> 00:16:10,450 Let's have a short recap of our attempts. 173 00:16:10,490 --> 00:16:14,950 We received RPC connections from highly privileged services. 174 00:16:14,950 --> 00:16:21,750 But we couldn't impersonate them because of the policy that determines we can only identify who the client is. 175 00:16:21,750 --> 00:16:23,810 But not impersonate it. 176 00:16:23,950 --> 00:16:28,070 We saw that there are authentication services that are launched late. 177 00:16:28,090 --> 00:16:32,930 But their clients will only connect to a server that is running as a local system account. 178 00:16:33,230 --> 00:16:37,890 At this point, I needed to go to the pit stop and strategize. 179 00:16:38,030 --> 00:16:41,070 I knew the potential of EPM poisoning. 180 00:16:41,250 --> 00:16:44,710 I just needed to find the right way to abuse it. 181 00:16:44,870 --> 00:16:47,890 Then I had an idea. 182 00:16:49,250 --> 00:16:55,250 Another way to achieve privilege escalation is performing an action we aren't allowed to do natively. 183 00:16:55,250 --> 00:16:58,810 Such as writing to the system 32 directory. 184 00:16:58,950 --> 00:17:09,750 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. 185 00:17:09,890 --> 00:17:14,630 Looking through my vulnerable interfaces list, I found a storage service. 186 00:17:14,630 --> 00:17:20,430 It is implemented in the file storage.dll and it is set to delayed start. 187 00:17:21,710 --> 00:17:25,550 The next step was launching my rogue server again. 188 00:17:25,550 --> 00:17:30,050 But this time registering only the interface of the storage service. 189 00:17:30,330 --> 00:17:37,790 I monitored the machine for RPC connections that happened naturally and gathered data on the clients of storage we see. 190 00:17:37,850 --> 00:17:42,430 The first service that connected to me was Windows updates. 191 00:17:42,430 --> 00:17:49,930 This is a highly privileged service in the operating system that can modify drivers and core DLL files. 192 00:17:49,930 --> 00:17:55,170 And it just connected to an unknown process running with low privileges. 193 00:17:55,290 --> 00:17:58,350 This security gap is just insane. 194 00:17:59,550 --> 00:18:08,390 Then I got a connection from storage service which doesn't make sense because that's who I'm pretending to be. 195 00:18:08,550 --> 00:18:14,590 Apparently this service uses its own RPC client to connect to itself. 196 00:18:14,630 --> 00:18:19,590 But since I registered the interface first, it connected to me instead. 197 00:18:20,530 --> 00:18:32,590 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. 198 00:18:33,070 --> 00:18:38,550 Something interesting about this service is that it runs as a protected process light. 199 00:18:38,670 --> 00:18:42,230 This shows the impact EPM poisoning has. 200 00:18:42,230 --> 00:18:45,850 And the choosing storage we see is the right path forward. 201 00:18:46,050 --> 00:18:49,770 Even the most protected services will connect to us. 202 00:18:51,610 --> 00:18:58,190 The way to manipulate the process is to understand what it receives as inputs and what it is used for. 203 00:18:58,450 --> 00:19:03,950 Out of 36 methods that the interface exposes, only three were invoked. 204 00:19:03,950 --> 00:19:05,970 All of them are undocumented. 205 00:19:05,970 --> 00:19:09,330 So it is difficult to understand what they are used for. 206 00:19:09,390 --> 00:19:13,690 But two out of three return an integer back to the clients. 207 00:19:13,690 --> 00:19:17,250 And this is very unlikely to have a major impact. 208 00:19:17,350 --> 00:19:22,110 The third method on the other hand returns an undocumented structure. 209 00:19:22,190 --> 00:19:24,630 That has more potential. 210 00:19:26,490 --> 00:19:33,430 We want to understand what is the definition of the structure returned by the method gate storage device info. 211 00:19:33,510 --> 00:19:39,110 One way to do that is to look at functions on the client side that receive this structure. 212 00:19:39,330 --> 00:19:45,430 The call stack that led to the RPC call went through a DLL called app X deployment clients. 213 00:19:45,570 --> 00:19:55,070 When I disassembled it, I was surprised to see its public symbols contain a lot of information about the interface of storage service. 214 00:19:56,250 --> 00:20:01,730 It had enums, variable names, basically everything I needed. 215 00:20:01,870 --> 00:20:06,950 And the best part was, it revealed our struct contains a path. 216 00:20:07,190 --> 00:20:15,850 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. 217 00:20:17,530 --> 00:20:29,350 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. 218 00:20:29,390 --> 00:20:33,550 And then it creates a directory based on that path. 219 00:20:33,550 --> 00:20:36,750 We found an action we can manipulate. 220 00:20:36,970 --> 00:20:43,390 Our low privilege process can return a path that will be used by a highly privileged process. 221 00:20:43,790 --> 00:20:49,370 The delivery optimization service is running as a user and authority network service. 222 00:20:49,510 --> 00:20:56,330 And the easiest way to exploit this vulnerability is to create a directory in the home folder of this user. 223 00:20:57,230 --> 00:21:00,910 As you can see in the screen shots, it works. 224 00:21:00,930 --> 00:21:11,230 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. 225 00:21:11,690 --> 00:21:13,970 But that's not enough. 226 00:21:14,250 --> 00:21:16,230 Let's see what more we can do. 227 00:21:17,550 --> 00:21:26,390 To gain the most out of this vulnerability, we first need to understand what is this user and what it is used for. 228 00:21:26,670 --> 00:21:32,590 Processes running as network service have a token with a very high integrity level. 229 00:21:32,590 --> 00:21:35,550 The same as the local system accounts. 230 00:21:35,770 --> 00:21:39,110 But still, there is a difference between them. 231 00:21:39,190 --> 00:21:43,370 The network service is not part of the administrator's group. 232 00:21:43,370 --> 00:21:51,150 It means that it doesn't have right access to most of the sensitive directories, registry keys and processes on the machine. 233 00:21:51,290 --> 00:21:59,430 The purpose of this user is to have a few privileges locally, but to be able to authenticate to remote machines. 234 00:21:59,430 --> 00:22:02,370 And it does that with the machine accounts. 235 00:22:02,470 --> 00:22:05,210 Now let's understand what is this account. 236 00:22:06,770 --> 00:22:15,250 When a computer joins an active directory domain, an account is created in the NTTS database that represents this computer. 237 00:22:15,610 --> 00:22:20,370 This account can be easily identified by the dollar character at the end of its name. 238 00:22:20,710 --> 00:22:30,770 Like any domain user, it has a password , group memberships and can be used to access remote, to access resources in the domain network. 239 00:22:32,090 --> 00:22:37,950 The machine account is often abused in pen testing, depending on the configuration of the domain. 240 00:22:38,070 --> 00:22:44,110 And logged on users cannot authenticate to remote resources with those credentials. 241 00:22:44,130 --> 00:22:48,670 They are only used by the local system and network service accounts. 242 00:22:48,870 --> 00:22:52,470 That is where our vulnerability comes in. 243 00:22:53,470 --> 00:22:59,890 We can bypass the limitation applied on logged on users and authenticate with the machine accounts. 244 00:22:59,910 --> 00:23:07,690 Previously I showed you my RPC server returned a network share of the C drive to the delivery optimization service. 245 00:23:07,730 --> 00:23:21,030 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. 246 00:23:22,250 --> 00:23:26,790 We successfully crossed the security boundary and won the race. 247 00:23:28,350 --> 00:23:30,590 Time to recap our attack. 248 00:23:30,610 --> 00:23:38,010 As a medium integrity process, we can create a schedule task that will be executed when the current user logs in. 249 00:23:38,050 --> 00:23:42,710 At this point, most of the RPC servers haven't launched yet. 250 00:23:42,850 --> 00:23:47,070 Our first step will be to register the interface of the storage service. 251 00:23:47,170 --> 00:23:54,070 Then we'll trigger the delivery optimization service to send an RPC request to the storage service. 252 00:23:54,070 --> 00:23:56,970 It will connect to it with a dynamic end point. 253 00:23:56,970 --> 00:24:02,670 Which means it will query the EPM and get the end points that we registered. 254 00:24:02,750 --> 00:24:06,930 Then it will invoke the method get storage device info. 255 00:24:06,930 --> 00:24:12,050 And in return, it will receive an SMB share to a server that we launched. 256 00:24:12,090 --> 00:24:19,130 The final step will be the delivery optimization service authenticating to us with the machine account credentials. 257 00:24:19,130 --> 00:24:21,770 And us relaying this authentication. 258 00:24:23,070 --> 00:24:28,630 This attack is done by another new tool called RPC Racer. 259 00:24:28,630 --> 00:24:30,470 And it is now available. 260 00:24:30,550 --> 00:24:38,650 In addition to forcing the authentication of the machine account, RPC Racer is designed to launch rogue RPC interfaces. 261 00:24:38,670 --> 00:24:41,990 It will print information about the clients connecting to it. 262 00:24:41,990 --> 00:24:46,430 This is helpful for researching vulnerabilities in other servers. 263 00:24:46,630 --> 00:24:50,570 The vulnerability in the storage service was acknowledged by Microsoft. 264 00:24:50,570 --> 00:24:53,590 And a fix was released on July 8th. 265 00:24:54,690 --> 00:24:58,610 We execute our tool without admin privileges. 266 00:24:58,610 --> 00:25:00,830 As a medium integrity process. 267 00:25:00,990 --> 00:25:09,070 If we could relay the machine account authentication back to the computer we are running on, we would escalate our privileges. 268 00:25:09,170 --> 00:25:13,130 But that is not possible due to security mitigation. 269 00:25:13,290 --> 00:25:18,510 An MTLM authentication can't be relayed back to the computer that originated it. 270 00:25:18,510 --> 00:25:22,570 Therefore, we need to find another server in the domain. 271 00:25:22,930 --> 00:25:31,030 To understand the impact of forcing and relaying a machine account authentication, we look at the machine account of the domain controller. 272 00:25:31,190 --> 00:25:40,630 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. 273 00:25:42,070 --> 00:25:51,550 ESC 8 is an attack that achieves privilege escalation by leveraging the Active Directory Certificate Service or ADCS. 274 00:25:51,550 --> 00:25:54,230 This server is part of the domain. 275 00:25:54,230 --> 00:25:59,590 And the certificate it generates are recognized by other computers in the network. 276 00:25:59,590 --> 00:26:07,150 Also, those certificates can be used for authentication against instead of plain text credentials. 277 00:26:07,470 --> 00:26:13,550 To be specific, ESC 8 targets the web enrollment feature of ADCS. 278 00:26:13,610 --> 00:26:21,690 This feature allows a user to log into a web server managed by ADCS and request to generate a certificate. 279 00:26:21,790 --> 00:26:33,430 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. 280 00:26:34,470 --> 00:26:40,870 Like I said before, MTLM authentication cannot be relayed back to the same computer. 281 00:26:40,870 --> 00:26:47,270 We want to use the privileges of the DC machine account, but we need another form of authentication. 282 00:26:47,830 --> 00:26:55,910 The first step to achieve that will be to relay the authentication created by RPC racer to the web server of ADCS. 283 00:26:56,230 --> 00:27:01,290 It will generate for us a certificate that represents the machine account of the domain controller. 284 00:27:01,430 --> 00:27:05,870 This is done by the tool MTLM relay X from in packets. 285 00:27:07,270 --> 00:27:12,050 We cannot authenticate anywhere across the domain with this certificate yet. 286 00:27:12,090 --> 00:27:19,010 Our next step will be to request from the domain controller a ticket granting tickets or TGT. 287 00:27:19,150 --> 00:27:25,170 This is a legitimate Kerberos ticket that can be used to request access to resources in the domain. 288 00:27:25,370 --> 00:27:29,050 This step is done by a tool called certify. 289 00:27:30,550 --> 00:27:37,510 Once we have the TGT of the domain controller machine account, we can use it to execute several attacks. 290 00:27:37,630 --> 00:27:42,830 The most common one will be to dump the password hashes of all the users in the domain. 291 00:27:43,150 --> 00:27:46,050 For this, we will use in packets again. 292 00:27:46,050 --> 00:27:48,750 But this time the tool secrets dump. 293 00:27:50,070 --> 00:27:52,530 Let's see how it all comes together. 294 00:27:53,390 --> 00:28:00,570 We'll launch a rogue SMB server with MTLM relay X and tell it to relay the authentication to the ADCS. 295 00:28:01,070 --> 00:28:04,970 Then we log on to the server as an unprivileged user. 296 00:28:07,090 --> 00:28:10,850 As you can see, we are running as a medium integrity process. 297 00:28:11,150 --> 00:28:14,010 At this point, the storage service is running. 298 00:28:14,110 --> 00:28:23,230 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. 299 00:28:24,910 --> 00:28:28,890 Our moment to strike will be after the machine reboots. 300 00:28:35,460 --> 00:28:45,220 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. 301 00:28:45,980 --> 00:28:50,980 Then we'll use certify to request a TGT based on that certificate. 302 00:28:51,520 --> 00:28:57,560 Once we have a TGT of the machine account, we can dump all of the domain controller secrets. 303 00:29:08,090 --> 00:29:12,450 Like I said before, EPM poisoning is a real attack. 304 00:29:12,450 --> 00:29:15,530 And we saw just one way to abuse it. 305 00:29:15,550 --> 00:29:17,790 There are a lot more to get out of it. 306 00:29:17,950 --> 00:29:28,090 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. 307 00:29:29,470 --> 00:29:33,750 An additional option for us is to just cause denial of service. 308 00:29:33,750 --> 00:29:40,350 By registering many interfaces and denying the requests, a lot of functionalities will be disabled. 309 00:29:40,390 --> 00:29:43,290 This is a much more sophisticated method. 310 00:29:43,310 --> 00:29:50,970 Instead of terminating processes or spamming them with packets, we can just register the RPC interface first. 311 00:29:52,170 --> 00:29:55,610 Another thing I talked about is stealing credentials. 312 00:29:55,810 --> 00:29:59,110 I looked at a few services that might be exploited for that. 313 00:29:59,110 --> 00:30:01,310 But there are probably more. 314 00:30:02,950 --> 00:30:06,730 We exposed some serious security issues at this talk. 315 00:30:06,730 --> 00:30:09,750 And there are a few lessons that should be learned from that. 316 00:30:09,750 --> 00:30:15,950 The first one is that the integrity of servers should be checked in every protocol. 317 00:30:16,090 --> 00:30:26,950 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. 318 00:30:27,090 --> 00:30:31,030 The current design of the EPM doesn't perform this verification. 319 00:30:31,130 --> 00:30:34,090 Therefore, it must be done by the clients. 320 00:30:35,410 --> 00:30:41,310 The second point I want to leave you with is the danger of setting services to delayed start. 321 00:30:41,450 --> 00:30:49,150 Software developers of RPC servers should be aware of the implications of launching the programs late in the boot process. 322 00:30:50,110 --> 00:30:54,430 Services are often set to delayed start to make the boot process faster. 323 00:30:54,530 --> 00:30:58,030 But performance cannot come at the expense of security. 324 00:30:58,030 --> 00:31:04,090 Any stage where untrusted code can be executed should be considered unsafe. 325 00:31:05,750 --> 00:31:09,190 The patch to this vulnerability was released on July 8th. 326 00:31:09,190 --> 00:31:11,850 The fix was made to the RPC clients. 327 00:31:11,850 --> 00:31:14,030 Storage usage dot DLL. 328 00:31:14,130 --> 00:31:17,050 It improved how the binding was made. 329 00:31:17,230 --> 00:31:22,630 Instead of creating a simple binding handle, a security quality of service was applied to it. 330 00:31:22,630 --> 00:31:29,890 Now, the RPC connection will be made only if the RPC server is running as a local system account. 331 00:31:31,330 --> 00:31:42,530 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. 332 00:31:42,570 --> 00:31:46,390 So, I have a, I have some suggestions to detect it. 333 00:31:46,430 --> 00:31:52,030 Security products can use hooking to monitor calls to RPC EP register. 334 00:31:52,030 --> 00:32:01,890 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. 335 00:32:03,150 --> 00:32:08,750 Another detection technique is to use event tracing for Windows or ETW. 336 00:32:08,870 --> 00:32:14,550 The operating system automatically generates events for many actions that occur in the machine. 337 00:32:14,590 --> 00:32:21,170 The provider named Microsoft Windows RPC logs a lot of useful information in this case. 338 00:32:21,170 --> 00:32:34,270 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. 339 00:32:34,270 --> 00:32:41,830 We can even see the exact procedure number that was invoked, which correlates to get storage device info. 340 00:32:42,070 --> 00:32:46,550 These event types can be used to detect cases of EPM poisoning. 341 00:32:46,710 --> 00:32:51,890 An unknown process received an RPC connection on a known interface. 342 00:32:53,510 --> 00:32:58,550 I exploited the vulnerability I found to force the authentication of the machine accounts. 343 00:32:58,550 --> 00:33:03,270 But I think it could even lead to an even stronger impact. 344 00:33:03,450 --> 00:33:12,570 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. 345 00:33:12,670 --> 00:33:21,810 This means that if we can point it to a directory with poisoned configs, that will affect the behavior of the service. 346 00:33:21,950 --> 00:33:26,010 One of the config files is key value LKG.dat. 347 00:33:26,010 --> 00:33:28,550 It contains many URLs. 348 00:33:28,790 --> 00:33:38,550 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. 349 00:33:39,750 --> 00:33:45,250 Another interesting config file is dosvcstate.dat. 350 00:33:45,250 --> 00:33:51,550 This is a standalone registry hive used to manage jobs assigned to the delivery optimization service. 351 00:33:51,550 --> 00:33:59,110 There are some values that definitely catch the eye, such as CDN URL and working directory. 352 00:33:59,110 --> 00:34:06,350 Creating a key with certain values might result in the service downloading files to protected directories. 353 00:34:06,810 --> 00:34:15,550 And of course, the most prominent attack vector I suggest you to chase is to find more vulnerable RPC servers. 354 00:34:15,550 --> 00:34:17,270 There are so many. 355 00:34:17,270 --> 00:34:19,710 I just began scratching the surface. 356 00:34:19,910 --> 00:34:24,390 For example, Windows Security Center is set to delayed starts. 357 00:34:24,390 --> 00:34:27,110 And Windows Defender interacts with it. 358 00:34:27,110 --> 00:34:32,890 Maybe it is possible to neutralize Defender by sending it back a malicious response. 359 00:34:33,970 --> 00:34:41,490 To conclude this talk, I presented a serious security issue in a core component of the RPC protocol. 360 00:34:41,570 --> 00:34:49,750 There are no verifications on who is registering an interface that will be used by crucial services of the operating system. 361 00:34:50,350 --> 00:34:56,210 I showed you how to map the operating system to find vulnerable RPC servers. 362 00:34:56,210 --> 00:35:00,550 And RPC recon is now available for you to do it by yourself. 363 00:35:02,170 --> 00:35:07,650 After the target is found, I described how to analyze and exploit the clients. 364 00:35:07,870 --> 00:35:08,890 Here is 365 00:35:21,790 --> 00:35:27,390 the link to the repository of the tools. 366 00:35:27,390 --> 00:35:29,690 Feel free to reach out and contact me. 367 00:35:29,690 --> 00:35:30,670 Thank you.