WEBVTT

00:15.040 --> 00:16.260
Hello, everyone.

00:16.260 --> 00:21.360
Welcome back to DEF CON 28 Safe Mode, Blue Team Village live stream.

00:21.360 --> 00:31.960
Today, we're going to be talking with, I'm not talking, but he'll be talking, Connor Morley, discussing Outer Haven, the UEFI memory space decision to be misused.

00:32.200 --> 00:44.540
Reminder, if you have any questions for the speaker, you can obviously reach them at their Twitter handle, DM them within the Discord channel, or reach them on the Flamingo Hotel Text Talks Track 1.

00:44.540 --> 00:46.980
We'll be watching for questions there.

00:47.220 --> 00:49.300
And over to you, Connor.

00:49.620 --> 00:50.900
Thank you very much.

00:50.900 --> 00:51.940
So, hi, everyone.

00:51.940 --> 00:53.100
My name is Connor Morley.

00:53.100 --> 00:57.580
I'm a threat hunter with F-Secure Countercept, which is an MDR DRT service.

00:57.740 --> 01:05.900
Today, I'll be talking about the UEFI memory space, how it can be exploited by a range of attackers, and how it can defend against it.

01:05.900 --> 01:08.420
And I give it the app name of Outer Haven.

01:08.820 --> 01:10.840
So, proper agenda.

01:10.840 --> 01:26.860
What we're going to run through, I'm going to do a quick crash course on what exactly UEFI is, why this is of interest to attackers and defenders, how to exploit the UEFI memory space, regardless of your technical expertise.

01:26.860 --> 01:30.920
So, all the way from APT actors, all the way down to script gettys.

01:31.340 --> 01:44.780
You better go over some of the issues with defending against exploitation of this memory sector, how we can overcome those difficulties and monitor this memory area, and what this means for us as an industry.

01:44.800 --> 01:47.180
So, let's dive straight in.

01:47.660 --> 01:50.440
The crash course of what exactly is UEFI.

01:50.440 --> 01:55.240
So, a lot of people may have heard the term UEFI, but may not know exactly what it is.

01:55.460 --> 01:59.620
So, UEFI stands for the Unified Extensible Firmware Interface.

01:59.620 --> 02:01.980
It's the successor to BIOS.

02:01.980 --> 02:05.740
Most people will be familiar with BIOS, the basic input-output system.

02:05.760 --> 02:11.820
It interfaces between the mechanical elements of a system and its operating system.

02:11.980 --> 02:21.680
So, effectively, it works as a translation layer between the operating system and the firmware for the hardware of your device, hence a firmware interface.

02:22.000 --> 02:35.360
So, for example, if the operating system requests a file to be opened, the file command gets run from the OS through the UEFI to the firmware of your storage device.

02:35.360 --> 02:42.080
It then allocates that memory sector and returns it, and then that's how it's read, as a very, very general basic overview.

02:42.320 --> 02:45.360
It's key for all system functionality.

02:45.540 --> 02:47.600
It conducts all boot operations.

02:47.600 --> 02:58.820
It can, as I said, conducts all interfaces between the software and the hardware, and it is essential in all modern computers.

02:58.820 --> 03:03.080
So, it is found everywhere, regardless of the operating system that you're using.

03:03.520 --> 03:08.120
It's also widely considered far more secure than BIOS.

03:08.120 --> 03:11.240
So, we introduced the concept of something called Secure Boot.

03:11.280 --> 03:23.880
So, Secure Boot is the idea that when drivers are loaded at boot time, their OEM signature is checked in order to guarantee and verify that they're the correct and authorized driver.

03:23.920 --> 03:40.240
This idea of Secure Boot actually eliminated a really easy physical access bypass to older machines, which basically means as soon as you had physical access to a machine, you could easily bypass any security.

03:40.400 --> 03:50.260
One of the key things to mention about UEFI is that it is stored on an independent chip on your motherboard, an NVRAM chip, which is totally isolated.

03:50.260 --> 03:56.260
It's its own independent component of the machine, and it is attached to the motherboard.

03:56.260 --> 03:58.760
So, it's completely isolated from everything else.

