我希望直接从两个内核模块(文件)获取基地址(不要与图像库混淆),以下代码100%来自Win XP赢得7 x32。
当我尝试在Win 8.1上映射 ntoskrnl.exe 或 win32k.sys 时仍会出现这些错误(仍未在Win 10中测试)。
ntoskrnl.exe 0xc0000017 和 win32k.sys (KeStackAttachProcess
到 csrss.exe < / em>进程(未经KeStackAttachProcess
测试未来)来自 0xc0000604 (未记录的错误))。
如何修复?
#define SEC_IMAGE 0x1000000
///////////////////////////// VARIABLES ///////////////////////////////////
CHAR buf[MAXIMUM_FILENAME_LENGTH]="\\SystemRoot\\system32\\ntoskrnl.exe";
OBJECT_ATTRIBUTES oaNtoskrnl,oa;
IO_STATUS_BLOCK stStatusBlock;
HANDLE hNtoskrnl=0,hSection=0;
UNICODE_STRING us;
PVOID pNtoskrnl=0;
ULONG dwViewSize=0;
STRING as;
//////////////////////////////////////////////////////////////////////////
RtlInitString(&as,(PCSZ)buf);
RtlAnsiStringToUnicodeString(&us,&as,TRUE);
DbgPrint("%wZ", &us);
InitializeObjectAttributes(&oaNtoskrnl,&us,OBJ_CASE_INSENSITIVE|OBJ_KERNEL_HANDLE,NULL,NULL);
status=ZwCreateFile(
&hNtoskrnl,
FILE_READ_DATA,
&oaNtoskrnl,
&stStatusBlock,
NULL,
FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_READ|FILE_SHARE_WRITE,
FILE_OPEN,
NULL,
NULL,
NULL);
RtlFreeUnicodeString(&us);
if(!NT_SUCCESS(status))
{
DbgPrint("Failed ZwCreateFile! 0x%x \n", status);
}
InitializeObjectAttributes(&oa,NULL,OBJ_CASE_INSENSITIVE|OBJ_KERNEL_HANDLE,NULL,NULL);
status=ZwCreateSection(
&hSection,
SECTION_MAP_READ,
&oa,
NULL,
PAGE_READONLY,
SEC_IMAGE,
hNtoskrnl
);
if(!NT_SUCCESS(status))
{
DbgPrint(("Failed ZwCreateSection! 0x%x \n", status));
ZwClose(hNtoskrnl);
}
status=ZwMapViewOfSection(
hSection,
NtCurrentProcess(),
&pNtoskrnl,
16,
NULL,
NULL,
&dwViewSize,
ViewUnmap,
NULL,
PAGE_READWRITE
);
if(!NT_SUCCESS(status))
{
DbgPrint("Failed ZwMapViewOfSection! 0x%x \n", status);
ZwClose(hSection);
ZwClose(hNtoskrnl);
}
DbgPrint("Initialize finished! 0x%x \n", pNtoskrnl);
ZwUnmapViewOfSection(NtCurrentProcess(), pNtoskrnl);
ZwClose(hSection);
ZwClose(hNtoskrnl);
修改
此后建议部分更改,但仍然遇到同样的问题(现在也在Win 10上测试过)。
ULONG modsz = 0; // receives size of file after execute MyEnumKernelModule()
MyEnumKernelModule("\\systemroot\\system32\\win32k.sys",&ModuleAddress, &modsz);
status=ZwCreateSection(
&hSection,
SECTION_ALL_ACCESS,
&oa,
(PLARGE_INTEGER)modsz,
PAGE_EXECUTE_READWRITE,
SEC_COMMIT,
hNtoskrnl
);
status=ZwMapViewOfSection(
hSection,
NtCurrentProcess(),
&pNtoskrnl,
NULL,
NULL,
NULL,
&modsz,
ViewUnmap,
MEM_RESERVE,
PAGE_EXECUTE_READWRITE
);
答案 0 :(得分:1)
基于错误代码:
似乎是基于错误的流程限制。