FAULTING_IP:
nt!SeCreateAccessStateEx+5b
80564184 848788000000 test byte ptr [edi+88h],al
TRAP_FRAME: f1c6756c -- (.trap 0xfffffffff1c6756c)
ErrCode = 00000000
eax=00000001 ebx=81be08e0 ecx=819a7af4 edx=00000000 esi=81be0994 edi=00000000
eip=80564184 esp=f1c675e0 ebp=f1c675ec iopl=0 nv up ei pl nz na po nc
cs=0008 ss=0010 ds=0023 es=0023 fs=0030 gs=0000 efl=00010202
nt!SeCreateAccessStateEx+0x5b:
80564184 848788000000 test byte ptr [edi+88h],al ds:0023:00000088=??
PROCESS_NAME: drwtsn32.exe
LAST_CONTROL_TRANSFER: from 805641e9 to 80564184
STACK_TEXT:
f1c675ec 805641e9 81baada8 819a7a88 81be08e0 nt!SeCreateAccessStateEx+0x5b
f1c6760c 80568481 81be08e0 81be0994 00100001 nt!SeCreateAccessState+0x28
f1c67644 8056cbeb 00000000 00000000 9a7a8800 nt!ObOpenObjectByName+0x90
f1c676c0 80579c80 f1c67778 00100001 f1c67758 nt!IopCreateFile+0x407
f1c67708 f7450c79 f1c67778 00100001 f1c67758 nt!IoCreateFileSpecifyDeviceObjectHint+0x52
f1c6777c f7450f63 821c5128 f1c677b4 f7451480 fltmgr!FltpNormalizeNameComponent+0x75
f1c67788 f7451480 821c5128 00000000 821c5128 fltmgr!FltpCallNormalizeNameComponentHandler+0x41
f1c677b4 f745215a 00000052 00000000 821c5128 fltmgr!FltpExpandShortNames+0x110
f1c677d0 f745276b 00005128 00000000 000000fe fltmgr!FltpGetNormalizedFileNameWorker+0x90
f1c677e8 f74502a2 821c5128 00000000 821c5128 fltmgr!FltpGetNormalizedFileName+0x19
f1c67800 f7450365 80552000 821c5128 f1c6783c fltmgr!FltpCreateFileNameInformation+0x84
f1c67810 f7440e0a 821c5128 822fdf14 00000000 fltmgr!CreateTemporaryFileNameInformation+0xf
f1c6783c f7441366 821c5128 821ec694 f1c678c4 fltmgr!FltpGetFileNameInformation+0xaa
f1c67864 f776bef5 122fdf14 00000101 f1c67888 fltmgr!FltGetFileNameInformation+0x114
f1c678a4 f743c888 822fdf14 f1c678c4 f1c678f4 mydrv!PreCleanup+0xf5
可见是访问了一个空指针导致的蓝屏,那这个BUG是怎么触发的?
PAGE:00495A13 push edi
PAGE:00495A14 push [ebp+arg_4]
PAGE:00495A17 mov [ebx+30h], esi
PAGE:00495A1A push [ebp+arg_0]
PAGE:00495A1D call _SeCaptureSubjectContextEx@12 ; SeCaptureSubjectContextEx(x,x,x)
PAGE:00495A22 mov edi, [edi]
PAGE:00495A24 test edi, edi
PAGE:00495A26 jnz short loc_495A2B -? 这里虽然判断了EDI是否为空,但为空还是继续走到下条指令
PAGE:00495A28 mov edi, [ebx+24h]
PAGE:00495A2B
PAGE:00495A2B loc_495A2B: ; CODE XREF: SeCreateAccessStateEx(x,x,x,x,x,x)+45 j
PAGE:00495A2B xor eax, eax
PAGE:00495A2D inc eax
PAGE:00495A2E test [edi+88h], al
可见是 _SeCaptureSubjectContextEx的第三个参数返回有问题. 第三个参数是指向如下结构体
typedef struct _SECURITY_SUBJECT_CONTEXT {
PACCESS_TOKEN ClientToken; -> 这里是ClientToken 为空.
SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
PACCESS_TOKEN PrimaryToken;
PVOID ProcessAuditId;
} SECURITY_SUBJECT_CONTEXT, *PSECURITY_SUBJECT_CONTEXT;
为啥 ClientToken 会空?根据进入 SeCaptureSubjectContextEx 发现有俩种情况 ClientToken 会空, 一种是当前线程为NULL,一种是PsReferenceImpersonationToken返回了NULL,很显然是第二种
PsReferenceImpersonationToken的入口有这么几条指令
PAGE:004952A8 mov ebp, esp
PAGE:004952AA push ebx
PAGE:004952AB mov ebx, [ebp+arg_0]
PAGE:004952AE test byte ptr [ebx+248h], 8
PAGE:004952B5 jnz loc_4A218F
PAGE:004952BB xor eax, eax
PAGE:004952BD
PAGE:004952BD loc_4952BD: ; CODE XREF: PsReferenceImpersonationToken(x,x,x,x)+CF79 j
PAGE:004952BD pop ebx
PAGE:004952BE pop ebp
PAGE:004952BF retn 10h
大意就是 test byte ptr [ebx+248h], 8 如果为真,就返回NULL,其实就是判断线程是否要结束,查看当前的线程情况
dt _ETHREAD @$thread
….
+0x248 Terminated : 0y1
+0x248 DeadThread : 0y0
+0x248 HideFromDebugger : 0y0
+0x248 ActiveImpersonationInfo : 0y0
所以这个BUG就是这么触发的。虽然是微软的BUG,但我们是增添了触发这个BUG的概率,因为我们的FILTER调用了 FltGetFileNameInformation 导致触发了这个BUG
结论: XP上,在PreCleanup上调用FltGetFileNameInformation要判断当前线程是否Terminated