루트킷 체크 프로그램인 gmer에 Modules탭에 보면은 현재 로드 된 커널 모듈을 볼 수 있습니다.
회사에서 작업을 하다가 해당 기능이 좀 필요해서 간단하게 인터넷 뒤져서 짜집기한 코드입니다.
( OpenRCE랑 Undocumented 사이트 참고하였습니다. )
컴파일을 하실려면 ntdll.lib이 필요한데 해당 lib파일은 WDK에 있습니다.
#include <Windows.h>
#define NT_SUCCESS(Status) (((NTSTATUS)(Status)) >= 0)
#define STATUS_INFO_LENGTH_MISMATCH ((NTSTATUS)0xC0000004L)
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,
SystemPowerInformationRedefine, // 이름이 중복되어서 변경하였습니다.
SystemProcessorSpeedInformation,
SystemCurrentTimeZoneInformation,
SystemLookasideInformation
} SYSTEM_INFORMATION_CLASS, *PSYSTEM_INFORMATION_CLASS;
extern "C" NTSYSAPI NTSTATUS NTAPI NtQuerySystemInformation(
IN SYSTEM_INFORMATION_CLASS SystemInformationClass,
OUT PVOID SystemInformation,
IN ULONG SystemInformationLength,
OUT PULONG ReturnLength OPTIONAL);
typedef struct _RTL_PROCESS_MODULE_INFORMATION {
HANDLE Section;
PVOID MappedBase;
PVOID ImageBase;
ULONG ImageSize;
ULONG Flags;
USHORT LoadOrderIndex;
USHORT InitOrderIndex;
USHORT LoadCount;
USHORT OffsetToFileName;
CHAR FullPathName[256];
} RTL_PROCESS_MODULE_INFORMATION, *PRTL_PROCESS_MODULE_INFORMATION;
typedef struct _RTL_PROCESS_MODULES {
ULONG NumberOfModules;
RTL_PROCESS_MODULE_INFORMATION Modules[1];
} RTL_PROCESS_MODULES, *PRTL_PROCESS_MODULES;
BOOL PrintSystemModuleList()
{
NTSTATUS Status;
PRTL_PROCESS_MODULES ModuleInfo;
PRTL_PROCESS_MODULE_INFORMATION ModuleEntry;
ULONG ReturnedLength;
ULONG i;
Status = NtQuerySystemInformation(SystemModuleInformation,
NULL,
0,
&ReturnedLength);
if (Status != STATUS_INFO_LENGTH_MISMATCH)
{
return FALSE;
}
ModuleInfo = (PRTL_PROCESS_MODULES)malloc(ReturnedLength);
Status = NtQuerySystemInformation(SystemModuleInformation,
ModuleInfo,
ReturnedLength,
&ReturnedLength);
if (!NT_SUCCESS(Status))
{
free(ModuleInfo);
return NULL;
}
for (i = 0; i < ModuleInfo->NumberOfModules; i++)
{
ModuleEntry = &ModuleInfo->Modules[i];
printf("%s\n", ModuleEntry->FullPathName);
}
free(ModuleInfo);
return TRUE;
}
int _tmain(int argc, _TCHAR* argv[])
{
PrintSystemModuleList();
return 0;
}
안녕하세요 ^^^;;;
까먹고 있다 이제 글 올립니다.
올려주신 글을 보고 아주아주 조금 수정한 소스를 제 블로그에 올려놨습니다.
http://kese111.tistory.com/entry/ZwQuerySystemInformation-을-사용한-System-Module-List-구하기
소스 공개해주신걸로 믿고 허락안받고 퍼간게 맘에 걸렸는데, 이제야왔네요.
감사합니다.