项目作者: AYIDouble

项目描述 :
🔍 Code to read / write the Process Memory from the Kernel 🔧
高级语言: C
项目地址: git://github.com/AYIDouble/Kernel-Memory-Reading-Writing.git
创建时间: 2019-08-12T06:18:57Z
项目社区:https://github.com/AYIDouble/Kernel-Memory-Reading-Writing

开源协议:MIT License

下载


🔍 Kernel Memory Reading Writing 🔧

🔍 Template to read / write the Process Memory from the Kernel (kernelmode) 🔧

How does it Work?

A: It uses the undocumented NT API “MmCopyVirtualMemory” function in ntoskrnl.exe (Windows NT operating system kernel)

📝 KernelReadWriteMemory.c 📝

  1. #include <ntdef.h>
  2. #include <ntifs.h>
  3. DRIVER_INITIALIZE DriverEntry;
  4. #pragma alloc_text(INIT, DriverEntry)
  5. // API function from ntoskrnl.exe which we use
  6. // to copy memory to and from an user process.
  7. NTSTATUS NTAPI MmCopyVirtualMemory
  8. (
  9. PEPROCESS SourceProcess,
  10. PVOID SourceAddress,
  11. PEPROCESS TargetProcess,
  12. PVOID TargetAddress,
  13. SIZE_T BufferSize,
  14. KPROCESSOR_MODE PreviousMode,
  15. PSIZE_T ReturnSize
  16. );
  17. NTKERNELAPI
  18. NTSTATUS
  19. PsLookupProcessByProcessId(
  20. _In_ HANDLE ProcessId,
  21. _Outptr_ PEPROCESS* Process
  22. );
  23. NTSTATUS KeReadProcessMemory(PEPROCESS Process, PVOID SourceAddress, PVOID TargetAddress, SIZE_T Size) {
  24. // Since the process we are reading from is the input process, we set
  25. // the source process variable for that.
  26. PEPROCESS SourceProcess = Process;
  27. // Since the "process" we read the output to is this driver
  28. // we set the target process as the current module.
  29. PEPROCESS TargetProcess = PsGetCurrentProcess();
  30. SIZE_T Result;
  31. if (NT_SUCCESS(MmCopyVirtualMemory(SourceProcess, SourceAddress, TargetProcess, TargetAddress, Size, KernelMode, &Result)))
  32. return STATUS_SUCCESS; // operation was successful
  33. else
  34. return STATUS_ACCESS_DENIED;
  35. }
  36. NTSTATUS KeWriteProcessMemory(PEPROCESS Process, PVOID SourceAddress, PVOID TargetAddress, SIZE_T Size) {
  37. // This write func is just like the read func, except vice versa.
  38. // Since the process writing from is our module
  39. // change the source process variable for that.
  40. PEPROCESS SourceProcess = PsGetCurrentProcess();
  41. // Since the process we write to is the input process
  42. // we set the target process as the argument
  43. PEPROCESS TargetProcess = Process;
  44. SIZE_T Result;
  45. if (NT_SUCCESS(MmCopyVirtualMemory(SourceProcess, SourceAddress, TargetProcess, TargetAddress, Size, KernelMode, &Result)))
  46. return STATUS_SUCCESS; // operation was successful
  47. else
  48. return STATUS_ACCESS_DENIED;
  49. }
  50. NTSTATUS DriverEntry(_In_ struct _DRIVER_OBJECT* DriverObject, _In_ PUNICODE_STRING RegistryPath)
  51. {
  52. int Writeval = 666;
  53. PEPROCESS Process; // our target process
  54. // enter your process ID here.
  55. PsLookupProcessByProcessId(4872, &Process); //lookup the process by it's id;
  56. KeWriteProcessMemory(Process, &Writeval, 0x010F29B0, sizeof(__int32));
  57. DbgPrint("Value of int i: %d", Writeval);
  58. return STATUS_SUCCESS;
  59. }

Binance Ready to give crypto a try ? buy bitcoin and other cryptocurrencies on binance