WIN7 X64 SSDT函数获得

曾经在网上看到一片文章,

在早期64位系统,内核函数开头地址的低四位一般是0,形如:xxxxxxxx`xxxxxxx0,这一特征在SSDT表中有很强大的引用,SSDT表在64位系统于32位系统有较大的差别。以下是在64位系统下的KeServiceDescriptorTable:

  1. kd> dp KeServiceDescriptorTable
  2. fffff800`0117bb80  fffff800`01076e00 00000000`00000000
  3. fffff800`0117bb90  00000000`00000128 00000000`00000000
复制代码


表的第二项于第四项都为0,这两项在32位系统下分别对应ServiceCounterTableBase与ParamTableBase。SSDT表还是同32位系统每4字节表示一项,由于函数的起始地址最低四位都是0,所以微软将SSDT中的低四位用来记录这个函数有多少个参数。并且由于表的每一项都为四个字节,保存的就不可能是绝对地址,而是相对KeServiceDescriptorTable表的地址。所以地址计算方法如下:

  1. FuncAddr=([KeServiceDescriptortable+index*4]+KeServiceDescriptortable)&0xFFFFFFF0
复制代码


用公式,尝试了一下,果然找到了正确的地址。



不过到了WIN7 X64下又有所改变 。

  1. nt!KiSystemServiceStart+0x7:
  2. fffff800`03cc7fe5 8bf8            mov     edi,eax ; copy system service number
  3. kd> p
  4. nt!KiSystemServiceStart+0x9:
  5. fffff800`03cc7fe7 c1ef07          shr     edi,7   ; isolate service table number(SERVICE_TABLE_SHIFT)
  6. kd> p
  7. nt!KiSystemServiceStart+0xc:
  8. fffff800`03cc7fea 83e720          and     edi,20h ;(SERVICE_TABLE_MASK)
  9. kd> p
  10. nt!KiSystemServiceStart+0xf:
  11. fffff800`03cc7fed 25ff0f0000      and     eax,0FFFh ;(SERVICE_NUMBER_MASK )isolate service table offset 0fffh
  12. kd> r
  13. rax=0000000000000138 rbx=fffffa800edc0100 rcx=0000000000000084
  14. rdx=0000000000000000 rsi=00000000002a8490 rdi=0000000000000000
  15. rip=fffff80003cc7fed rsp=fffff8800245dc20 rbp=fffff8800245dca0
  16. r8=0000000000000001  r9=0000000000000001 r10=0000000000000084
  17. r11=0000000000000206 r12=00000000772c4420 r13=0000000000000000
  18. r14=00000000772c4400 r15=00000000772c4498
  19. iopl=0         nv up ei pl zr na po nc
  20. cs=0010  ss=0018  ds=002b  es=002b  fs=0053  gs=002b             efl=00000246
  21. nt!KiSystemServiceStart+0xf:
  22. fffff800`03cc7fed 25ff0f0000      and     eax,0FFFh
  23. kd> p
  24. nt!KiSystemServiceRepeat:
  25. fffff800`03cc7ff2 4c8d1547782300  lea     r10,[nt!KeServiceDescriptorTable (fffff800`03eff840)]
  26. kd> r
  27. rax=0000000000000138 rbx=fffffa800edc0100 rcx=0000000000000084
  28. rdx=0000000000000000 rsi=00000000002a8490 rdi=0000000000000000
  29. rip=fffff80003cc7ff2 rsp=fffff8800245dc20 rbp=fffff8800245dca0
  30. r8=0000000000000001  r9=0000000000000001 r10=0000000000000084
  31. r11=0000000000000206 r12=00000000772c4420 r13=0000000000000000
  32. r14=00000000772c4400 r15=00000000772c4498
  33. iopl=0         nv up ei pl nz na pe nc
  34. cs=0010  ss=0018  ds=002b  es=002b  fs=0053  gs=002b             efl=00000202
  35. nt!KiSystemServiceRepeat:
  36. fffff800`03cc7ff2 4c8d1547782300  lea     r10,[nt!KeServiceDescriptorTable (fffff800`03eff840)]
  37. kd> p
  38. nt!KiSystemServiceRepeat+0x7:
  39. fffff800`03cc7ff9 4c8d1d80782300  lea     r11,[nt!KeServiceDescriptorTableShadow (fffff800`03eff880)]
  40. kd> p
  41. nt!KiSystemServiceRepeat+0xe:
  42. fffff800`03cc8000 f7830001000080000000 test dword ptr [rbx+100h],80h
  43. kd> r
  44. rax=0000000000000138 rbx=fffffa800edc0100 rcx=0000000000000084
  45. rdx=0000000000000000 rsi=00000000002a8490 rdi=0000000000000000
  46. rip=fffff80003cc8000 rsp=fffff8800245dc20 rbp=fffff8800245dca0
  47. r8=0000000000000001  r9=0000000000000001 r10=fffff80003eff840
  48. r11=fffff80003eff880 r12=00000000772c4420 r13=0000000000000000
  49. r14=00000000772c4400 r15=00000000772c4498
  50. iopl=0         nv up ei pl nz na pe nc
  51. cs=0010  ss=0018  ds=002b  es=002b  fs=0053  gs=002b             efl=00000202
  52. nt!KiSystemServiceRepeat+0xe:
  53. fffff800`03cc8000 f7830001000080000000 test dword ptr [rbx+100h],80h ds:002b:fffffa80`0edc0200=00000060
  54. kd> db fffff800`03eff840
  55. fffff800`03eff840  00 9b cc 03 00 f8 ff ff-00 00 00 00 00 00 00 00  ................
  56. fffff800`03eff850  91 01 00 00 00 00 00 00-8c a7 cc 03 00 f8 ff ff  ................
  57. fffff800`03eff860  00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  ................
  58. fffff800`03eff870  00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  ................
  59. fffff800`03eff880  00 9b cc 03 00 f8 ff ff-00 00 00 00 00 00 00 00  ................
  60. fffff800`03eff890  91 01 00 00 00 00 00 00-8c a7 cc 03 00 f8 ff ff  ................
  61. fffff800`03eff8a0  00 1c 0e 00 60 f9 ff ff-00 00 00 00 00 00 00 00  ....`...........
  62. fffff800`03eff8b0  3b 03 00 00 00 00 00 00-1c 39 0e 00 60 f9 ff ff  ;........9..`...
  63. kd> p
  64. nt!KiSystemServiceRepeat+0x18:
  65. fffff800`03cc800a 4d0f45d3        cmovne  r10,r11
  66. kd> p
  67. nt!KiSystemServiceRepeat+0x1c:
  68. fffff800`03cc800e 423b441710      cmp     eax,dword ptr [rdi+r10+10h] ;check if valid service
  69. kd> r
  70. rax=0000000000000138 rbx=fffffa800edc0100 rcx=0000000000000084
  71. rdx=0000000000000000 rsi=00000000002a8490 rdi=0000000000000000
  72. rip=fffff80003cc800e rsp=fffff8800245dc20 rbp=fffff8800245dca0
  73. r8=0000000000000001  r9=0000000000000001 r10=fffff80003eff840
  74. r11=fffff80003eff880 r12=00000000772c4420 r13=0000000000000000
  75. r14=00000000772c4400 r15=00000000772c4498
  76. iopl=0         nv up ei pl zr na po nc
  77. cs=0010  ss=0018  ds=002b  es=002b  fs=0053  gs=002b             efl=00000246
  78. nt!KiSystemServiceRepeat+0x1c:
  79. fffff800`03cc800e 423b441710      cmp     eax,dword ptr [rdi+r10+10h] ds:002b:fffff800`03eff850=00000191
  80. kd> p
  81. nt!KiSystemServiceRepeat+0x21:
  82. fffff800`03cc8013 0f83e9020000    jae     nt!KiSystemServiceExit+0x1a7 (fffff800`03cc8302)
  83. kd> p
  84. nt!KiSystemServiceRepeat+0x27:
  85. fffff800`03cc8019 4e8b1417        mov     r10,qword ptr [rdi+r10] ;table base
  86. kd> p
  87. nt!KiSystemServiceRepeat+0x2b:
  88. fffff800`03cc801d 4d631c82        movsxd  r11,dword ptr [r10+rax*4] ; get system service offset
  89. kd> r
  90. rax=0000000000000138 rbx=fffffa800edc0100 rcx=0000000000000084
  91. rdx=0000000000000000 rsi=00000000002a8490 rdi=0000000000000000
  92. rip=fffff80003cc801d rsp=fffff8800245dc20 rbp=fffff8800245dca0
  93. r8=0000000000000001  r9=0000000000000001 r10=fffff80003cc9b00
  94. r11=fffff80003eff880 r12=00000000772c4420 r13=0000000000000000
  95. r14=00000000772c4400 r15=00000000772c4498
  96. iopl=0         nv up ei ng nz na pe cy
  97. cs=0010  ss=0018  ds=002b  es=002b  fs=0053  gs=002b             efl=00000283
  98. nt!KiSystemServiceRepeat+0x2b:
  99. fffff800`03cc801d 4d631c82        movsxd  r11,dword ptr [r10+rax*4] ds:002b:fffff800`03cc9fe0=000f3080
  100. kd> p
  101. nt!KiSystemServiceRepeat+0x2f:
  102. fffff800`03cc8021 498bc3          mov     rax,r11 ; system service offset
  103. kd> r
  104. rax=0000000000000138 rbx=fffffa800edc0100 rcx=0000000000000084
  105. rdx=0000000000000000 rsi=00000000002a8490 rdi=0000000000000000
  106. rip=fffff80003cc8021 rsp=fffff8800245dc20 rbp=fffff8800245dca0
  107. r8=0000000000000001  r9=0000000000000001 r10=fffff80003cc9b00
  108. r11=00000000000f3080 r12=00000000772c4420 r13=0000000000000000
  109. r14=00000000772c4400 r15=00000000772c4498
  110. iopl=0         nv up ei ng nz na pe cy
  111. cs=0010  ss=0018  ds=002b  es=002b  fs=0053  gs=002b             efl=00000283
  112. nt!KiSystemServiceRepeat+0x2f:
  113. fffff800`03cc8021 498bc3          mov     rax,r11
  114. kd> p
  115. nt!KiSystemServiceRepeat+0x32:
  116. fffff800`03cc8024 49c1fb04        sar     r11,4 ;关键所在 ,还得再右移4位
  117. kd> p
  118. nt!KiSystemServiceRepeat+0x36:
  119. fffff800`03cc8028 4d03d3          add     r10,r11 ;; add table base to 获得真正的函数地址
  120. kd> r
  121. rax=00000000000f3080 rbx=fffffa800edc0100 rcx=0000000000000084
  122. rdx=0000000000000000 rsi=00000000002a8490 rdi=0000000000000000
  123. rip=fffff80003cc8028 rsp=fffff8800245dc20 rbp=fffff8800245dca0
  124. r8=0000000000000001  r9=0000000000000001 r10=fffff80003cc9b00
  125. r11=000000000000f308 r12=00000000772c4420 r13=0000000000000000
  126. r14=00000000772c4400 r15=00000000772c4498
  127. iopl=0         nv up ei pl nz na pe nc
  128. cs=0010  ss=0018  ds=002b  es=002b  fs=0053  gs=002b             efl=00000202
  129. nt!KiSystemServiceRepeat+0x36:
  130. fffff800`03cc8028 4d03d3          add     r10,r11
  131. kd> p
  132. nt!KiSystemServiceRepeat+0x39:
  133. fffff800`03cc802b 83ff20          cmp     edi,20h
  134. kd> r
  135. rax=00000000000f3080 rbx=fffffa800edc0100 rcx=0000000000000084
  136. rdx=0000000000000000 rsi=00000000002a8490 rdi=0000000000000000
  137. rip=fffff80003cc802b rsp=fffff8800245dc20 rbp=fffff8800245dca0
  138. r8=0000000000000001  r9=0000000000000001 r10=fffff80003cd8e08
  139. r11=000000000000f308 r12=00000000772c4420 r13=0000000000000000
  140. r14=00000000772c4400 r15=00000000772c4498
  141. iopl=0         nv up ei ng nz na pe nc
  142. cs=0010  ss=0018  ds=002b  es=002b  fs=0053  gs=002b             efl=00000282
  143. nt!KiSystemServiceRepeat+0x39:
  144. fffff800`03cc802b 83ff20          cmp     edi,20h
  145. kd> u fffff80003cd8e08
  146. nt!NtReleaseWorkerFactoryWorker:
  147. fffff800`03cd8e08 4c8bdc          mov     r11,rsp
  148. fffff800`03cd8e0b 49895b08        mov     qword ptr [r11+8],rbx
  149. fffff800`03cd8e0f 49896b18        mov     qword ptr [r11+18h],rbp
  150. fffff800`03cd8e13 49897320        mov     qword ptr [r11+20h],rsi
  151. fffff800`03cd8e17 57              push    rdi
  152. fffff800`03cd8e18 4154            push    r12
  153. fffff800`03cd8e1a 4155            push    r13
  154. fffff800`03cd8e1c 4883ec60        sub     rsp,60h
  155. kd> p
  156. nt!KiSystemServiceRepeat+0x3c:
  157. fffff800`03cc802e 7550            jne     nt!KiSystemServiceGdiTebAccess+0x49 (fffff800`03cc8080)
  158. kd> p
  159. nt!KiSystemServiceGdiTebAccess+0x49:
  160. fffff800`03cc8080 83e00f          and     eax,0Fh
  161. kd> p
  162. nt!KiSystemServiceGdiTebAccess+0x4c:
  163. fffff800`03cc8083 0f84b7000000    je      nt!KiSystemServiceCopyEnd (fffff800`03cc8140)
  164. kd> p
  165. nt!KiSystemServiceCopyEnd:
  166. fffff800`03cc8140 f705fee4180040000000 test dword ptr [nt!PerfGlobalGroupMask+0x8 (fffff800`03e56648)],40h
  167. kd> p
  168. nt!KiSystemServiceCopyEnd+0xa:
  169. fffff800`03cc814a 0f8550020000    jne     nt!KiSystemServiceExit+0x245 (fffff800`03cc83a0)
  170. kd> p
  171. nt!KiSystemServiceCopyEnd+0x10:
  172. fffff800`03cc8150 41ffd2          call    r10 ; ; call system service
复制代码


所以WIN7 X64下应该是:
  1. FuncAddr=([KeServiceDescriptortable+index*4] >>4 +KeServiceDescriptortable)&0xFFFFFFF0.
复制代码


而且和以前不同的是原来是从ETHREAD里取TABLE 地址,但现在通过 lea     r10,[nt!KeServiceDescriptorTable (fffff800`03eff840)]
,扑灭了ROOTKITER们的最后一线HOOK 希望。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值