03:58.760 --> 04:01.460
It is its own piece of kit.

04:01.800 --> 04:09.320
So, just to really intensify and solidify where this sits in your computer.

04:09.320 --> 04:14.600
So, the UEFI, as I said, sits between the operating system and firmware, and the firmware that talks to the hardware.

04:14.600 --> 04:18.880
So, the operating system, if it wants to talk to your hardware, has to go through the UEFI.

04:20.620 --> 04:31.880
It is essentially just a translation layer of operating system commands down to firmware layer commands to receive whatever the operating system needs the host to do.

04:33.100 --> 04:38.420
So, most people, when you're talking about UEFI and BIOS, they'll think of this sort of screen.

04:38.420 --> 04:44.760
Your boot screen, sometimes with the boot menu or BIOS settings as one of those options at the bottom.

04:44.760 --> 04:51.720
But the majority of the users will see this sort of screen and just, you know, as it boots up your computer and not the device.

04:52.820 --> 04:57.640
Some people will obviously go into those settings, which looks something like this.

04:57.640 --> 05:08.980
So, on the left, you have the older BIOS settings configuration menu, and on the right, you have the newer UEFI interactive GUI.

05:09.000 --> 05:15.580
So, one of the things that UEFI actually allows to do is the use of graphical user interfaces, which is not available in BIOS.

05:15.580 --> 05:18.300
This allows for, as you can see, this is there.

05:18.300 --> 05:22.920
It allows for branding, it allows for, you know, CPU temperatures and all this sort of stuff.

05:22.920 --> 05:27.960
It also allows for point and click, so the use of a mouse, whereas BIOS doesn't.

05:27.960 --> 05:36.300
This is to do primarily with how EFI operates using EFI binary files, which allows for these layers to be put on top of it.

05:37.340 --> 05:45.040
Again, this allows for security settings, it allows for the boot order to be configured, and such things like that.

05:46.060 --> 05:55.020
So, most people will think this is sort of the limit of what you can, or this will be like the limit of what most people have dealt with, but the UEFI itself is actually a lot more complicated.

05:55.060 --> 06:12.280
It does a lot more in relation to your host, and it runs the entire time that your computer is operating, and so it's not just the boot service, it's fundamental to all operations of all modern hosts that you find around the world.

06:12.600 --> 06:27.140
So, there's a lot more to it that a lot of people are not privy to, but the key thing to know is it is always active, is essential, and it's isolated from the rest of the system.

06:27.720 --> 06:34.880
So, why is UEFI interesting to attackers and defenders alike?

06:34.880 --> 06:39.340
So, why are attackers, red team, is looking at UEFI?

06:39.360 --> 06:46.020
So, as I said earlier, the UEFI is isolated from the rest of the system on its own little island of silicon.

06:46.020 --> 06:48.700
So, it's segregated from the rest of the system by design.

06:50.580 --> 07:08.540
Because it's isolated, it's not well known about, and it's considered quite low-level technology, it's commonly overlooked in a lot of attack situations, and normally isolated to the sort of APT rootkit sort of attack frameworks and methodologies and TDPs.

07:08.580 --> 07:18.160
So, it's normally overlooked in most operations by defenders, so it gives this sort of idea that it's lucrative and valuable to pro attackers.

07:18.700 --> 07:24.940
The other thing to note is that remediation of anything on the UEFI is really difficult.

07:26.260 --> 07:33.900
With a lot of components on the machine, obviously you can chop and change them, hard drives, RAM, CPU, all that sort of stuff, if you really had to.

07:34.000 --> 07:37.480
Changing the UEFI, if you had to, much more difficult.

07:37.480 --> 07:40.280
A lot of the time, they're soldered onto the motherboard.

07:40.600 --> 07:43.520
So, as you can imagine, changing that is a real pain.

07:43.960 --> 07:51.640
And even removing it, obviously, interactively through an interface can be really tricky if you don't have experience with UEFI.

07:53.800 --> 08:02.240
So, as I said, there's a whole section later on that I'm going to cover about why remediation is difficult, and I'm going to go over that in a lot more detail.

