Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Ntddk.h>
- #include <wdm.h>
- #include <Kbdmou.h>
- #include <ntstrsafe.h>
- #include "Utils.h"
- #include "SectionScanner.h"
- #include "main.h"
- #include "util.h"
- #include <stdlib.h>
- PEPROCESS MyOwnProcess;
- PEPROCESS Process;
- PEPROCESS MyOwnProcess2;
- PEPROCESS Process2;
- NTSTATUS Status;
- ULONG BytesIO = 0;
- PIO_STACK_LOCATION stack;
- ULONG ControlCode;
- PKERNEL_REQUEST request;
- uint64_t* OutPut;
- SIZE_T File = 0;
- BOOLEAN QWMKMBnBBVXF12();
- uint64_t ClearCacheEntry();
- typedef void(__fastcall *MouseClassServiceCallback)(PDEVICE_OBJECT mou, PMOUSE_INPUT_DATA a1, PMOUSE_INPUT_DATA a2, PULONG a3);
- MouseClassServiceCallback MouseClassServiceCallbackRoutine;
- typedef NTSTATUS(__fastcall* _IoCreateDriver)(PUNICODE_STRING DriverName, PDRIVER_INITIALIZE InitializationFunction);
- _IoCreateDriver IoCreateDriver;
- PDEVICE_OBJECT mouTarget;
- USHORT mouId = 1;
- MOUSE_INPUT_DATA data = { 0 };
- char *eSplCHthSwKd;
- #ifdef ALLOC_PRAGMA
- #pragma alloc_text(PAGE,NewDoMappedCopy)
- #endif
- //
- // The maximum amount to try to Probe and Lock is 14 pages, this
- // way it always fits in a 16 page allocation.
- //
- #define MAX_LOCK_SIZE ((ULONG)(14 * PAGE_SIZE))
- NTSTATUS
- NewDoMappedCopy(
- IN PEPROCESS FromProcess,
- IN CONST VOID *FromAddress,
- IN PEPROCESS ToProcess,
- OUT PVOID ToAddress,
- IN SIZE_T BufferSize,
- IN KPROCESSOR_MODE PreviousMode,
- OUT PSIZE_T NumberOfBytesRead
- )
- {
- KAPC_STATE ApcState;
- SIZE_T AmountToMove;
- ULONG_PTR BadVa;
- LOGICAL Moving;
- LOGICAL Probing;
- CONST VOID *InVa;
- SIZE_T LeftToMove;
- SIZE_T MaximumMoved;
- PMDL pSrcMdl;
- PSIZE_T pSrcMappedAddress;
- LOGICAL LockedSrcMdlPages;
- PMDL pDstMdl;
- PSIZE_T pDstMappedAddress;
- LOGICAL LockedDstMdlPages;
- PVOID OutVa;
- LOGICAL MappingFailed;
- LOGICAL ExceptionAddressConfirmed;
- PAGED_CODE();
- MappingFailed = FALSE;
- InVa = FromAddress;
- OutVa = ToAddress;
- MaximumMoved = MAX_LOCK_SIZE;
- if (BufferSize <= MAX_LOCK_SIZE) {
- MaximumMoved = BufferSize;
- }
- //
- // Map the data into the system part of the address space, then copy it.
- //
- LeftToMove = BufferSize;
- AmountToMove = MaximumMoved;
- Probing = FALSE;
- //
- // Initializing BadVa & ExceptionAddressConfirmed is not needed for
- // correctness but without it the compiler cannot compile this code
- // W4 to check for use of uninitialized variables.
- //
- BadVa = 0;
- ExceptionAddressConfirmed = FALSE;
- while (LeftToMove > 0) {
- if (LeftToMove < AmountToMove) {
- //
- // Set to move the remaining bytes.
- //
- AmountToMove = LeftToMove;
- }
- pSrcMdl = NULL;
- pSrcMappedAddress = NULL;
- LockedSrcMdlPages = FALSE;
- pDstMdl = NULL;
- pDstMappedAddress = NULL;
- LockedDstMdlPages = FALSE;
- Moving = FALSE;
- ASSERT(Probing == FALSE);
- //
- // We may be touching a user's memory which could be invalid,
- // declare an exception handler.
- //
- try {
- //
- // Map sourc address
- //
- KeStackAttachProcess(&FromProcess->Pcb, &ApcState);
- pSrcMdl = IoAllocateMdl((PVOID)InVa, AmountToMove, FALSE, FALSE, NULL);
- MmProbeAndLockPages(pSrcMdl, PreviousMode, IoReadAccess);
- LockedSrcMdlPages = TRUE;
- pSrcMappedAddress = MmGetSystemAddressForMdlSafe(pSrcMdl, HighPagePriority);
- if (pSrcMappedAddress == NULL) {
- MappingFailed = TRUE;
- ExRaiseStatus(STATUS_INSUFFICIENT_RESOURCES);
- }
- KeUnstackDetachProcess(&ApcState);
- //
- // Map destination address
- //
- KeStackAttachProcess(&ToProcess->Pcb, &ApcState);
- pDstMdl = IoAllocateMdl((PVOID)OutVa, AmountToMove, FALSE, FALSE, NULL);
- MmProbeAndLockPages(pDstMdl, PreviousMode, IoReadAccess);
- LockedDstMdlPages = TRUE;
- pDstMappedAddress = MmGetSystemAddressForMdlSafe(pDstMdl, HighPagePriority);
- if (pDstMappedAddress == NULL) {
- MappingFailed = TRUE;
- ExRaiseStatus(STATUS_INSUFFICIENT_RESOURCES);
- }
- MmProtectMdlSystemAddress(pDstMdl, PAGE_READWRITE);
- KeUnstackDetachProcess(&ApcState);
- Moving = TRUE;
- RtlCopyMemory(pSrcMappedAddress, pDstMappedAddress, AmountToMove);
- } except(MiGetExceptionInfo(GetExceptionInformation(),
- &ExceptionAddressConfirmed,
- &BadVa)) {
- if (pDstMappedAddress != NULL) {
- MmUnmapLockedPages(pDstMappedAddress, pDstMdl);
- }
- if (LockedDstMdlPages == TRUE) {
- MmUnlockPages(pDstMdl);
- }
- if (pDstMdl) {
- IoFreeMdl(pDstMdl);
- }
- if (pSrcMappedAddress != NULL) {
- MmUnmapLockedPages(pSrcMappedAddress, pSrcMdl);
- }
- if (LockedSrcMdlPages == TRUE) {
- MmUnlockPages(pSrcMdl);
- }
- if (pSrcMdl) {
- IoFreeMdl(pSrcMdl);
- }
- if (GetExceptionCode() == STATUS_WORKING_SET_QUOTA) {
- return STATUS_WORKING_SET_QUOTA;
- }
- if ((Probing == TRUE) || (MappingFailed == TRUE)) {
- return GetExceptionCode();
- }
- //
- // If the failure occurred during the move operation, determine
- // which move failed, and calculate the number of bytes
- // actually moved.
- //
- *NumberOfBytesRead = BufferSize - LeftToMove;
- if (Moving == TRUE) {
- if (ExceptionAddressConfirmed == TRUE) {
- *NumberOfBytesRead = (SIZE_T)((ULONG_PTR)BadVa - (ULONG_PTR)FromAddress);
- }
- }
- return STATUS_PARTIAL_COPY;
- }
- KeUnstackDetachProcess(&ApcState);
- MmUnmapLockedPages(pDstMappedAddress, pDstMdl);
- MmUnlockPages(pDstMdl);
- IoFreeMdl(pDstMdl);
- MmUnmapLockedPages(pSrcMappedAddress, pSrcMdl);
- MmUnlockPages(pSrcMdl);
- IoFreeMdl(pSrcMdl);
- LeftToMove -= AmountToMove;
- InVa = (PVOID)((ULONG_PTR)InVa + AmountToMove);
- OutVa = (PVOID)((ULONG_PTR)OutVa + AmountToMove);
- }
- //
- // Set number of bytes moved.
- //
- *NumberOfBytesRead = BufferSize;
- return STATUS_SUCCESS;
- }
- UINT64 buJgjAUKqYvU2(PLONG relAddress)
- {
- UINT64 value = (INT64)relAddress + sizeof(LONG) + *relAddress;
- return value;
- }
- NTSTATUS MqolXQXwXhsd3()
- {
- NTSTATUS status = STATUS_UNSUCCESSFUL;
- UCHAR* oUydVxdnNJik5 = (UCHAR*)MmCopyMemory;
- for (int i = 0; i < 0x1000; i++)
- {
- if ((*(UINT64*)oUydVxdnNJik5 == 0x74D2854DC98B4C00))
- {
- PUINT64 MNCGCRdRDhRH4 = (PUINT64)buJgjAUKqYvU2((PLONG)(oUydVxdnNJik5 - 3));
- if (MmIsAddressValid(MNCGCRdRDhRH4))
- {
- *MNCGCRdRDhRH4 = 0;
- status = STATUS_SUCCESS;
- }
- break;
- }
- oUydVxdnNJik5++;
- }
- return status;
- }
- NTSTATUS AxSynZVWvEMM6(PEPROCESS Process_, PVOID SourceAddress, PVOID TargetAddress, SIZE_T Size)
- {
- VIRTUALIZER_TIGER_RED_START
- File = 0;
- NTSTATUS status;
- try {
- if (NT_SUCCESS(MmCopyVirtualMemory(Process_, SourceAddress, MyOwnProcess, TargetAddress, Size, KernelMode, &File)))
- status = STATUS_SUCCESS;
- else
- status = STATUS_ACCESS_DENIED;
- }except(EXCEPTION_EXECUTE_HANDLER) {
- status = STATUS_ACCESS_DENIED;
- }
- VIRTUALIZER_TIGER_RED_END
- return status;
- }
- NTSTATUS KeWriteVirtualMemory(PEPROCESS Process, PVOID SourceAddress, PVOID TargetAddress, SIZE_T Size)
- {
- PSIZE_T Bytes;
- if (NT_SUCCESS(MmCopyVirtualMemory(PsGetCurrentProcess(), SourceAddress, Process,
- TargetAddress, Size, KernelMode, &Bytes)))
- return STATUS_SUCCESS;
- else
- return STATUS_ACCESS_DENIED;
- }
- uint64_t scanCameraPtr(uint64_t address, uint64_t size) {
- for (uint64_t i = address; i < address + size; i = i + (4096 * 3)) {
- unsigned char buf[4096 * 3];
- MmCopyVirtualMemory(Process, i, IoGetCurrentProcess(), &buf[0], 4096 * 3, KernelMode, &File);
- // 41 00 01 1C 02 00 00 00 08 00 01 00 40 00 00 00
- for (uint64_t j = 0; j < (4096 * 3) - 20; j++)
- if (buf[j] == 0x41)
- if (buf[j + 1] == 0)
- if (buf[j + 2] == 0x1)
- if (buf[j + 3] == 0x1C)
- if (buf[j + 4] == 0x2)
- if (buf[j + 5] == 0)
- if (buf[j + 6] == 0)
- if (buf[j + 7] == 0)
- if (buf[j + 8] == 0x8)
- if (buf[j + 9] == 0)
- if (buf[j + 10] == 0x1)
- if (buf[j + 11] == 0)
- if (buf[j + 12] == 0x40)
- if (buf[j + 13] == 0)
- if (buf[j + 14] == 0)
- if (buf[j + 15] == 0)
- return i + j;
- // 41 00 01 1C 02 00 00 00 08 00 01 00 40 00 00 00
- }
- return 0;
- }
- uint64_t scanEntitiesPtr(uint64_t address, uint64_t size) {
- for (uint64_t i = address; i < address + size; i = i + (4096 * 3)) {
- unsigned char buf[4096 * 3];
- MmCopyVirtualMemory(Process, i, IoGetCurrentProcess(), &buf[0], 4096 * 3, KernelMode, &File);
- for (uint64_t j = 0; j < (4096 * 3) - 25; j++)
- if ((buf[j] == 0x0) && (buf[j + 1] == 0x0) && (buf[j + 2] == 0) && (buf[j + 3] == 0) && (buf[j + 6] == 0) && (buf[j + 7] == 0) && (buf[j + 9] == 0) && (buf[j + 10] == 0) &&
- (buf[j + 11] == 0) && (buf[j + 13] == 0) && (buf[j + 14] == 0) && (buf[j + 15] == 0) && (buf[j + 16] == 0) && (buf[j + 17] == 0) && (buf[j + 18] == 0xFF) && (buf[j + 19] == 0xFF) &&
- (buf[j + 20] == 0) && (buf[j + 21] == 0x01) && (buf[j + 22] == 0) && (buf[j + 23] == 0) && (buf[j + 24] == 0x02)) {
- return i + j;
- }
- // 00 00 00 00 ?? ?? 00 00 ?? 00 00 00 ?? 00 00 00 00 00 FF FF 00 01 00 00 02
- }
- return 0;
- }
- PVOID mjxfSYenJqyg7(uint64_t pid) {
- PEPROCESS Process;
- if (NT_SUCCESS(PsLookupProcessByProcessId((HANDLE)pid, &Process))) {
- KeAttachProcess(Process);
- PVOID address = PsGetProcessSectionBaseAddress(Process);
- KeDetachProcess();
- ObDereferenceObject(Process);
- return address;
- }
- else {
- return 0;
- }
- }
- NTSTATUS MySleep(ULONGLONG milliseconds)
- {
- LARGE_INTEGER delay;
- ULONG *split;
- milliseconds *= 1000000;
- milliseconds /= 100;
- milliseconds = -milliseconds;
- split = (ULONG*)&milliseconds;
- delay.LowPart = *split;
- split++;
- delay.HighPart = *split;
- KeDelayExecutionThread(KernelMode, 0, &delay);
- return STATUS_SUCCESS;
- }
- NTSTATUS SleepMicrosec(ULONGLONG microseconds)
- {
- LARGE_INTEGER delay;
- ULONG *split;
- microseconds = -microseconds;
- split = (ULONG*)µseconds;
- delay.LowPart = *split;
- split++;
- delay.HighPart = *split;
- KeDelayExecutionThread(KernelMode, 0, &delay);
- return STATUS_SUCCESS;
- }
- NTSTATUS useMouse(LONG LastX, LONG LastY, USHORT Flags, ULONG Buttons, USHORT ButtonFlags, USHORT ButtonData) {
- NTSTATUS status;
- struct _MOUSE_INPUT_DATA newItem;
- PMOUSE_INPUT_DATA pInputData;
- try {
- pInputData = (PMOUSE_INPUT_DATA)&newItem;
- data.LastX = LastX;
- data.LastY = LastY;
- data.Flags = Flags;
- data.Buttons = Buttons;
- data.ButtonFlags = ButtonFlags;
- data.ButtonData = ButtonData;
- data.ExtraInformation = 0;
- char* endptr;
- endptr = (char*)&data;
- endptr = endptr + sizeof(MOUSE_INPUT_DATA);
- ULONG fill = 1;
- KIRQL irql;
- KeRaiseIrql(DISPATCH_LEVEL, &irql);
- MouseClassServiceCallbackRoutine(mouTarget, &data, (PMOUSE_INPUT_DATA)endptr, &fill);
- KeLowerIrql(irql);
- status = STATUS_SUCCESS;
- } except(EXCEPTION_EXECUTE_HANDLER) {
- status = STATUS_INVALID_PARAMETER;
- }
- return status;
- }
- NTSTATUS InitMouseManipulation() {
- NTSTATUS status;
- UNICODE_STRING nameBuf, numBuf, appendBuf;
- wchar_t mouName[24] = L"\\Device\\PointerClass";
- wchar_t wcNumBuf[3] = L"00";
- InitUtils();
- InitSectionScanner();
- PVOID baseAddr = NULL;
- baseAddr = KernelGetModuleBase("mouclass.sys");
- if (baseAddr == NULL) {
- DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, "InputFaker: DriverEntry: Could not get base address of mouclass.sys.\n");
- return STATUS_FAILED_DRIVER_ENTRY;
- }
- KdPrintEx((DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, "mouclass.sys baseAddr: %08x\n", baseAddr));
- CHAR MouseClassServiceCallbackPattern[] = "\x48\x89\x5C\x24\x10\x48\x89\x74\x24\x18\x48\x89\x7C\x24\x20\x55";
- PVOID offset = NULL;
- ScanSection(baseAddr, ".text", (PCUCHAR)MouseClassServiceCallbackPattern, 0xCC, sizeof(MouseClassServiceCallbackPattern) - 1, &offset);
- if (offset == NULL) {
- DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, "InputFaker: DriverEntry: Could not get MouseClassServiceCallback address.\n");
- return STATUS_FAILED_DRIVER_ENTRY;
- }
- MouseClassServiceCallbackRoutine = (PVOID)((PUCHAR)baseAddr + (ULONG)offset);
- KdPrintEx((DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, "MouseClassServiceCallback: %08x\n", MouseClassServiceCallbackRoutine));
- PFILE_OBJECT file;
- PDEVICE_OBJECT classObj;
- RtlInitUnicodeString(&nameBuf, mouName);
- RtlInitEmptyUnicodeString(&numBuf, wcNumBuf, sizeof(wcNumBuf));
- for (;;) {
- RtlInitEmptyUnicodeString(&appendBuf, mouName, sizeof(mouName));
- RtlIntegerToUnicodeString(mouId, 10, &numBuf);
- RtlUnicodeStringCat(&appendBuf, &nameBuf);
- RtlUnicodeStringCat(&appendBuf, &numBuf);
- status = IoGetDeviceObjectPointer(&appendBuf, SYNCHRONIZE | STANDARD_RIGHTS_ALL, &file, &classObj);
- if (status != STATUS_SUCCESS) {
- if (mouId == 0) {
- DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, "DriverEntry: Could not get PointerClass0-99: %08x\n", status);
- return status;
- }
- mouId++;
- if (mouId > 99) {
- // try 1-99 first, then 0
- mouId = 0;
- }
- }
- else {
- DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, "using %wZ\n", &appendBuf);
- ObDereferenceObject(file);
- break;
- }
- }
- mouTarget = classObj;
- data.UnitId = mouId;
- return STATUS_SUCCESS;
- }
- void manageThread() {
- // este thread nace 1 vez por conexión y por binario. Cuando un exe se ejecuta, se suscribe aqui
- executionNumber++;
- int myExecutionNumber = executionNumber;
- while (executionNumber == myExecutionNumber && executionNumber != 8739227892) {
- VIRTUALIZER_MUTATE_ONLY_START
- // se ejecuta este bucle mientras sea la misma ejecución
- // aqui es donde va la magia
- if (NT_SUCCESS(PsLookupProcessByProcessId(pid, &MyOwnProcess))) {
- PVOID some;
- MyStruct ms;
- pMyStruct structData = &ms;
- MmCopyVirtualMemory(MyOwnProcess, structAddress1, IoGetCurrentProcess(), structData, sizeof(MyStruct), KernelMode, &File);
- if (&structData != NULL) {
- if (!structData->Completed) {
- if (structData->ProtocolMsg == 1) {
- // READ
- if (NT_SUCCESS(PsLookupProcessByProcessId(structData->GamePid, &Process))) {
- Status = AxSynZVWvEMM6(Process, structData->GameAddressOffset, structData->UserBufferAdress, structData->ReadSize);
- BOOLEAN Completed = TRUE;
- Status = MmCopyVirtualMemory(MyOwnProcess, &Completed, MyOwnProcess, structData->pCompleted, sizeof(BOOLEAN), KernelMode, &File);
- ObDereferenceObject(Process);
- }
- }
- else if (structData->ProtocolMsg == 2) {
- // READ (bytes)
- if (NT_SUCCESS(PsLookupProcessByProcessId(structData->GamePid, &Process))) {
- AxSynZVWvEMM6(Process, structData->GameAddressOffset, structData->UserBufferAdressBytes, structData->ReadSize);
- BOOLEAN Completed = TRUE;
- MmCopyVirtualMemory(MyOwnProcess, &Completed, MyOwnProcess, structData->pCompleted, sizeof(BOOLEAN), KernelMode, &File);
- ObDereferenceObject(Process);
- }
- }
- else if (structData->ProtocolMsg == 3) {
- // GET BASE ADDRESS
- uint64_t baseAddress = (uint64_t)mjxfSYenJqyg7(structData->GamePid);
- MmCopyVirtualMemory(MyOwnProcess, &baseAddress, MyOwnProcess, structData->UserBufferAdress, 8, KernelMode, &File);
- BOOLEAN Completed = TRUE;
- MmCopyVirtualMemory(MyOwnProcess, &Completed, MyOwnProcess, structData->pCompleted, sizeof(BOOLEAN), KernelMode, &File);
- }
- else if (structData->ProtocolMsg == 8) {
- // WRITE MEMORY
- if (NT_SUCCESS(PsLookupProcessByProcessId(structData->GamePid, &Process))) {
- PEPROCESS GameProc = Process, pSourceProc = NULL, pTargetProc = NULL;
- PVOID pSource = NULL, pTarget = NULL;
- SIZE_T bytes;
- pSourceProc = MyOwnProcess;
- pTargetProc = GameProc;
- pSource = (PVOID)structData->UserBufferAdress;
- pTarget = (PVOID)structData->GameAddressOffset;
- DbgPrintEx(0, 0, "pSource : %I64X \n", pSource); // pSource : C0421AF0F8 (esta es la address que contiene los datos en MyOwnProcess)
- DbgPrintEx(0, 0, "pTarget : %I64X \n", pTarget); // pTarget : 7FF6150F9200 (esta es la address donde debemos escribir)
- Status = NewDoMappedCopy(pSourceProc, pSource, pTargetProc, pTarget, structData->ReadSize, KernelMode, &bytes);
- DbgPrintEx(0, 0, "Status : %I64X \n", Status);
- BOOLEAN Completed = TRUE;
- MmCopyVirtualMemory(MyOwnProcess, &Completed, MyOwnProcess, structData->pCompleted, sizeof(BOOLEAN), KernelMode, &File);
- ObDereferenceObject(Process);
- }
- }
- else if (structData->ProtocolMsg == 4) {
- // Clear unloaded drivers
- // MqolXQXwXhsd3();
- // QWMKMBnBBVXF12();
- if (!QWMKMBnBBVXF12() && MqolXQXwXhsd3() != STATUS_SUCCESS) {
- // ninguno de los 2 metodos de limpiar drivers ha ido bien
- uint64_t opResult = 545180006;
- MmCopyVirtualMemory(MyOwnProcess, &opResult, MyOwnProcess, structData->UserBufferAdress, 8, KernelMode, &File);
- BOOLEAN Completed = TRUE;
- MmCopyVirtualMemory(MyOwnProcess, &Completed, MyOwnProcess, structData->pCompleted, sizeof(BOOLEAN), KernelMode, &File);
- }
- else {
- // alguno ha ido bien
- uint64_t opResult = ClearCacheEntry();
- MmCopyVirtualMemory(MyOwnProcess, &opResult, MyOwnProcess, structData->UserBufferAdress, 8, KernelMode, &File);
- BOOLEAN Completed = TRUE;
- MmCopyVirtualMemory(MyOwnProcess, &Completed, MyOwnProcess, structData->pCompleted, sizeof(BOOLEAN), KernelMode, &File);
- }
- }
- else if (structData->ProtocolMsg == 11) {
- // scanCameraPtr (bytes)
- if (NT_SUCCESS(PsLookupProcessByProcessId(structData->GamePid, &Process))) {
- uint64_t some = (uint64_t)scanCameraPtr(structData->GameAddressOffset, structData->ReadSize);
- MmCopyVirtualMemory(MyOwnProcess, &some, MyOwnProcess, structData->UserBufferAdress, 8, KernelMode, &File);
- BOOLEAN Completed = TRUE;
- MmCopyVirtualMemory(MyOwnProcess, &Completed, MyOwnProcess, structData->pCompleted, sizeof(BOOLEAN), KernelMode, &File);
- ObDereferenceObject(Process);
- }
- }
- else if (structData->ProtocolMsg == 12) {
- // scanEntitiesPtr (bytes)
- if (NT_SUCCESS(PsLookupProcessByProcessId(structData->GamePid, &Process))) {
- uint64_t some = (uint64_t)scanEntitiesPtr(structData->GameAddressOffset, structData->ReadSize);
- MmCopyVirtualMemory(MyOwnProcess, &some, MyOwnProcess, structData->UserBufferAdress, 8, KernelMode, &File);
- BOOLEAN Completed = TRUE;
- MmCopyVirtualMemory(MyOwnProcess, &Completed, MyOwnProcess, structData->pCompleted, sizeof(BOOLEAN), KernelMode, &File);
- ObDereferenceObject(Process);
- }
- }
- else if (structData->ProtocolMsg == 999) {
- // Unset executionNumber
- executionNumber = 8739227892;
- BOOLEAN Completed = TRUE;
- MmCopyVirtualMemory(MyOwnProcess, &Completed, MyOwnProcess, structData->pCompleted, sizeof(BOOLEAN), KernelMode, &File);
- }
- else if (structData->ProtocolMsg == 101) {
- // go down
- useMouse(0, 1, 0, 0, 0, 0);
- BOOLEAN Completed = TRUE;
- MmCopyVirtualMemory(MyOwnProcess, &Completed, MyOwnProcess, structData->pCompleted, sizeof(BOOLEAN), KernelMode, &File);
- }
- else if (structData->ProtocolMsg == 102) {
- // go up
- useMouse(0, -1, 0, 0, 0, 0);
- BOOLEAN Completed = TRUE;
- MmCopyVirtualMemory(MyOwnProcess, &Completed, MyOwnProcess, structData->pCompleted, sizeof(BOOLEAN), KernelMode, &File);
- }
- else if (structData->ProtocolMsg == 103) {
- // go right
- useMouse(1, 0, 0, 0, 0, 0);
- BOOLEAN Completed = TRUE;
- MmCopyVirtualMemory(MyOwnProcess, &Completed, MyOwnProcess, structData->pCompleted, sizeof(BOOLEAN), KernelMode, &File);
- }
- else if (structData->ProtocolMsg == 104) {
- // go left
- useMouse(-1, 0, 0, 0, 0, 0);
- BOOLEAN Completed = TRUE;
- MmCopyVirtualMemory(MyOwnProcess, &Completed, MyOwnProcess, structData->pCompleted, sizeof(BOOLEAN), KernelMode, &File);
- }
- }
- }
- ObDereferenceObject(MyOwnProcess);
- }
- VIRTUALIZER_MUTATE_ONLY_END
- }
- }
- void funcionDelThread() {
- // int WriteDelay = 5000; /* delay is 500 ms */
- HANDLE InputFile;
- IO_STATUS_BLOCK IoStatusBlock;
- OBJECT_ATTRIBUTES ObjectAttributes;
- UNICODE_STRING ObjectName;
- NTSTATUS Status;
- RtlInitUnicodeString(&ObjectName, L"\\SystemRoot\\outfile22.txt");
- InitializeObjectAttributes(
- &ObjectAttributes,
- &ObjectName,
- OBJ_CASE_INSENSITIVE,
- NULL, NULL
- );
- while (TRUE) {
- Status = ZwOpenFile(
- &InputFile,
- GENERIC_ALL | SYNCHRONIZE,
- &ObjectAttributes,
- &IoStatusBlock,
- FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
- FILE_RANDOM_ACCESS | FILE_SYNCHRONOUS_IO_NONALERT
- );
- if (NT_SUCCESS(Status)) {
- VIRTUALIZER_TIGER_RED_START
- LARGE_INTEGER byteOffset;
- #define BUFFER_SIZE 30
- CHAR buffer[BUFFER_SIZE];
- IO_STATUS_BLOCK ioStatusBlock;
- byteOffset.LowPart = byteOffset.HighPart = 0;
- ZwReadFile(InputFile, NULL, NULL, NULL, &ioStatusBlock,
- buffer, BUFFER_SIZE, &byteOffset, NULL);
- char *p;
- char delim[] = "#";
- p = strtok(buffer, delim); // split by #
- char *pidTmp = p;
- p = strtok(NULL, delim); // split by #
- char *structAddress1Tmp = p;
- p = strtok(NULL, delim); // split by #
- char *structAddress2Tmp = p;
- pid = atoi(pidTmp);
- structAddress1 = _strtoui64(structAddress1Tmp, NULL, 0);
- structAddress2 = _strtoui64(structAddress2Tmp, NULL, 0);
- ZwClose(InputFile);
- HANDLE thread;
- PsCreateSystemThread(&thread, THREAD_ALL_ACCESS, NULL, 0, 0, manageThread, 0);
- ZwDeleteFile(&ObjectAttributes);
- VIRTUALIZER_TIGER_RED_END
- }
- else {
- MySleep(1000);
- }
- }
- }
- NTSTATUS DriverEntry(PDRIVER_OBJECT driverObject, PUNICODE_STRING registryPath) {
- UNREFERENCED_PARAMETER(registryPath);
- UNREFERENCED_PARAMETER(driverObject);
- VIRTUALIZER_TIGER_RED_START
- InitMouseManipulation();
- HANDLE thread;
- PsCreateSystemThread(&thread, THREAD_ALL_ACCESS, NULL, 0, 0, funcionDelThread, 0);
- VIRTUALIZER_TIGER_RED_END
- return STATUS_SUCCESS;
- }
- typedef struct _RTL_PROCESS_MODULE_INFORMATION
- {
- HANDLE Section;
- PVOID MappedBase;
- PVOID ImageBase;
- ULONG ImageSize;
- ULONG Flags;
- USHORT LoadOrderIndex;
- USHORT InitOrderIndex;
- USHORT LoadCount;
- USHORT OffsetToFileName;
- UCHAR FullPathName[256];
- } RTL_PROCESS_MODULE_INFORMATION, *PRTL_PROCESS_MODULE_INFORMATION;
- typedef struct _RTL_PROCESS_MODULES
- {
- ULONG NumberOfModules;
- RTL_PROCESS_MODULE_INFORMATION Modules[1];
- } RTL_PROCESS_MODULES, *PRTL_PROCESS_MODULES;
- typedef unsigned char BYTE;
- BOOLEAN bDataCompare(const BYTE* pData, const BYTE* bMask, const char* szMask)
- {
- for (; *szMask; ++szMask, ++pData, ++bMask)
- if (*szMask == 'x' && *pData != *bMask)
- return 0;
- return (*szMask) == 0;
- }
- UINT64 FindPattern(UINT64 dwAddress, UINT64 dwLen, BYTE *bMask, char * szMask)
- {
- for (UINT64 i = 0; i < dwLen; i++)
- if (bDataCompare((BYTE*)(dwAddress + i), bMask, szMask))
- return (UINT64)(dwAddress + i);
- return 0;
- }
- BOOLEAN QWMKMBnBBVXF12()
- {
- ULONG bytes = 0;
- NTSTATUS status = ZwQuerySystemInformationRoutine(SystemModuleInformation, 0, bytes, &bytes);
- if (!bytes)
- {
- return FALSE;
- }
- PRTL_PROCESS_MODULES modules = (PRTL_PROCESS_MODULES)ExAllocatePoolWithTag(NonPagedPool, bytes, 0x454E4F45); // 'ENON'
- status = ZwQuerySystemInformationRoutine(SystemModuleInformation, modules, bytes, &bytes);
- if (!NT_SUCCESS(status))
- {
- return FALSE;
- }
- PRTL_PROCESS_MODULE_INFORMATION module = modules->Modules;
- UINT64 ntoskrnlBase = 0, ntoskrnlSize = 0;
- for (ULONG i = 0; i < modules->NumberOfModules; i++)
- {
- if (!strcmp((char*)module[i].FullPathName, "\\SystemRoot\\system32\\ntoskrnl.exe"))
- {
- ntoskrnlBase = (UINT64)module[i].ImageBase;
- ntoskrnlSize = (UINT64)module[i].ImageSize;
- break;
- }
- }
- if (modules)
- ExFreePoolWithTag(modules, 0);
- if (ntoskrnlBase <= 0)
- {
- return FALSE;
- }
- // NOTE: 4C 8B ? ? ? ? ? 4C 8B C9 4D 85 ? 74 + 3] + current signature address = MNCGCRdRDhRH4
- UINT64 mmUnloadedDriversPtr = FindPattern((UINT64)ntoskrnlBase, (UINT64)ntoskrnlSize, (BYTE*)"\x4C\x8B\x00\x00\x00\x00\x00\x4C\x8B\xC9\x4D\x85\x00\x74", "xx?????xxxxx?x");
- if (!mmUnloadedDriversPtr)
- {
- return FALSE;
- }
- UINT64 mmUnloadedDrivers = (UINT64)((PUCHAR)mmUnloadedDriversPtr + *(PULONG)((PUCHAR)mmUnloadedDriversPtr + 3) + 7);
- UINT64 bufferPtr = *(UINT64*)mmUnloadedDrivers;
- // NOTE: 0x7D0 is the size of the MNCGCRdRDhRH4 array for win 7 and above
- PVOID newBuffer = ExAllocatePoolWithTag(NonPagedPoolNx, 0x7D0, 0x54446D4D);
- if (!newBuffer)
- return FALSE;
- memset(newBuffer, 0, 0x7D0);
- // NOTE: replace MNCGCRdRDhRH4
- *(UINT64*)mmUnloadedDrivers = (UINT64)newBuffer;
- // NOTE: clean the old buffer
- ExFreePoolWithTag((PVOID)bufferPtr, 0x54446D4D); // 'MmDT'
- return TRUE;
- }
- PVOID ResolveRelativeAddress(
- _In_ PVOID Instruction,
- _In_ ULONG OffsetOffset,
- _In_ ULONG InstructionSize
- )
- {
- ULONG_PTR Instr = (ULONG_PTR)Instruction;
- LONG RipOffset = *(PLONG)(Instr + OffsetOffset);
- PVOID ResolvedAddr = (PVOID)(Instr + InstructionSize + RipOffset);
- return ResolvedAddr;
- }
- EXTERN_C IMAGE_DOS_HEADER __ImageBase;
- uint64_t ClearCacheEntry() {
- ULONG bytes = 0;
- NTSTATUS status = ZwQuerySystemInformationRoutine(SystemModuleInformation, 0, bytes, &bytes);
- if (!bytes)
- {
- return 9990;
- }
- PRTL_PROCESS_MODULES modules = (PRTL_PROCESS_MODULES)ExAllocatePoolWithTag(NonPagedPool, bytes, 0x454E4F45); // 'ENON'
- status = ZwQuerySystemInformationRoutine(SystemModuleInformation, modules, bytes, &bytes);
- if (!NT_SUCCESS(status))
- {
- return 9991;
- }
- PRTL_PROCESS_MODULE_INFORMATION module = modules->Modules;
- UINT64 ntoskrnlBase = 0, ntoskrnlSize = 0;
- if (module == NULL) {
- return 9992;
- }
- for (ULONG i = 0; i < modules->NumberOfModules; i++)
- {
- if (!strcmp((char*)module[i].FullPathName, "\\SystemRoot\\system32\\ntoskrnl.exe"))
- {
- ntoskrnlBase = (UINT64)module[i].ImageBase;
- ntoskrnlSize = (UINT64)module[i].ImageSize;
- break;
- }
- }
- if (modules)
- ExFreePoolWithTag(modules, 0);
- PVOID PiDDBLockPtr = FindPattern((UINT64)ntoskrnlBase, (UINT64)ntoskrnlSize, (UCHAR*)"\x48\x8D\x0D\x00\x00\x00\x00\xE8\x00\x00\x00\x00\x4C\x8B\x8C", "xxx????x????xxx");
- PVOID PiDDBCacheTablePtr = FindPattern((UINT64)ntoskrnlBase, (UINT64)ntoskrnlSize, (UCHAR*)"\x66\x03\xD2\x48\x8D\x0D", "xxxxxx");
- if (PiDDBLockPtr == 0) {
- return 999510;
- }
- if (PiDDBCacheTablePtr == 0) {
- return 999511;
- }
- // DbgPrintEx(0, 0, "BlockPtr: %p CacheTable. %p\n", ResolveRelativeAddress(PiDDBLockPtr, 3, 7), ResolveRelativeAddress(PiDDBCacheTablePtr, 6, 10));
- PERESOURCE PiDDBLock; PRTL_AVL_TABLE PiDDBCacheTable;
- PiDDBLock = ResolveRelativeAddress(PiDDBLockPtr, 3, 7);
- PiDDBCacheTable = ResolveRelativeAddress(PiDDBCacheTablePtr, 6, 10);
- if (&__ImageBase == NULL) {
- return 9996;
- }
- PIMAGE_NT_HEADERS pNtHeaders = MakePtr(PIMAGE_NT_HEADERS, &__ImageBase, __ImageBase.e_lfanew);
- if (pNtHeaders == NULL) {
- return 9997;
- }
- if (&pNtHeaders->FileHeader == NULL) {
- return 999754;
- }
- PiDDBCacheTable->TableContext = (PVOID)1;
- UNICODE_STRING nameBuf;
- RtlInitUnicodeString(&nameBuf, L"ncdrv.sys");
- // build a lookup entry
- PiDDBCacheEntry lookupEntry = { 0 };
- lookupEntry.DriverName = nameBuf;
- // until here all is okay (at least not crashes)
- // acquire the ddb resource lock
- ExAcquireResourceExclusiveLite(PiDDBLock, TRUE);
- // search our entry in the table
- PiDDBCacheEntry* pFoundEntry = (PiDDBCacheEntry*)RtlLookupElementGenericTableAvl(PiDDBCacheTable, &lookupEntry);
- if (pFoundEntry == NULL)
- {
- // release the ddb resource lock
- ExReleaseResourceLite(PiDDBLock);
- return 9998;
- }
- // first, unlink from the list
- RemoveEntryList(&pFoundEntry->List);
- // then delete the element from the avl table
- RtlDeleteElementGenericTableAvl(PiDDBCacheTable, pFoundEntry);
- // release the ddb resource lock
- ExReleaseResourceLite(PiDDBLock);
- return 9999;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement