WEBVTT

00:00.000 --> 00:00.320
All right.

00:00.320 --> 00:02.900
Good evening, DEF CON Track 4.

00:02.900 --> 00:03.520
Welcome.

00:03.520 --> 00:04.660
Welcome back.

00:04.660 --> 00:06.920
We have one more speaker for you guys.

00:06.920 --> 00:10.960
It is my absolute pleasure to introduce Antoine.

00:10.960 --> 00:16.740
The title of his talk is Overlaps, Overriding Lapsed Logic.

00:16.740 --> 00:18.660
Let's give it up for Antoine.

00:24.320 --> 00:25.340
Okay.

00:25.340 --> 00:26.460
So, hello.

00:26.500 --> 00:28.120
Thank you very much.

00:28.120 --> 00:32.360
So this is my second DEF CON but first time as a speaker.

00:32.360 --> 00:39.520
And I will present some subject about lapsed and in particular its internal logic.

00:39.580 --> 00:41.000
So, quick introduction.

00:41.000 --> 00:43.520
I am Antoine, working at Pederasi Luxembourg.

00:43.520 --> 00:49.000
I spent the last 10 years breaking things to help our clients improving their security.

00:49.000 --> 00:52.820
And yes, I am from Dijon, the capital of the mustard.

00:53.460 --> 00:56.660
A quick agenda.

00:56.660 --> 00:59.480
So we will start with a quick refresher about lapsed.

00:59.480 --> 01:02.960
We will cover the background and scope of this talk.

01:02.960 --> 01:07.380
And the core of the talk will be how lapsed works and how we can mess with it.

01:07.380 --> 01:09.580
And we will finish with a conclusion.

01:10.640 --> 01:13.000
So let's start with some definitions.

01:13.100 --> 01:16.260
So lapsed stands for Local Administrator Password Solution.

01:16.300 --> 01:24.580
It's a Microsoft product to manage local admin password by setting unique random password that will change regularly.

01:24.580 --> 01:26.640
There is two versions of lapsed.

01:26.640 --> 01:32.540
First one, Microsoft Lapse, that we will call V1 in this talk, that was released 10 years ago.

01:32.540 --> 01:37.840
It's Active Directory only and passwords are stored in clear text, in AD.

01:38.320 --> 01:44.600
And we have Windows Lapse, that we will call V2, or the current version, that was released 2 years ago.

01:44.600 --> 01:50.380
It's built-in into Windows and supports both Active Directory and Enter ID setup.

01:50.380 --> 01:53.920
And passwords are encrypted and it supports extra features.

01:55.060 --> 01:59.080
Now, let's have a quick overview about lapsed.

01:59.080 --> 02:06.320
So both versions, V1 and V2, follow the same high-level process during each password rotation cycle.

02:06.320 --> 02:12.400
So if the password needs to be changed, first we will generate a new password on the local system.

02:12.400 --> 02:19.060
Then we will send the password to the directory, so either Enter ID or Active Directory, depending on the config.

02:19.060 --> 02:22.160
After that, we set the password locally on the system.

02:22.160 --> 02:28.080
And there is also an additional step for device match via Entra.

02:28.600 --> 02:32.800
There is an update in the registry on the local system that we will cover later.

02:33.260 --> 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.

02:45.460 --> 02:49.180
So just a quick word on Lapse V1 for completeness.

02:49.180 --> 02:52.960
So it runs as a group policy extension on domain-joined machines.

02:52.960 --> 03:00.120
On the device, there is one DLL called admpwd.dll in charge of the core logic of Lapse.

03:00.420 --> 03:07.280
Password and expiration time are stored in Active Directory on the computer object and in clear text.

03:07.280 --> 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.

03:17.460 --> 03:19.480
And we have now Lapse V2.

03:19.480 --> 03:26.840
So first difference, managed device can be either domain-joined or Entra-joined.

03:26.840 --> 03:31.440
It's not a GPO extension anymore, but it still reacts to policy changes.

03:31.440 --> 03:37.840
You can also manually use PowerShell complex with admin privileges to force a refresh cycle.

03:37.840 --> 03:41.340
The polling cycle is hard-coded to once per hour.

03:41.520 --> 03:45.480
On the managed devices, we have three main DLLs.

03:45.480 --> 03:51.880
And the passwords are now stored both with encryption and ACL on Active Directory.

03:52.020 --> 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.

03:58.920 --> 04:03.460
And there is also protection against password tampering on the local system.

04:04.520 --> 04:10.400
So moving on, we'll start about the motivation and goals behind this research.

