sysenter后如何找到内核里的对应函数的

来源:互联网 发布:相册mv制作软件 编辑:程序博客网 时间:2024/06/02 03:57

比如,我们调用ntdll!NtReadFile后,如何进入内核的?很多书、文章都描述了,那么在调用到sysenter以后,内核是如何找到对应的函数的?

还是需要通过SSDT,但是nt!KiFastCallEntry却没有了nt!KiSystemService的踪迹。

跟踪前,先找到SSDT的地址

接下里,我们看下SSDT表的地址

kd> dd KeServiceDescriptorTable
80553fa0  80502b8c 00000000 0000011c 80503000
80553fb0  00000000 00000000 00000000 00000000
80553fc0  00000000 00000000 00000000 00000000
80553fd0  00000000 00000000 00000000 00000000
80553fe0  00002710 bf80c0b6 00000000 00000000

反汇编nt!KiFastCallEntry,进行单步跟踪

kd> u nt!KiFastCallEntry L50
nt!KiFastCallEntry:
8053e540 b923000000      mov     ecx,23h
8053e545 6a30            push    30h
8053e547 0fa1            pop     fs
8053e549 8ed9            mov     ds,cx
8053e54b 8ec1            mov     es,cx
8053e54d 8b0d40f0dfff    mov     ecx,dword ptr ds:[0FFDFF040h]  //TSS(ring0时,fs:[0]、ds:[ffdff000] 处是一个叫做KPCR 的结构)
8053e553 8b6104          mov     esp,dword ptr [ecx+4]
8053e556 6a23            push    23h
8053e558 52              push    edx
8053e559 9c              pushfd
8053e55a 6a02            push    2
8053e55c 83c208          add     edx,8
8053e55f 9d              popfd
8053e560 804c240102      or      byte ptr [esp+1],2
8053e565 6a1b            push    1Bh
8053e567 ff350403dfff    push    dword ptr ds:[0FFDF0304h]
8053e56d 6a00            push    0
8053e56f 55              push    ebp
8053e570 53              push    ebx
8053e571 56              push    esi
8053e572 57              push    edi
8053e573 8b1d1cf0dfff    mov     ebx,dword ptr ds:[0FFDFF01Ch]   //EBX=KPCR.SelfPcr
8053e579 6a3b            push    3Bh
8053e57b 8bb324010000    mov     esi,dword ptr [ebx+124h]           //ESI=KTHREAD
8053e581 ff33            push    dword ptr [ebx]
..........................................................................//此处滤去

8053e5cc fb              sti
8053e5cd 8bf8            mov     edi,eax
8053e5cf c1ef08          shr     edi,8
8053e5d2 83e730          and     edi,30h
8053e5d5 8bcf            mov     ecx,edi
8053e5d7 03bee0000000    add     edi,dword ptr [esi+0E0h]   //ssdt在这里,详细看_KTHREAD结构的,0x0e0 ServiceTable
8053e5dd 8bd8            mov     ebx,eax
8053e5df 25ff0f0000      and     eax,0FFFh
8053e5e4 3b4708          cmp     eax,dword ptr [edi+8]
..........................................................................//此处滤去
8053e60a 58              pop     eax
8053e60b 5a              pop     edx
8053e60c ff0538f6dfff    inc     dword ptr ds:[0FFDFF638h]
8053e612 8bf2            mov     esi,edx
8053e614 8b5f0c          mov     ebx,dword ptr [edi+0Ch]
8053e617 33c9            xor     ecx,ecx
8053e619 8a0c18          mov     cl,byte ptr [eax+ebx]
8053e61c 8b3f            mov     edi,dword ptr [edi]
8053e61e 8b1c87          mov     ebx,dword ptr [edi+eax*4]    //找到SSDT,对应的函数地址
8053e621 2be1            sub     esp,ecx
8053e623 c1e902          shr     ecx,2
8053e626 8bfc            mov     edi,esp
8053e628 3b35d4995580    cmp     esi,dword ptr [nt!MmUserProbeAddress (805599d4)]
8053e62e 0f83a8010000    jae     nt!KiSystemCallExit2+0x9f (8053e7dc)
8053e634 f3a5            rep movs dword ptr es:[edi],dword ptr [esi]
8053e636 ffd3            call    ebx                                                                  //这里调用了对应的函数。如nt!NtReadFile
8053e638 8be5            mov     esp,ebp
8053e63a 8b0d24f1dfff    mov     ecx,dword ptr ds:[0FFDFF124h]


