Advertisement
Guest User

Untitled

a guest
Aug 29th, 2019
587
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 28.88 KB | None | 0 0
  1. #include <Ntddk.h>
  2. #include <wdm.h>
  3. #include <Kbdmou.h>
  4. #include <ntstrsafe.h>
  5. #include "Utils.h"
  6. #include "SectionScanner.h"
  7. #include "main.h"
  8. #include "util.h"
  9. #include <stdlib.h>
  10.  
  11. PEPROCESS MyOwnProcess;
  12. PEPROCESS Process;
  13. PEPROCESS MyOwnProcess2;
  14. PEPROCESS Process2;
  15. NTSTATUS Status;
  16. ULONG BytesIO = 0;
  17. PIO_STACK_LOCATION stack;
  18. ULONG ControlCode;
  19. PKERNEL_REQUEST request;
  20. uint64_t* OutPut;
  21. SIZE_T File = 0;
  22.  
  23. BOOLEAN QWMKMBnBBVXF12();
  24. uint64_t ClearCacheEntry();
  25.  
  26. typedef void(__fastcall *MouseClassServiceCallback)(PDEVICE_OBJECT mou, PMOUSE_INPUT_DATA a1, PMOUSE_INPUT_DATA a2, PULONG a3);
  27. MouseClassServiceCallback MouseClassServiceCallbackRoutine;
  28.  
  29.  
  30. typedef NTSTATUS(__fastcall* _IoCreateDriver)(PUNICODE_STRING DriverName, PDRIVER_INITIALIZE InitializationFunction);
  31. _IoCreateDriver IoCreateDriver;
  32.  
  33. PDEVICE_OBJECT mouTarget;
  34. USHORT mouId = 1;
  35. MOUSE_INPUT_DATA data = { 0 };
  36.  
  37. char *eSplCHthSwKd;
  38.  
  39. #ifdef ALLOC_PRAGMA
  40. #pragma alloc_text(PAGE,NewDoMappedCopy)
  41. #endif
  42.  
  43. //
  44. // The maximum amount to try to Probe and Lock is 14 pages, this
  45. // way it always fits in a 16 page allocation.
  46. //
  47.  
  48. #define MAX_LOCK_SIZE ((ULONG)(14 * PAGE_SIZE))
  49.  
  50. NTSTATUS
  51. NewDoMappedCopy(
  52.     IN PEPROCESS FromProcess,
  53.     IN CONST VOID *FromAddress,
  54.     IN PEPROCESS ToProcess,
  55.     OUT PVOID ToAddress,
  56.     IN SIZE_T BufferSize,
  57.     IN KPROCESSOR_MODE PreviousMode,
  58.     OUT PSIZE_T NumberOfBytesRead
  59. )
  60. {
  61.     KAPC_STATE ApcState;
  62.     SIZE_T AmountToMove;
  63.     ULONG_PTR BadVa;
  64.     LOGICAL Moving;
  65.     LOGICAL Probing;
  66.     CONST VOID *InVa;
  67.     SIZE_T LeftToMove;
  68.     SIZE_T MaximumMoved;
  69.  
  70.     PMDL pSrcMdl;
  71.     PSIZE_T pSrcMappedAddress;
  72.     LOGICAL LockedSrcMdlPages;
  73.  
  74.     PMDL pDstMdl;
  75.     PSIZE_T pDstMappedAddress;
  76.     LOGICAL LockedDstMdlPages;
  77.  
  78.     PVOID OutVa;
  79.     LOGICAL MappingFailed;
  80.     LOGICAL ExceptionAddressConfirmed;
  81.  
  82.     PAGED_CODE();
  83.  
  84.     MappingFailed = FALSE;
  85.  
  86.     InVa = FromAddress;
  87.     OutVa = ToAddress;
  88.  
  89.     MaximumMoved = MAX_LOCK_SIZE;
  90.     if (BufferSize <= MAX_LOCK_SIZE) {
  91.         MaximumMoved = BufferSize;
  92.     }
  93.  
  94.     //
  95.     // Map the data into the system part of the address space, then copy it.
  96.     //
  97.  
  98.     LeftToMove = BufferSize;
  99.     AmountToMove = MaximumMoved;
  100.  
  101.     Probing = FALSE;
  102.  
  103.     //
  104.     // Initializing BadVa & ExceptionAddressConfirmed is not needed for
  105.     // correctness but without it the compiler cannot compile this code
  106.     // W4 to check for use of uninitialized variables.
  107.     //
  108.  
  109.     BadVa = 0;
  110.     ExceptionAddressConfirmed = FALSE;
  111.  
  112.     while (LeftToMove > 0) {
  113.  
  114.         if (LeftToMove < AmountToMove) {
  115.  
  116.             //
  117.             // Set to move the remaining bytes.
  118.             //
  119.  
  120.             AmountToMove = LeftToMove;
  121.         }
  122.  
  123.         pSrcMdl = NULL;
  124.         pSrcMappedAddress = NULL;
  125.         LockedSrcMdlPages = FALSE;
  126.  
  127.         pDstMdl = NULL;
  128.         pDstMappedAddress = NULL;
  129.         LockedDstMdlPages = FALSE;
  130.  
  131.         Moving = FALSE;
  132.         ASSERT(Probing == FALSE);
  133.  
  134.         //
  135.         // We may be touching a user's memory which could be invalid,
  136.         // declare an exception handler.
  137.         //
  138.  
  139.         try {
  140.  
  141.             //
  142.             // Map sourc address
  143.             //
  144.  
  145.             KeStackAttachProcess(&FromProcess->Pcb, &ApcState);
  146.  
  147.             pSrcMdl = IoAllocateMdl((PVOID)InVa, AmountToMove, FALSE, FALSE, NULL);
  148.  
  149.             MmProbeAndLockPages(pSrcMdl, PreviousMode, IoReadAccess);
  150.  
  151.             LockedSrcMdlPages = TRUE;
  152.  
  153.             pSrcMappedAddress = MmGetSystemAddressForMdlSafe(pSrcMdl, HighPagePriority);
  154.  
  155.             if (pSrcMappedAddress == NULL) {
  156.                 MappingFailed = TRUE;
  157.                 ExRaiseStatus(STATUS_INSUFFICIENT_RESOURCES);
  158.             }
  159.  
  160.             KeUnstackDetachProcess(&ApcState);
  161.  
  162.             //
  163.             // Map destination address
  164.             //
  165.  
  166.             KeStackAttachProcess(&ToProcess->Pcb, &ApcState);
  167.  
  168.             pDstMdl = IoAllocateMdl((PVOID)OutVa, AmountToMove, FALSE, FALSE, NULL);
  169.  
  170.             MmProbeAndLockPages(pDstMdl, PreviousMode, IoReadAccess);
  171.  
  172.             LockedDstMdlPages = TRUE;
  173.  
  174.             pDstMappedAddress = MmGetSystemAddressForMdlSafe(pDstMdl, HighPagePriority);
  175.  
  176.             if (pDstMappedAddress == NULL) {
  177.                 MappingFailed = TRUE;
  178.                 ExRaiseStatus(STATUS_INSUFFICIENT_RESOURCES);
  179.             }
  180.  
  181.             MmProtectMdlSystemAddress(pDstMdl, PAGE_READWRITE);
  182.  
  183.             KeUnstackDetachProcess(&ApcState);
  184.  
  185.             Moving = TRUE;
  186.             RtlCopyMemory(pSrcMappedAddress, pDstMappedAddress, AmountToMove);
  187.  
  188.         } except(MiGetExceptionInfo(GetExceptionInformation(),
  189.             &ExceptionAddressConfirmed,
  190.             &BadVa)) {
  191.  
  192.             if (pDstMappedAddress != NULL) {
  193.                 MmUnmapLockedPages(pDstMappedAddress, pDstMdl);
  194.             }
  195.             if (LockedDstMdlPages == TRUE) {
  196.                 MmUnlockPages(pDstMdl);
  197.             }
  198.             if (pDstMdl) {
  199.                 IoFreeMdl(pDstMdl);
  200.             }
  201.  
  202.             if (pSrcMappedAddress != NULL) {
  203.                 MmUnmapLockedPages(pSrcMappedAddress, pSrcMdl);
  204.             }
  205.             if (LockedSrcMdlPages == TRUE) {
  206.                 MmUnlockPages(pSrcMdl);
  207.             }
  208.             if (pSrcMdl) {
  209.                 IoFreeMdl(pSrcMdl);
  210.             }
  211.  
  212.             if (GetExceptionCode() == STATUS_WORKING_SET_QUOTA) {
  213.                 return STATUS_WORKING_SET_QUOTA;
  214.             }
  215.  
  216.             if ((Probing == TRUE) || (MappingFailed == TRUE)) {
  217.                 return GetExceptionCode();
  218.  
  219.             }
  220.  
  221.             //
  222.             // If the failure occurred during the move operation, determine
  223.             // which move failed, and calculate the number of bytes
  224.             // actually moved.
  225.             //
  226.  
  227.             *NumberOfBytesRead = BufferSize - LeftToMove;
  228.  
  229.             if (Moving == TRUE) {
  230.                 if (ExceptionAddressConfirmed == TRUE) {
  231.                     *NumberOfBytesRead = (SIZE_T)((ULONG_PTR)BadVa - (ULONG_PTR)FromAddress);
  232.                 }
  233.             }
  234.  
  235.             return STATUS_PARTIAL_COPY;
  236.         }
  237.  
  238.         KeUnstackDetachProcess(&ApcState);
  239.  
  240.         MmUnmapLockedPages(pDstMappedAddress, pDstMdl);
  241.         MmUnlockPages(pDstMdl);
  242.         IoFreeMdl(pDstMdl);
  243.  
  244.         MmUnmapLockedPages(pSrcMappedAddress, pSrcMdl);
  245.         MmUnlockPages(pSrcMdl);
  246.         IoFreeMdl(pSrcMdl);
  247.  
  248.         LeftToMove -= AmountToMove;
  249.         InVa = (PVOID)((ULONG_PTR)InVa + AmountToMove);
  250.         OutVa = (PVOID)((ULONG_PTR)OutVa + AmountToMove);
  251.     }
  252.  
  253.     //
  254.     // Set number of bytes moved.
  255.     //
  256.  
  257.     *NumberOfBytesRead = BufferSize;
  258.     return STATUS_SUCCESS;
  259. }
  260.  
  261.  
  262. UINT64 buJgjAUKqYvU2(PLONG relAddress)
  263. {
  264.     UINT64 value = (INT64)relAddress + sizeof(LONG) + *relAddress;
  265.     return value;
  266. }
  267.  
  268. NTSTATUS MqolXQXwXhsd3()
  269. {
  270.     NTSTATUS status = STATUS_UNSUCCESSFUL;
  271.     UCHAR* oUydVxdnNJik5 = (UCHAR*)MmCopyMemory;
  272.     for (int i = 0; i < 0x1000; i++)
  273.     {
  274.         if ((*(UINT64*)oUydVxdnNJik5 == 0x74D2854DC98B4C00))
  275.         {
  276.             PUINT64 MNCGCRdRDhRH4 = (PUINT64)buJgjAUKqYvU2((PLONG)(oUydVxdnNJik5 - 3));
  277.             if (MmIsAddressValid(MNCGCRdRDhRH4))
  278.             {
  279.                 *MNCGCRdRDhRH4 = 0;
  280.                 status = STATUS_SUCCESS;
  281.             }
  282.             break;
  283.         }
  284.         oUydVxdnNJik5++;
  285.     }
  286.     return status;
  287. }
  288.  
  289. NTSTATUS AxSynZVWvEMM6(PEPROCESS Process_, PVOID SourceAddress, PVOID TargetAddress, SIZE_T Size)
  290. {
  291.     VIRTUALIZER_TIGER_RED_START
  292.     File = 0;
  293.     NTSTATUS status;
  294.     try {
  295.         if (NT_SUCCESS(MmCopyVirtualMemory(Process_, SourceAddress, MyOwnProcess, TargetAddress, Size, KernelMode, &File)))
  296.             status = STATUS_SUCCESS;
  297.         else
  298.             status = STATUS_ACCESS_DENIED;
  299.     }except(EXCEPTION_EXECUTE_HANDLER) {
  300.         status = STATUS_ACCESS_DENIED;
  301.     }
  302.     VIRTUALIZER_TIGER_RED_END
  303.     return status;
  304. }
  305.  
  306. NTSTATUS KeWriteVirtualMemory(PEPROCESS Process, PVOID SourceAddress, PVOID TargetAddress, SIZE_T Size)
  307. {
  308.     PSIZE_T Bytes;
  309.     if (NT_SUCCESS(MmCopyVirtualMemory(PsGetCurrentProcess(), SourceAddress, Process,
  310.         TargetAddress, Size, KernelMode, &Bytes)))
  311.         return STATUS_SUCCESS;
  312.     else
  313.         return STATUS_ACCESS_DENIED;
  314. }
  315.  
  316. uint64_t scanCameraPtr(uint64_t address, uint64_t size) {
  317.     for (uint64_t i = address; i < address + size; i = i + (4096 * 3)) {
  318.         unsigned char buf[4096 * 3];
  319.         MmCopyVirtualMemory(Process, i, IoGetCurrentProcess(), &buf[0], 4096 * 3, KernelMode, &File);
  320.         // 41 00 01 1C 02 00 00 00 08 00 01 00 40 00 00 00
  321.         for (uint64_t j = 0; j < (4096 * 3) - 20; j++)
  322.             if (buf[j] == 0x41)
  323.                 if (buf[j + 1] == 0)
  324.                     if (buf[j + 2] == 0x1)
  325.                         if (buf[j + 3] == 0x1C)
  326.                             if (buf[j + 4] == 0x2)
  327.                                 if (buf[j + 5] == 0)
  328.                                     if (buf[j + 6] == 0)
  329.                                         if (buf[j + 7] == 0)
  330.                                             if (buf[j + 8] == 0x8)
  331.                                                 if (buf[j + 9] == 0)
  332.                                                     if (buf[j + 10] == 0x1)
  333.                                                         if (buf[j + 11] == 0)
  334.                                                             if (buf[j + 12] == 0x40)
  335.                                                                 if (buf[j + 13] == 0)
  336.                                                                     if (buf[j + 14] == 0)
  337.                                                                         if (buf[j + 15] == 0)
  338.                                                                             return i + j;
  339.  
  340.                 //  41 00 01 1C 02 00 00 00 08 00 01 00 40 00 00 00
  341.  
  342.  
  343.     }
  344.     return 0;
  345. }
  346.  
  347. uint64_t scanEntitiesPtr(uint64_t address, uint64_t size) {
  348.     for (uint64_t i = address; i < address + size; i = i + (4096 * 3)) {
  349.         unsigned char buf[4096 * 3];
  350.         MmCopyVirtualMemory(Process, i, IoGetCurrentProcess(), &buf[0], 4096 * 3, KernelMode, &File);
  351.         for (uint64_t j = 0; j < (4096 * 3) - 25; j++)
  352.             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) &&
  353.              (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) &&
  354.               (buf[j + 20] == 0) && (buf[j + 21] == 0x01) && (buf[j + 22] == 0) && (buf[j + 23] == 0) && (buf[j + 24] == 0x02)) {
  355.                         return i + j;
  356.                     }
  357.  
  358.             // 00 00 00 00 ?? ?? 00 00 ?? 00 00 00 ?? 00 00 00 00 00 FF FF 00 01 00 00 02
  359.     }
  360.     return 0;
  361. }
  362.  
  363. PVOID mjxfSYenJqyg7(uint64_t pid) {
  364.     PEPROCESS Process;
  365.     if (NT_SUCCESS(PsLookupProcessByProcessId((HANDLE)pid, &Process))) {
  366.         KeAttachProcess(Process);
  367.         PVOID address = PsGetProcessSectionBaseAddress(Process);
  368.         KeDetachProcess();
  369.         ObDereferenceObject(Process);
  370.         return address;
  371.     }
  372.     else {
  373.         return 0;
  374.     }
  375. }
  376.  
  377. NTSTATUS MySleep(ULONGLONG milliseconds)
  378. {
  379.     LARGE_INTEGER delay;
  380.     ULONG *split;
  381.  
  382.     milliseconds *= 1000000;
  383.  
  384.     milliseconds /= 100;
  385.     milliseconds = -milliseconds;
  386.  
  387.     split = (ULONG*)&milliseconds;
  388.  
  389.     delay.LowPart = *split;
  390.  
  391.     split++;
  392.     delay.HighPart = *split;
  393.  
  394.     KeDelayExecutionThread(KernelMode, 0, &delay);
  395.  
  396.     return STATUS_SUCCESS;
  397. }
  398.  
  399. NTSTATUS SleepMicrosec(ULONGLONG microseconds)
  400. {
  401.     LARGE_INTEGER delay;
  402.     ULONG *split;
  403.  
  404.     microseconds = -microseconds;
  405.  
  406.     split = (ULONG*)&microseconds;
  407.  
  408.     delay.LowPart = *split;
  409.  
  410.     split++;
  411.     delay.HighPart = *split;
  412.  
  413.     KeDelayExecutionThread(KernelMode, 0, &delay);
  414.  
  415.     return STATUS_SUCCESS;
  416. }
  417.  
  418. NTSTATUS useMouse(LONG LastX, LONG LastY, USHORT Flags, ULONG Buttons, USHORT ButtonFlags, USHORT ButtonData) {
  419.     NTSTATUS status;
  420.  
  421.     struct _MOUSE_INPUT_DATA newItem;
  422.     PMOUSE_INPUT_DATA pInputData;
  423.     try {
  424.         pInputData = (PMOUSE_INPUT_DATA)&newItem;
  425.  
  426.         data.LastX = LastX;
  427.         data.LastY = LastY;
  428.         data.Flags = Flags;
  429.         data.Buttons = Buttons;
  430.         data.ButtonFlags = ButtonFlags;
  431.         data.ButtonData = ButtonData;
  432.         data.ExtraInformation = 0;
  433.  
  434.         char* endptr;
  435.         endptr = (char*)&data;
  436.         endptr = endptr + sizeof(MOUSE_INPUT_DATA);
  437.  
  438.         ULONG fill = 1;
  439.         KIRQL irql;
  440.         KeRaiseIrql(DISPATCH_LEVEL, &irql);
  441.         MouseClassServiceCallbackRoutine(mouTarget, &data, (PMOUSE_INPUT_DATA)endptr, &fill);
  442.         KeLowerIrql(irql);
  443.  
  444.         status = STATUS_SUCCESS;
  445.  
  446.     } except(EXCEPTION_EXECUTE_HANDLER) {
  447.         status = STATUS_INVALID_PARAMETER;
  448.     }
  449.  
  450.     return status;
  451. }
  452.  
  453. NTSTATUS InitMouseManipulation() {
  454.     NTSTATUS status;
  455.     UNICODE_STRING nameBuf, numBuf, appendBuf;
  456.     wchar_t mouName[24] = L"\\Device\\PointerClass";
  457.     wchar_t wcNumBuf[3] = L"00";
  458.  
  459.     InitUtils();
  460.     InitSectionScanner();
  461.  
  462.     PVOID baseAddr = NULL;
  463.     baseAddr = KernelGetModuleBase("mouclass.sys");
  464.     if (baseAddr == NULL) {
  465.         DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, "InputFaker: DriverEntry: Could not get base address of mouclass.sys.\n");
  466.         return STATUS_FAILED_DRIVER_ENTRY;
  467.     }
  468.     KdPrintEx((DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, "mouclass.sys baseAddr: %08x\n", baseAddr));
  469.  
  470.     CHAR MouseClassServiceCallbackPattern[] = "\x48\x89\x5C\x24\x10\x48\x89\x74\x24\x18\x48\x89\x7C\x24\x20\x55";
  471.     PVOID offset = NULL;
  472.     ScanSection(baseAddr, ".text", (PCUCHAR)MouseClassServiceCallbackPattern, 0xCC, sizeof(MouseClassServiceCallbackPattern) - 1, &offset);
  473.     if (offset == NULL) {
  474.         DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, "InputFaker: DriverEntry: Could not get MouseClassServiceCallback address.\n");
  475.         return STATUS_FAILED_DRIVER_ENTRY;
  476.     }
  477.  
  478.     MouseClassServiceCallbackRoutine = (PVOID)((PUCHAR)baseAddr + (ULONG)offset);
  479.     KdPrintEx((DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, "MouseClassServiceCallback: %08x\n", MouseClassServiceCallbackRoutine));
  480.  
  481.  
  482.     PFILE_OBJECT file;
  483.     PDEVICE_OBJECT classObj;
  484.     RtlInitUnicodeString(&nameBuf, mouName);
  485.     RtlInitEmptyUnicodeString(&numBuf, wcNumBuf, sizeof(wcNumBuf));
  486.  
  487.     for (;;) {
  488.         RtlInitEmptyUnicodeString(&appendBuf, mouName, sizeof(mouName));
  489.         RtlIntegerToUnicodeString(mouId, 10, &numBuf);
  490.         RtlUnicodeStringCat(&appendBuf, &nameBuf);
  491.         RtlUnicodeStringCat(&appendBuf, &numBuf);
  492.         status = IoGetDeviceObjectPointer(&appendBuf, SYNCHRONIZE | STANDARD_RIGHTS_ALL, &file, &classObj);
  493.         if (status != STATUS_SUCCESS) {
  494.             if (mouId == 0) {
  495.                 DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, "DriverEntry: Could not get PointerClass0-99: %08x\n", status);
  496.                 return status;
  497.             }
  498.             mouId++;
  499.             if (mouId > 99) {
  500.                 // try 1-99 first, then 0
  501.                 mouId = 0;
  502.             }
  503.         }
  504.         else {
  505.             DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, "using %wZ\n", &appendBuf);
  506.             ObDereferenceObject(file);
  507.             break;
  508.         }
  509.     }
  510.  
  511.     mouTarget = classObj;
  512.  
  513.     data.UnitId = mouId;
  514.  
  515.     return STATUS_SUCCESS;
  516. }
  517.  
  518. void manageThread() {
  519.  
  520.     // este thread nace 1 vez por conexión y por binario. Cuando un exe se ejecuta, se suscribe aqui
  521.     executionNumber++;
  522.     int myExecutionNumber = executionNumber;
  523.     while (executionNumber == myExecutionNumber && executionNumber != 8739227892) {
  524.             VIRTUALIZER_MUTATE_ONLY_START
  525.             // se ejecuta este bucle mientras sea la misma ejecución
  526.             // aqui es donde va la magia
  527.             if (NT_SUCCESS(PsLookupProcessByProcessId(pid, &MyOwnProcess))) {
  528.                 PVOID some;
  529.                 MyStruct ms;
  530.                 pMyStruct structData = &ms;
  531.                 MmCopyVirtualMemory(MyOwnProcess, structAddress1, IoGetCurrentProcess(), structData, sizeof(MyStruct), KernelMode, &File);
  532.  
  533.                 if (&structData != NULL) {
  534.                     if (!structData->Completed) {
  535.                         if (structData->ProtocolMsg == 1) {
  536.                             // READ
  537.                             if (NT_SUCCESS(PsLookupProcessByProcessId(structData->GamePid, &Process))) {
  538.                                 Status = AxSynZVWvEMM6(Process, structData->GameAddressOffset, structData->UserBufferAdress, structData->ReadSize);
  539.                                 BOOLEAN Completed = TRUE;
  540.                                 Status = MmCopyVirtualMemory(MyOwnProcess, &Completed, MyOwnProcess, structData->pCompleted, sizeof(BOOLEAN), KernelMode, &File);
  541.                                 ObDereferenceObject(Process);
  542.                             }
  543.                         }
  544.                         else if (structData->ProtocolMsg == 2) {
  545.                             // READ (bytes)
  546.                             if (NT_SUCCESS(PsLookupProcessByProcessId(structData->GamePid, &Process))) {
  547.                                 AxSynZVWvEMM6(Process, structData->GameAddressOffset, structData->UserBufferAdressBytes, structData->ReadSize);
  548.                                 BOOLEAN Completed = TRUE;
  549.                                 MmCopyVirtualMemory(MyOwnProcess, &Completed, MyOwnProcess, structData->pCompleted, sizeof(BOOLEAN), KernelMode, &File);
  550.                                 ObDereferenceObject(Process);
  551.                             }
  552.                         }
  553.                         else if (structData->ProtocolMsg == 3) {
  554.                             // GET BASE ADDRESS
  555.                             uint64_t baseAddress = (uint64_t)mjxfSYenJqyg7(structData->GamePid);
  556.                             MmCopyVirtualMemory(MyOwnProcess, &baseAddress, MyOwnProcess, structData->UserBufferAdress, 8, KernelMode, &File);
  557.                             BOOLEAN Completed = TRUE;
  558.                             MmCopyVirtualMemory(MyOwnProcess, &Completed, MyOwnProcess, structData->pCompleted, sizeof(BOOLEAN), KernelMode, &File);
  559.                         }
  560.                         else if (structData->ProtocolMsg == 8) {
  561.                             // WRITE MEMORY
  562.                             if (NT_SUCCESS(PsLookupProcessByProcessId(structData->GamePid, &Process))) {
  563.                                 PEPROCESS    GameProc = Process, pSourceProc = NULL, pTargetProc = NULL;
  564.                                 PVOID pSource = NULL, pTarget = NULL;
  565.                                 SIZE_T bytes;
  566.  
  567.                                 pSourceProc = MyOwnProcess;
  568.                                 pTargetProc = GameProc;
  569.                                 pSource = (PVOID)structData->UserBufferAdress;
  570.                                 pTarget = (PVOID)structData->GameAddressOffset;
  571.  
  572.                                 DbgPrintEx(0, 0, "pSource : %I64X \n", pSource); // pSource : C0421AF0F8   (esta es la address que contiene los datos en MyOwnProcess)
  573.                                 DbgPrintEx(0, 0, "pTarget : %I64X \n", pTarget); // pTarget : 7FF6150F9200    (esta es la address donde debemos escribir)
  574.                                
  575.                                 Status = NewDoMappedCopy(pSourceProc, pSource, pTargetProc, pTarget, structData->ReadSize, KernelMode, &bytes);
  576.                                 DbgPrintEx(0, 0, "Status : %I64X \n", Status);
  577.  
  578.                                 BOOLEAN Completed = TRUE;
  579.                                 MmCopyVirtualMemory(MyOwnProcess, &Completed, MyOwnProcess, structData->pCompleted, sizeof(BOOLEAN), KernelMode, &File);
  580.                                 ObDereferenceObject(Process);
  581.                             }
  582.                         }
  583.                         else if (structData->ProtocolMsg == 4) {
  584.                             // Clear unloaded drivers
  585.                             // MqolXQXwXhsd3();
  586.                             // QWMKMBnBBVXF12();
  587.  
  588.                             if (!QWMKMBnBBVXF12() && MqolXQXwXhsd3() != STATUS_SUCCESS) {
  589.                                 // ninguno de los 2 metodos de limpiar drivers ha ido bien
  590.                                 uint64_t opResult = 545180006;
  591.                                 MmCopyVirtualMemory(MyOwnProcess, &opResult, MyOwnProcess, structData->UserBufferAdress, 8, KernelMode, &File);
  592.                                 BOOLEAN Completed = TRUE;
  593.                                 MmCopyVirtualMemory(MyOwnProcess, &Completed, MyOwnProcess, structData->pCompleted, sizeof(BOOLEAN), KernelMode, &File);
  594.                             }
  595.                             else {
  596.                                 // alguno ha ido bien
  597.                                 uint64_t opResult = ClearCacheEntry();
  598.                                 MmCopyVirtualMemory(MyOwnProcess, &opResult, MyOwnProcess, structData->UserBufferAdress, 8, KernelMode, &File);
  599.                                 BOOLEAN Completed = TRUE;
  600.                                 MmCopyVirtualMemory(MyOwnProcess, &Completed, MyOwnProcess, structData->pCompleted, sizeof(BOOLEAN), KernelMode, &File);
  601.                             }
  602.                         }
  603.                         else if (structData->ProtocolMsg == 11) {
  604.                             // scanCameraPtr (bytes)
  605.                             if (NT_SUCCESS(PsLookupProcessByProcessId(structData->GamePid, &Process))) {
  606.                                 uint64_t some = (uint64_t)scanCameraPtr(structData->GameAddressOffset, structData->ReadSize);
  607.                                 MmCopyVirtualMemory(MyOwnProcess, &some, MyOwnProcess, structData->UserBufferAdress, 8, KernelMode, &File);
  608.                                 BOOLEAN Completed = TRUE;
  609.                                 MmCopyVirtualMemory(MyOwnProcess, &Completed, MyOwnProcess, structData->pCompleted, sizeof(BOOLEAN), KernelMode, &File);
  610.                                 ObDereferenceObject(Process);
  611.                             }
  612.                         }
  613.                         else if (structData->ProtocolMsg == 12) {
  614.                             // scanEntitiesPtr (bytes)
  615.                             if (NT_SUCCESS(PsLookupProcessByProcessId(structData->GamePid, &Process))) {
  616.                                 uint64_t some = (uint64_t)scanEntitiesPtr(structData->GameAddressOffset, structData->ReadSize);
  617.                                 MmCopyVirtualMemory(MyOwnProcess, &some, MyOwnProcess, structData->UserBufferAdress, 8, KernelMode, &File);
  618.                                 BOOLEAN Completed = TRUE;
  619.                                 MmCopyVirtualMemory(MyOwnProcess, &Completed, MyOwnProcess, structData->pCompleted, sizeof(BOOLEAN), KernelMode, &File);
  620.                                 ObDereferenceObject(Process);
  621.                             }
  622.                         }
  623.                         else if (structData->ProtocolMsg == 999) {
  624.                             // Unset executionNumber
  625.                             executionNumber = 8739227892;
  626.                             BOOLEAN Completed = TRUE;
  627.                             MmCopyVirtualMemory(MyOwnProcess, &Completed, MyOwnProcess, structData->pCompleted, sizeof(BOOLEAN), KernelMode, &File);
  628.                         }
  629.                         else if (structData->ProtocolMsg == 101) {
  630.                             // go down
  631.                             useMouse(0, 1, 0, 0, 0, 0);
  632.                             BOOLEAN Completed = TRUE;
  633.                             MmCopyVirtualMemory(MyOwnProcess, &Completed, MyOwnProcess, structData->pCompleted, sizeof(BOOLEAN), KernelMode, &File);
  634.                         }
  635.                         else if (structData->ProtocolMsg == 102) {
  636.                             // go up
  637.                             useMouse(0, -1, 0, 0, 0, 0);
  638.                             BOOLEAN Completed = TRUE;
  639.                             MmCopyVirtualMemory(MyOwnProcess, &Completed, MyOwnProcess, structData->pCompleted, sizeof(BOOLEAN), KernelMode, &File);
  640.                         }
  641.                         else if (structData->ProtocolMsg == 103) {
  642.                             // go right
  643.                             useMouse(1, 0, 0, 0, 0, 0);
  644.                             BOOLEAN Completed = TRUE;
  645.                             MmCopyVirtualMemory(MyOwnProcess, &Completed, MyOwnProcess, structData->pCompleted, sizeof(BOOLEAN), KernelMode, &File);
  646.                         }
  647.                         else if (structData->ProtocolMsg == 104) {
  648.                             // go left
  649.                             useMouse(-1, 0, 0, 0, 0, 0);
  650.                             BOOLEAN Completed = TRUE;
  651.                             MmCopyVirtualMemory(MyOwnProcess, &Completed, MyOwnProcess, structData->pCompleted, sizeof(BOOLEAN), KernelMode, &File);
  652.                         }
  653.                     }
  654.                 }
  655.                 ObDereferenceObject(MyOwnProcess);
  656.             }
  657.             VIRTUALIZER_MUTATE_ONLY_END
  658.     }
  659. }
  660.  
  661. void funcionDelThread() {
  662.     // int WriteDelay = 5000; /* delay is 500 ms */
  663.  
  664.     HANDLE InputFile;
  665.     IO_STATUS_BLOCK IoStatusBlock;
  666.     OBJECT_ATTRIBUTES ObjectAttributes;
  667.     UNICODE_STRING ObjectName;
  668.     NTSTATUS Status;
  669.  
  670.     RtlInitUnicodeString(&ObjectName, L"\\SystemRoot\\outfile22.txt");
  671.  
  672.     InitializeObjectAttributes(
  673.         &ObjectAttributes,
  674.         &ObjectName,
  675.         OBJ_CASE_INSENSITIVE,
  676.         NULL, NULL
  677.     );
  678.  
  679.     while (TRUE) {
  680.         Status = ZwOpenFile(
  681.             &InputFile,
  682.             GENERIC_ALL | SYNCHRONIZE,
  683.             &ObjectAttributes,
  684.             &IoStatusBlock,
  685.             FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
  686.             FILE_RANDOM_ACCESS | FILE_SYNCHRONOUS_IO_NONALERT
  687.         );
  688.         if (NT_SUCCESS(Status)) {
  689.             VIRTUALIZER_TIGER_RED_START
  690.             LARGE_INTEGER      byteOffset;
  691.             #define  BUFFER_SIZE 30
  692.             CHAR     buffer[BUFFER_SIZE];
  693.             IO_STATUS_BLOCK    ioStatusBlock;
  694.  
  695.  
  696.             byteOffset.LowPart = byteOffset.HighPart = 0;
  697.             ZwReadFile(InputFile, NULL, NULL, NULL, &ioStatusBlock,
  698.                 buffer, BUFFER_SIZE, &byteOffset, NULL);
  699.  
  700.             char *p;
  701.             char delim[] = "#";
  702.             p = strtok(buffer, delim); // split by #
  703.  
  704.             char *pidTmp = p;
  705.             p = strtok(NULL, delim); // split by #
  706.             char *structAddress1Tmp = p;
  707.             p = strtok(NULL, delim); // split by #
  708.             char *structAddress2Tmp = p;
  709.  
  710.             pid = atoi(pidTmp);
  711.             structAddress1 = _strtoui64(structAddress1Tmp, NULL, 0);
  712.             structAddress2 = _strtoui64(structAddress2Tmp, NULL, 0);
  713.  
  714.             ZwClose(InputFile);
  715.  
  716.             HANDLE              thread;
  717.             PsCreateSystemThread(&thread, THREAD_ALL_ACCESS, NULL, 0, 0, manageThread, 0);
  718.  
  719.             ZwDeleteFile(&ObjectAttributes);
  720.  
  721.             VIRTUALIZER_TIGER_RED_END
  722.         }
  723.         else {
  724.             MySleep(1000);
  725.         }
  726.     }
  727. }
  728.  
  729. NTSTATUS DriverEntry(PDRIVER_OBJECT driverObject, PUNICODE_STRING registryPath) {
  730.     UNREFERENCED_PARAMETER(registryPath);
  731.     UNREFERENCED_PARAMETER(driverObject);
  732.  
  733.     VIRTUALIZER_TIGER_RED_START
  734.  
  735.     InitMouseManipulation();
  736.  
  737.     HANDLE              thread;
  738.     PsCreateSystemThread(&thread, THREAD_ALL_ACCESS, NULL, 0, 0, funcionDelThread, 0);
  739.  
  740.     VIRTUALIZER_TIGER_RED_END
  741.  
  742.     return STATUS_SUCCESS;
  743. }
  744.  
  745.  
  746.  
  747.  
  748.  
  749.  
  750.  
  751.  
  752. typedef struct _RTL_PROCESS_MODULE_INFORMATION
  753. {
  754.     HANDLE Section;
  755.     PVOID MappedBase;
  756.     PVOID ImageBase;
  757.     ULONG ImageSize;
  758.     ULONG Flags;
  759.     USHORT LoadOrderIndex;
  760.     USHORT InitOrderIndex;
  761.     USHORT LoadCount;
  762.     USHORT OffsetToFileName;
  763.     UCHAR  FullPathName[256];
  764. } RTL_PROCESS_MODULE_INFORMATION, *PRTL_PROCESS_MODULE_INFORMATION;
  765.  
  766. typedef struct _RTL_PROCESS_MODULES
  767. {
  768.     ULONG NumberOfModules;
  769.     RTL_PROCESS_MODULE_INFORMATION Modules[1];
  770. } RTL_PROCESS_MODULES, *PRTL_PROCESS_MODULES;
  771.  
  772. typedef unsigned char BYTE;
  773.  
  774.  
  775. BOOLEAN bDataCompare(const BYTE* pData, const BYTE* bMask, const char* szMask)
  776. {
  777.     for (; *szMask; ++szMask, ++pData, ++bMask)
  778.         if (*szMask == 'x' && *pData != *bMask)
  779.             return 0;
  780.  
  781.     return (*szMask) == 0;
  782. }
  783.  
  784. UINT64 FindPattern(UINT64 dwAddress, UINT64 dwLen, BYTE *bMask, char * szMask)
  785. {
  786.     for (UINT64 i = 0; i < dwLen; i++)
  787.         if (bDataCompare((BYTE*)(dwAddress + i), bMask, szMask))
  788.             return (UINT64)(dwAddress + i);
  789.  
  790.     return 0;
  791. }
  792.  
  793. BOOLEAN QWMKMBnBBVXF12()
  794. {
  795.     ULONG bytes = 0;
  796.     NTSTATUS status = ZwQuerySystemInformationRoutine(SystemModuleInformation, 0, bytes, &bytes);
  797.  
  798.     if (!bytes)
  799.     {
  800.         return FALSE;
  801.     }
  802.  
  803.     PRTL_PROCESS_MODULES modules = (PRTL_PROCESS_MODULES)ExAllocatePoolWithTag(NonPagedPool, bytes, 0x454E4F45); // 'ENON'
  804.  
  805.     status = ZwQuerySystemInformationRoutine(SystemModuleInformation, modules, bytes, &bytes);
  806.  
  807.     if (!NT_SUCCESS(status))
  808.     {
  809.         return FALSE;
  810.     }
  811.  
  812.     PRTL_PROCESS_MODULE_INFORMATION module = modules->Modules;
  813.     UINT64 ntoskrnlBase = 0, ntoskrnlSize = 0;
  814.  
  815.     for (ULONG i = 0; i < modules->NumberOfModules; i++)
  816.     {
  817.         if (!strcmp((char*)module[i].FullPathName, "\\SystemRoot\\system32\\ntoskrnl.exe"))
  818.         {
  819.             ntoskrnlBase = (UINT64)module[i].ImageBase;
  820.             ntoskrnlSize = (UINT64)module[i].ImageSize;
  821.             break;
  822.         }
  823.     }
  824.  
  825.     if (modules)
  826.         ExFreePoolWithTag(modules, 0);
  827.  
  828.     if (ntoskrnlBase <= 0)
  829.     {
  830.         return FALSE;
  831.     }
  832.  
  833.     // NOTE: 4C 8B ? ? ? ? ? 4C 8B C9 4D 85 ? 74 + 3] + current signature address = MNCGCRdRDhRH4
  834.     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");
  835.  
  836.     if (!mmUnloadedDriversPtr)
  837.     {
  838.         return FALSE;
  839.     }
  840.  
  841.     UINT64 mmUnloadedDrivers = (UINT64)((PUCHAR)mmUnloadedDriversPtr + *(PULONG)((PUCHAR)mmUnloadedDriversPtr + 3) + 7);
  842.     UINT64 bufferPtr = *(UINT64*)mmUnloadedDrivers;
  843.  
  844.     // NOTE: 0x7D0 is the size of the MNCGCRdRDhRH4 array for win 7 and above
  845.     PVOID newBuffer = ExAllocatePoolWithTag(NonPagedPoolNx, 0x7D0, 0x54446D4D);
  846.  
  847.     if (!newBuffer)
  848.         return FALSE;
  849.  
  850.     memset(newBuffer, 0, 0x7D0);
  851.  
  852.     // NOTE: replace MNCGCRdRDhRH4
  853.     *(UINT64*)mmUnloadedDrivers = (UINT64)newBuffer;
  854.  
  855.     // NOTE: clean the old buffer
  856.     ExFreePoolWithTag((PVOID)bufferPtr, 0x54446D4D); // 'MmDT'
  857.  
  858.     return TRUE;
  859. }
  860.  
  861. PVOID ResolveRelativeAddress(
  862.     _In_ PVOID Instruction,
  863.     _In_ ULONG OffsetOffset,
  864.     _In_ ULONG InstructionSize
  865. )
  866. {
  867.     ULONG_PTR Instr = (ULONG_PTR)Instruction;
  868.     LONG RipOffset = *(PLONG)(Instr + OffsetOffset);
  869.     PVOID ResolvedAddr = (PVOID)(Instr + InstructionSize + RipOffset);
  870.  
  871.     return ResolvedAddr;
  872. }
  873.  
  874. EXTERN_C IMAGE_DOS_HEADER __ImageBase;
  875.  
  876. uint64_t ClearCacheEntry() {
  877.  
  878.     ULONG bytes = 0;
  879.     NTSTATUS status = ZwQuerySystemInformationRoutine(SystemModuleInformation, 0, bytes, &bytes);
  880.  
  881.     if (!bytes)
  882.     {
  883.         return 9990;
  884.     }
  885.  
  886.     PRTL_PROCESS_MODULES modules = (PRTL_PROCESS_MODULES)ExAllocatePoolWithTag(NonPagedPool, bytes, 0x454E4F45); // 'ENON'
  887.  
  888.     status = ZwQuerySystemInformationRoutine(SystemModuleInformation, modules, bytes, &bytes);
  889.  
  890.     if (!NT_SUCCESS(status))
  891.     {
  892.         return 9991;
  893.     }
  894.  
  895.     PRTL_PROCESS_MODULE_INFORMATION module = modules->Modules;
  896.     UINT64 ntoskrnlBase = 0, ntoskrnlSize = 0;
  897.  
  898.     if (module == NULL) {
  899.         return 9992;
  900.     }
  901.  
  902.     for (ULONG i = 0; i < modules->NumberOfModules; i++)
  903.     {
  904.         if (!strcmp((char*)module[i].FullPathName, "\\SystemRoot\\system32\\ntoskrnl.exe"))
  905.         {
  906.             ntoskrnlBase = (UINT64)module[i].ImageBase;
  907.             ntoskrnlSize = (UINT64)module[i].ImageSize;
  908.             break;
  909.         }
  910.     }
  911.  
  912.     if (modules)
  913.         ExFreePoolWithTag(modules, 0);
  914.  
  915.     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");
  916.     PVOID PiDDBCacheTablePtr = FindPattern((UINT64)ntoskrnlBase, (UINT64)ntoskrnlSize, (UCHAR*)"\x66\x03\xD2\x48\x8D\x0D", "xxxxxx");
  917.     if (PiDDBLockPtr == 0) {
  918.         return 999510;
  919.     }
  920.     if (PiDDBCacheTablePtr == 0) {
  921.         return 999511;
  922.     }
  923.  
  924.     // DbgPrintEx(0, 0, "BlockPtr: %p  CacheTable. %p\n", ResolveRelativeAddress(PiDDBLockPtr, 3, 7), ResolveRelativeAddress(PiDDBCacheTablePtr, 6, 10));
  925.  
  926.     PERESOURCE PiDDBLock; PRTL_AVL_TABLE PiDDBCacheTable;
  927.     PiDDBLock = ResolveRelativeAddress(PiDDBLockPtr, 3, 7);
  928.     PiDDBCacheTable = ResolveRelativeAddress(PiDDBCacheTablePtr, 6, 10);
  929.  
  930.     if (&__ImageBase == NULL) {
  931.         return 9996;
  932.     }
  933.  
  934.     PIMAGE_NT_HEADERS pNtHeaders = MakePtr(PIMAGE_NT_HEADERS, &__ImageBase, __ImageBase.e_lfanew);
  935.     if (pNtHeaders == NULL) {
  936.         return 9997;
  937.     }
  938.  
  939.     if (&pNtHeaders->FileHeader == NULL) {
  940.         return 999754;
  941.     }
  942.  
  943.     PiDDBCacheTable->TableContext = (PVOID)1;
  944.  
  945.  
  946.     UNICODE_STRING nameBuf;
  947.     RtlInitUnicodeString(&nameBuf, L"ncdrv.sys");
  948.  
  949.     // build a lookup entry
  950.     PiDDBCacheEntry lookupEntry = { 0 };
  951.     lookupEntry.DriverName = nameBuf;
  952.  
  953.     // until here all is okay (at least not crashes)
  954.  
  955.     // acquire the ddb resource lock
  956.     ExAcquireResourceExclusiveLite(PiDDBLock, TRUE);
  957.  
  958.     // search our entry in the table
  959.     PiDDBCacheEntry* pFoundEntry = (PiDDBCacheEntry*)RtlLookupElementGenericTableAvl(PiDDBCacheTable, &lookupEntry);
  960.     if (pFoundEntry == NULL)
  961.     {
  962.         // release the ddb resource lock
  963.         ExReleaseResourceLite(PiDDBLock);
  964.  
  965.         return 9998;
  966.     }
  967.  
  968.     // first, unlink from the list
  969.     RemoveEntryList(&pFoundEntry->List);
  970.     // then delete the element from the avl table
  971.     RtlDeleteElementGenericTableAvl(PiDDBCacheTable, pFoundEntry);
  972.  
  973.     // release the ddb resource lock
  974.     ExReleaseResourceLite(PiDDBLock);
  975.  
  976.     return 9999;
  977. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement