Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results

Before Posting...
Please check out the Community Guidelines in the Announcements and Administration Category.

How to get base address of ntdll.dll under kernel Windows 8

Valery_DrubaValery_Druba Member Posts: 27
Hello!

I need get pase address of ntdll.dll. For Windows 7 and lower I used
ZwQuerySystemInformation. But under Windows 8 ntdll.dll is invisible
for this function.
I have implemented another algorithm using ZwQuerySection. It correct
works on Windows 7, but it returns bad address for Windows 8. The
address defers from real base address on constant 0x30670.

Could anybody explain what is the problem ?
There is the code of my new algorithm implementation :

PVOID LookforNtdll( )
{
PVOID pDLL = NULL;
IO_STATUS_BLOCK IoStBlock;
UNICODE_STRING usLibraryName ;
OBJECT_ATTRIBUTES ObjAttrF;
NTSTATUS status = 0;
HANDLE hFile = INVALID_HANDLE_VALUE;
HANDLE hSect = INVALID_HANDLE_VALUE;
PSECTION_IMAGE_INFORMATION pB = NULL;

RtlInitUnicodeString ( &usLibraryName,
L"\\DosDevices\\c:\\windows\\system32\\ntdll.dll" ) ;
InitializeObjectAttributes( &ObjAttrF, &usLibraryName,
OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE, NULL, NULL );

status = ZwOpenFile(&hFile, GENERIC_READ, &ObjAttrF, &IoStBlock,
FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_NON_DIRECTORY_FILE );
if ( status == STATUS_SUCCESS ) {
UNICODE_STRING usSectName;
OBJECT_ATTRIBUTES ObjAttrS;
LARGE_INTEGER Size;

RtlInitUnicodeString ( &usSectName,
L"\\BaseNamedObjects\\NtDllSharedSection" ) ;
InitializeObjectAttributes ( &ObjAttrS, &usSectName,
OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE, NULL, NULL ) ;

Size.HighPart = 0 ;
Size.LowPart = 0x1000 ;

status = ZwCreateSection ( &hSect, SECTION_ALL_ACCESS,
&ObjAttrS, &Size, PAGE_EXECUTE_READ, 0x1000000, hFile ) ;
if ( status == STATUS_SUCCESS ) {
ULONG bufSize = 0;

bufSize = Size.LowPart;
pB = ExAllocatePoolWithTag(NonPagedPool, bufSize, 'Fnd2' );
if (pB) {
status = ZwQuerySection ( hSect,
SectionImageInformation, pB, bufSize, &bufSize );
if (status == STATUS_SUCCESS)
pDLL = pB->EntryPoint ;
}
}
}
}

if (hFile != INVALID_HANDLE_VALUE)
ZwClose( hFile ) ;

if (hSect != INVALID_HANDLE_VALUE)
ZwClose( hSect ) ;

if (pB)
ExFreePool(pB);

return ( pDLL ) ;
}

Thanks
Valery

Comments

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Upcoming OSR Seminars
OSR has suspended in-person seminars due to the Covid-19 outbreak. But, don't miss your training! Attend via the internet instead!
Kernel Debugging 30 Mar 2020 OSR Seminar Space
Developing Minifilters 20 Apr 2020 LIVE ONLINE
Writing WDF Drivers 11 May 2020 LIVE ONLINE
Internals & Software Drivers 28 Sept 2020 Dulles, VA