08:02.440 --> 08:14.300
One of the other things to note about UEFI is that by standard, by the standards of UEFI, everything written to it is automatically put as a system.

08:14.380 --> 08:19.980
So, it's non-volatile and everything that's written will automatically stay there throughout boot.

08:19.980 --> 08:28.480
Which, as you can imagine, from a sort of persistence attack methodology sort of mentality, is inherently quite valuable.

08:29.460 --> 08:34.480
So, although this is why attackers are looking at it, why are they looking at it now?

08:34.480 --> 08:36.220
What exactly has changed?

08:37.300 --> 08:46.640
So, as I said, it's normally put as being rootkits and little actors, ATPs, because it's a complex sort of area and a lot of people overlook or don't really understand.

08:47.140 --> 09:02.520
But what's happened is that since Windows... actually, since Windows XP, surprisingly, but more recently since Windows Vista and onwards, Windows has... Microsoft has gradually introduced more runtime access to the UEFI memory space.

09:02.700 --> 09:21.460
So, UEFI runs boot services and runtime services, and through the iterations of Windows and obviously their updates and newer versions, they've steadily introduced more and more runtime service access to the UEFI memory space.

09:21.500 --> 09:39.740
So, research done last year at DEF CON, DEF CON 27, Michael Liebowitz and Tova Timson, they did a whole presentation on this type of attack, about how to avoid threat hunters and EDR by utilizing the UEFI memory space, because it avoids detection.

09:39.940 --> 09:46.580
I was really recommending their research, really cool stuff, and obviously this is where this entire piece of research stemmed from.

09:47.440 --> 09:55.420
And they went into how they could use native Windows API functions to read and write into the UEFI memory space.

09:56.520 --> 10:03.340
So, originally, when I first saw their talk, I thought, oh, this is worrying, but surely there must be a way around this.

10:03.720 --> 10:15.660
Again, this is a section that will come later on, but it was a gap that was found, or that I, when looking into it, I did see was in the security defensive structure.

10:17.160 --> 10:34.840
So, because of their research, there is now very, because, not because of the research, but because of Microsoft's expansion, which is runtime service access, there is, by their exposure, Windows API basic functionalities that allow read and write access into this lucrative,

10:34.840 --> 10:42.960
sort of, not well understood memory sector that's isolated from the rest of the system, which is pretty valuable.

10:44.180 --> 10:49.260
So, how is it that the UEFI memory space is exploited?

10:49.260 --> 10:57.020
All the way from the APT actors, all the way down to script kitties or, you know, newer attackers.

10:57.820 --> 11:17.820
So, the way that Leibovitz and Timson exposed was to use C-sharp precompiled payloads using kernel32.dll exploit functions and get firmware environment variable ex and set firmware environment variable ex.

11:17.820 --> 11:20.660
As you can imagine, these are the read and write functions.

11:21.440 --> 11:43.440
With these two methods, an attacker can install a payload into this memory space and then create an external persistence mechanism to read from this isolated memory space at a later point or by a trigger in order to run a more malicious or internal payload or a beacon or agent or anything like that from the UEFI memory space.

11:44.260 --> 11:55.300
This obviously requires the payloads to be pre-built, so they have to be obviously targeted and have an understanding of where they're going and what they can leverage out of the environment they're going into.

11:56.620 --> 12:09.060
It also has to specify, at the time of compilation, the variable names and the GUIDs or the vendor IDs of the variable they're going to be injecting into the memory space.

12:09.580 --> 12:22.880
And because of this, and obviously you have to have an understanding of how C-sharp can be used for API DLL interactions in order to leverage the kernel32.dll in order to access the UEFI and write into it.

12:22.880 --> 12:33.280
So you have to have a good understanding and preparedness of who you're going to attack, how you're going to attack them, and obviously an understanding of the programming language itself in order to utilize it.

12:33.280 --> 12:42.460
So as attack methods go, this is quite advanced compared to obviously just copying and pasting off the internet and running it as you like.

12:43.980 --> 12:50.200
You also have to have an understanding of UEFI variable constructs, their attributes, and how they're constructed.

