1 00:00:00,000 --> 00:00:00,320 All right. 2 00:00:00,320 --> 00:00:02,900 Good evening, DEF CON Track 4. 3 00:00:02,900 --> 00:00:03,520 Welcome. 4 00:00:03,520 --> 00:00:04,660 Welcome back. 5 00:00:04,660 --> 00:00:06,920 We have one more speaker for you guys. 6 00:00:06,920 --> 00:00:10,960 It is my absolute pleasure to introduce Antoine. 7 00:00:10,960 --> 00:00:16,740 The title of his talk is Overlaps, Overriding Lapsed Logic. 8 00:00:16,740 --> 00:00:18,660 Let's give it up for Antoine. 9 00:00:24,320 --> 00:00:25,340 Okay. 10 00:00:25,340 --> 00:00:26,460 So, hello. 11 00:00:26,500 --> 00:00:28,120 Thank you very much. 12 00:00:28,120 --> 00:00:32,360 So this is my second DEF CON but first time as a speaker. 13 00:00:32,360 --> 00:00:39,520 And I will present some subject about lapsed and in particular its internal logic. 14 00:00:39,580 --> 00:00:41,000 So, quick introduction. 15 00:00:41,000 --> 00:00:43,520 I am Antoine, working at Pederasi Luxembourg. 16 00:00:43,520 --> 00:00:49,000 I spent the last 10 years breaking things to help our clients improving their security. 17 00:00:49,000 --> 00:00:52,820 And yes, I am from Dijon, the capital of the mustard. 18 00:00:53,460 --> 00:00:56,660 A quick agenda. 19 00:00:56,660 --> 00:00:59,480 So we will start with a quick refresher about lapsed. 20 00:00:59,480 --> 00:01:02,960 We will cover the background and scope of this talk. 21 00:01:02,960 --> 00:01:07,380 And the core of the talk will be how lapsed works and how we can mess with it. 22 00:01:07,380 --> 00:01:09,580 And we will finish with a conclusion. 23 00:01:10,640 --> 00:01:13,000 So let's start with some definitions. 24 00:01:13,100 --> 00:01:16,260 So lapsed stands for Local Administrator Password Solution. 25 00:01:16,300 --> 00:01:24,580 It's a Microsoft product to manage local admin password by setting unique random password that will change regularly. 26 00:01:24,580 --> 00:01:26,640 There is two versions of lapsed. 27 00:01:26,640 --> 00:01:32,540 First one, Microsoft Lapse, that we will call V1 in this talk, that was released 10 years ago. 28 00:01:32,540 --> 00:01:37,840 It's Active Directory only and passwords are stored in clear text, in AD. 29 00:01:38,320 --> 00:01:44,600 And we have Windows Lapse, that we will call V2, or the current version, that was released 2 years ago. 30 00:01:44,600 --> 00:01:50,380 It's built-in into Windows and supports both Active Directory and Enter ID setup. 31 00:01:50,380 --> 00:01:53,920 And passwords are encrypted and it supports extra features. 32 00:01:55,060 --> 00:01:59,080 Now, let's have a quick overview about lapsed. 33 00:01:59,080 --> 00:02:06,320 So both versions, V1 and V2, follow the same high-level process during each password rotation cycle. 34 00:02:06,320 --> 00:02:12,400 So if the password needs to be changed, first we will generate a new password on the local system. 35 00:02:12,400 --> 00:02:19,060 Then we will send the password to the directory, so either Enter ID or Active Directory, depending on the config. 36 00:02:19,060 --> 00:02:22,160 After that, we set the password locally on the system. 37 00:02:22,160 --> 00:02:28,080 And there is also an additional step for device match via Entra. 38 00:02:28,600 --> 00:02:32,800 There is an update in the registry on the local system that we will cover later. 39 00:02:33,260 --> 00:02:44,740 And basically, on Active Directory, resetting the lapsed password equals to setting the expiration time to now and wait for a new cycle. 40 00:02:45,460 --> 00:02:49,180 So just a quick word on Lapse V1 for completeness. 41 00:02:49,180 --> 00:02:52,960 So it runs as a group policy extension on domain-joined machines. 42 00:02:52,960 --> 00:03:00,120 On the device, there is one DLL called admpwd.dll in charge of the core logic of Lapse. 43 00:03:00,420 --> 00:03:07,280 Password and expiration time are stored in Active Directory on the computer object and in clear text. 44 00:03:07,280 --> 00:03:16,640 The password is only protected by ACLs, meaning that only authorized users can access the password, but the expiration time is visible to anyone. 45 00:03:17,460 --> 00:03:19,480 And we have now Lapse V2. 46 00:03:19,480 --> 00:03:26,840 So first difference, managed device can be either domain-joined or Entra-joined. 47 00:03:26,840 --> 00:03:31,440 It's not a GPO extension anymore, but it still reacts to policy changes. 48 00:03:31,440 --> 00:03:37,840 You can also manually use PowerShell complex with admin privileges to force a refresh cycle. 49 00:03:37,840 --> 00:03:41,340 The polling cycle is hard-coded to once per hour. 50 00:03:41,520 --> 00:03:45,480 On the managed devices, we have three main DLLs. 51 00:03:45,480 --> 00:03:51,880 And the passwords are now stored both with encryption and ACL on Active Directory. 52 00:03:52,020 --> 00:03:58,920 And for Entra-ID, it's in the cloud, but it's written in the documentation that passwords are further encrypted at rest. 53 00:03:58,920 --> 00:04:03,460 And there is also protection against password tampering on the local system. 54 00:04:04,520 --> 00:04:10,400 So moving on, we'll start about the motivation and goals behind this research. 55 00:04:10,600 --> 00:04:13,520 So Lapse V1 and V2 have been widely analyzed. 56 00:04:13,520 --> 00:04:16,640 There is a lot of tools, a lot of paper on this subject. 57 00:04:16,740 --> 00:04:26,940 But most of the attacks focus on the server side of Lapse, so meaning abusing authorized accounts to read the password. 58 00:04:27,380 --> 00:04:34,720 On the other hand, client-side remains not so explored in public tooling and research, but it's not a new observation. 59 00:04:34,940 --> 00:04:43,690 Actually, we studied the client-side of Lapse V1 eight years ago with my colleague Max Clements, who is in this room with me. 60 00:04:44,180 --> 00:04:53,220 And just to summarize our previous talk, Lapse V1 is based on an open source project called ADMPWD, and it's backward compatible. 61 00:04:53,220 --> 00:05:01,670 So basically, you recompile ADMPWD with your extra features, and you put it on the device, and you will override Lapse. 62 00:05:03,400 --> 00:05:07,060 Eight years later, a lot of things changed. 63 00:05:07,060 --> 00:05:13,270 There is a new feature, and it's not based on an open source component anymore. 64 00:05:13,880 --> 00:05:20,500 So we have the support of EnterID with Active Directory, so making things a bit more complex. 65 00:05:20,540 --> 00:05:26,000 Passwords are stored with encryption, and there is this password tampering protection mechanism. 66 00:05:26,780 --> 00:05:31,400 In this context, we would like to explore three different questions. 67 00:05:31,400 --> 00:05:33,540 Can we capture the password? 68 00:05:33,540 --> 00:05:40,140 Can we desynchronize the password from the local system to the directory? 69 00:05:40,640 --> 00:05:43,560 And can we trigger a password change on demand? 70 00:05:44,700 --> 00:05:52,560 So for this research, we have defined a scope, so we will focus exclusively on Lapse V2. 71 00:05:52,840 --> 00:06:00,200 We will enable encryption, but I will not take into the details of cryptographic internals. 72 00:06:00,200 --> 00:06:04,880 For that, you can check XPN blog that is really great on this subject. 73 00:06:05,620 --> 00:06:16,560 And our testing lab will include two small infrastructures, one with Active Directory, with one client, and the other with a client that is domain joined. 74 00:06:17,040 --> 00:06:25,900 In both cases, we will use Windows 11, and Lapse will be used to manage the built-in local admin account. 75 00:06:25,900 --> 00:06:34,900 And an important note, so now Lapse runs inside LSAS process, so we will disable run as PPL just to ease our research. 76 00:06:34,940 --> 00:06:43,520 Bypassing run as PPL is a different topic, and we assume local, temporary administrator access on the client device. 77 00:06:44,360 --> 00:06:48,200 So, time to dig into the guts of Windows Lapse. 78 00:06:48,500 --> 00:06:57,800 So, as I mentioned earlier, the client side relies on three main DLLs, but we will focus only on Lapse.dll, which contains the core logic of Lapse. 79 00:06:57,960 --> 00:07:07,980 And luckily for us, Microsoft provides with the PDB files, which makes the understanding of the logic easier, and gives us as well internal function names. 80 00:07:10,240 --> 00:07:20,220 Here we have a simplified code tree of some of the Lapse functions inside Lapse.dll, and we can see three main zones in this diagram. 81 00:07:20,220 --> 00:07:25,860 So first, on the left, we have functions that are for active directory setup only. 82 00:07:26,160 --> 00:07:32,040 On the other side, we have functions only for intra-join setup. 83 00:07:32,040 --> 00:07:37,740 And on the middle, we have shared functions that are used for password generation, and password changes. 84 00:07:39,040 --> 00:07:47,240 We will use Frida just to ease our research, and to hook some functions that we will see in a minute. 85 00:07:47,840 --> 00:07:49,180 Actually, in a second. 86 00:07:49,180 --> 00:07:56,040 To start with our objective, we will try to capture the password every time it changes. 87 00:07:56,040 --> 00:08:07,080 So we can have a look at this function, that is an undocumented function exposed by some server DLL, and is used by Lapse to change the manager account password. 88 00:08:07,620 --> 00:08:17,420 And by doing some instrumentation, we can find that two parameters are quite interesting, and are pointers to Unicode string structure. 89 00:08:17,420 --> 00:08:26,260 And just by applying an offset, we can have the actual string that is stored in these pointers. 90 00:08:26,260 --> 00:08:30,820 And you can see on the slide, for instance, a password. 91 00:08:30,820 --> 00:08:34,520 But we will have a demo to ease the understanding. 92 00:08:35,140 --> 00:08:42,380 So before we start, on the left, we have a domain controller. 93 00:08:42,400 --> 00:08:44,600 On the right, our client. 94 00:08:45,460 --> 00:08:48,800 On the machine, you will see two command prompts. 95 00:08:48,800 --> 00:08:56,160 The one on the top will run with admin privileges, and we will use it to attach to Lsas and to hook our function. 96 00:08:56,500 --> 00:09:07,100 And below, we will use it just to run a GP update, just to have a refresh of the GPO easier. 97 00:09:07,640 --> 00:09:10,340 So let's start the video. 98 00:09:10,340 --> 00:09:14,320 So first, we check the password is not expired. 99 00:09:16,620 --> 00:09:19,220 We launch our hook. 100 00:09:21,420 --> 00:09:25,040 Now we expire the password, and we launch a GP update. 101 00:09:25,040 --> 00:09:31,940 It's just to force, to ease the setup, and to avoid waiting for a real expiration. 102 00:09:31,940 --> 00:09:35,080 And you can see that we have already captured the password. 103 00:09:35,520 --> 00:09:44,300 And I will just test the password on the local system, just to prove that the password that I captured is really the LAPS password. 104 00:09:47,160 --> 00:09:48,060 And here we are. 105 00:09:48,060 --> 00:09:49,520 We are administrator. 106 00:09:50,300 --> 00:09:53,200 Now, same on the EnterID setup. 107 00:09:53,200 --> 00:09:54,900 So exact same code. 108 00:09:55,100 --> 00:10:04,440 And again, we will force an expiration just to ease, but the process is the same when the password expires for real. 109 00:10:05,060 --> 00:10:11,980 We just wait a couple of seconds that the password will be changed. 110 00:10:11,980 --> 00:10:13,040 Yes, it is. 111 00:10:13,520 --> 00:10:18,540 And same, we can see that the password on Entra is the same that the one that we have captured. 112 00:10:22,480 --> 00:10:25,420 Here, another example to achieve the same result. 113 00:10:25,420 --> 00:10:27,800 We can hook internal function with Frida. 114 00:10:27,800 --> 00:10:39,760 So for instance, if we look at reset local admin account password, we just need to find the offset of this function, and then to find interesting parameters. 115 00:10:40,000 --> 00:10:49,240 And again, by doing some instrumentation, we can find that there is a parameter that contains the password. 116 00:10:49,240 --> 00:10:53,780 So again, we just hook this function and we can capture the password in cleartext. 117 00:10:54,360 --> 00:10:58,160 And it works exactly the same on EntraID setup. 118 00:11:00,280 --> 00:11:06,540 So basically, we have achieved our first objective, and we will move to our second objective. 119 00:11:06,540 --> 00:11:10,240 So can we try to desynchronize the LAPS password? 120 00:11:11,040 --> 00:11:13,120 So for this, we have two options. 121 00:11:13,120 --> 00:11:25,280 So either we modify the password on the local system, so we have a control on the local password, but the password on the directory remains random. 122 00:11:25,720 --> 00:11:27,400 Or we do the opposite. 123 00:11:27,400 --> 00:11:33,260 We don't modify the local password, but we modify the one on the directory. 124 00:11:33,260 --> 00:11:39,940 But the impact is quite limited used alone, because the actual password will be random and you don't have it. 125 00:11:40,440 --> 00:11:54,040 Both options can be useful for a kind of denial of service, because LAPS will not be usable by administrator, because the password they will see on the directory is not the one that is actually set. 126 00:11:54,740 --> 00:12:02,300 I didn't record a video for this one, but just a screenshot to demonstrate this. 127 00:12:02,300 --> 00:12:08,780 So on top, you have the Active Directory setup. 128 00:12:08,780 --> 00:12:17,100 So the actual password is a random password, while the one that admin will see on the domain controller is really random. 129 00:12:17,100 --> 00:12:19,440 And on the bottom, it's the opposite. 130 00:12:19,440 --> 00:12:27,240 So we have changed the password that is sent to the directory without changing the real one. 131 00:12:28,840 --> 00:12:30,740 So second objective achieved. 132 00:12:30,740 --> 00:12:34,100 So we will move on to the third one. 133 00:12:34,100 --> 00:12:36,800 So can we trigger a password change on demand? 134 00:12:38,020 --> 00:12:47,060 So our goal now is to hook the password expiration check and force it to return that the password is expired, even when it's not. 135 00:12:48,300 --> 00:12:50,920 And to do this, it's quite easy. 136 00:12:50,920 --> 00:12:53,380 So we can use these two functions. 137 00:12:53,380 --> 00:12:57,600 So one for Active Directory setup and the other for Enter ID setup. 138 00:12:57,620 --> 00:13:04,120 And we will just basically modify one parameter before the function returns. 139 00:13:05,000 --> 00:13:16,980 So you can see on the screenshot, we just modify the args5 in parameter and we change the value to 1 to force the reset. 140 00:13:17,400 --> 00:13:20,740 So we'll have a quick video on this. 141 00:13:20,740 --> 00:13:22,760 Again, same setup. 142 00:13:24,800 --> 00:13:27,120 We attach our hook. 143 00:13:29,080 --> 00:13:36,500 And now, each and every time a GP update or a GPO refresh will happen, the password will be changed. 144 00:13:37,360 --> 00:13:39,520 So here, we just check. 145 00:13:39,520 --> 00:13:44,700 So the password that we have captured is the same as the one on the directory. 146 00:13:45,180 --> 00:13:56,440 And now, I will do it a couple of times, but each and every time there will be a GPO update, the password will be changed. 147 00:13:57,300 --> 00:14:00,480 And in this case, synchronized with the Active Directory. 148 00:14:03,200 --> 00:14:05,900 And it works the same on Enter ID setup. 149 00:14:05,900 --> 00:14:13,760 It's just less convenient to force a refresh cycle, except using the PowerShell samelet. 150 00:14:14,880 --> 00:14:17,860 But for Enter ID, we have another approach. 151 00:14:17,860 --> 00:14:26,140 In this introduction, I briefly mentioned that for Enter ID setups, there is the expiration time that is stored locally on the register. 152 00:14:26,300 --> 00:14:31,220 And I didn't really explain how the password expire block works in that case. 153 00:14:31,900 --> 00:14:39,940 If you look at Microsoft documentation, you will see basically the same diagram as mine, but they are separated in two parts. 154 00:14:40,180 --> 00:14:44,340 One for Active Directory and one for Enter ID. 155 00:14:44,520 --> 00:14:47,480 But functions are basically the same. 156 00:14:47,480 --> 00:14:51,760 And if we zoom a bit on the top of the diagram, there is this block. 157 00:14:51,760 --> 00:14:55,580 Query local registry password for current password expiration time. 158 00:14:55,700 --> 00:14:58,320 So maybe you have the same idea as mine. 159 00:14:58,320 --> 00:15:00,140 What if we change it? 160 00:15:00,200 --> 00:15:06,440 So on the registry, there is two values that are interesting. 161 00:15:06,440 --> 00:15:11,340 One called Azure Password Expiry Time and the other Last Password Update Time. 162 00:15:11,340 --> 00:15:14,100 The purpose is pretty self-explanatory. 163 00:15:14,100 --> 00:15:19,080 Azure Password Expiry Time will be used to have the expiration of the password. 164 00:15:19,080 --> 00:15:23,160 Both values are stored as Windows file time. 165 00:15:23,160 --> 00:15:29,060 And here you can see readable functions for humans. 166 00:15:30,420 --> 00:15:35,440 So question now, what if we change the Azure Password Expiry Time key? 167 00:15:36,600 --> 00:15:38,620 Let's have a quick video. 168 00:15:40,420 --> 00:15:48,940 So I will just run the simulate function and check the logs to see if the password is expired. 169 00:15:49,000 --> 00:15:50,160 The answer is not. 170 00:15:50,160 --> 00:15:52,980 The password is not expired at this time. 171 00:15:54,260 --> 00:16:00,060 Now we'll go on the registry and edit the key just for convenience. 172 00:16:00,060 --> 00:16:08,880 And because the format is quite complex, I will just copy the value from the other key in this one. 173 00:16:10,000 --> 00:16:14,080 And now I will force a cycle with the PowerShell commandlet. 174 00:16:15,600 --> 00:16:23,790 And now if we check the logs, the local admin account was updated with a new password. 175 00:16:23,790 --> 00:16:27,470 And the reason, the current password was considered expired. 176 00:16:28,470 --> 00:16:33,250 So basically we managed to force a reset of the password. 177 00:16:33,990 --> 00:16:50,730 If you are wondering what if we put a password in the future, basically it will break LAPS because on the directory it's written that the password is expired, but on the local system it says that it's not expired. 178 00:16:50,830 --> 00:16:53,810 So LAPS is in a weird state. 179 00:16:53,810 --> 00:16:57,890 So basically we have achieved our three objectives. 180 00:16:58,310 --> 00:17:05,450 But with Frida, maybe Frida is not installed on the victims. 181 00:17:05,450 --> 00:17:10,630 So we can use, for instance, Microsoft Detour library. 182 00:17:10,630 --> 00:17:14,040 So it's an open source looking library from Microsoft. 183 00:17:14,330 --> 00:17:15,830 And the diagram shows the principle. 184 00:17:15,830 --> 00:17:20,550 We place our own function between the original call and destination call. 185 00:17:20,550 --> 00:17:22,130 And we will do something in between. 186 00:17:22,130 --> 00:17:25,390 So for instance, capturing the LAPS password. 187 00:17:26,850 --> 00:17:29,330 So, quick video for this. 188 00:17:29,430 --> 00:17:38,890 First we will hook some asset password for an user to, from some server DLL. 189 00:17:39,730 --> 00:17:43,150 So again, I will force the expiration time, run gpupdate. 190 00:17:43,610 --> 00:17:47,150 And here we have a txt file that has been created in the background. 191 00:17:49,070 --> 00:17:51,850 And if we look, it contains the password. 192 00:17:51,850 --> 00:17:53,510 So we managed to capture it. 193 00:17:53,530 --> 00:17:57,710 And now I will do exactly the same but using an internal function. 194 00:17:57,710 --> 00:17:59,830 So reset local admin account password. 195 00:18:04,890 --> 00:18:05,970 Again. 196 00:18:09,090 --> 00:18:11,510 And again, a new txt file is created. 197 00:18:11,510 --> 00:18:13,970 And if we look, it contains the password. 198 00:18:13,970 --> 00:18:17,710 So basically we can just do like this. 199 00:18:19,690 --> 00:18:23,630 So now it will be time to conclude this talk. 200 00:18:23,630 --> 00:18:28,710 So, if you are wondering, can we hook other functions for similar results? 201 00:18:28,750 --> 00:18:30,710 The quick answer is yes. 202 00:18:30,950 --> 00:18:37,920 Here on this screenshot, for instance, I captured the LAPS password on six different functions on active directory setup. 203 00:18:38,150 --> 00:18:42,510 And there is probably other functions that can be hooked for similar results. 204 00:18:43,670 --> 00:18:48,270 In the introduction, I mentioned the password tampering. 205 00:18:48,930 --> 00:18:55,230 It's written in the documentation that LAPS protects accounts from accidental or careless tampering. 206 00:18:55,610 --> 00:18:59,190 So, for instance, if you use a net user command, it won't work. 207 00:18:59,230 --> 00:19:01,210 But with this approach, it will work. 208 00:19:01,210 --> 00:19:05,830 So, in other words, intentional tampering is still possible if you know what you are doing. 209 00:19:08,090 --> 00:19:10,610 So, did we accomplish our mission? 210 00:19:10,610 --> 00:19:13,790 Yes, we managed to achieve our three objectives. 211 00:19:13,790 --> 00:19:20,050 So, capturing the password, desynchronizing the password from the directory, and trigger a password change on demand. 212 00:19:20,530 --> 00:19:22,250 But let's be clear. 213 00:19:22,270 --> 00:19:29,630 For, let's say, a real scenario, you will need to bypass RANAS PPL, you will need to fight against ADR, and so on. 214 00:19:29,630 --> 00:19:33,990 And we are touching ELSA, so it's always a tricky question. 215 00:19:34,350 --> 00:19:39,990 But my objective was to, let's say, lay the foundation. 216 00:19:39,990 --> 00:19:49,310 And I hope some of you will have some ideas and will build on this research to go further and to develop other scenarios. 217 00:19:51,510 --> 00:19:53,630 Some key takeaways. 218 00:19:53,630 --> 00:19:57,750 So , for our Red Team friends, in two words, be creative. 219 00:19:57,890 --> 00:19:59,630 Think beyond the spoke. 220 00:19:59,630 --> 00:20:03,830 You can retrieve the password via the network or other scenarios. 221 00:20:03,890 --> 00:20:08,110 As I mentioned, other functions can be hooked or abused. 222 00:20:09,030 --> 00:20:22,090 The logic of LAPS might change with updates, so we need to check basically each and every patch Tuesday if there is a new version of LAPS. 223 00:20:22,950 --> 00:20:28,210 For Blue Teamers, watch for unexpected LAPS reset. 224 00:20:28,210 --> 00:20:39,310 Because if you are not using LAPS evilly, the reset of the LAPS password should more or less match the rotation period that you have configured. 225 00:20:39,430 --> 00:20:46,210 Of course, limit privilege escalation vector, because we assume that we have compromised already a system. 226 00:20:46,210 --> 00:20:51,690 And ensure that your technical controls are working, such as RANAS PPL, ADR, and so on. 227 00:20:53,290 --> 00:20:56,190 So, thank you all for your attention. 228 00:20:56,190 --> 00:21:03,170 So, all the talks that I showed and additional words are available on this GitHub repository. 229 00:21:03,170 --> 00:21:11,450 There is also some scripts to help finding the offset automatically once a new LAPS version is released. 230 00:21:11,850 --> 00:21:15,550 So, feel free to check them out and reach out if you have any questions. 231 00:21:15,790 --> 00:21:16,830 Thank you.