smode
+135 byte enablestackswap
+136 byte largestack
+137 byte resourceindex
+138 uint32 kerneltime
+13c uint32 usertime
+140 struct _kapc_state savedapcstate
+158 byte alertable
+159 byte apcstateindex
+15a byte apcqueueable
+15b byte autoalignment
+15c void *stackbase
+160 struct _kapc suspendapc
+190 struct _ksemaphore suspendsemaphore
+1a4 struct _list_entry threadlistentry
+1ac char freezecount
+1ad char suspendcount
+1ae byte idealprocessor
+1af byte disableboost
在偏移0x5c处有一个waitlistentry成员,这个就是用来链接到线程调度链表的。在偏移0x34处有一个apcstate成员结构,在apcstate中的process域就是指向当前线程关联的进程的kprocess块,由于kprocess块是eprocess块的第一个元素,所以找到了kprocess块指针也就是找到了eprocess块的指针。找到了eprocess就不用多少了,就可以取得当前线程的进程的名字,id号等。
2. 线程调度
在windows系统中,线程调度主要分成三条主要的调度链表。分别是kiwaitinlisthead, kiwaitoutlisthead,kidispatcherreadylisthead,分别是两条阻塞链,一条就绪链表,当线程获得cpu执行的时候,系统分配一, , 个时间片给线程,当发生一次时钟中断就从分配的时间片上减去一个时钟中断的值,如果这个值小于零了也就是时间片用完了,那么这个线程根据其优先级载入到相应的就绪队列末尾。kidispatcherreadylisthead是一个数组链的头部,在windows 2000中它包含有32个队列,分别对应线程的32个优先级。如果线程因为同步,或者是对外设请求,那么阻塞线程,让出cpu的所有权,加如到阻塞队列里面去。cpu从就绪队列里面,按照优先权的前后,重新调度新的线程的执行。当阻塞队列里面的线程获得所需求的资源,或者是同步完成就又重新加到就绪队列里面等待执行。
3.通过线程调度链表进行隐藏进程的检测
void displaylist(plist_entry listhead)
{
plist_entry list = listhead->flink;
if ( list == listhead )
{
// dbgprint("return\n");
return;
}
plist_entry nextlist = list;
while ( nextlist != listhead )
{
pkthread thread = ontaining_record(nextlist, kthread, waitlistentry);
pkprocess process = thread->apcstate.process;
peprocess peprocess = (peprocess)process;
dbgprint("imagefilename = %s \n",peprocess->imagefilename);
nextlist = nextlist->flink;
}
}
以上是对一条链进行进程枚举。所以我们必须找到kiwaitinlistheadkiwaitoutlistheadkidispatcherreadylisthead的地址,由于他们都没有被ntoskrnl.exe导出来,所以只有通过硬编码的办法给他们赋值。通过内核调试器,能找到(windows2000 sp4):
plist_entry kiwaitinlisthead = (plist_entry)0x80482258;
plist_entry kidispatcherreadylisthead = (plist_entry)0x804822e0;
plist_entry kiwaitoutlisthead = (plist_entry)0x80482808;
遍历所有的线程调度链表。
for ( i =0; i<32 ;i++ )
{
displaylist(kidispatcherreadylisthead+i);
}
displaylist(kiwaitinlisthead);
displaylist(kiwaitoutlisthead
<< 上一页 [11] [12] [13] [14] 下一页