Nov 7, 2016 07:11 AM
(This post was last modified: Nov 7, 2016 07:13 AM by Zer0Memo0ry.)
This code is made working using the undocumented API Function "MmCopyVirtualMemory" in ntoskrnl.exe, which allows the manipulation
of a usermode process. These functions are designed to be working like regular
WPM/RPM functions, except they operate from ring0.
This method works for regular x64 processes and for WOW64 Processes (x86)
regardless of the architecture of the system.
Github: github.com/Zer0Memory/KernelReadWriteMemory
PEPROCESS Handle can be obtained with:
of a usermode process. These functions are designed to be working like regular
WPM/RPM functions, except they operate from ring0.
This method works for regular x64 processes and for WOW64 Processes (x86)
regardless of the architecture of the system.
Github: github.com/Zer0Memory/KernelReadWriteMemory
Code
NTSTATUS NTAPI MmCopyVirtualMemory
(
PEPROCESS SourceProcess,
PVOID SourceAddress,
PEPROCESS TargetProcess,
PVOID TargetAddress,
SIZE_T BufferSize,
KPROCESSOR_MODE PreviousMode,
PSIZE_T ReturnSize
);
NTSTATUS KeReadVirtualMemory(PEPROCESS Process, PVOID SourceAddress, PVOID TargetAddress, SIZE_T Size)
{
PSIZE_T Bytes;
if (NT_SUCCESS(MmCopyVirtualMemory(Process, SourceAddress, PsGetCurrentProcess(),
TargetAddress, Size, KernelMode, &Bytes)))
{
return STATUS_SUCCESS;
}
return STATUS_ACCESS_DENIED;
}
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;
}
return STATUS_ACCESS_DENIED;
}PEPROCESS Handle can be obtained with:
Code
HANDLE ProcessId = 1032 // for example from taskmanager
PEPROCESS Process;
PsLookupProcessByProcessId(ProcessId, &Process);
