Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

[TUT] C Read/Write Memory Of A Process From Kernel Mode

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

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);
pretty nice, would be surprised if anyone on here could actually put it to good use except all the shitty vb.net malware.
(Nov 7, 2016 01:45 PM)paggarotti Wrote:  pretty nice, would be surprised if anyone on here could actually put it to good use except all the shitty vb.net malware.

Yup, people on hackforums should focus less on "skid stuff" like kali linux or ddossing shit, and focus instead on lower level on programming and the actual security and exploits and so forth.

Kernel module programming is interesting area.
(Nov 7, 2016 02:36 PM)Zer0Memo0ry Wrote:  Yup, people on hackforums should focus less on "skid stuff" like kali linux or ddossing shit, and focus instead on lower level on programming and the actual security and exploits and so forth.

Kernel module programming is interesting area.

totally agree, though shame all public forums and communities are mostly filled with absolute trash, it's good to see actual skill and talent from time to time, there were some pretty great malware communities with skilled people around some years back that would of appreciated your work very much.
(Nov 7, 2016 02:49 PM)paggarotti Wrote:  totally agree, though shame all public forums and communities are mostly filled with absolute trash, it's good to see actual skill and talent from time to time, there were some pretty great malware communities with skilled people around some years back that would of appreciated your work very much.

That's true. I am glad though that there are some really good underground forums on the darkweb which are totally different from these toxic script kiddy communities. Hell & Kickass Forums are both great.
Thanks for the share!!!!!!!!!!!
(Nov 11, 2016 02:16 PM)_View_ Wrote:  Thanks for the share!!!!!!!!!!!

No problem =)
Thanks for the share!!!!!!!!!!!


Possibly Related Threads...
Thread / Author Replies Views Last Post
by Elite_xApr 13, 2025 04:44 PM 4 571 Apr 13, 2025 04:44 PM
Last Post: SS2580G
by w3w3w3Mar 15, 2021 04:54 AM 1 183 Mar 15, 2021 04:54 AM
Last Post: w3w3w3
by w3w3w3Mar 15, 2021 04:53 AM 0 144 Mar 15, 2021 04:53 AM
Last Post: w3w3w3