今天微信朋友圈被蓝屏刷屏了,各大厂商也都在出热补,写着玩,不知道会不会PG
EXTERN_C POBJECT_TYPE
*
IoDriverObjectType;
EXTERN_C NTSTATUS ObReferenceObjectByName(
PUNICODE_STRING ObjectName,
ULONG Attributes,
PACCESS_STATE AccessState,
ACCESS_MASK DesiredAccess,
POBJECT_TYPE ObjectType,
KPROCESSOR_MODE AccessMode,
PVOID ParseContext,
PVOID
*
Object
);
/
/
全局变量
PDRIVER_OBJECT g_Con
=
NULL;
PDRIVER_DISPATCH g_OriginalCreate
=
NULL;
NTSTATUS HookCreate(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
{
PIO_STACK_LOCATION pStack
=
IoGetCurrentIrpStackLocation(Irp);
DbgPrint(
"Open File:%wZ\n"
, &pStack
-
>FileObject
-
>FileName);
UNICODE_STRING usFileName
=
{
0
};
RtlInitUnicodeString(&usFileName, L
"\\KernelConnect"
);
if
(RtlCompareUnicodeString(&pStack
-
>FileObject
-
>FileName, &usFileName, TRUE)
=
=
0
)
{
/
/
走到这里说明在访问漏洞函数了,再检查请求是否来自UserMode
if
(Irp
-
>RequestorMode)
{
Irp
-
>IoStatus.Information
=
0
;
Irp
-
>IoStatus.Status
=
STATUS_ACCESS_DENIED;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return
Irp
-
>IoStatus.Status;
}
}
return
g_OriginalCreate(DeviceObject, Irp);
}
NTSTATUS Init()
{
NTSTATUS status
=
STATUS_UNSUCCESSFUL;
UNICODE_STRING usDrvName
=
{
0
};
/
/
install Hook
RtlInitUnicodeString(&usDrvName, L
"\\Driver\\condrv"
);
status
=
ObReferenceObjectByName(&usDrvName, OBJ_CASE_INSENSITIVE, NULL,
0
,
*
IoDriverObjectType, KernelMode, NULL, (PVOID
*
)&g_Con);
if
(!NT_SUCCESS(status))
{
DbgPrint(
"Couldn't get the driver object \n"
);
return
status;
}
else
{
/
/
Start Hooking
if
(!g_OriginalCreate)
{
g_OriginalCreate
=
g_Con
-
>MajorFunction[IRP_MJ_CREATE];
g_Con
-
>MajorFunction[IRP_MJ_CREATE]
=
HookCreate;
}
DbgPrint(
"Hook: HOOK driver object! Success\n"
);
}
return
STATUS_SUCCESS;
}
void UnInit()
{
if
(g_Con)
{
g_Con
-
>MajorFunction[IRP_MJ_CREATE]
=
g_OriginalCreate;
g_OriginalCreate
=
NULL;
ObDereferenceObject(g_Con);
g_Con
=
NULL;
DbgPrint(
"Restore hook!\n"
);
}
}
void DriverUnload(PDRIVER_OBJECT DriverObject)
{
UNREFERENCED_PARAMETER(DriverObject);
DbgPrint(
"Driver Unloadiang\n"
);
UnInit();
}
EXTERN_C_START
NTSTATUS DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
{
UNREFERENCED_PARAMETER(RegistryPath);
DriverObject
-
>DriverUnload
=
DriverUnload;
ULONG MajorVersion
=
0
;
ULONG MinorVersion
=
0
;
ULONG BuildNumber
=
0
;
PsGetVersion(&MajorVersion, &MinorVersion, &BuildNumber,
0
);
if
(MajorVersion
=
=
10
&& BuildNumber >
=
15063
)
{
Init();
}
return
STATUS_SUCCESS;
}
EXTERN_C_END
EXTERN_C POBJECT_TYPE
*
IoDriverObjectType;
EXTERN_C NTSTATUS ObReferenceObjectByName(
PUNICODE_STRING ObjectName,
ULONG Attributes,
PACCESS_STATE AccessState,
ACCESS_MASK DesiredAccess,
POBJECT_TYPE ObjectType,
KPROCESSOR_MODE AccessMode,
PVOID ParseContext,
PVOID
*
Object
);
/
/
全局变量
PDRIVER_OBJECT g_Con
=
NULL;
PDRIVER_DISPATCH g_OriginalCreate
=
NULL;
NTSTATUS HookCreate(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
{
PIO_STACK_LOCATION pStack
=
IoGetCurrentIrpStackLocation(Irp);
DbgPrint(
"Open File:%wZ\n"
, &pStack
-
>FileObject
-
>FileName);
UNICODE_STRING usFileName
=
{
0
};
RtlInitUnicodeString(&usFileName, L
"\\KernelConnect"
);
if
(RtlCompareUnicodeString(&pStack
-
>FileObject
-
>FileName, &usFileName, TRUE)
=
=
0
)
{
/
/
走到这里说明在访问漏洞函数了,再检查请求是否来自UserMode
if
(Irp
-
>RequestorMode)
{
Irp
-
>IoStatus.Information
=
0
;
Irp
-
>IoStatus.Status
=
STATUS_ACCESS_DENIED;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return
Irp
-
>IoStatus.Status;
}
}
return
g_OriginalCreate(DeviceObject, Irp);
}
NTSTATUS Init()
{
NTSTATUS status
=
STATUS_UNSUCCESSFUL;
UNICODE_STRING usDrvName
=
{
0
};
/
/
install Hook
RtlInitUnicodeString(&usDrvName, L
"\\Driver\\condrv"
);
status
=
ObReferenceObjectByName(&usDrvName, OBJ_CASE_INSENSITIVE, NULL,
0
,
*
IoDriverObjectType, KernelMode, NULL, (PVOID
*
)&g_Con);
if
(!NT_SUCCESS(status))
[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)