12:50.820 --> 12:59.540
So there's a lot of layers to this sort of attack, but it is very powerful and if leveraged correctly, as they demonstrated, was very effective.

13:00.020 --> 13:02.240
I decided to approach this from another angle.

13:02.240 --> 13:10.540
So instead of going for something pre-compiled and thought about what if we could just do like a drive-by sort of attack.

13:10.760 --> 13:23.140
So we went back to the tried-and-true PowerShell, which is able to leverage the same DLL import functionality.

13:23.500 --> 13:34.760
So ignoring high-level codes, we found that the same functionality into the UEFI memory space read and write could be emulated in PowerShell just as effectively.

13:36.800 --> 13:45.400
You can do this as a PowerShell script, or you can actually do it as a on-the-fly sort of write to terminal and execute, and both work just as well.

13:45.400 --> 13:50.700
The only caveat for both attacks is that it has to be run at an administrative level.

13:50.700 --> 14:02.180
The reason for this is the session that you're using in order to have firmware edit privileges, you have to do token escalation that can only occur as an admin.

14:04.760 --> 14:22.580
So emulating what Tinsman and Leibovitz did, I was able to replicate theirs as a PowerShell, as I said, as a script and as a drive-by, and they were both extremely effective and fully functional.

14:22.720 --> 14:44.040
It was only after I translated their C Sharp code into PowerShell, I found that a guy called Michael Nehas, sorry if I'm pronouncing that wrong, he's actually already written a PowerShell module online which you can download and import, which has the read and write functionality nicely wrapped as two separate functions,

14:44.040 --> 15:00.920
arguments, and all this sort of stuff, making the copy-paste of my PowerShell scripting even easier and much smaller because you don't have to take into account the token escalation and importing the APIs and understanding how to do that.

15:00.920 --> 15:02.220
It does it all for you.

15:02.220 --> 15:21.700
So we've gone from pre-compiled targeted C Sharp payloads to very small on-the-fly copy-paste PowerShell scripting, which as you can imagine if you put that online anyone can tweak the payload and start playing around with it and it's much easier to do much quicker.

15:22.980 --> 15:29.240
So I made some POC code, there's a link at the end to a repository where this is available to everyone.

15:30.620 --> 15:40.800
So the POC code is PowerShell dumps a reverse shell payload, the idea is that it dumps a reverse shell payload into your file and then immediately runs it.

15:40.800 --> 15:44.140
So it's just a write, read, execute.

15:44.140 --> 15:51.320
Obviously in the real world, as I said earlier, you'd obviously write it to the memory space, you'd create persistence, read it later, extract it and execute.

15:51.760 --> 15:55.760
For a PSA this seemed to work very well.

15:57.080 --> 16:16.660
When I tested this, so the antivirus I was using on the host, Windows 10, it detected obviously the reverse shell when it was running to memory, which is what you'd expect, but it didn't terminate it and it didn't remove the payload itself from the UFI memory space.

16:16.660 --> 16:26.780
So the payload itself was still on the host even after the AV had flagged it, which I'll demonstrate later.

16:28.020 --> 16:48.820
As an extra point, this will tie into the defensive problems later, as an attacker, you might want to do is the first write operation you have into a UFI memory space and the persistence that you create, when you run that first payload, delete the original entry into UEFI and the persistence and recreate it again.

16:48.820 --> 17:00.640
The reason is that the payload inside the first UEFI, if they find the way that you've injected into it, they can obviously trace that back and figure out what you put there or what you've labeled it under and things like that.

17:00.640 --> 17:15.240
Whereas if you do it a second time from an encoded or encrypted payload inside the UEFI that you then extract and run again, it becomes much, much harder for investigators to track that from a point of infection to where you're going and what you're doing.

17:15.960 --> 17:18.080
So now comes the tricky bit.

17:18.260 --> 17:19.680
I do have a demo.

17:20.140 --> 17:30.320
So the demo has been created, just as a heads up, to... it was OBS of a virtual machine, however it is fairly small.

17:30.720 --> 17:32.180
So I do apologize.

17:32.180 --> 17:36.300
The videos themselves are available afterwards.

