首页
社区
课程
招聘
[求助]NtAllocateVirtualMemory 失败,分配内存0页失败,求解决
发表于: 2018-4-20 10:12 5223

[求助]NtAllocateVirtualMemory 失败,分配内存0页失败,求解决

2018-4-20 10:12
5223
环境win7 x64,总是分配失败,求原因
代码如下

typedef NTSTATUS(WINAPI *ptrNtAllocateVirtualMemory)(
HANDLE ProcessHandle,
PVOID *BaseAddress,
ULONG ZeroBits,
PULONG AllocationSize,
ULONG AllocationType,
ULONG Protect
);


int main()
{
// Resolve NtAllocateVirtualMemory
ptrNtAllocateVirtualMemory NtAllocateVirtualMemory = (ptrNtAllocateVirtualMemory)GetProcAddress(GetModuleHandle("ntdll.dll"), "NtAllocateVirtualMemory");
if (NtAllocateVirtualMemory == NULL)
{
printf("[-] Failed to export NtAllocateVirtualMemory.");
exit(-1);
}

printf("[+] Found address of NtAllocateVirtualMemory: 0x%p\n", NtAllocateVirtualMemory);

// Allocate the NULL page
LPVOID baseAddress = (LPVOID)0x1;
ULONG allocSize = 0x1000;
char* uBuffer = (char*)NtAllocateVirtualMemory(
GetCurrentProcess(),
&baseAddress, // Putting a small non-zero value gets rounded down to page granularity, pointing to the NULL page
0,
&allocSize,
MEM_COMMIT | MEM_RESERVE,
PAGE_EXECUTE_READWRITE);



DWORD dummy;
if (!VirtualProtect(0x0, 0x1000, PAGE_EXECUTE_READWRITE, &dummy))
{
printf("[-] Failed to allocate the NULL page.\n");
exit(-1);
}
*(INT_PTR*)(uBuffer + 8) = 0x12345678;

//printf("[+] Successfully allocated the NULL page.\n");

}


[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

最后于 2018-4-20 10:12 被小旭msx编辑 ,原因:
收藏
免费 0
支持
分享
最新回复 (1)
雪    币: 914
活跃值: (2768)
能力值: ( LV5,RANK:68 )
在线值:
发帖
回帖
粉丝
2
你倒是把返回状态贴出来啊
2018-4-20 13:20
0
游客
登录 | 注册 方可回帖
返回