要獲取windows 內核中所有驅動模塊信息,調用 系統服務函數 NtQuerySystemInformation,參數SystemInformationClass 傳入SystemModuleInformation.
NtQuerySystemInformation申明如下:
- //
- // System Information Classes.
- //
- typedef enum _SYSTEM_INFORMATION_CLASS {
- SystemBasicInformation,
- SystemProcessorInformation, // obsolete...delete
- SystemPerformanceInformation,
- SystemTimeOfDayInformation,
- SystemPathInformation,
- SystemProcessInformation, //系統進程信息
- SystemCallCountInformation,
- SystemDeviceInformation,
- SystemProcessorPerformanceInformation,
- SystemFlagsInformation,
- SystemCallTimeInformation,
- SystemModuleInformation, //系統模塊
- SystemLocksInformation,
- SystemStackTraceInformation,
- SystemPagedPoolInformation,
- SystemNonPagedPoolInformation,
- SystemHandleInformation,
- SystemObjectInformation,
- SystemPageFileInformation,
- SystemVdmInstemulInformation,
- SystemVdmBopInformation,
- SystemFileCacheInformation,
- SystemPoolTagInformation,
- SystemInterruptInformation,
- SystemDpcBehaviorInformation,
- SystemFullMemoryInformation,
- SystemLoadGdiDriverInformation,
- SystemUnloadGdiDriverInformation,
- SystemTimeAdjustmentInformation,
- SystemSummaryMemoryInformation,
- SystemMirrorMemoryInformation,
- SystemPerformanceTraceInformation,
- SystemObsolete0,
- SystemExceptionInformation,
- SystemCrashDumpStateInformation,
- SystemKernelDebuggerInformation,
- SystemContextSwitchInformation,
- SystemRegistryQuotaInformation,
- SystemExtendServiceTableInformation,
- SystemPrioritySeperation,
- SystemVerifierAddDriverInformation,
- SystemVerifierRemoveDriverInformation,
- SystemProcessorIdleInformation,
- SystemLegacyDriverInformation,
- SystemCurrentTimeZoneInformation,
- SystemLookasideInformation,
- SystemTimeSlipNotification,
- SystemSessionCreate,
- SystemSessionDetach,
- SystemSessionInformation,
- SystemRangeStartInformation,
- SystemVerifierInformation,
- SystemVerifierThunkExtend,
- SystemSessionProcessInformation,
- SystemLoadGdiDriverInSystemSpace,
- SystemNumaProcessorMap,
- SystemPrefetcherInformation,
- SystemExtendedProcessInformation,
- SystemRecommendedSharedDataAlignment,
- SystemComPlusPackage,
- SystemNumaAvailableMemory,
- SystemProcessorPowerInformation,
- SystemEmulationBasicInformation,
- SystemEmulationProcessorInformation,
- SystemExtendedHandleInformation,
- SystemLostDelayedWriteInformation,
- SystemBigPoolInformation,
- SystemSessionPoolTagInformation,
- SystemSessionMappedViewInformation,
- SystemHotpatchInformation,
- SystemObjectSecurityMode,
- SystemWatchdogTimerHandler,
- SystemWatchdogTimerInformation,
- SystemLogicalProcessorInformation,
- SystemWow64SharedInformation,
- SystemRegisterFirmwareTableInformationHandler,
- SystemFirmwareTableInformation,
- SystemModuleInformationEx,
- SystemVerifierTriageInformation,
- SystemSuperfetchInformation,
- SystemMemoryListInformation,
- SystemFileCacheInformationEx,
- MaxSystemInfoClass // MaxSystemInfoClass should always be the last enum
- } SYSTEM_INFORMATION_CLASS;
// // System Information Classes. // typedef enum _SYSTEM_INFORMATION_CLASS { SystemBasicInformation, SystemProcessorInformation, // obsolete...delete SystemPerformanceInformation, SystemTimeOfDayInformation, SystemPathInformation, SystemProcessInformation, //系統進程信息 SystemCallCountInformation, SystemDeviceInformation, SystemProcessorPerformanceInformation, SystemFlagsInformation, SystemCallTimeInformation, SystemModuleInformation, //系統模塊 SystemLocksInformation, SystemStackTraceInformation, SystemPagedPoolInformation, SystemNonPagedPoolInformation, SystemHandleInformation, SystemObjectInformation, SystemPageFileInformation, SystemVdmInstemulInformation, SystemVdmBopInformation, SystemFileCacheInformation, SystemPoolTagInformation, SystemInterruptInformation, SystemDpcBehaviorInformation, SystemFullMemoryInformation, SystemLoadGdiDriverInformation, SystemUnloadGdiDriverInformation, SystemTimeAdjustmentInformation, SystemSummaryMemoryInformation, SystemMirrorMemoryInformation, SystemPerformanceTraceInformation, SystemObsolete0, SystemExceptionInformation, SystemCrashDumpStateInformation, SystemKernelDebuggerInformation, SystemContextSwitchInformation, SystemRegistryQuotaInformation, SystemExtendServiceTableInformation, SystemPrioritySeperation, SystemVerifierAddDriverInformation, SystemVerifierRemoveDriverInformation, SystemProcessorIdleInformation, SystemLegacyDriverInformation, SystemCurrentTimeZoneInformation, SystemLookasideInformation, SystemTimeSlipNotification, SystemSessionCreate, SystemSessionDetach, SystemSessionInformation, SystemRangeStartInformation, SystemVerifierInformation, SystemVerifierThunkExtend, SystemSessionProcessInformation, SystemLoadGdiDriverInSystemSpace, SystemNumaProcessorMap, SystemPrefetcherInformation, SystemExtendedProcessInformation, SystemRecommendedSharedDataAlignment, SystemComPlusPackage, SystemNumaAvailableMemory, SystemProcessorPowerInformation, SystemEmulationBasicInformation, SystemEmulationProcessorInformation, SystemExtendedHandleInformation, SystemLostDelayedWriteInformation, SystemBigPoolInformation, SystemSessionPoolTagInformation, SystemSessionMappedViewInformation, SystemHotpatchInformation, SystemObjectSecurityMode, SystemWatchdogTimerHandler, SystemWatchdogTimerInformation, SystemLogicalProcessorInformation, SystemWow64SharedInformation, SystemRegisterFirmwareTableInformationHandler, SystemFirmwareTableInformation, SystemModuleInformationEx, SystemVerifierTriageInformation, SystemSuperfetchInformation, SystemMemoryListInformation, SystemFileCacheInformationEx, MaxSystemInfoClass // MaxSystemInfoClass should always be the last enum } SYSTEM_INFORMATION_CLASS;
- NTSTATUS
- NtQuerySystemInformation (
- IN SYSTEM_INFORMATION_CLASS SystemInformationClass,
- OUT PVOID SystemInformation,
- IN ULONG SystemInformationLength,
- OUT PULONG ReturnLength OPTIONAL
- )
NTSTATUS NtQuerySystemInformation ( IN SYSTEM_INFORMATION_CLASS SystemInformationClass, OUT PVOID SystemInformation, IN ULONG SystemInformationLength, OUT PULONG ReturnLength OPTIONAL )根據泄漏出的widows 2000 部分源代碼,NtQuerySystemInformation 有關 SystemModuleInformation的實現部分如下:
- case SystemModuleInformation:
- KeEnterCriticalRegion();
- ExAcquireResourceExclusive( &PsLoadedModuleResource, TRUE );
- ReleaseModuleResoure = TRUE;
- Status = ExpQueryModuleInformation( &PsLoadedModuleList,
- &MmLoadedUserImageList,
- (PRTL_PROCESS_MODULES)SystemInformation,
- SystemInformationLength,
- ReturnLength
- );
- ExReleaseResource (&PsLoadedModuleResource);
- ReleaseModuleResoure = FALSE;
- KeLeaveCriticalRegion();
- break;
case SystemModuleInformation: KeEnterCriticalRegion(); ExAcquireResourceExclusive( &PsLoadedModuleResource, TRUE ); ReleaseModuleResoure = TRUE; Status = ExpQueryModuleInformation( &PsLoadedModuleList, &MmLoadedUserImageList, (PRTL_PROCESS_MODULES)SystemInformation, SystemInformationLength, ReturnLength ); ExReleaseResource (&PsLoadedModuleResource); ReleaseModuleResoure = FALSE; KeLeaveCriticalRegion(); break;
在Windows內核實現中,存在兩個存儲系統加載模塊的兩個鏈表,分別是PsLoadedModuleList和 MmLoadedUserImageList,兩個全局變量 申明如下:
- LIST_ENTRY PsLoadedModuleList;//驅動模塊列表
- LIST_ENTRY MmLoadedUserImageList;//應用程序映像列表
LIST_ENTRY PsLoadedModuleList;//驅動模塊列表 LIST_ENTRY MmLoadedUserImageList;//應用程序映像列表
Windows就是通過這兩個鏈表將代表系統模塊的_LDR_DATA_ENTRY結構鏈接在一起。
_LDR_DATA_ENTRY結構體中有3個 _LIST_ENTRY,系統根據不同排列順序串連系統中所加載的所有模塊,情況就相當明顯了,只要遍歷任何一個雙向鏈表,即可獲得加載的模塊信息。
在Windows 內核中,表示每個模塊的數據結構是_LDR_DATA_TABLE_ENTRY,其結構申明為:
- kd> dt _LDR_DATA_TABLE_ENTRY
- nt!_LDR_DATA_TABLE_ENTRY
- +0x000 InLoadOrderLinks : _LIST_ENTRY
- +0x008 InMemoryOrderLinks : _LIST_ENTRY
- +0x010 InInitializationOrderLinks : _LIST_ENTRY
- +0x018 DllBase : Ptr32 Void
- +0x01c EntryPoint : Ptr32 Void
- +0x020 SizeOfImage : Uint4B
- +0x024 FullDllName : _UNICODE_STRING
- +0x02c BaseDllName : _UNICODE_STRING
- +0x034 Flags : Uint4B
- +0x038 LoadCount : Uint2B
- +0x03a TlsIndex : Uint2B
- +0x03c HashLinks : _LIST_ENTRY
- +0x03c SectionPointer : Ptr32 Void
- +0x040 CheckSum : Uint4B
- +0x044 TimeDateStamp : Uint4B
- +0x044 LoadedImports : Ptr32 Void
- +0x048 EntryPointActivationContext : Ptr32 Void
- +0x04c PatchInformation : Ptr32 Void
kd> dt _LDR_DATA_TABLE_ENTRY nt!_LDR_DATA_TABLE_ENTRY +0x000 InLoadOrderLinks : _LIST_ENTRY +0x008 InMemoryOrderLinks : _LIST_ENTRY +0x010 InInitializationOrderLinks : _LIST_ENTRY +0x018 DllBase : Ptr32 Void +0x01c EntryPoint : Ptr32 Void +0x020 SizeOfImage : Uint4B +0x024 FullDllName : _UNICODE_STRING +0x02c BaseDllName : _UNICODE_STRING +0x034 Flags : Uint4B +0x038 LoadCount : Uint2B +0x03a TlsIndex : Uint2B +0x03c HashLinks : _LIST_ENTRY +0x03c SectionPointer : Ptr32 Void +0x040 CheckSum : Uint4B +0x044 TimeDateStamp : Uint4B +0x044 LoadedImports : Ptr32 Void +0x048 EntryPointActivationContext : Ptr32 Void +0x04c PatchInformation : Ptr32 Void
jpg改rar