17:36.300 --> 17:40.040
They'll be available for people to look over.

17:40.920 --> 17:44.440
And it will be a good description of what's going on.

17:44.440 --> 17:46.340
So this is the first one.

17:46.340 --> 17:53.160
So this screen shows the drive by header that I'm going to be using in Notepad.

17:53.160 --> 17:55.940
As you can see, it's in byte arrays.

17:56.420 --> 17:58.560
So I copy that.

18:00.000 --> 18:04.900
This payload is fully available from the repository that's available at the end.

18:05.200 --> 18:10.400
This is pasted into the administrative PowerShell terminal.

18:10.400 --> 18:13.360
As you can see the whoami cm underscore test.

18:14.500 --> 18:16.800
That's now being executed.

18:17.760 --> 18:23.080
So that's being written into the UEFI memory space and then being extracted and executed.

18:23.080 --> 18:35.340
So we're going to go to my attack box where I have a reverse TCP handler waiting for the connection from the POC code, which is going to be extracted from UEFI memory.

18:35.340 --> 18:38.440
So we give that a few seconds.

18:43.080 --> 18:44.240
And there it is.

18:44.240 --> 18:48.600
So that's the reverse shell from the UEFI hosted payload.

18:48.600 --> 18:51.780
And the whoami shows that it is cm underscore test.

18:51.780 --> 18:57.360
So it's the same machine that we just ran the PowerShell POC code on.

19:01.140 --> 19:06.980
One thing to note is that the PowerShell instance in that case will be running

19:14.660 --> 19:16.480
in the background.

19:23.220 --> 19:35.540
So when you execute the outputs of the PID of the PowerShell instance that it's going to be running as a POC code, obviously in real attacks you wouldn't keep it as a PowerShell instance.

19:35.540 --> 19:39.720
You might migrate it to something else, but they're irrelevant.

19:41.020 --> 19:52.680
So that's basically the advance of moving from generating payloads and then targeted attacks all the way down to copy pasting and getting the same effect.

19:52.680 --> 19:55.520
So that's the attack side of it, but what about defending?

19:55.680 --> 20:00.740
So there are a number of issues with defending UEFI memory space.

20:01.020 --> 20:11.020
And to understand these issues, it's good to understand why Microsoft has slowly included more access controls to this memory space in their iterative versions.

20:12.100 --> 20:19.060
One of the main reasons is the simplification for firmware updates and maintenance.

20:19.060 --> 20:39.380
So for example, if you're a vendor of any sort of hardware, if you want to update the firmware of your device in the old versions, you would have to run the update and or you'd have to do specialized boot time scans in order to check that it was the correct version.

20:39.480 --> 20:50.800
Whereas now using these interfaces, the operating system is able to run software that can check the installed version, make sure it's compatible, the right type, the right vendor, so on and so forth.

20:51.240 --> 20:57.420
It's also able to change the boot order from runtime, so you no longer have to go into the UEFI or BIOS menu.

20:57.420 --> 21:04.820
You can just do that straight from the operating system, which obviously is much more user-friendly for a lot of users.

21:06.140 --> 21:14.660
One of the interesting things is that in development of Windows, they use UEFI variables and memory space for crash dump data.

21:15.220 --> 21:26.880
So if you ever run Windows Developer Editions and you have a crash, you'll find that it will output crash data to the UEFI memory space because it's non-volatile by nature.

21:26.900 --> 21:30.480
They know that it will be stored and it will be safe so that they output there.

21:32.600 --> 21:44.220
Yeah, so it allows for just much easier maintenance and upgrading and patching of the firmware level of a machine.

21:45.280 --> 21:50.860
But what restrictions are there on this variable access that Windows has introduced?

21:50.860 --> 21:53.900
Well, none, effectively.

21:53.900 --> 21:58.880
The only restriction I could find was a variable size.

21:58.880 --> 22:06.700
Over a certain size, when you try to extract it, you might have some issues because it assumes that it's going to be a certain size.

22:06.700 --> 22:14.740
You can overload the UEFI if you try hard enough, although I haven't actually tried that and I don't recommend it.

