rootkit ring3进ring0之门系列[三] -- 任务门
http://bbs.pediy.com/showthread.php?t=62510
来练习一下^^
先在GDT表中找出所有的TSS段描述符
0028 80042000 000020AB 0 P 1b 32-Bit TSS (Busy)
//0050 8054A300 00000068 0 P 1b 32-Bit TSS (Available)
//0058 8054A368 00000068 0 P 1b 32-Bit TSS (Available)
00A0 80ED5B30 00000068 0 P 1b 32-Bit TSS (Available)
kd> !pcr
.
.
IDT: 8003f400
GDT: 8003f000
TSS: 80042000
.
/*全局了解的信息*/
-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------
/*下面是在运行11.exe之前的信息*/
kd> !process
PROCESS 80552d80 SessionId: none Cid: 0000 Peb: 00000000 ParentCid: 0000
DirBase: 00aee000 ObjectTable: e1000a80 HandleCount: 322.
Image: Idle
kd> r cr3
cr3=00aee000
kd> !process 0 0
PROCESS ffae0b30 SessionId: 0 Cid: 00c0 Peb: 7ffd6000 ParentCid: 00bc
DirBase: 02980280 ObjectTable: e154e4e8 HandleCount: 7.
Image: 11.exe
kd> dt _KTSS 80042000 //Busy Task
nt!_KTSS
+0x000 Backlink : 0
+0x002 Reserved0 : 0x838d
+0x004 Esp0 : 0x8054a0f0
+0x008 Ss0 : 0x10
+0x00a Reserved1 : 0xb9fc
+0x00c NotUsed1 : [4] 0x1000
+0x01c CR3 : 0xaee000
+0x020 Eip : 0x14453b02
+0x024 EFlags : 0x8a870f
+0x028 Eax : 0xc18b0000
+0x02c Ecx : 0x8d02e9c1
+0x030 Edx : 0xfb8b0272
+0x034 Ebx : 0xc88ba5f3
+0x038 Esp : 0xf303e183
+0x03c Ebp : 0xc5d03a4
+0x040 Esi : 0x3bf8558b
+0x044 Edi : 0x7174fc5d
+0x048 Es : 0x458b
+0x04a Reserved2 : 0x8314
+0x04c Cs : 0xfec0
+0x04e Reserved3 : 0xd03b
+0x050 Ss : 0x6777
+0x052 Reserved4 : 0xc2f6
+0x054 Ds : 0x7401
+0x056 Reserved5 : 0x8a0d
+0x058 Fs : 0x8802
+0x05a Reserved6 : 0x1045
+0x05c Gs : 0x428a
+0x05e Reserved7 : 0x8801
+0x060 LDT : 0
+0x062 Reserved8 : 0x7eb
+0x064 Flags : 0
+0x066 IoMapBase : 0x20ac
+0x068 IoMaps : [1] _KiIoAccessMap
+0x208c IntDirectionMap : [32] "???"
kd> dt _KTSS 80ED5B30 //Available Task We Need
nt!_KTSS
+0x000 Backlink : 0
+0x002 Reserved0 : 0
+0x004 Esp0 : 0x80547300
+0x008 Ss0 : 0x10
+0x00a Reserved1 : 0
+0x00c NotUsed1 : [4] 0
+0x01c CR3 : 0xaee000
+0x020 Eip : 0x806cfbe8 //here!
+0x024 EFlags : 0
+0x028 Eax : 0
+0x02c Ecx : 0
+0x030 Edx : 0
+0x034 Ebx : 0
+0x038 Esp : 0x80547300
+0x03c Ebp : 0
+0x040 Esi : 0
+0x044 Edi : 0
+0x048 Es : 0x23
+0x04a Reserved2 : 0
+0x04c Cs : 8
+0x04e Reserved3 : 0
+0x050 Ss : 0x10
+0x052 Reserved4 : 0
+0x054 Ds : 0x23
+0x056 Reserved5 : 0
+0x058 Fs : 0x30
+0x05a Reserved6 : 0
+0x05c Gs : 0
+0x05e Reserved7 : 0
+0x060 LDT : 0
+0x062 Reserved8 : 0
+0x064 Flags : 0
+0x066 IoMapBase : 0x20ad
+0x068 IoMaps : [1] _KiIoAccessMap
+0x208c IntDirectionMap : [32] "???"
/*两个任务的Esp0不同!!!*/
kd> bp 0x806cfbe8
kd> g
-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------
/*下面是在运行11.exe之后中断到WinDBG的信息*/
806cfbe8 fa cli
WARNING: Process directory table base 02980280 doesn't match CR3 00AEE000
WARNING: Process directory table base 02980280 doesn't match CR3 00AEE000
kd> u
806cfbe8 fa cli
806cfbe9 ff3540f0dfff push dword ptr ds:[0FFDFF040h]
806cfbef a13cf0dfff mov eax,dword ptr ds:[FFDFF03Ch]
806cfbf4 8aa8a7000000 mov ch,byte ptr [eax+0A7h]
806cfbfa 8a88a4000000 mov cl,byte ptr [eax+0A4h]
806cfc00 c1e110 shl ecx,10h
806cfc03 668b88a2000000 mov cx,word ptr [eax+0A2h]
806cfc0a 890d40f0dfff mov dword ptr ds:[0FFDFF040h],ecx
kd> r tr
tr=000000a0 //OK!
kd> r cr3 ,esp, eip
cr3=00aee000 esp=80547300 eip=806cfbe8 //哈哈!确实切换了!
kd> dt _KTSS 80ED5B30 //现在的任务!!
nt!_KTSS
+0x000 Backlink : 0x28 //上一个任务,哈哈!没错!!
+0x002 Reserved0 : 0
+0x004 Esp0 : 0x80547300
+0x008 Ss0 : 0x10
+0x00a Reserved1 : 0
+0x00c NotUsed1 : [4] 0
+0x01c CR3 : 0xaee000
+0x020 Eip : 0x806cfbe8
+0x024 EFlags : 0
+0x028 Eax : 0
+0x02c Ecx : 0
+0x030 Edx : 0
+0x034 Ebx : 0
+0x038 Esp : 0x80547300
+0x03c Ebp : 0
+0x040 Esi : 0
+0x044 Edi : 0
+0x048 Es : 0x23
+0x04a Reserved2 : 0
+0x04c Cs : 8
+0x04e Reserved3 : 0
+0x050 Ss : 0x10
+0x052 Reserved4 : 0
+0x054 Ds : 0x23
+0x056 Reserved5 : 0
+0x058 Fs : 0x30
+0x05a Reserved6 : 0
+0x05c Gs : 0
+0x05e Reserved7 : 0
+0x060 LDT : 0
+0x062 Reserved8 : 0
+0x064 Flags : 0
+0x066 IoMapBase : 0x20ad
+0x068 IoMaps : [1] _KiIoAccessMap
+0x208c IntDirectionMap : [32] "???"
kd> dt _KTSS 80042000
nt!_KTSS
+0x000 Backlink : 0
+0x002 Reserved0 : 0x838d
+0x004 Esp0 : 0xfa399de0
+0x008 Ss0 : 0x10
+0x00a Reserved1 : 0xb9fc
+0x00c NotUsed1 : [4] 0x1000
+0x01c CR3 : 0x2980280 //没错
+0x020 Eip : 0x40103c //还真是,哈哈!!
+0x024 EFlags : 0x346
+0x028 Eax : 0
+0x02c Ecx : 0
+0x030 Edx : 0x430a00
+0x034 Ebx : 0x7ffd6000
+0x038 Esp : 0x12ff2c
+0x03c Ebp : 0x12ff80
+0x040 Esi : 0xffffffff
+0x044 Edi : 0x12ff80
+0x048 Es : 0x23
+0x04a Reserved2 : 0x8314
+0x04c Cs : 0x1b
+0x04e Reserved3 : 0xd03b
+0x050 Ss : 0x23
+0x052 Reserved4 : 0xc2f6
+0x054 Ds : 0x23
+0x056 Reserved5 : 0x8a0d
+0x058 Fs : 0x3b
+0x05a Reserved6 : 0x1045
+0x05c Gs : 0
+0x05e Reserved7 : 0x8801
+0x060 LDT : 0
+0x062 Reserved8 : 0x7eb
+0x064 Flags : 0
+0x066 IoMapBase : 0x20ac
+0x068 IoMaps : [1] _KiIoAccessMap
+0x208c IntDirectionMap : [32] "???"
kd> dd esp //看看堆栈,哦晕!
80547300 00000000 00000000 00000000 00000000
80547310 00000000 00000000 00000000 00000000
80547320 00000000 00000000 00000000 00000000
80547330 00000000 00000000 00000000 00000000
kd> .formats efl //看看EFLAGS
Evaluate expression:
Hex: 00004002
Decimal: 16386
Octal: 00000040002
Binary: 00000000 00000000 01000000 00000010
/*看到NT(第15)位吧,iret的时候看NT=1,所以返回时堆栈是没用的,Intel也就不在call时压栈了
但int时候应该有(返回时也是没用的,没试过!)*/
kd> u eip L1A
806cfbe8 fa cli
806cfbe9 ff3540f0dfff push dword ptr ds:[0FFDFF040h]
806cfbef a13cf0dfff mov eax,dword ptr ds:[FFDFF03Ch]
806cfbf4 8aa8a7000000 mov ch,byte ptr [eax+0A7h]
806cfbfa 8a88a4000000 mov cl,byte ptr [eax+0A4h]
806cfc00 c1e110 shl ecx,10h
806cfc03 668b88a2000000 mov cx,word ptr [eax+0A2h]
806cfc0a 890d40f0dfff mov dword ptr ds:[0FFDFF040h],ecx
806cfc10 8b0d3cf0dfff mov ecx,dword ptr ds:[0FFDFF03Ch]
806cfc16 8d81a0000000 lea eax,[ecx+0A0h]
806cfc1c c6400589 mov byte ptr [eax+5],89h
806cfc20 9c pushfd
806cfc21 812424ffbfffff and dword ptr [esp],0FFFFBFFFh
806cfc28 9d popfd
806cfc29 e8d44b0000 call 806d4802
806cfc2e 8f0540f0dfff pop dword ptr ds:[0FFDFF040h]
806cfc34 8b0d3cf0dfff mov ecx,dword ptr ds:[0FFDFF03Ch]
806cfc3a 8d4128 lea eax,[ecx+28h]
806cfc3d c640058b mov byte ptr [eax+5],8Bh
806cfc41 9c pushfd
806cfc42 810c2400400000 or dword ptr [esp],4000h //NT位置1,为了保险!
806cfc49 9d popfd
806cfc4a cf iretd
806cfc4b eb9b jmp 806cfbe8 //任务结束后EIP指向的地方,所以一定要跑回去!
806cfc4d cc int 3
806cfc4e cc int 3
注意千万不要单步iret,否则系统会挂掉的!因为windbg会根据压入栈中的EIP下int3断点,但call任务门是不压栈的,所以……
(困了我很久……)