04:10.600 --> 04:13.520
So Lapse V1 and V2 have been widely analyzed.

04:13.520 --> 04:16.640
There is a lot of tools, a lot of paper on this subject.

04:16.740 --> 04:26.940
But most of the attacks focus on the server side of Lapse, so meaning abusing authorized accounts to read the password.

04:27.380 --> 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.

04:34.940 --> 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.

04:44.180 --> 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.

04:53.220 --> 05:01.670
So basically, you recompile ADMPWD with your extra features, and you put it on the device, and you will override Lapse.

05:03.400 --> 05:07.060
Eight years later, a lot of things changed.

05:07.060 --> 05:13.270
There is a new feature, and it's not based on an open source component anymore.

05:13.880 --> 05:20.500
So we have the support of EnterID with Active Directory, so making things a bit more complex.

05:20.540 --> 05:26.000
Passwords are stored with encryption, and there is this password tampering protection mechanism.

05:26.780 --> 05:31.400
In this context, we would like to explore three different questions.

05:31.400 --> 05:33.540
Can we capture the password?

05:33.540 --> 05:40.140
Can we desynchronize the password from the local system to the directory?

05:40.640 --> 05:43.560
And can we trigger a password change on demand?

05:44.700 --> 05:52.560
So for this research, we have defined a scope, so we will focus exclusively on Lapse V2.

05:52.840 --> 06:00.200
We will enable encryption, but I will not take into the details of cryptographic internals.

06:00.200 --> 06:04.880
For that, you can check XPN blog that is really great on this subject.

06:05.620 --> 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.

06:17.040 --> 06:25.900
In both cases, we will use Windows 11, and Lapse will be used to manage the built-in local admin account.

06:25.900 --> 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.

06:34.940 --> 06:43.520
Bypassing run as PPL is a different topic, and we assume local, temporary administrator access on the client device.

06:44.360 --> 06:48.200
So, time to dig into the guts of Windows Lapse.

06:48.500 --> 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.

06:57.960 --> 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.

07:10.240 --> 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.

07:20.220 --> 07:25.860
So first, on the left, we have functions that are for active directory setup only.

07:26.160 --> 07:32.040
On the other side, we have functions only for intra-join setup.

07:32.040 --> 07:37.740
And on the middle, we have shared functions that are used for password generation, and password changes.

07:39.040 --> 07:47.240
We will use Frida just to ease our research, and to hook some functions that we will see in a minute.

07:47.840 --> 07:49.180
Actually, in a second.

07:49.180 --> 07:56.040
To start with our objective, we will try to capture the password every time it changes.

07:56.040 --> 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.

08:07.620 --> 08:17.420
And by doing some instrumentation, we can find that two parameters are quite interesting, and are pointers to Unicode string structure.

08:17.420 --> 08:26.260
And just by applying an offset, we can have the actual string that is stored in these pointers.

08:26.260 --> 08:30.820
And you can see on the slide, for instance, a password.

08:30.820 --> 08:34.520
But we will have a demo to ease the understanding.

08:35.140 --> 08:42.380
So before we start, on the left, we have a domain controller.

08:42.400 --> 08:44.600
On the right, our client.

08:45.460 --> 08:48.800
On the machine, you will see two command prompts.

08:48.800 --> 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.

08:56.500 --> 09:07.100
And below, we will use it just to run a GP update, just to have a refresh of the GPO easier.

09:07.640 --> 09:10.340
So let's start the video.

09:10.340 --> 09:14.320
So first, we check the password is not expired.

09:16.620 --> 09:19.220
We launch our hook.

09:21.420 --> 09:25.040
Now we expire the password, and we launch a GP update.

09:25.040 --> 09:31.940
It's just to force, to ease the setup, and to avoid waiting for a real expiration.

09:31.940 --> 09:35.080
And you can see that we have already captured the password.

09:35.520 --> 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.

09:47.160 --> 09:48.060
And here we are.

09:48.060 --> 09:49.520
We are administrator.

09:50.300 --> 09:53.200
Now, same on the EnterID setup.

09:53.200 --> 09:54.900
So exact same code.

09:55.100 --> 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.

10:05.060 --> 10:11.980
We just wait a couple of seconds that the password will be changed.

10:11.980 --> 10:13.040
Yes, it is.

10:13.520 --> 10:18.540
And same, we can see that the password on Entra is the same that the one that we have captured.

10:22.480 --> 10:25.420
Here, another example to achieve the same result.