22:15.740 --> 22:27.820
You must provide, if you want to read data from UEFI, you must provide the variable name and the GUID or the vendor ID to access that particular variable's data.

22:28.840 --> 22:33.100
And this is where the trouble arises from.

22:33.100 --> 22:51.200
There is no currently available way to enumerate the variables, well, there wasn't, available way to enumerate the variables on the UEFI RAM chip at runtime, with only one exception, which Ligritz and Timzen demonstrated last year.

22:51.380 --> 22:54.700
I couldn't find any other except for one exception, which I'll cover in a second.

22:55.220 --> 23:04.200
Therefore, users, software systems, operating systems, anything like that, can only access variables that they already know exist and they already have the necessary credentials for.

23:04.320 --> 23:07.780
So, from a defense point of view, that creates an issue.

23:07.960 --> 23:24.680
If an attacker creates a new variable with a randomized name and a GUID that's non-specific, an attacker, a defender, can't enumerate these variables and therefore can't analyze what's inside the UEFI memory.

23:24.960 --> 23:34.160
So these, any nasties they put in there, effectively go undetected because the defender doesn't know where they're called and can't extract them, can't access them.

23:34.960 --> 23:39.600
So, the only exception that was found was a tool called Chipsack.

23:39.600 --> 23:41.900
It was designed by the guys over at Intel.

23:41.900 --> 23:47.620
It's a deep firmware security analysis and repair tool.

23:48.000 --> 23:49.900
It's really powerful.

23:50.360 --> 23:51.880
I was quite impressed with it.

23:51.880 --> 23:55.760
It does output the UEFI variables at runtime.

23:55.760 --> 23:59.920
It was the only tool, and I did a lot of searching, and I found it did that.

24:01.160 --> 24:05.660
But the tool itself, even in their reputations, they say it's not for production.

24:05.660 --> 24:07.220
It's for development only.

24:07.240 --> 24:09.040
It's very large.

24:09.040 --> 24:10.400
It's quite clunky.

24:10.400 --> 24:28.860
It requires the installation of a custom kernel driver, and it also requires the disablement of certain security functions in order for it to operate, which obviously, as a defense software, if you're going to be using this remotely in production, is counterintuitive.

24:28.860 --> 24:36.620
Although it does what I was looking for, it wasn't capable of doing it in the way that was required.

24:43.320 --> 24:46.900
Although those are the difficulties, how do you monitor the memory space?

24:47.820 --> 24:54.520
I tested a lot of methods in order to try and find runtime access and enumeration.

24:54.900 --> 24:59.840
This is just a few of them, but I spent a lot of time going through these methods.

25:00.320 --> 25:03.880
Examination of runtime enumeration.

25:04.660 --> 25:11.880
First of all, I looked at the UEFI specification itself, which is really extensive.

25:11.880 --> 25:29.760
There are lots of sections that explain how you can enumerate UEFI variables, but they mainly focus on what's called the EFI shell, which is a specialized shell that can be accessed at boot time in order to interface with the EFI layer of your device.

25:29.760 --> 25:38.200
It requires a custom loader to be put normally on removal medium, which you then access and it provides the shell.

25:38.760 --> 25:50.640
So the specification provides a lot of information about commands that can be run in this particular terminal, this sort of environment, in order to get these variables, but not enough really to do it from runtime.

25:50.900 --> 25:56.240
So it was inconclusive and I couldn't find runtime services from the specification, unfortunately.

25:58.660 --> 26:06.620
Attempts to... so the operating system, as I said, Windows introduced the interaction for the operating system to have access and control over certain elements of UEFI.

26:06.620 --> 26:12.140
So UEFI should have an understanding of what is in there.

26:13.040 --> 26:26.620
So analyzing how the operating system interfaces with the UEFI showed that it works off of a database inside the isolated EFI partition of your hard drive.

26:26.920 --> 26:41.900
From that partition, it then interfaces with a file called BCD, which is a registry file, so key value pairs, which effectively match up to the values that it already knows about at installation.

26:42.200 --> 26:45.280
So backtracing this all the way down.

