偶然在硬盘上翻到了很久之前的一个过滤驱动,源码不知什么时候遗失了,出于研究的
目的将这个驱动逆向了一下,若有错误还望大家多指教。
IDA 载入,在导入表中没有找到特别明显的标志,以 hex 模式查看驱动的时候,在
00011150处发现以下内容:
.text:00011150 5C 00 44 00 65 00 76 00 69 00 63 00 65 00 5C 00
\.D.e.v.i.c.e.\.
.text:00011160 4B 00 65 00 79 00 62 00 6F 00 61 00 72 00 64 00
K.e.y.b.o.a.r.d.
.text:00011170 43 00 6C 00 61 00 73 00 73 00 31 00 00 00 CC CC C.l.a.s.s.1..
Device\KeyboardClass1,百度一下可以知道这是键盘上层过滤驱动的。 只要有keyboard
类的驱动加载,kbdclass就会自动 attach到相应的设备堆栈上。kbdclass然后同时向底层
的设备发送 IOCTL_INTERNAL_KEYBOARD_CONNECT 消息,意思是让底层设备记住一个回调函
数。这样,底层设备(比如 8042 设备,中断得到一个键盘相应,就操作 kdbdclass 提供的
回调函数,把键盘操作的事件插入到队列里)。csrss.exe 的 win32k!RawInputThread 会不
停的把事件取出来,然后转化成windows事件。
驱动的开头如下:
mov eax, [ebp+DriverObject]
mov dword ptr [eax+38h], offset sub_105A0
mov ecx, [ebp+DriverObject]
mov dword ptr [ecx+40h], offset sub_105A0
mov edx, [ebp+DriverObject]
mov dword ptr [edx+44h], offset sub_10B70
push offset SourceString ; \\Device\\HK_KBD //驱动名
lea eax, [ebp+DestinationString]
push eax ; DestinationString
call ds:RtlInitUnicodeString
push offset aDosdevicesHk_k ; "\\DosDevices\\HK_KBD"
lea ecx, [ebp+SymbolicLinkName]
push ecx ; DestinationString
call ds:RtlInitUnicodeString
lea edx, [ebp+DeviceObject]
push edx ; 驱动对象
push 0 ; Exclusive
push 0 ; DeviceCharacteristics
push 22h ; DeviceType
lea eax, [ebp+DestinationString]
push eax ; DeviceName
push 0 ; DeviceExtensionSize
mov ecx, [ebp+DriverObject]
push ecx ; DriverObject
call ds:IoCreateDevice
mov [ebp+var_1C], eax
cmp [ebp+var_1C], 0
jge short loc_10538
这一段汇编码中,驱动定义了设备对象名并创建了此设备,任何内核驱动都可以用
IoCreateDevice 例程创建设备对象,创建成功后,这个函数返回分配的设备对象的指针。
接下来跟踪到此处:
loc_1062D: ; "\\Device"
push offset aDevice
lea eax, [ebp+DestinationString]
push eax ; DestinationString
call ds:RtlInitUnicodeString
mov [ebp+ObjectAttributes.Length], 18h
mov [ebp+ObjectAttributes.RootDirectory], 0
mov [ebp+ObjectAttributes.Attributes], 40h
lea ecx, [ebp+DestinationString]
mov [ebp+ObjectAttributes.ObjectName], ecx
mov [ebp+ObjectAttributes.SecurityDescriptor], 0
mov [ebp+ObjectAttributes.SecurityQualityOfService], 0
lea edx, [ebp+ObjectAttributes] |