获取系统信息
获取系统信息
DriverEntry
1 | typedef NTSTATUS(NTAPI* LPFN_RTLGETVERSION)( |
获取系统版本
先判断MajorVersion,2003、 xp、 2000都是5,后面的都是6,win10是10。再判断MinorVersion,分辨win7、win8。对于win8、win10的一些小版本,通过BuildNumber来判断。
1 | ULONG __BuildNumber = 0; |
获取系统信息
csrss.exe是微软客户端、服务端运行时子系统,管理Windows图形相关任务,Hook SSSDT必须。SSSDT就是win32k.sys里面的函数,大多数都跟图形相关,比如什么NtUserGetDCEx或者NtUserCreateWindowEx等。所以要查看这些内核函数地址,光在驱动中进行和SSDT一样的访问会引发异常蓝屏的。所以有前辈就想出办法,在驱动程序里面调用KeAttachProces到csrss.exe中,获取这个系统进程的地址空间从而在驱动中获取SSSDT中的函数地址
ZwQuerySystemInformation函数需要导出使用。配合枚举类型指示获取系统的什么信息。代码中获取了系统的所有模块,这个函数返回了首地址和大小。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91NTSYSAPI NTSTATUS NTAPI ZwQuerySystemInformation(
ULONG SystemInformationClass,
PVOID SystemInformation,
ULONG SystemInformationLength,
PULONG ReturnLength
);
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;strrchr用于从右查找字符数组第一次出现对应标识的地方,并返回指向这个被截断的数组的指针。RtlStringCchCatW连接两个字符串(Unicode),RtlStringCchCatNW限制连接的大小。
win10下,win32k.sys变为了win32kfull.sys
内核有效地址从MmSystemRangeStart开始。模块枚举不到ntdll时,可以使用内存映射的方法获取ntdll信息。
注意比较csrss.exe的最大session id不能大于10。
1 | NTSTATUS GetSystemInfo() |
使用内存映射方法获取ntdll模块信息
1 | PVOID MappingModuleInfo(LPCWSTR FilePath, PULONG ImageFileSize, PULONG ImageSize) |
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.