26:45.340 --> 26:53.460
By the way, the BCD file in the EFI partition is held by system, so you can't access it from while you're running the Windows system, which was always a fun caveat.

26:55.620 --> 27:04.140
So the operating system only knows what it knows at installation, it can't enumerate what is in the EFI memory space.

27:04.140 --> 27:06.640
So unfortunately, that was a dead end.

27:08.660 --> 27:19.180
I turned back to Chipseq as it was the only tool that I could find that did what I was looking for, and the source code is fully available online, which is really, really cool, a really good thing to look at.

27:19.560 --> 27:26.340
So I began looking at how it functions, I began following its procedures and how it accesses the memory.

27:28.600 --> 27:36.700
On assessment, I found that it imported something called EDK2, which seemed to be very important in EFI enumeration.

27:40.380 --> 27:58.540
Effectively, what the EDK2 does is, after a lot of time playing with it, extracting it, running it independently from Chipseq, which was very difficult, I found that instead of accessing it from runtime, what EDK2 does is it creates what's called an EFI payload,

27:58.540 --> 28:03.040
which can be run within an EFI shell to output specific results.

28:03.040 --> 28:20.740
So it's more like a compiler for EFI payloads or capsules, as you may call them, which was run from Chipseq for, I think, mainly for remediation or repairs to the firmware.

28:21.040 --> 28:24.760
Unfortunately, it didn't do what I was looking for, which was obviously runtime enumeration.

28:26.520 --> 28:30.700
So the operating system doesn't enumerate, it only has a list of what it already knows.

28:30.700 --> 28:42.700
The specification didn't provide the information I was looking for, and the tool under analysis that I knew could do it, I stumbled at the first hurdle and couldn't figure out how it was operating.

28:42.700 --> 28:48.060
So I ended up kind of down a rabbit hole for quite a while, trying to dig myself out of it.

28:48.060 --> 29:00.100
Eventually, I did basically knuckle down and get back to Chipseq, and I spent a lot of time following it, debugging it, really analyzing how it worked.

29:00.100 --> 29:10.160
And eventually, I figured out through its abstract process how it accesses the UEFI memory space from runtime.

29:10.160 --> 29:22.200
And to do this, it uses an undocumented function of the NTDLL.DLL file called NTEnumerateSystemEnvironmentVariable values EX.

29:22.760 --> 29:36.420
And what this command does is it extracts the variable information within UEFI to a buffer of your creation, which can then be extracted and carved to find each variable within it.

29:37.480 --> 29:41.280
So you run this function from the NTDLL.

29:41.280 --> 29:48.880
It provides a data blob in a buffer, which you can then loop through and carve and extract all of the variables for analysis.

29:48.880 --> 29:52.340
And this proved to be the saving grace.

29:53.280 --> 30:04.840
From the Chipseq tool, I extracted the methodology, I put it in a lightweight wrapper, really analyzed it, put it through its paces.

30:05.120 --> 30:14.320
The resulting POC code, which is in Python, runs on everything Windows 7 forwards that I tested.

30:14.640 --> 30:27.880
It should, in theory, run on Windows XP because the function within NTDLL was introduced in one of the NTDLL versions, which was released alongside a Windows XP Service Pack 2.

30:28.120 --> 30:32.260
So technically, it should run on Windows XP, but I didn't try that one.

30:32.540 --> 30:40.840
It does check if the system you're on is UEFI-based before it allows it to run, which is obviously something else to note.

30:41.980 --> 30:53.860
As it uses the native NTDLL.dll, which is found on every single Windows host, you're not required to install anything custom except for Python, but also run the POC code.

30:53.860 --> 30:58.540
So it leverages local files in order to enumerate this memory space.

30:59.120 --> 31:06.040
As with the attacks, it must be run as admin because of the token escalation that's required for firmware access.

31:06.800 --> 31:26.600
But as you can see from the left, when running this POC Python code, it did successfully dump all of the AFI variables, including the malicious codes that were not defined anywhere else, and allowed them for analysis as byte data and as translated Unicode.

31:27.020 --> 31:40.880
So we've gone from a very large, powerful, clunky tool to a very lightweight, wrapped Python script, which can run on any Windows host post-Windows 7.