10:25.420 --> 10:27.800
We can hook internal function with Frida.

10:27.800 --> 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.

10:40.000 --> 10:49.240
And again, by doing some instrumentation, we can find that there is a parameter that contains the password.

10:49.240 --> 10:53.780
So again, we just hook this function and we can capture the password in cleartext.

10:54.360 --> 10:58.160
And it works exactly the same on EntraID setup.

11:00.280 --> 11:06.540
So basically, we have achieved our first objective, and we will move to our second objective.

11:06.540 --> 11:10.240
So can we try to desynchronize the LAPS password?

11:11.040 --> 11:13.120
So for this, we have two options.

11:13.120 --> 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.

11:25.720 --> 11:27.400
Or we do the opposite.

11:27.400 --> 11:33.260
We don't modify the local password, but we modify the one on the directory.

11:33.260 --> 11:39.940
But the impact is quite limited used alone, because the actual password will be random and you don't have it.

11:40.440 --> 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.

11:54.740 --> 12:02.300
I didn't record a video for this one, but just a screenshot to demonstrate this.

12:02.300 --> 12:08.780
So on top, you have the Active Directory setup.

12:08.780 --> 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.

12:17.100 --> 12:19.440
And on the bottom, it's the opposite.

12:19.440 --> 12:27.240
So we have changed the password that is sent to the directory without changing the real one.

12:28.840 --> 12:30.740
So second objective achieved.

12:30.740 --> 12:34.100
So we will move on to the third one.

12:34.100 --> 12:36.800
So can we trigger a password change on demand?

12:38.020 --> 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.

12:48.300 --> 12:50.920
And to do this, it's quite easy.

12:50.920 --> 12:53.380
So we can use these two functions.

12:53.380 --> 12:57.600
So one for Active Directory setup and the other for Enter ID setup.

12:57.620 --> 13:04.120
And we will just basically modify one parameter before the function returns.

13:05.000 --> 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.

13:17.400 --> 13:20.740
So we'll have a quick video on this.

13:20.740 --> 13:22.760
Again, same setup.

13:24.800 --> 13:27.120
We attach our hook.

13:29.080 --> 13:36.500
And now, each and every time a GP update or a GPO refresh will happen, the password will be changed.

13:37.360 --> 13:39.520
So here, we just check.

13:39.520 --> 13:44.700
So the password that we have captured is the same as the one on the directory.

13:45.180 --> 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.

13:57.300 --> 14:00.480
And in this case, synchronized with the Active Directory.

14:03.200 --> 14:05.900
And it works the same on Enter ID setup.

14:05.900 --> 14:13.760
It's just less convenient to force a refresh cycle, except using the PowerShell samelet.

14:14.880 --> 14:17.860
But for Enter ID, we have another approach.

14:17.860 --> 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.

14:26.300 --> 14:31.220
And I didn't really explain how the password expire block works in that case.

14:31.900 --> 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.

14:40.180 --> 14:44.340
One for Active Directory and one for Enter ID.

14:44.520 --> 14:47.480
But functions are basically the same.

14:47.480 --> 14:51.760
And if we zoom a bit on the top of the diagram, there is this block.

14:51.760 --> 14:55.580
Query local registry password for current password expiration time.

14:55.700 --> 14:58.320
So maybe you have the same idea as mine.

14:58.320 --> 15:00.140
What if we change it?

15:00.200 --> 15:06.440
So on the registry, there is two values that are interesting.

15:06.440 --> 15:11.340
One called Azure Password Expiry Time and the other Last Password Update Time.

15:11.340 --> 15:14.100
The purpose is pretty self-explanatory.

15:14.100 --> 15:19.080
Azure Password Expiry Time will be used to have the expiration of the password.

15:19.080 --> 15:23.160
Both values are stored as Windows file time.

15:23.160 --> 15:29.060
And here you can see readable functions for humans.

15:30.420 --> 15:35.440
So question now, what if we change the Azure Password Expiry Time key?

15:36.600 --> 15:38.620
Let's have a quick video.

15:40.420 --> 15:48.940
So I will just run the simulate function and check the logs to see if the password is expired.

15:49.000 --> 15:50.160
The answer is not.

15:50.160 --> 15:52.980
The password is not expired at this time.

15:54.260 --> 16:00.060
Now we'll go on the registry and edit the key just for convenience.

16:00.060 --> 16:08.880
And because the format is quite complex, I will just copy the value from the other key in this one.

16:10.000 --> 16:14.080
And now I will force a cycle with the PowerShell commandlet.

