CVE-2024-20693: Windows cached code signature manipulation
A cached code-signature extended attribute on a file could be trusted when the file lived on an SMB share, because the kernel asked the SMB server whether the volume was a trusted container and believed its answer. An attacker controlling a share could therefore set an arbitrary cached signing level on a DLL or executable, which could be used to bypass signature checks such as WDAC allowlisting.
In the Patch Tuesday update of April 2024, Microsoft released a fix for CVE-2024-20693, a vulnerability we reported. This vulnerability allowed manipulating the cached signature signing level of an executable or DLL.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
In the Patch Tuesday update of April 2024, Microsoft released a fix for CVE-2024-20693, a vulnerability we reported. It allowed manipulating the cached signature signing level of an executable or DLL. This post describes how we found the issue and what the impact could be on Windows 11.
## Context
Windows caches the result of Authenticode verification for signed PE files so that it does not have to re-verify a signature every time a DLL or EXE is loaded. The cached result is stored in an NTFS Extended Attribute (EA) named `$KERNEL.PURGE.ESBCACHE`. The `$KERNEL` part means only the Windows kernel may set or change the EA. The `PURGE` part means the EA is automatically removed when the file contents change, which depends on the NTFS journal, so it only works on journaled NTFS partitions. Nothing in the EA binds it to a particular file: it contains the journal ID, but no file path or inode number.
Protected processes only load DLLs signed at an acceptable signature level, so a way to forge the cached level is a way past that check. Protected Process Light (PPL) services only load DLLs signed at an acceptable level, so a way to forge the cached level is a way past that check.
## Setup
We started a project to improve our knowledge of Windows internals, specifically local vulnerabilities such as privilege escalation. The most helpful prior work was the presentation "The Print Spooler Bug that Wasn't in the Print Spooler" at OffensiveCon 2023 by Maddie Stone and James Forshaw from Google, which describes a Windows privilege escalation exploit discovered in the wild.
{{media:1}}
That talk summarises as follows: a highly privileged Windows service that handles requests on behalf of lower-privileged processes can impersonate the requesting process, so that all its operations run with the permissions and privileges of the lower-privileged process. A lowly privileged process on Windows can change its device map, which redirects a device letter such as `C:` to a different location, for example `C:\fakeroot`. The changed device map is part of what is impersonated. If the impersonating service loads a DLL while impersonating a process with a different device map, the wrong file can be loaded. James Forshaw reported that in 2015 and it was fixed.
The logic for choosing which file `LoadLibrary` loads becomes complicated with side-by-side assemblies (WinSxS). Multiple versions of a DLL can be installed and manifest files specify which version to load. DLLs can also carry an embedded manifest specifying which version of their versioned dependencies to load; these are "isolation aware" DLLs. When an isolation aware DLL is loaded, the impersonated device map was used to find the manifests of its dependencies. Combined with a path traversal in the manifest file, a privileged service could be made to load a DLL from a folder chosen by the lower-privileged process. Loading that malicious DLL gives privilege escalation, because the loaded code can revert the impersonation. The attack requires the impersonating service to load an isolation aware DLL that depends on at least one other DLL.
Microsoft's fix for that issue applied a mitigation disabling the loading of WinSxS manifests through the impersonated device map, but only for processes that specifically opted in. The flag was set for a few services known to be vulnerable, leaving many privileged services to examine for the same issue. Maddie and James explained how to configure Process Monitor to find them:
{{media:2}}
We made a list of isolation aware DLLs with at least one dependency on another library, set up the Process Monitor filters as described, and wrote a simple PowerShell script using the NtObjectManager PowerShell module, also from James Forshaw, to enumerate all RPC services and attempt to call all methods. We then cross-referenced the libraries loaded under impersonation with the list of DLLs using a manifest. We found a single match: `wscsvc.dll`.
## Finding it
Calling RPC endpoint number 12 on this service, which takes no arguments, indirectly loads `gpedit.dll`. That is an isolation aware DLL which depends on, among others, `comctl32.dll`. We replicated the in-the-wild setup: created a new directory at `C:\fakeroot`, added the required manifest and DLL files, redirected `C:` to `C:\fakeroot`, and sent the COM message.
It almost worked. Process Monitor showed the service opening and reading our fake DLL file, but it never reached "Load Image", the step where code execution starts. The DLL was being resolved but its code was refused.
The process behind the `wscsvc.dll` service, the Windows Security Center Service, is a PPL (Protected Process Light). That places restrictions on the code signature of the DLLs it loads.
## Protected Process (Light)
Windows recognises several protection levels that stop a process from being modified (terminated, have its memory changed, have threads added) by a process at a lower level. This is used, for example, to make it harder to disable AV tools or important Windows services. As of Windows 11 the levels are:
| Level | Value |
| --- | --- |
| App | 8 |
| WinSystem | 7 |
| WinTcb | 6 |
| Windows | 5 |
| Lsa | 4 |
| Antimalware | 3 |
| CodeGen | 2 |
| Authenticode | 1 |
| None | 0 |
Whether an operation is allowed is determined by a table known as `RtlProtectedAccess`, which we summarised as follows:
| Requesting → / Target ↓ | Authenticode | CodeGen | Antimalware | Lsa | Windows | WinTcb | WinSystem | App |
| --- | --- | --- | --- | --- | --- | --- | --- | --- |
| Authenticode | �
| | | | | | | |
| CodeGen | | �
| | | | | | |
| Antimalware | | | �
| | | | | �
|
| Lsa | | | | �
| | | | |
| Windows | �
| �
| �
| �
| �
| | | |
| WinTcb | �
| �
| �
| �
| �
| �
| | �
|
| WinSystem | �
| �
| �
| �
| �
| �
| �
| �
|
Roughly: Windows, WinTcb and WinSystem form a hierarchy (Windows < WinTcb < WinSystem). Authenticode, CodeGen, Antimalware and Lsa are separate groups that only allow access from processes in the same group or the Win-* hierarchy. We are not sure how App is used; it is new in Windows 10 and not well documented.
There is also a difference between a Protected Process (PP) and a Protected Process Light (PPL): a PP can modify a PPL according to the table, but not the other way around. Examples are Antimalware PPLs for third-party security tools and WinTCB or Windows at PP for critical Windows services such as DRM management. These levels are in addition to all other authorisation checks, such as integrity levels.
Microsoft does not consider this a defended security boundary: a process running as Administrator can load an exploitable kernel driver and modify all protected processes. Since admin to kernel is not a security boundary, protected processes cannot be one for Administrators either.
Protected processes are also limited in which DLLs they may load. Anti-malware services, for example, may only load DLLs signed with the same code-signing certificate or by Microsoft itself. From "Protecting anti-malware services":
> DLL signing requirements
>
> [A]ny non-Windows DLLs that get loaded into the protected service must be signed with the same certificate that was used to sign the anti-malware service.
In general, protected processes may only load a DLL signed with a specific signature level, assigned based on the certificate and its issuer. The exact rules for which PPL level may load which signature level are complicated and can be customised with a secure boot policy; we do not go into them. In short, only certain Windows-signed DLLs were allowed into our target service.
We had two options: find a different service with the same WinSxS-under-impersonation vulnerability, or try to bypass the signing of Windows DLL files. Looking for another service was the more likely to yield results, but the goal of the project was to understand Windows internals better, so we spent some time on how DLL files are signed.
{{media:3}}
## DLL signatures
The code-signing process for PE files is Authenticode. Like TLS, it is based on X.509 certificates. The signature is generated by hashing the PE file, leaving out fields that change after signing such as the checksum and the section holding the signature, signing that hash, and appending it to the file with the certificate chain and optionally a timestamp.
Because verification is slow and DLL loading is frequent, the result of certificate verification for a signed DLL or EXE can be cached in the `$KERNEL.PURGE.ESBCACHE` EA described above. It should not be possible to set this EA from usermode, nor to modify the file without removing the EA.
In 2017 James Forshaw reported that the application of this EA could be raced: by making the file refer to a catalogue, verification could be slowed enough to modify the file contents between signature verification and the EA being applied. Since that was found a while ago, it was unlikely to work again.
We experimented with placing the file on an SMB share and rewriting the contents between verification and image loading, but that did not work either: the file was only read once. Looking at our Wireshark capture and the decompiled code in CI.DLL that parses the `$KERNEL.PURGE.ESBCACHE` extended attribute, something stood out:
{{media:4}}
A `$KERNEL.PURGE.ESBCACHE` EA should only be trusted on the local volume, because a filesystem on, for example, a USB drive or a mounted disk image could have been manipulated by the user. There was a check in the code that we assumed was meant to enforce this and only allow the local boot disk, using the function `CipGetVolumeFlags`:
```c
__int64 __fastcall CipGetVolumeFlags(__int64 file, int *attributeInformation, _BYTE *containerState)
{
int *v6; // x20
BOOL shouldFree; // w21
int ioctlResponse; // w9
unsigned int err; // w19
unsigned int v10; // w19
__int64 buffer; // x0
int outputBuffer; // [xsp+0h] [xbp-40h] BYREF
int returnedOutputBufferLength; // [xsp+4h] [xbp-3Ch] BYREF
int fsInformation[14]; // [xsp+8h] [xbp-38h] BYREF
outputBuffer = 0;
returnedOutputBufferLength = 0;
memset(fsInformation, 0, 48);
v6 = fsInformation;
shouldFree = 0;
// containerState will be set based on the response to the ioctl with ID 0x90390LL on the file
if ( (int)FsRtlKernelFsControlFile(file, 0x90390LL, 0LL, 0LL, &outputBuffer, 4LL, &returnedOutputBufferLength) >= 0 )
ioctlResponse = outputBuffer;
else
ioctlResponse = 0;
outputBuffer = ioctlResponse;
*containerState = ioctlResponse & 1;
// attributeInformation will be set based on the IoQueryVolumeInformation for FileFsAttributeInformation (5)
err = IoQueryVolumeInformation(file, 5LL, 48LL, fsInformation, &returnedOutputBufferLength);
if ( err == 0x80000005 )
{
// Retry in case the buffer is too small
v10 = fsInformation[2] + 8;
buffer = ExAllocatePool2(258LL, (unsigned int)(fsInformation[2] + 8), 'csIC');
v6 = (int *)buffer;
if ( !buffer )
return 0xC000009A;
shouldFree = 1;
err = IoQueryVolumeInformation(file, 5LL, v10, buffer, &returnedOutputBufferLength);
}
if ( (err & 0x80000000) == 0 )
*attributeInformation = *v6;
if ( shouldFree )
ExFreePoolWithTag(v6, 'csIC');
return err;
}
```
This was called from `CipGetFileCache`:
```c
__int64 __fastcall CipGetFileCache(
__int64 fileObject,
unsigned __int8 a2,
int a3,
unsigned int *a4,
_DWORD *a5,
unsigned __int8 *a6,
int *a7,
__int64 a8,
_DWORD *a9,
_DWORD *a10,
__int64 a11,
__int64 a12,
_QWORD *a13,
__int64 *a14)
{
__int64 eaBuffer_1; // x20
unsigned __int64 v17; // x22
unsigned int fileAttributes; // w25
unsigned int attributeInformation_FileSystemAttributes; // w19
unsigned int err; // w19
unsigned int err_1; // w0
__int64 v22; // x4
__int64 v23; // x3
__int64 v24; // x2
__int64 v25; // x1
int containerState_1; // w10
unsigned int v28; // w8
__int64 eaBuffer; // x0
_DWORD *v30; // x23
unsigned __int8 *v31; // x24
int v32; // w8
char v33; // w22
const char *v34; // x10
__int16 v35; // w9
char v36; // w8
unsigned int v37; // w25
int v38; // w9
int IsEnabled; // w0
unsigned int v40; // w8
unsigned int ContextForReplay; // w0
__int64 v42; // x2
_QWORD *v43; // x11
int v44; // w10
__int64 v45; // x9
unsigned __int8 containerState; // [xsp+10h] [xbp-C0h] BYREF
char v47[7]; // [xsp+11h] [xbp-BFh] BYREF
_DWORD *v48; // [xsp+18h] [xbp-B8h]
unsigned __int8 *v49; // [xsp+20h] [xbp-B0h]
unsigned __int8 v50; // [xsp+28h] [xbp-A8h]
unsigned __int64 v51; // [xsp+30h] [xbp-A0h] BYREF
unsigned int v52; // [xsp+38h] [xbp-98h]
int attributeInformation; // [xsp+3Ch] [xbp-94h] BYREF
int v54; // [xsp+40h] [xbp-90h] BYREF
int lengthReturned_1; // [xsp+44h] [xbp-8Ch] BYREF
int lengthReturned; // [xsp+48h] [xbp-88h] BYREF
int v57; // [xsp+4Ch] [xbp-84h]
__int64 v58; // [xsp+50h] [xbp-80h]
__int64 v59; // [xsp+58h] [xbp-78h]
__int64 v60; // [xsp+60h] [xbp-70h]
_QWORD *v61; // [xsp+68h] [xbp-68h]
int *v62; // [xsp+70h] [xbp-60h]
int eaList[8]; // [xsp+78h] [xbp-58h] BYREF
char fileBasicInformation[40]; // [xsp+98h] [xbp-38h] BYREF
[...]
if ( (*(_DWORD *)(*(_QWORD *)(fileObject + 8) + 48LL) & 0x100) != 0 )
{
containerState_1 = 0;
}
else
{
lengthReturned_1 = 0;
memset(fileBasicInformation, 0, sizeof(fileBasicInformation));
err = IoQueryFileInformation(fileObject, 4LL, 40LL, fileBasicInformation, &lengthReturned_1);
if ( (err & 0x80000000) != 0 )
{
[...]
goto LABEL_8;
}
fileAttributes = *(_DWORD *)&fileBasicInformation[32];
// Calling the function above
err_1 = CipGetVolumeFlags(fileObject, &attributeInformation, &containerState);
v17 = v51;
err = err_1;
if ( (err_1 & 0x80000000) != 0 )
{
*a4 = 27;
LABEL_7:
v22 = *a4;
goto LABEL_8;
}
attributeInformation_FileSystemAttributes = attributeInformation;
containerState_1 = containerState;
}
// If the out variable containerState was non-zero, all of the checks don't matter and we go to LABEL_19 to read the EA.
if ( (*(_DWORD *)(*(_QWORD *)(fileObject + 8) + 48LL) & 0x100) != 0 || containerState_1 )
goto LABEL_19;
if ( (g_CiOptions & 0x100) == 0 )
{
if ( (attributeInformation_FileSystemAttributes & 0x20000) == 0 || (fileAttributes & 0x4000) == 0 )
{
*a4 = 5;
v17 = fileAttributes | ((unsigned __int64)attributeInformation_FileSystemAttributes << 32);
err = 0xC00000BB;
goto LABEL_7;
}
goto LABEL_23;
}
if ( (attributeInformation_FileSystemAttributes & 0x20000) != 0 && (fileAttributes & 0x4000) != 0 )
{
[...]
}
LABEL_19:
eaBuffer = ExAllocateFromPagedLookasideList(&g_CiEaCacheLookasideList);
eaBuffer_1 = eaBuffer;
if ( !eaBuffer )
{
v28 = 28;
err = 0xC0000017;
goto LABEL_12;
}
v33 = v50;
eaList[0] = 0;
LOBYTE(eaList[1]) = 22;
if ( v50 )
{
v34 = "$Kernel.Purge.CIpCache";
*(_OWORD *)((char *)&eaList[1] + 1) = *(_OWORD *)"$Kernel.Purge.CIpCache";
}
else
{
v34 = "$Kernel.Purge.ESBCache";
*(_OWORD *)((char *)&eaList[1] + 1) = *(_OWORD *)"$Kernel.Purge.ESBCache";
}
v35 = *((_WORD *)v34 + 10);
*(int *)((char *)&eaList[5] + 1) = *((_DWORD *)v34 + 4);
v36 = v34[22];
*(_WORD *)((char *)&eaList[6] + 1) = v35;
HIBYTE(eaList[6]) = v36;
err = FsRtlQueryKernelEaFile(fileObject, eaBuffer, 380LL, 0LL, eaList, 32LL, 0LL, 1LL, &lengthReturned);
if ( (err & 0x80000000) != 0 )
{
*a4 = 2;
LABEL_34:
v30 = v48;
v31 = v49;
LABEL_35:
ExFreeToPagedLookasideList(&g_CiEaCacheLookasideList, eaBuffer_1);
v17 = v51;
goto LABEL_36;
}
err = CipParseFileCache(eaBuffer_1, v33, (int *)a4, &v51, eaBuffer_1 + 488);
if ( (err & 0x80000000) != 0 )
goto LABEL_34;
v37 = v57;
err = CipVerifyFileCache((__int64 *)(eaBuffer_1 + 488), eaBuffer_1, fileObject, v57, v58, &v54, (int *)a4, &v51);
[...]
return err;
}
```
What we assumed was an ioctl handled by the SMB driver, code `0x90390`, which is not officially documented but may refer to `FSCTL_QUERY_VOLUME_CONTAINER_STATE` based on Microsoft's Rust headers, turned out to be an ioctl forwarded over SMB to the server. Although we called them NTFS Extended Attributes, these EAs work over SMB too.
If that ioctl returns a value with the lowest bit set, `containerState`/`containerState_1` in `CipGetFileCache` become non-zero and the code jumps to `LABEL_19`, skipping a number of checks on the file type, device type and a `g_CiOptions` global we do not fully understand either. In other words, the `$KERNEL.PURGE.ESBCACHE` EA on a file on an SMB share is trusted if the SMB server itself responds to this ioctl that it should be trusted. That is a problem, because by default non-admin users can mount new network shares.
## Exploitation
### Step 1: a Samba server that answers the ioctl
We started with Samba and patched it to always respond `0x00000001` to this ioctl, which it does not implement, and implemented two more ioctls: `0x900f4` (`FSCTL_QUERY_USN_JOURNAL`) for reading the journaling information and `0x900ef` (`FSCTL_WRITE_USN_CLOSE_RECORD`) for flushing the journal. We configured Samba to use the ext3 extended attributes to store the EAs used for SMB.
It worked. From our Linux server running Samba we could apply any `$KERNEL.PURGE.ESBCACHE` attribute to a file and Windows would trust it. On Linux, the extended attributes used by Samba can be set with `setfattr`:
```sh
setfattr -n 'user.$KERNEL.PURGE.ESBCACHE' -v '[redacted]+[redacted]/[redacted]+H/RilbYQrLrbj' "$1"
```
We could now create fake EAs specifying any code-signing level we wanted.
One detail from the setup: Samba and Windows disagree about what an `SMB2_FILE_FULL_EA_INFO` GetInfo request means. Windows issues it to query the value of a specific EA, while Samba responds with all EAs on the file, which confuses Windows. Rather than patch Samba, we made sure the `$KERNEL.PURGE.ESBCACHE` EA was the only EA set on the file.
### Step 2: combining the DLL load with the signature bypass
The next challenge was combining the two issues. We could make `wscsvc.dll` load our own DLL using path traversal, but we cannot path traverse from `C:` into an SMB share. A symbolic link could work, but by default non-admin users on Windows are not allowed to create them. Directory junctions and other symlink-like constructs Windows supports cannot point to SMB shares.
The attack would work if the user plugged in an NTFS-formatted USB device with a symlink to the SMB share, and then created a directory junction from the new `C:` mountpoint in their device map to the USB disk:
```text
C:\fakeroot --(directory junction)--> E:\ --(symlink)--> \\sambaserver\mount
```
That required physical access to the machine, and we preferred something that worked remotely. So we needed a third vulnerability: creating a symlink as a non-admin user. We tried various things, such as mounting disk images or unpacking zip files with symlinks, but before we found a way, Microsoft rolled out a more extensive fix for WinSxS manifest loading under impersonated device maps in August 2023 as CVE-2023-35359: instead of being opt-in per process, the device map was now always ignored when reading the manifest.
Our DLL loading vulnerability in `wscsvc.dll` no longer worked, but we still had the signature bypass. The question became what can be done with cached signature level manipulation alone.
### Step 3: privilege escalation to SYSTEM using .theme files
In our previous post "Getting SYSTEM on Windows in style" we elevated privileges by racing a signing check for a DLL included from a Windows `.theme` file. We originally found that by setting a manipulated `$KERNEL.PURGE.ESBCACHE` attribute on the `*.msstyles_vrf.dll` file. It worked in essentially the same way: we set a new theme referring to a specifically crafted `.msstyles` file, and next to the `.msstyles` file we placed a `.msstyles_vrf.dll` file. When the user logs in, or sets DPI scaling above 100%, WinLogon.exe, which runs as SYSTEM, checks the signature level of this DLL and, if it is signed at level 6 ("Store") or higher, loads it, elevating our privileges.
Microsoft completely removed the loading of `*.msstyles_vrf.dll` files from themes for CVE-2023-38146, so this issue was fixed too.
### Step 4: bypassing WDAC
One place where cached signatures are used for executables is Windows Defender Application Control (WDAC), an allowlisting technology for executables on Windows. It can be used, typically in a corporate environment, to limit which applications a user may run and which DLLs may be loaded. Binaries can be allowlisted by file path, file hash or the identity of the code signer. WDAC policies can be very powerful and granular, so each company using it probably has its own policy, but the default templates allow all software signed by Microsoft itself to run.
Assuming the WDAC policy allows all software signed by Microsoft, we can add an EA indicating Microsoft as the signer to any executable and run it.
### Step 5: injecting code into protected processes
The signature bypass can also be used by administrators to inject code into a protected process, regardless of its level. For example, by replacing a DLL from `system32` with a symlink to an SMB share and then launching a service that runs as a protected process.
Microsoft does not consider this a security boundary, which also means known techniques that abuse it do not get fixed. For our demonstration we combined it with the approach used by ANGRYORCHARD to mark our thread as a kernel mode thread and then map the device's physical memory into our process.
{{media:5}}
### Step 6: combining all steps
1. We use the modified EA on a `.msstyles_vrf.dll` file to bypass signature verification in Winlogon.exe and elevate privileges to `SYSTEM`.
2. We replace a DLL file from `system32` with a symlink to a file with a manipulated cached signature on the SMB share. Then we launch a protected process running at level `WindowsTCB` (we chose `services.exe`).
3. We use our code running in `services.exe` to inject code into `CSRSS.exe` and apply the ANGRYORCHARD technique to gain physical memory read/write.
Combined with the Mark-of-the-Web bypass found by carrot_c4k3 for `.themepack` files, this attack could have been triggered with just the user opening a downloaded file. Depending on the WDAC policy, we could also have bypassed that.
## Root cause
The kernel's cached-signature lookup, `CipGetFileCache`, asks the volume for its container state through ioctl `0x90390`. When the lowest bit of the response is set, the code jumps straight to reading the `$KERNEL.PURGE.ESBCACHE` EA and skips the file type, device type and `g_CiOptions` checks. The ioctl is forwarded over SMB to the server, so a remote SMB server controls the answer. A server that replies `0x00000001` makes Windows trust a `$KERNEL.PURGE.ESBCACHE` EA that the server's filesystem holds, even though the EA is supposed to be kernel-managed and local-only. Nothing in the EA binds it to a file, so the server can attach any cached signing level to any file it serves.
The `$KERNEL` prefix only restricts who may set the EA locally, and the check we assumed was meant to enforce the local-volume rule could be satisfied by a remote server. The earlier race reported by James Forshaw in 2017 was a different mechanism, and it was unlikely to work again.
## Impact
With a forged cached signature level, an attacker can:
- elevate to `SYSTEM` through the `.theme` / `*.msstyles_vrf.dll` path, when the user logs in or changes DPI scaling above 100%;
- bypass WDAC allowlisting when the policy trusts Microsoft-signed software, as the default templates do;
- as an administrator, inject code into protected processes of any level, for example by replacing a `system32` DLL with a symlink to an SMB share and launching a protected service.
The attack depends on the victim connecting to a malicious SMB server; by default non-admin users can mount new network shares. Combined with the `.themepack` Mark-of-the-Web bypass, this attack could have been triggered with just the user opening a downloaded file. The protected-process part is not considered a defended security boundary by Microsoft.
## Fix
We had hoped Microsoft would disable reading `$KERNEL.*` extended attributes from SMB completely. Instead, the specific instances we exploited were fixed:
1. The fix for CVE-2023-38146 already disabled loading of `*.msstyles_vrf.dll` files completely, fixing the privilege escalation.
2. When WDAC is enabled, the function that retrieves the cached signature level of a file now always returns an error, even for local files.
3. When loading a DLL into a protected process, the cached signature level is no longer used. This was fixed even though Microsoft does not consider it a defended security boundary.
The fix for the WDAC and PPL bypass was released as CVE-2024-20693 on 9 April 2024.
## Timeline
- August 25, 2023: issue reported to MSRC.
- September 12, 2023: fix for CVE-2023-38146 released, breaking our privilege escalation exploit.
- September 20, 2023: MSRC indicates it reproduced the issue and that a fix is scheduled for January 2024.
- December 11, 2023: MSRC informs us a regression was found and asks to reschedule the fix to April 2024.
- April 9, 2024: fix released for the WDAC and PPL bypass as CVE-2024-20693.
- April 25, 2024: MSRC asks Microsoft Bounty Team for an update, CCing us.
- April 26, 2024: Microsoft Bounty Team sends a boilerplate reply that the case is under review.
- May 17, 2024: MSRC asks Microsoft Bounty Team for an update, CCing us again.
- May 22, 2024: Microsoft Bounty Team replies that the vulnerability was out of scope for a bounty, claiming it did not reproduce on the right WIP build.
- May 23, 2024: we inform Microsoft Bounty Team that we believe the exploit did reproduce on the latest WIP build and that the WDAC bypass was not a known issue.
- May 29, 2024: Microsoft Bounty Team re-evaluates the issue and assigns a bounty.
## Mitigation
The attack depends on the victim connecting to a malicious SMB server. Blocking outgoing SMB to the internet makes it a lot harder, unless the attacker already has a foothold on the local network. Preventing users from mounting new SMB shares is another option, but could have more unintended results. SMB traffic can also be examined for exploitation by looking for responses to ioctl `0x90390` or responses for the EA `$KERNEL.PURGE.ESBCACHE`.
## Variants to test
- **Other kernel consumers of `$KERNEL.*` EAs over SMB.** Look for code paths that read kernel EAs from a file object without confirming the volume is local. A positive result is a file on a Samba share whose EA is honoured by Windows.
- **Other ioctls forwarded over SMB that influence trust decisions.** The container-state ioctl was the lever here; enumerate other FSCTLs whose response changes a security check. A positive result is a server-controlled response that skips a validation branch.
- **Other isolation-aware DLLs loaded under impersonation.** Repeat the Process Monitor filtering and RPC enumeration against services that did not opt in to the WinSxS mitigation. A positive result is a privileged service reading a manifest or DLL from the impersonated device map.
- **Other signature-level consumers.** Check components that consult the cached signature level, such as theme verification, WDAC and protected-process loading, on builds before the fixes. A positive result is code executing with a forged level.
- **Symlink creation as a non-admin user.** The chain needed a way to point a path at an SMB share without admin rights; mounting disk images or unpacking archives with symlinks are worth trying. A positive result is a symlink or junction that redirects a privileged load to the share.
## Conclusion
We set out to understand Windows internals better by adapting research into DLL loading in impersonating services using WinSxS, but got sidetracked into the code-signing method for DLL files and found a way to bypass it. We could not apply it in the scenario we started with, but found other places to elevate privileges, bypass WDAC and inject code into protected processes. As with our earlier research on a signature verification bypass for macOS `.pkg` files, vulnerabilities in cryptographic operations can often be applied in many ways, allowing different security measures to be bypassed, and this one could go from a user opening a downloaded file to full system compromise.## What happened, in plain words
In April 2024, Microsoft released a security update that fixed a problem we had reported. The problem is tracked as CVE-2024-20693. "CVE" stands for Common Vulnerabilities and Exposures: it is a public catalogue number given to a security flaw so that everyone can refer to the same thing. The flaw let someone manipulate the *cached signature signing level* of a program file or a DLL on Windows. A DLL (Dynamic Link Library) is a file full of code that other programs load and run, a bit like a shared toolbox that many programs borrow from. A "signature" is a cryptographic stamp that says who made a file and that nobody changed it since. The "signing level" is a ranking Windows gives to that stamp. By faking the cached ranking, an attacker could make Windows believe a file they wrote themselves carried a higher signing level.
This post explains how we found the flaw and what it could do on Windows 11.
## Background
Last year we started a project to learn more about how Windows works inside, especially about *local* security problems. A local problem is one where the attacker already has some access to the machine, for example as an ordinary user, and tries to become a more powerful user. The class of attack is called *privilege escalation*: gaining rights you were not given. The best way to start on a new target is to read what other researchers have published recently. That gives you the most current picture of how the security is designed, and it lets you look for variations of a known bug, or for ways around the fixes that were shipped.
The most helpful earlier work we found was a talk called "The Print Spooler Bug that Wasn't in the Print Spooler", given at the OffensiveCon 2023 conference by Maddie Stone and James Forshaw from Google. The talk describes a Windows privilege escalation exploit that was found being used in the real world, not just in a lab.
{{media:1}}
## Privilege escalation using an impersonated device map and isolation-aware DLLs
If you have not watched that talk, here is a summary. Windows runs many background programs called *services*. A service is a program that runs without a visible window, usually under a powerful account, and does jobs on behalf of the user. Some services are highly privileged: they can do almost anything on the machine. When such a service handles a request from an ordinary, low-privileged program, it can *impersonate* the requesting program. Impersonation means the service temporarily acts as if it were that low-privileged program, so every operation it performs is checked against the low-privileged program's permissions. This is a good safety measure: the powerful service can never accidentally do something the weak program could not do itself.
One thing to know is that an ordinary program on Windows can change its *device map*. A device map is the table that tells Windows what a drive letter means. Normally `C:` points at the main disk, but a program can redirect `C:` to a different place, for example a folder such as `C:\fakeroot`. That changed device map is one of the things included when a service impersonates the program. This is risky: what if the impersonating service tries to load a DLL while it is impersonating a program that has pointed `C:` somewhere else? The service would load a file from the wrong place. James Forshaw reported that problem in 2015 and it was fixed.
The logic for deciding which file `LoadLibrary` loads can get complicated when *side-by-side assemblies* (WinSxS) are involved. `LoadLibrary` is the Windows function a program calls to load a DLL. WinSxS is the part of Windows that keeps several versions of the same DLL installed at once. *Manifest* files are small text files that say which version to use for a particular application. A DLL can also carry an embedded manifest that says which version of the other DLLs it depends on should be loaded. DLLs that carry such a manifest are called "isolation aware" DLLs.
The heart of the exploited flaw is this: when an isolation-aware DLL is loaded, the impersonated device map was used to find the manifests of the DLLs it depends on. By combining that with a *path traversal* in the manifest file, a privileged service could be made to load a DLL from a folder chosen by the low-privileged program. Path traversal means putting `..` style pieces in a file path so that it climbs out of the folder it was supposed to stay in, like writing `../..` in a web address to reach a folder above the one you were given. Loading that malicious DLL gives privilege escalation, because once your code is running inside the powerful service it can simply undo the impersonation and act with the service's full rights. For the attack to work, the impersonating service has to load an isolation-aware DLL that depends on at least one other DLL.
Microsoft's fix for the issue in the Maddie Stone and James Forshaw talk added a mitigation: it disabled the loading of WinSxS manifests through the impersonated device map, but only for processes that specifically opted in. A mitigation is a change that makes an attack harder without removing the underlying feature. The opt-in flag was set for only a few services that were known to be vulnerable. That left a lot of privileged services that could be examined for the same issue. Very helpfully, Maddie and James explained how to configure Process Monitor on Windows to find them. Process Monitor is a free Microsoft tool that records what files, registry keys and other resources a program touches, like a security camera for a program's activity.
{{media:2}}
So we set to work looking for issues like this. We made a list of isolation-aware DLLs that depend on at least one other library, set up the Process Monitor filters as described, and wrote a simple PowerShell script. PowerShell is a scripting language built into Windows for automating tasks. The script used the NtObjectManager PowerShell module, also from James Forshaw, to list all RPC services and try to call every method on them. RPC (Remote Procedure Call) is a way for one program to ask another program to run a function for it, a bit like ordering from a menu rather than walking into the kitchen. A "method" here is one of those callable functions. We then compared the libraries that were loaded while impersonation was active against the list of DLLs that use a manifest. We found a single match: `wscsvc.dll`.
## wscsvc.dll
Calling RPC endpoint number 12 on this service, which takes no arguments, indirectly loads `gpedit.dll`. An endpoint here is one numbered entry point on the service. `gpedit.dll` is an isolation-aware DLL that depends on, among others, `comctl32.dll`. We copied the setup from the real-world exploit: we created a new directory at `C:\fakeroot`, put the required manifest and DLL files in it, redirected `C:` to `C:\fakeroot`, and then sent the COM message. COM (Component Object Model) is an older Windows mechanism that lets programs call each other's objects; it is another way of asking a service to do something.
And it works... almost. Process Monitor shows that the service opens and reads our fake DLL file, but it never reaches "Load Image", which is the step where the actual code execution starts. Somehow it was finding our DLL but refusing to run its code.
Then we found out that the process behind the `wscsvc.dll` service, the "Windows Security Center Service", is categorised as a PPL (Protected Process Light). That means it places restrictions on the code signature of the DLL files it loads.
## Protected Process (Light)
Windows recognises a number of different protection levels that stop a process from being "modified" by a process at a lower protection level. "Modified" here means things like being terminated, having its memory changed, or having new threads added. A thread is one stream of execution inside a program; adding one is a way to run your own code inside someone else's process. These levels are used, for example, to make it harder to disable antivirus tools or important Windows services.
As of Windows 11, the protection levels are:
| Level | Value |
| --- | --- |
| App | 8 |
| WinSystem | 7 |
| WinTcb | 6 |
| Windows | 5 |
| Lsa | 4 |
| Antimalware | 3 |
| CodeGen | 2 |
| Authenticode | 1 |
| None | 0 |
Whether an operation is allowed is determined by a table known as `RtlProtectedAccess`. We have summarised it as follows:
| Requesting → / Target ↓ | Authenticode | CodeGen | Antimalware | Lsa | Windows | WinTcb | WinSystem | App |
| --- | --- | --- | --- | --- | --- | --- | --- | --- |
| Authenticode | �
| | | | | | | |
| CodeGen | | �
| | | | | | |
| Antimalware | | | �
| | | | | �
|
| Lsa | | | | �
| | | | |
| Windows | �
| �
| �
| �
| �
| | | |
| WinTcb | �
| �
| �
| �
| �
| �
| | �
|
| WinSystem | �
| �
| �
| �
| �
| �
| �
| �
|
It can roughly be summarised as follows: Windows, WinTcb and WinSystem form a hierarchy (Windows < WinTcb < WinSystem). Authenticode, CodeGen, Antimalware and Lsa are separate groups that only allow access from processes in the same group or the Win-* hierarchy. We are not sure how "App" is used; it is new in Windows 10 and has not been documented very well.
In addition, there is a difference between a Protected Process (PP) and a Protected Process Light (PPL): a Protected Process can modify a Protected Process Light (based on the table above), but not the other way around. Some examples are Antimalware PPLs for third-party security tools, and WinTCB or Windows at PP for critical Windows services such as managing DRM. DRM (Digital Rights Management) is the technology that protects things like films and music from being copied. Keep in mind that these protection levels are also in addition to all the other authorisation checks in Windows, such as integrity levels. An integrity level is a label on a process or file (low, medium, high, system) that Windows uses to decide who may write to what.
Note that Microsoft does not consider this a defended security boundary. A security boundary is a line that Microsoft promises attackers cannot cross, so bugs that cross it get fixed as security issues. Here, a process running as Administrator can load an exploitable kernel driver, and a driver runs with full control of the machine, so it can modify all protected processes. Since admin to kernel is not a security boundary according to Microsoft, protected processes cannot be a security boundary for Administrators either.
Aside from the restrictions on being manipulated by other processes, protected processes are also limited in which DLLs they may load. For example, anti-malware services may only load DLLs signed with the same code-signing certificate or by Microsoft itself. A certificate is the digital document that carries a public key and identifies who signed something. From "Protecting anti-malware services":
> DLL signing requirements
>
> [A]ny non-Windows DLLs that get loaded into the protected service must be signed with the same certificate that was used to sign the anti-malware service.
For protected processes in general, they are only allowed to load a DLL signed with a specific *Signature Level*. Signature levels are assigned to a DLL based on the certificate and its issuer used for the code signature. The exact rules for when which PPL level may load a DLL with a specific signature level are quite complicated, and these rules can even be customised with a secure boot policy. Secure boot is the firmware feature that checks the boot process has not been tampered with. We will not go into those rules here. But to summarise: only certain Windows-signed DLLs were allowed to be loaded into our target service.
At this point we had two options: find a different service with the same WinSxS-under-impersonation vulnerability, or try to bypass the signing of Windows DLL files. The most likely to yield results would of course have been to look for a different service, but the goal of the project was to understand Windows internals better, so we decided to spend a little bit of time on understanding how DLL files are signed.
{{media:3}}
## DLL signatures
The code-signing process for PE files is known as *Authenticode*. A PE file (Portable Executable) is the standard format for Windows programs and DLLs. Just like TLS, the encryption protocol that protects HTTPS websites, Authenticode is based on X.509 certificates. An Authenticode signature is generated by computing the hash of the PE file, then signing that hash and appending it to the file together with the certificate chain and optionally a timestamp. A hash is a short fingerprint computed from the file's contents: change one byte and the fingerprint changes completely. The certificate chain is the list of certificates linking the signer up to a trusted root. The hash leaves out certain fields that will change after signing, such as the checksum and the section for the signature itself.
Because signature verification can be slow and loading DLLs happens often on Windows, a caching method has been implemented for code signatures. For a signed DLL or EXE file, the result of the certificate verification can be stored in an NTFS Extended Attribute (EA) named `$KERNEL.PURGE.ESBCACHE`. NTFS is the standard Windows file system. An Extended Attribute is a small named field attached to a file, like a sticky note on a folder, holding extra information that is not part of the file's contents. The `$KERNEL` part of this name means that only the Windows kernel is allowed to set or change this EA. The kernel is the core of the operating system, the part that talks to the hardware and enforces the rules. The `PURGE` part means that the EA will be automatically removed if the contents of the file are modified. This means that it should not be possible to set this EA from usermode, nor to modify the file without removing the EA. Usermode is the ordinary world where your programs run, as opposed to kernel mode. This only works on journaled NTFS partitions, because the `PURGE` functionality depends on the journal. A journal is a log the file system keeps of changes, so it can recover from crashes. Note that nothing in this EA binds it to the file: these attributes contain the journal ID, but nothing like a file path or inode number. An inode number is the internal identifier a file system gives a file.
In 2017, James Forshaw had reported that it was possible to race the application of this EA. A race condition is when two operations happen at nearly the same time and the attacker tries to slip something in between them. By making the file refer to a catalogue, it was possible to slow down the verification enough to modify the contents of the file in between the verification of the signature and the application of the EA. A catalogue is a signed list of file hashes that Windows can check instead of the file's own signature. As this was already found a while ago, it was unlikely that doing this was going to work.
We experimented with placing the file on an SMB share instead and attempting to rewrite the contents in between the verification and image loading, but this wasn't working either (the file was only being read once). SMB (Server Message Block) is the protocol Windows uses to access files over a network, the same way you open a folder on another computer. But looking at our Wireshark capture and the decompiled code in CI.DLL that parses the `$KERNEL.PURGE.ESBCACHE` extended attribute, we noticed something standing out. Wireshark is a tool that records network traffic so you can read it. Decompiled code is machine code turned back into something resembling source code so a human can read it. CI.DLL is the Windows library that handles code integrity, the checks on whether code is allowed to run.
{{media:4}}
A `$KERNEL.PURGE.ESBCACHE` extended attribute should only be trusted on the local volume, as a filesystem on, for example, a USB drive or mounted disk image could have been manipulated by the user. A volume is one storage area with its own file system, such as a disk or a partition. There was a check in the code we assumed was meant to check for this and only allow the local boot disk, using the function `CipGetVolumeFlags`.
```c
__int64 __fastcall CipGetVolumeFlags(__int64 file, int *attributeInformation, _BYTE *containerState)
{
int *v6; // x20
BOOL shouldFree; // w21
int ioctlResponse; // w9
unsigned int err; // w19
unsigned int v10; // w19
__int64 buffer; // x0
int outputBuffer; // [xsp+0h] [xbp-40h] BYREF
int returnedOutputBufferLength; // [xsp+4h] [xbp-3Ch] BYREF
int fsInformation[14]; // [xsp+8h] [xbp-38h] BYREF
outputBuffer = 0;
returnedOutputBufferLength = 0;
memset(fsInformation, 0, 48);
v6 = fsInformation;
shouldFree = 0;
// containerState will be set based on the response to the ioctl with ID 0x90390LL on the file
if ( (int)FsRtlKernelFsControlFile(file, 0x90390LL, 0LL, 0LL, &outputBuffer, 4LL, &returnedOutputBufferLength) >= 0 )
ioctlResponse = outputBuffer;
else
ioctlResponse = 0;
outputBuffer = ioctlResponse;
*containerState = ioctlResponse & 1;
// attributeInformation will be set based on the IoQueryVolumeInformation for FileFsAttributeInformation (5)
err = IoQueryVolumeInformation(file, 5LL, 48LL, fsInformation, &returnedOutputBufferLength);
if ( err == 0x80000005 )
{
// Retry in case the buffer is too small
v10 = fsInformation[2] + 8;
buffer = ExAllocatePool2(258LL, (unsigned int)(fsInformation[2] + 8), 'csIC');
v6 = (int *)buffer;
if ( !buffer )
return 0xC000009A;
shouldFree = 1;
err = IoQueryVolumeInformation(file, 5LL, v10, buffer, &returnedOutputBufferLength);
}
if ( (err & 0x80000000) == 0 )
*attributeInformation = *v6;
if ( shouldFree )
ExFreePoolWithTag(v6, 'csIC');
return err;
}
```
Line by line, in plain words:
- The first line declares a function called `CipGetVolumeFlags`. It takes a file, a place to store some information about the volume, and a place to store a "container state" value. A function is a named block of code that does one job and can be called from elsewhere.
- The lines starting with `int` and `__int64` declare local variables: named boxes in memory that hold values while the function runs. The comments such as `// x20` are notes left by the decompiler about which processor register held the value.
- `outputBuffer = 0;` and `returnedOutputBufferLength = 0;` set two of those boxes to zero, so they start clean.
- `memset(fsInformation, 0, 48);` fills the 48-byte area used for file system information with zeros.
- `v6 = fsInformation;` makes `v6` point at that area, so the code can use either name for it.
- `shouldFree = 0;` records that we have not yet allocated any memory that needs freeing.
- The comment says `containerState` will be set from the response to an ioctl with ID `0x90390` on the file. An ioctl (input/output control) is a request sent to a device or file system asking it to do something specific and return an answer, like pressing a button on a machine and reading the display.
- `FsRtlKernelFsControlFile(file, 0x90390LL, ...)` sends that ioctl. If it succeeds (the result is not negative), the answer is copied into `ioctlResponse`; otherwise `ioctlResponse` is set to 0.
- `*containerState = ioctlResponse & 1;` keeps only the lowest bit of the answer. The `& 1` operation is a bitwise AND: it keeps the last binary digit and throws the rest away, so the result is either 0 or 1.
- The next block asks the file system for its attributes with `IoQueryVolumeInformation`. If the answer is `0x80000005`, which means the buffer was too small, it allocates a bigger buffer with `ExAllocatePool2`, retries, and remembers that the buffer must be freed later.
- If the query succeeded, `*attributeInformation = *v6;` copies the first value of the answer out to the caller.
- Finally, if a buffer was allocated, `ExFreePoolWithTag` frees it, and the function returns the error code.
This was being called from `CipGetFileCache`:
```c
__int64 __fastcall CipGetFileCache(
__int64 fileObject,
unsigned __int8 a2,
int a3,
unsigned int *a4,
_DWORD *a5,
unsigned __int8 *a6,
int *a7,
__int64 a8,
_DWORD *a9,
_DWORD *a10,
__int64 a11,
__int64 a12,
_QWORD *a13,
__int64 *a14)
{
__int64 eaBuffer_1; // x20
unsigned __int64 v17; // x22
unsigned int fileAttributes; // w25
unsigned int attributeInformation_FileSystemAttributes; // w19
unsigned int err; // w19
unsigned int err_1; // w0
__int64 v22; // x4
__int64 v23; // x3
__int64 v24; // x2
__int64 v25; // x1
int containerState_1; // w10
unsigned int v28; // w8
__int64 eaBuffer; // x0
_DWORD *v30; // x23
unsigned __int8 *v31; // x24
int v32; // w8
char v33; // w22
const char *v34; // x10
__int16 v35; // w9
char v36; // w8
unsigned int v37; // w25
int v38; // w9
int IsEnabled; // w0
unsigned int v40; // w8
unsigned int ContextForReplay; // w0
__int64 v42; // x2
_QWORD *v43; // x11
int v44; // w10
__int64 v45; // x9
unsigned __int8 containerState; // [xsp+10h] [xbp-C0h] BYREF
char v47[7]; // [xsp+11h] [xbp-BFh] BYREF
_DWORD *v48; // [xsp+18h] [xbp-B8h]
unsigned __int8 *v49; // [xsp+20h] [xbp-B0h]
unsigned __int8 v50; // [xsp+28h] [xbp-A8h]
unsigned __int64 v51; // [xsp+30h] [xbp-A0h] BYREF
unsigned int v52; // [xsp+38h] [xbp-98h]
int attributeInformation; // [xsp+3Ch] [xbp-94h] BYREF
int v54; // [xsp+40h] [xbp-90h] BYREF
int lengthReturned_1; // [xsp+44h] [xbp-8Ch] BYREF
int lengthReturned; // [xsp+48h] [xbp-88h] BYREF
int v57; // [xsp+4Ch] [xbp-84h]
__int64 v58; // [xsp+50h] [xbp-80h]
__int64 v59; // [xsp+58h] [xbp-78h]
__int64 v60; // [xsp+60h] [xbp-70h]
_QWORD *v61; // [xsp+68h] [xbp-68h]
int *v62; // [xsp+70h] [xbp-60h]
int eaList[8]; // [xsp+78h] [xbp-58h] BYREF
char fileBasicInformation[40]; // [xsp+98h] [xbp-38h] BYREF
[...]
if ( (*(_DWORD *)(*(_QWORD *)(fileObject + 8) + 48LL) & 0x100) != 0 )
{
containerState_1 = 0;
}
else
{
lengthReturned_1 = 0;
memset(fileBasicInformation, 0, sizeof(fileBasicInformation));
err = IoQueryFileInformation(fileObject, 4LL, 40LL, fileBasicInformation, &lengthReturned_1);
if ( (err & 0x80000000) != 0 )
{
[...]
goto LABEL_8;
}
fileAttributes = *(_DWORD *)&fileBasicInformation[32];
// Calling the function above
err_1 = CipGetVolumeFlags(fileObject, &attributeInformation, &containerState);
v17 = v51;
err = err_1;
if ( (err_1 & 0x80000000) != 0 )
{
*a4 = 27;
LABEL_7:
v22 = *a4;
goto LABEL_8;
}
attributeInformation_FileSystemAttributes = attributeInformation;
containerState_1 = containerState;
}
// If the out variable containerState was non-zero, all of the checks don't matter and we go to LABEL_19 to read the EA.
if ( (*(_DWORD *)(*(_QWORD *)(fileObject + 8) + 48LL) & 0x100) != 0 || containerState_1 )
goto LABEL_19;
if ( (g_CiOptions & 0x100) == 0 )
{
if ( (attributeInformation_FileSystemAttributes & 0x20000) == 0 || (fileAttributes & 0x4000) == 0 )
{
*a4 = 5;
v17 = fileAttributes | ((unsigned __int64)attributeInformation_FileSystemAttributes << 32);
err = 0xC00000BB;
goto LABEL_7;
}
goto LABEL_23;
}
if ( (attributeInformation_FileSystemAttributes & 0x20000) != 0 && (fileAttributes & 0x4000) != 0 )
{
[...]
}
LABEL_19:
eaBuffer = ExAllocateFromPagedLookasideList(&g_CiEaCacheLookasideList);
eaBuffer_1 = eaBuffer;
if ( !eaBuffer )
{
v28 = 28;
err = 0xC0000017;
goto LABEL_12;
}
v33 = v50;
eaList[0] = 0;
LOBYTE(eaList[1]) = 22;
if ( v50 )
{
v34 = "$Kernel.Purge.CIpCache";
*(_OWORD *)((char *)&eaList[1] + 1) = *(_OWORD *)"$Kernel.Purge.CIpCache";
}
else
{
v34 = "$Kernel.Purge.ESBCache";
*(_OWORD *)((char *)&eaList[1] + 1) = *(_OWORD *)"$Kernel.Purge.ESBCache";
}
v35 = *((_WORD *)v34 + 10);
*(int *)((char *)&eaList[5] + 1) = *((_DWORD *)v34 + 4);
v36 = v34[22];
*(_WORD *)((char *)&eaList[6] + 1) = v35;
HIBYTE(eaList[6]) = v36;
err = FsRtlQueryKernelEaFile(fileObject, eaBuffer, 380LL, 0LL, eaList, 32LL, 0LL, 1LL, &lengthReturned);
if ( (err & 0x80000000) != 0 )
{
*a4 = 2;
LABEL_34:
v30 = v48;
v31 = v49;
LABEL_35:
ExFreeToPagedLookasideList(&g_CiEaCacheLookasideList, eaBuffer_1);
v17 = v51;
goto LABEL_36;
}
err = CipParseFileCache(eaBuffer_1, v33, (int *)a4, &v51, eaBuffer_1 + 488);
if ( (err & 0x80000000) != 0 )
goto LABEL_34;
v37 = v57;
err = CipVerifyFileCache((__int64 *)(eaBuffer_1 + 488), eaBuffer_1, fileObject, v57, v58, &v54, (int *)a4, &v51);
[...]
return err;
}
```
Line by line, in plain words:
- The function `CipGetFileCache` is the kernel routine that looks up the cached signature for a file. It takes many arguments, most of which are places to write results back to the caller.
- The long block of declarations creates local variables, including `containerState`, which will hold the answer from `CipGetVolumeFlags`.
- The first `if` checks a flag on the file object. If that bit is set, `containerState_1` is set to 0 and the volume check is skipped.
- Otherwise the code asks for basic information about the file with `IoQueryFileInformation`, and stores the file attributes it gets back.
- It then calls `CipGetVolumeFlags`, the function shown above, passing the file and two output variables. If that call fails, it records error 27 and jumps to the exit path.
- If it succeeds, the volume attributes and the container state are saved.
- The comment explains the key point: if `containerState` was non-zero, all of the checks do not matter and the code goes to `LABEL_19` to read the EA. The `if` right after it does exactly that: if the earlier flag was set, or `containerState_1` is non-zero, it jumps to `LABEL_19`.
- The checks that are skipped are visible next: a test of `g_CiOptions` (a global settings variable for code integrity), a test of a file system attribute bit `0x20000`, and a test of a file attribute bit `0x4000`. If those do not match, the function returns error `0xC00000BB`.
- At `LABEL_19`, the code allocates a buffer, builds a small structure naming the EA it wants (`$Kernel.Purge.CIpCache` or `$Kernel.Purge.ESBCache`, depending on `v50`), and calls `FsRtlQueryKernelEaFile` to read that EA from the file.
- If reading succeeds, `CipParseFileCache` parses the cached data and `CipVerifyFileCache` checks it against the file. The function then returns the result.
What we assumed to be an ioctl that would be handled by the SMB driver (using code `0x90390`, which isn't documented officially, but may refer to `FSCTL_QUERY_VOLUME_CONTAINER_STATE`, based on Microsoft's Rust headers) turned out to be an ioctl that gets forwarded over SMB to the server. While we called it **NTFS** Extended Attributes, these extended attributes in fact work over SMB too.
If that ioctl results in a value with the lowest bit set, `containerState`/`containerState_1` in `CipGetFileCache` become non-zero and the code jumps to `LABEL_19` above, skipping a lot of checks on the file type, device type and a `g_CiOptions` global we don't fully understand either.
In other words: the `$KERNEL.PURGE.ESBCACHE` extended attribute on a file on an SMB share is trusted *if the SMB server itself responds to this ioctl that it should be trusted!* This is of course a problem, as by default non-admin users can mount new network shares. Mounting a share means connecting a network folder so it appears like a local drive.
We started out with Samba and patched it to always respond `0x00000001` to this ioctl (it is not implemented currently) and implemented two more ioctls: `0x900f4` (`FSCTL_QUERY_USN_JOURNAL`) for reading the journaling information and `0x900ef` (`FSCTL_WRITE_USN_CLOSE_RECORD`) for flushing the journal. Samba is a free implementation of the SMB file-sharing protocol that runs on Linux and other systems. We configured Samba to use the ext3 extended attributes to store the EAs used for SMB. ext3 is a Linux file system.
And it worked! From our Linux server running Samba, we could apply any `$KERNEL.PURGE.ESBCACHE` attribute on a file and Windows would trust it. On Linux, the extended attributes used by Samba can be set using `setfattr`.
```sh
setfattr -n 'user.$KERNEL.PURGE.ESBCACHE' -v '[redacted]+[redacted]/[redacted]+H/RilbYQrLrbj' "$1"
```
This is a single shell command. `setfattr` is a Linux utility that sets an extended attribute on a file. `-n` gives the name of the attribute, here `user.$KERNEL.PURGE.ESBCACHE`. `-v` gives the value, a long string of encoded bytes that represents the cached signature data. `"$1"` is the file name passed to the script as its first argument. In short: this command attaches a fake cached signature to a file on the Linux server.
We could now create fake EAs that could specify any code signing level we wanted. How can we abuse this?
## Combining the DLL load and signature bypass
Now we got to the next challenge: how do we combine these two vulnerabilities? We could make `wscsvc.dll` load our own DLL using path traversal, but we can't path traverse from `C:` into an SMB share. A symbolic link could work, but by default non-admin users on Windows are not allowed to create these. A symbolic link is a file that acts as a signpost pointing at another file or folder. Directory junctions and other symlink-like constructs that Windows supports can not point to SMB shares.
We could perform the attack if the user plugged in a NTFS formatted USB device with a symlink to the SMB share. The user could then create a directory junction from the new `C:` mountpoint in their devicemap to the USB disk.
```text
C:\fakeroot --(directory junction)--> E:\ --(symlink)--> \\sambaserver\mount
```
This diagram reads left to right: the folder `C:\fakeroot` is a directory junction pointing at the USB disk `E:\`, and on that disk a symbolic link points at the network share `\\sambaserver\mount`. Chaining them like this would let a path that starts on `C:` end up on the SMB share.
But this required physical access to the machine. We preferred something that would also work remotely.
So we needed a third vulnerability: creating a symlink as a non-admin user.
We tried various things, like mounting disk images or unpacking zip files with symlinks, but before we had found a way to do this, Microsoft had rolled out a more extensive fix for the WinSxS manifest loading under impersonated device maps in August 2023 (as CVE-2023-35359): instead of being opt-in for processes, the device map was now always ignored for reading the manifest.
This meant that our DLL loading vulnerability in `wscsvc.dll` was no longer working, but we still had the signature bypass. So, next question: what can we do with just cached signature level manipulation on Windows?
## Applying the signature bypass
## Privilege escalation to SYSTEM using .theme files
In the previous post "Getting SYSTEM on Windows in style" we showed how we managed to elevate privileges on Windows by racing a signing check for a DLL included from a Windows `.theme` file. SYSTEM is the most powerful account on a Windows machine, the one the operating system itself runs as. A `.theme` file is a Windows file that describes desktop appearance: colours, sounds, and which visual style to use. In that post, we used a race condition, but we originally found it by setting a manipulated `$KERNEL.PURGE.ESBCACHE` attribute on the `*.msstyles_vrf.dll` file. This worked in essentially the same way: we set a new theme which refers to a specifically crafted `.msstyles` file. Next to the `.msstyles` file, we place a `.msstyles_vrf.dll` file. When the user logs in (or sets DPI scaling to >100%), WinLogon.exe (which runs as SYSTEM) will check the signature level of this DLL file, and if it is at least signed at level 6 ("Store"), it will load it, elevating our privileges. DPI scaling is the setting that makes text and icons bigger on high-resolution screens.
As Microsoft completely removed the loading of `*.msstyles_vrf.dll` files from themes for CVE-2023-38146, this issue was also fixed.
## Bypassing WDAC
One place where cached signatures were used for executables is for Windows Defender Application Control (WDAC), which is an allowlisting technology for executables on Windows. Allowlisting means only programs on an approved list are allowed to run; everything else is blocked. This functionality can be used (typically in a corporate environment) to limit which applications a user is allowed to run and which DLLs may be loaded. Binaries can be allowlisted based on file path, file hash but also the identity of the code signer. WDAC policies can be very powerful and granular, so each company using it probably has their own policy, but the default templates allow all software signed by Microsoft itself to run.
Assuming the WDAC policy allows all software signed by Microsoft, we can add an EA indicating Microsoft as the signer to any executable and run it.
## Injecting code into protected processes
The signature bypass can also be used by administrators to inject code into a protected process (regardless of the level). For example, by replacing a DLL from system32 with a symlink to a SMB share and then launching a service that runs as a protected process. system32 is the folder where core Windows files live.
Keep in mind that this is not considered a security boundary by Microsoft, which also means that known techniques that abuse this do not get fixed. So for our demonstration we combined it with the approach used by ANGRYORCHARD to mark our thread as a kernel mode thread and then map the device's physical memory into our process. Mapping physical memory means making the machine's raw memory readable and writable from your own program.
{{media:5}}
## Combining all steps
1. We use the modified EA on a `.msstyles_vrf.dll` file to bypass the signature verification in Winlogon.exe to elevate privileges to `SYSTEM`.
2. We replace a DLL file from `system32` with a symlink to a file with a manipulated cached signature on the SMB share. Then, we launch a protected process running at level `WindowsTCB` (we chose `services.exe`).
3. We use our code running in `services.exe` to inject code into `CSRSS.exe` and apply the technique from ANGRYORCHARD to gain physical memory r/w.
Combined with the Mark-of-the-Web bypass found by carrot_c4k3 for .themepack files, this attack could have been triggered with just the user opening a downloaded file. Mark-of-the-Web is the little marker Windows puts on files downloaded from the internet so it can warn you before opening them. Depending on the WDAC policy, we could also have bypassed that.
## Fix
So, how did Microsoft fix this?
We had hoped they would disable the reading of `$KERNEL.*` extended attributes from SMB completely. However, that was not the approach that was taken. Instead, the instances we exploited were fixed:
1. The fix for CVE-2023-38146 already disabled the loading for `*.msstyles_vrf.dll` files completely, fixing the privilege escalation.
2. When WDAC is enabled, the function to retrieve the cached signature level of a file now always returns an error (even for local files!).
3. When loading a DLL into a protected process, the cached signature level is no longer used. (This was fixed despite Microsoft not considering it a defended security boundary.)
## Timeline
- August 25, 2023: Issue reported to MSRC.
- September 12, 2023: The fix for CVE-2023-38146 was released, breaking our privilege escalation exploit.
- September 20, 2023: MSRC indicates that they have reproduced the issue and that a fix is scheduled for January 2024.
- December 11, 2023: MSRC informs us that a regression was found and asks to reschedule the fix to April 2024.
- April 9, 2024: Fix released for the WDAC and PPL bypass as CVE-2024-20693.
- April 25, 2024: MSRC asks Microsoft Bounty Team for an update, CCing us.
- April 26, 2024: Microsoft Bounty Team sends back a boilerplate reply that the case is under review.
- May 17, 2024: MSRC asks Microsoft Bounty Team for an update, CCing us again.
- May 22, 2024: Microsoft Bounty Team replies that the vulnerability was out of scope for a bounty, claiming it didn't reproduce on the right WIP build.
- May 23, 2024: Informed Microsoft Bounty Team that we believe the exploit did reproduce on the latest WIP build and that the WDAC bypass was not a known isue.
- May 29, 2024: Microsoft Bounty Team had re-evaluted the issue and assigns a bounty.
A bounty is a cash reward Microsoft pays for a valid report.
## Mitigation
This attack depends on the victim connecting to a malicious SMB server. Therefore, blocking outgoing SMB to the internet would make this attack a lot harder (unless the attacker already has a foothold on the local network). Preventing users from mounting new SMB shares could also be done as a mitigation, but could have more unintended results.
Examining SMB traffic for exploitation of this issue should also be possible by looking for responses to the ioctl `0x90390` or responses for the EA `$KERNEL.PURGE.ESBCACHE`.
## Conclusion
We set out to increase our understanding of Windows internals by adapting research into DLL loading into impersonating services using WinSxS, but we got sidetracked into examining the code signing method used for DLL files and we found a way to bypass it. While we were unable to apply it in the scenario we started out with, we did find other places where we could use it to elevate privileges, bypass WDAC and inject code into protected processes. Just like our previous research "Bad things come in large packages: .pkg signature verification bypass on macOS" about a signature bypass for macOS .pkg files, we see here that vulnerabilities in cryptographic operations can often be applied in a multitude of ways, allowing different security measures to be bypassed. Just like that example, this vulnerability could go from a user opening a downloaded file to full system compromise.
---
1. There appears to be a disagreement between Samba and Windows about what a `SMB2_FILE_FULL_EA_INFO` GetInfo request means. Windows issues it to query the value for a specific EA, while Samba responds with all EAs on a file, which confuses Windows. Instead of trying to patch Samba to fix this, we have resolved it by making sure the `$KERNEL.PURGE.ESBCACHE` EA is the *only* EA set on the file.
## Glossary
- **API**: Application Programming Interface, a defined way for one program to ask another program or the operating system to do something.
- **Allowlisting**: a security setting where only approved programs are allowed to run and everything else is blocked.
- **Authenticode**: Microsoft's system for signing Windows program files so their origin and integrity can be checked.
- **Binary**: a compiled program file, as opposed to source code.
- **Bit**: the smallest unit of digital information, a 0 or a 1.
- **Bitwise AND**: an operation that compares two numbers bit by bit and keeps a bit only where both have a 1; `& 1` keeps only the lowest bit.
- **Bounty**: a cash reward paid for a valid security report.
- **Catalogue**: a signed list of file hashes that Windows can check instead of a file's own signature.
- **Certificate**: a digital document that carries a public key and identifies who signed something.
- **Certificate chain**: the list of certificates linking a signer up to a trusted root.
- **CI.DLL**: the Windows library that handles code integrity checks.
- **Code integrity**: the Windows system that decides whether code is allowed to run based on its signature.
- **Code signing**: attaching a cryptographic signature to a program so its origin and integrity can be verified.
- **COM**: Component Object Model, an older Windows mechanism that lets programs call each other's objects.
- **Container state**: a value a volume reports about itself, used here to decide whether a cached signature can be trusted.
- **CVE**: Common Vulnerabilities and Exposures, a public catalogue number for a security flaw.
- **Decompiled code**: machine code turned back into something resembling source code so a human can read it.
- **Device map**: the Windows table that says what each drive letter points at.
- **Directory junction**: a Windows shortcut that redirects one folder to another folder on the same machine.
- **DLL**: Dynamic Link Library, a file full of code that other programs load and run.
- **DPI scaling**: the Windows setting that makes text and icons bigger on high-resolution screens.
- **DRM**: Digital Rights Management, technology that protects things like films and music from being copied.
- **EA**: Extended Attribute, a small named field attached to a file holding extra information.
- **Endpoint**: one numbered entry point on a service that can be called.
- **ext3**: a Linux file system.
- **Function**: a named block of code that does one job and can be called from elsewhere.
- **Hash**: a short fingerprint computed from a file's contents; change one byte and it changes completely.
- **Impersonation**: a service temporarily acting as if it were the low-privileged program that asked it to do something.
- **Integrity level**: a label on a process or file (low, medium, high, system) that Windows uses to decide who may write to what.
- **Inode number**: the internal identifier a file system gives a file.
- **ioctl**: input/output control, a request sent to a device or file system asking it to do something specific and return an answer.
- **Isolation-aware DLL**: a DLL that carries an embedded manifest saying which version of its dependencies to load.
- **Journal**: a log a file system keeps of changes, so it can recover from crashes.
- **Kernel**: the core of the operating system, the part that talks to the hardware and enforces the rules.
- **Kernel mode**: the privileged mode the kernel and drivers run in, with full access to the machine.
- **LoadLibrary**: the Windows function a program calls to load a DLL.
- **Local vulnerability**: a security problem where the attacker already has some access to the machine and tries to gain more.
- **Manifest**: a small text file that says which version of a DLL to use for a particular application.
- **Mark-of-the-Web**: the marker Windows puts on files downloaded from the internet so it can warn you before opening them.
- **Method**: one callable function on a service.
- **Mitigation**: a change that makes an attack harder without removing the underlying feature.
- **MSRC**: Microsoft Security Response Center, the team that receives reports of security bugs.
- **NTFS**: the standard Windows file system.
- **Path traversal**: putting `..` style pieces in a file path so it climbs out of the folder it was supposed to stay in.
- **PE file**: Portable Executable, the standard format for Windows programs and DLLs.
- **PowerShell**: a scripting language built into Windows for automating tasks.
- **PP**: Protected Process, a process Windows protects from being modified by lower-level processes.
- **PPL**: Protected Process Light, a lighter form of protected process with its own rules.
- **Privilege escalation**: gaining rights on a machine that you were not given.
- **Process Monitor**: a free Microsoft tool that records what files, registry keys and other resources a program touches.
- **Race condition**: when two operations happen at nearly the same time and an attacker tries to slip something in between them.
- **RPC**: Remote Procedure Call, a way for one program to ask another program to run a function for it.
- **Samba**: a free implementation of the SMB file-sharing protocol that runs on Linux and other systems.
- **Secure boot**: the firmware feature that checks the boot process has not been tampered with.
- **Security boundary**: a line Microsoft promises attackers cannot cross, so bugs that cross it get fixed as security issues.
- **Service**: a background program that runs without a visible window, usually under a powerful account.
- **setfattr**: a Linux utility that sets an extended attribute on a file.
- **SMB**: Server Message Block, the protocol Windows uses to access files over a network.
- **Symbolic link**: a file that acts as a signpost pointing at another file or folder.
- **SYSTEM**: the most powerful account on a Windows machine, the one the operating system itself runs as.
- **system32**: the folder where core Windows files live.
- **Thread**: one stream of execution inside a program.
- **TLS**: the encryption protocol that protects HTTPS websites.
- **Usermode**: the ordinary world where your programs run, as opposed to kernel mode.
- **Volume**: one storage area with its own file system, such as a disk or a partition.
- **WDAC**: Windows Defender Application Control, an allowlisting technology for executables on Windows.
- **WinSxS**: the part of Windows that keeps several versions of the same DLL installed at once (side-by-side assemblies).
- **WIP build**: a work-in-progress build, an early test version of Windows.
- **Wireshark**: a tool that records network traffic so you can read it.
- **X.509**: the standard format for digital certificates.