31:42.600 --> 31:44.560
I do have another demo for that.

31:45.040 --> 31:46.140
Bear with me.

31:59.770 --> 32:02.430
So this just shows some Python code.

32:03.110 --> 32:07.250
We're now going to run that Python file, Python 2.

32:09.770 --> 32:14.110
As you can see, it's outputting the AFI variables nice and clearly.

32:14.110 --> 32:20.050
As you can see, the ones going past, although it may be quite small on your screen, is showing the DefCon demo.

32:21.010 --> 32:37.210
P2 entries, that was from the attack that I demonstrated earlier, along with the associated byte data and the Unicode of the reverse TCP payload that I generated using NSFenum.

32:40.200 --> 32:41.080
There we are.

32:41.080 --> 32:47.460
That on the left there is DefCon demo-p1.

32:47.560 --> 32:50.560
That's an example of how that works.

33:02.240 --> 33:13.140
So now we have a good understanding of how this attack can be used at all range of attack levels and how it can be monitored and defended against.

33:13.140 --> 33:16.620
Very lightweight and integrated into defensive software.

33:16.620 --> 33:23.580
What does this mean for computer users and as researchers?

33:24.520 --> 33:26.620
Everyone can be targeted.

33:26.620 --> 33:28.980
Equally, everyone can patch them now.

33:29.220 --> 33:48.550
So despite the obvious ease with which all critical attackers can leverage this memory space using the API function exposed last year, and as I've demonstrated, it can be all the way up from defined calculated attack methodology all the way down to drive-by copy-pasting,

33:50.810 --> 33:58.830
defenders equally now have the equal ease in accessing and enumerating this memory space for analysis.

34:00.270 --> 34:13.770
So although standard hunting procedures or antivirus or defensive technologies may not look into this currently, the integration of such technologies now is very, very easy.

34:14.490 --> 34:36.670
So integration into standard detection rules, processes, techniques, and defensive software is extremely easy using the lightweight capabilities that I've outlined, which effectively neuter this as a malicious haven on all available modern operating systems,

34:36.670 --> 34:38.650
modern hosts.

34:39.610 --> 34:45.230
It also allows for increased sort of research in this area.

34:45.230 --> 35:05.030
So although we now can monitor this, there may be custom payloads that they use that are specific, or there might be malware variations that are specific for leveraging this memory space, which allow us to create custom rules and remediation methods in order to remove this as a threat.

35:05.030 --> 35:19.190
So as we can now enumerate these malicious payloads when they're on a unified memory space, it also allows us to remediate it by leveraging the same capabilities of the attackers, the read-write.

35:19.190 --> 35:28.010
If a defender knows what the payloads are called and where they're stored, they can overwrite and remove their payloads from the victim's host.

35:28.010 --> 35:44.870
So we are in a situation now where attackers have this capability to leverage this isolated memory space, but defenders equally have the same level of ease in order to monitor and neuter any attempts to leverage it.

35:46.430 --> 35:48.350
So that's me.

35:48.350 --> 35:51.070
That's my email, if anyone has any questions.

35:51.070 --> 36:03.850
The GitHub below is the repository with the POC codes, as well as the full research paper, which outlines processes taken and has a lot more technical information than this presentation.

36:04.990 --> 36:08.110
So if anyone does have any questions, please feel free to email me.

36:08.110 --> 36:13.330
There's also the talk.txt channel, if anyone has any questions there.

36:13.330 --> 36:18.870
Or please feel free to direct message me, and I will answer any questions that I'm capable of.

36:19.670 --> 36:22.170
And I look forward to hearing from you guys.

36:24.310 --> 36:25.890
The last slide I have prepared.

36:25.890 --> 36:29.110
So please, if anyone has any questions, do just let me know.

36:29.110 --> 36:30.070
Thank you very much.

36:31.150 --> 36:32.050
Thanks a lot, Connor.

36:32.050 --> 36:32.930
Appreciate it.

36:33.030 --> 36:33.810
Good talk.

36:33.810 --> 36:34.430
Thank you.

