先分析一下 ZwQuerySystemInformaition 這個函數,它提供給桌面app 使用。他用來檢索指定的系統信息。看非文檔化的資料說明: 它的一個參數的類型是:SYSTEM_INFORMATION_CLASS 是一個枚舉類型,定義了許多系統設置信息。它被用在NtQuerySystemInfomation 和 NtSetSystemInformaiton. 如:這個枚舉類型包含: SystemBasicInformation, SystemProcessInformaion.等枚舉類型。 因此當咱們進行改寫的時候,這個類型能夠設置爲ULONG型的。在wrk的public\sdk\inc\ntexapi.h中有具體的定義。html
函數指針: //指針
typedef NTSTATUS (*ZWQUERYSYSTEMINFORMATION)(
ULONG SystemInformationCLass,
PVOID SystemInformation,
ULONG SystemInformationLength,
PULONG ReturnLength
);api
ZWQUERYSYSTEMINFORMATION OldZwQuerySystemInformation;數組
SystemInformationClass == 5 表示SystemProcessInformation.app
參看非文檔列表:ide
typedef enum _SYSTEM_INFORMATION_CLASS {函數
SystemBasicInformation,
SystemProcessorInformation,
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,
SystemNextEventIdInformation,
SystemEventIdsInformation,
SystemCrashDumpInformation,
SystemExceptionInformation,
SystemCrashDumpStateInformation,
SystemKernelDebuggerInformation,
SystemContextSwitchInformation,
SystemRegistryQuotaInformation,
SystemExtendServiceTableInformation,
SystemPrioritySeperation,
SystemPlugPlayBusInformation,
SystemDockInformation,
SystemPowerInformation,
SystemProcessorSpeedInformation,
SystemCurrentTimeZoneInformation,
SystemLookasideInformationui
} SYSTEM_INFORMATION_CLASS, *PSYSTEM_INFORMATION_CLASS;spa
當SYSTEM_INFORMATION_CLASS == 5的時候,表示請求進程列表。.net
咱們須要在這個時候,查詢以進程名 '_root_' 開始的進程,並過濾掉它,就實現了進程的隱藏。3d
#define SYSTEMSERVICE(_function) KeServiceDescriptorTable.ServiceTableBase[ *(PULONG)((PUCHAR)_function+1)]
這個結構體,在前面接觸過,着是第二次遇見:OldZwQuerySystemInformation =(ZWQUERYSYSTEMINFORMATION)(SYSTEMSERVICE(ZwQuerySystemInformation))
戰鬥一: 什麼是MDL?
Memory Discription List 一個MDL會描述一塊虛擬地址空間,該空間肯能在用戶空間,也肯能在系統空間。在進行IO操做時,若是採用DEVICE_IN_DIRECT 和DEVICE_OUT_DIRECT,將一塊用戶空間在系統空間創建映射.就是用戶虛擬地址空間和系統虛擬地址空間都同時指向一塊物理內存,而後鎖定該內存不容許其換出,這樣就可以在系統內核中操做用戶空間了. namelcx的專欄中有這方面的描述: http://blog.csdn.net/namelcx/article/details/6833519 以及 http://blog.csdn.net/kaizitop/article/details/2231056 .
破解SSDT的原理,無非就是使用MDL使得SSDT的只讀內存的虛擬地址從新映射一次,這樣MDL這個內存頁和原先的SSDT內存實際指向的物理地址是同樣的,可是MDL內存並無寫保護!
http://topic.csdn.net/u/20090701/15/d3df62cb-c455-412a-91ef-b757cec42869.html
MmBuildMdlForNonPagedPool : routine receives an MDL that specifies a virtural memeory buffer in nonpaged pool,and updates it to describe the underlying physical pages. MmBuildMdlForNonPagedPool( IN OUT PMDL MemoryDescriptorList );
算是知道了怎樣hook SSDT的流程: 使用映射的方式,突破SSDT的保護,將原來的API地址改寫爲咱們的函數地址,重寫咱們的函數。 將本身消耗的時間+ Idl的時間中。響應和進行相關的請求。
因爲咱們是在驅動程序中使用這些函數,故要從新定義,若是直接包含SDK頭文件會出現問題。 當SystemInformationClass取值SytemProcessInformation時,SystemInformation對應地指向一個SYSTEM_PROCESS_INFORMATION結構的數組,這個數組的每一個結構元素表明一個正在運行的進程:
typedef struct _SYSTEM_PROCESS_INFO
{
ULONG NextEntryOffset;
ULONG NumberOfThreads;
ULONG Reserved [6] ;
LARGE_INTEGER CreateTime;
LARGE_INTEGER UserTime;
LARGE_INTEGER KernelTime;
UNICODE_STRING ProcessName;
KPRIORITY BasePriority;
HANDLE UniqueProcessID;
PVOID Reserved3;
ULONG HandleCount;
BYTE Reserved4{4] ;
PVOID ReservedS [11] ;
SIZE_T PeakPagefileUsage;
SIZE_T PrivatePageCount;
LARGE_INTEGER Reserved6[ 6] ;
}SYSTEM_ROCESS_INFO,*PSYSTEM_ROCESS_INFO;
噹噹SystemInformationClass取值SytemProcessorPerformationInformation時,SystemInformation對應地指向一個以下結構的數組:
typedef struct _SYSTEM]ROCESSOR]ERFORMANCE_INFO { LARGE_INTEGER IdleTime; LARGE_INTEGER KernelTime; LARGE_INTEGER UserTime; LARGE_INTEGER Reservedl[2]; ULONG Reserved2; }SYSTEM_ROCESSOR_ERFORMANCE_INFO, *PSYSTEM_ROCESSOR_ERFORMANCE_INFO;