16:15.600 --> 16:23.790
And now if we check the logs, the local admin account was updated with a new password.

16:23.790 --> 16:27.470
And the reason, the current password was considered expired.

16:28.470 --> 16:33.250
So basically we managed to force a reset of the password.

16:33.990 --> 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.

16:50.830 --> 16:53.810
So LAPS is in a weird state.

16:53.810 --> 16:57.890
So basically we have achieved our three objectives.

16:58.310 --> 17:05.450
But with Frida, maybe Frida is not installed on the victims.

17:05.450 --> 17:10.630
So we can use, for instance, Microsoft Detour library.

17:10.630 --> 17:14.040
So it's an open source looking library from Microsoft.

17:14.330 --> 17:15.830
And the diagram shows the principle.

17:15.830 --> 17:20.550
We place our own function between the original call and destination call.

17:20.550 --> 17:22.130
And we will do something in between.

17:22.130 --> 17:25.390
So for instance, capturing the LAPS password.

17:26.850 --> 17:29.330
So, quick video for this.

17:29.430 --> 17:38.890
First we will hook some asset password for an user to, from some server DLL.

17:39.730 --> 17:43.150
So again, I will force the expiration time, run gpupdate.

17:43.610 --> 17:47.150
And here we have a txt file that has been created in the background.

17:49.070 --> 17:51.850
And if we look, it contains the password.

17:51.850 --> 17:53.510
So we managed to capture it.

17:53.530 --> 17:57.710
And now I will do exactly the same but using an internal function.

17:57.710 --> 17:59.830
So reset local admin account password.

18:04.890 --> 18:05.970
Again.

18:09.090 --> 18:11.510
And again, a new txt file is created.

18:11.510 --> 18:13.970
And if we look, it contains the password.

18:13.970 --> 18:17.710
So basically we can just do like this.

18:19.690 --> 18:23.630
So now it will be time to conclude this talk.

18:23.630 --> 18:28.710
So, if you are wondering, can we hook other functions for similar results?

18:28.750 --> 18:30.710
The quick answer is yes.

18:30.950 --> 18:37.920
Here on this screenshot, for instance, I captured the LAPS password on six different functions on active directory setup.

18:38.150 --> 18:42.510
And there is probably other functions that can be hooked for similar results.

18:43.670 --> 18:48.270
In the introduction, I mentioned the password tampering.

18:48.930 --> 18:55.230
It's written in the documentation that LAPS protects accounts from accidental or careless tampering.

18:55.610 --> 18:59.190
So, for instance, if you use a net user command, it won't work.

18:59.230 --> 19:01.210
But with this approach, it will work.

19:01.210 --> 19:05.830
So, in other words, intentional tampering is still possible if you know what you are doing.

19:08.090 --> 19:10.610
So, did we accomplish our mission?

19:10.610 --> 19:13.790
Yes, we managed to achieve our three objectives.

19:13.790 --> 19:20.050
So, capturing the password, desynchronizing the password from the directory, and trigger a password change on demand.

19:20.530 --> 19:22.250
But let's be clear.

19:22.270 --> 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.

19:29.630 --> 19:33.990
And we are touching ELSA, so it's always a tricky question.

19:34.350 --> 19:39.990
But my objective was to, let's say, lay the foundation.

19:39.990 --> 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.

19:51.510 --> 19:53.630
Some key takeaways.

19:53.630 --> 19:57.750
So , for our Red Team friends, in two words, be creative.

19:57.890 --> 19:59.630
Think beyond the spoke.

19:59.630 --> 20:03.830
You can retrieve the password via the network or other scenarios.

20:03.890 --> 20:08.110
As I mentioned, other functions can be hooked or abused.

20:09.030 --> 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.

20:22.950 --> 20:28.210
For Blue Teamers, watch for unexpected LAPS reset.

20:28.210 --> 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.

20:39.430 --> 20:46.210
Of course, limit privilege escalation vector, because we assume that we have compromised already a system.

20:46.210 --> 20:51.690
And ensure that your technical controls are working, such as RANAS PPL, ADR, and so on.

20:53.290 --> 20:56.190
So, thank you all for your attention.

20:56.190 --> 21:03.170
So, all the talks that I showed and additional words are available on this GitHub repository.

21:03.170 --> 21:11.450
There is also some scripts to help finding the offset automatically once a new LAPS version is released.

21:11.850 --> 21:15.550
So, feel free to check them out and reach out if you have any questions.

21:15.790 --> 21:16.830
Thank you.