kd> dt _KTHREAD

ntdll!_KTHREAD
   +0x000 Header           : _DISPATCHER_HEADER
   +0x010 MutantListHead   : _LIST_ENTRY
   +0x018 InitialStack     : Ptr32 Void
   +0x01c StackLimit       : Ptr32 Void
   +0x020 Teb              : Ptr32 Void
   +0x024 TlsArray         : Ptr32 Void
   +0x028 KernelStack      : Ptr32 Void
   +0x02c DebugActive      : UChar
   +0x02d State            : UChar
   +0x02e Alerted          : [2] UChar
   +0x030 Iopl             : UChar
   +0x031 NpxState         : UChar
   +0x032 Saturation       : Char
   +0x033 Priority         : Char
   +0x034 ApcState         : _KAPC_STATE
   +0x04c ContextSwitches  : Uint4B
   +0x050 IdleSwapBlock    : UChar
   +0x051 Spare0           : [3] UChar
   +0x054 WaitStatus       : Int4B
   +0x058 WaitIrql         : UChar
   +0x059 WaitMode         : Char
   +0x05a WaitNext         : UChar
   +0x05b WaitReason       : UChar
   +0x05c WaitBlockList    : Ptr32 _KWAIT_BLOCK
   +0x060 WaitListEntry    : _LIST_ENTRY
   +0x060 SwapListEntry    : _SINGLE_LIST_ENTRY
   +0x068 WaitTime         : Uint4B
   +0x06c BasePriority     : Char
   +0x06d DecrementCount   : UChar
   +0x06e PriorityDecrement : Char
   +0x06f Quantum          : Char
   +0x070 WaitBlock        : [4] _KWAIT_BLOCK
   +0x0d0 LegoData         : Ptr32 Void
   +0x0d4 KernelApcDisable : Uint4B
   +0x0d8 UserAffinity     : Uint4B
   +0x0dc SystemAffinityActive : UChar
   +0x0dd PowerState       : UChar
   +0x0de NpxIrql          : UChar
   +0x0df InitialNode      : UChar
   +0x0e0 ServiceTable     : Ptr32 Void
   +0x0e4 Queue            : Ptr32 _KQUEUE
   +0x0e8 ApcQueueLock     : Uint4B
   +0x0f0 Timer            : _KTIMER
   +0x118 QueueListEntry   : _LIST_ENTRY
   +0x120 SoftAffinity     : Uint4B
   +0x124 Affinity         : Uint4B
   +0x128 Preempted        : UChar
   +0x129 ProcessReadyQueue : UChar
   +0x12a KernelStackResident : UChar
   +0x12b NextProcessor    : UChar
   +0x12c CallbackStack    : Ptr32 Void
   +0x130 Win32Thread      : Ptr32 Void
   +0x134 TrapFrame        : Ptr32 _KTRAP_FRAME
   +0x138 ApcStatePointer  : [2] Ptr32 _KAPC_STATE
   +0x140 PreviousMode     : Char
   +0x141 EnableStackSwap  : UChar
   +0x142 LargeStack       : UChar
   +0x143 ResourceIndex    : UChar
   +0x144 KernelTime       : Uint4B
   +0x148 UserTime         : Uint4B
   +0x14c SavedApcState    : _KAPC_STATE
   +0x164 Alertable        : UChar
   +0x165 ApcStateIndex    : UChar
   +0x166 ApcQueueable     : UChar
   +0x167 AutoAlignment    : UChar
   +0x168 StackBase        : Ptr32 Void
   +0x16c SuspendApc       : _KAPC
   +0x19c SuspendSemaphore : _KSEMAPHORE
   +0x1b0 ThreadListEntry  : _LIST_ENTRY
   +0x1b8 FreezeCount      : Char
   +0x1b9 SuspendCount     : Char
   +0x1ba IdealProcessor   : UChar
   +0x1bb DisableBoost     : UChar

原创粉丝点击