首页
社区
课程
招聘
[旧帖] [求助]这样的IDT HOOK为什么在多线程运行的情况下蓝屏?附上代码和DUMP!!! 0.00雪花
发表于: 2009-3-31 18:58 4765

[旧帖] [求助]这样的IDT HOOK为什么在多线程运行的情况下蓝屏?附上代码和DUMP!!! 0.00雪花

2009-3-31 18:58
4765
#include "MyKeyHook.h"

///////////////////////////////////////////////////
// IDT structures
///////////////////////////////////////////////////
#pragma pack(1)

// entry in the IDT, this is sometimes called
// an "interrupt gate"
typedef struct
{
        unsigned short LowOffset;
        unsigned short selector;
        unsigned char unused_lo;
        unsigned char segment_type:4;        //0x0E is an interrupt gate
        unsigned char system_segment_flag:1;
        unsigned char DPL:2;        // descriptor privilege level
        unsigned char P:1; /* present */
        unsigned short HiOffset;
} IDTENTRY;

/* sidt returns idt in this format */
typedef struct
{
        unsigned short IDTLimit;
        unsigned short LowIDTbase;
        unsigned short HiIDTbase;
} IDTINFO;

#pragma pack()

unsigned long old_ISR_pointer;
unsigned char keystroke_buffer[MAX_CHARS];
int kb_array_ptr=0;

       
VOID OnUnload( IN PDRIVER_OBJECT DriverObject )
{
        IDTINFO                idt_info;
        IDTENTRY*        idt_entries;
//        char _t[255];

        // load idt_info
        __asm        sidt        idt_info       
        idt_entries = (IDTENTRY*) MAKELONG(idt_info.LowIDTbase,idt_info.HiIDTbase);

        DbgPrint("UnHooking Interrupt...");

        // restore the original interrupt handler
        __asm cli
        idt_entries[kb_int].LowOffset = (unsigned short) old_ISR_pointer;
        idt_entries[kb_int].HiOffset = (unsigned short)((unsigned long)old_ISR_pointer >> 16);
        __asm sti

        DbgPrint("UnHooking Interrupt complete.");
       
        DbgPrint("Keystroke Buffer is: ");
        DbgPrint("%s", keystroke_buffer);
}

#pragma data_seg()
LARGE_INTEGER gl_CurrentTime;
#pragma data_seg()
LARGE_INTEGER result;
KIRQL irql,irql2;
void __stdcall print_timecount()
{

        result=KeQueryPerformanceCounter(&gl_CurrentTime);

        DbgPrint("my___________________________________Hook%16u %16u\n",result.HighPart,result.LowPart);          //经测试,在有其它线程运行时,由于此处发生蓝屏,为什么?????????

                                                                                                                  //如果没有其它线程运行,则此IDT HOOK正常运行
}

__declspec(naked) my_interrupt_hook()
{
       
        __asm
        {
                cli
                pushad                                        // save all general purpose registers
                pushfd                                        // save the flags register

        }

       

        __asm call print_timecount
       
        __asm
        {
                       

                popfd                                        // restore the flags
                popad                                        // restore the general registers

                sti
                jmp                old_ISR_pointer        // goto the original ISR

        }
}

#pragma INITCODE
NTSTATUS DriverEntry( IN PDRIVER_OBJECT theDriverObject, IN PUNICODE_STRING theRegistryPath )
{
        IDTINFO                idt_info;
        IDTENTRY*        idt_entries;
//        char _t[255];
       
        theDriverObject->DriverUnload  = OnUnload;

        kb_int= 0x93;//为本机键盘中断号
        DbgPrint("kb_int = 0x%02X\n", kb_int);

        // load idt_info
        __asm        sidt        idt_info
       
        idt_entries = (IDTENTRY*) MAKELONG(idt_info.LowIDTbase,idt_info.HiIDTbase);

        DbgPrint("Hooking Interrupt...");
        old_ISR_pointer = MAKELONG(idt_entries[kb_int].LowOffset,idt_entries[kb_int].HiOffset);
       
        // remember we disable interrupts while we patch the table
        __asm cli
        idt_entries[kb_int].LowOffset = (unsigned short)my_interrupt_hook;
        idt_entries[kb_int].HiOffset = (unsigned short)((unsigned long)my_interrupt_hook >> 16);
        __asm sti

        DbgPrint("Hooking Interrupt complete: Old = 0x%08X, New = 0x%08X\n", old_ISR_pointer, my_interrupt_hook);

         _asm int 0x93;

        return STATUS_SUCCESS;
}

[课程]FART 脱壳王!加量不加价!FART作者讲授!

收藏
免费 0
支持
分享
最新回复 (6)
雪    币: 201
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
我在任意的一下进程中,新建一个线程,如
WORD WINAPI ThreadProc1( LPVOID lpParam )
{
        while(1)
        {

        }

        return 1;
}

hThread[1] = CreateThread(
                        NULL,              // default security attributes
                        0,                 // use default stack size  
                        ThreadProc1,        // thread function
                        NULL,             // argument to thread function
                        0,                 // use default creation flags
                        &dwThreadId[1]);   // returns the thread identifier

这样再按键盘就会出现蓝屏,DUMP如下
kd> !analyze -v
*******************************************************************************
*                                                                             *
*                        Bugcheck Analysis                                    *
*                                                                             *
*******************************************************************************

UNEXPECTED_KERNEL_MODE_TRAP (7f)
This means a trap occurred in kernel mode, and it's a trap of a kind
that the kernel isn't allowed to have/catch (bound trap) or that
is always instant death (double fault).  The first number in the
bugcheck params is the number of the trap (8 = double fault, etc)
Consult an Intel x86 family manual to learn more about what these
traps are. Here is a *portion* of those codes:
If kv shows a taskGate
        use .tss on the part before the colon, then kv.
Else if kv shows a trapframe
        use .trap on that value
Else
        .trap on the appropriate frame will show where the trap was taken
        (on x86, this will be the ebp that goes with the procedure KiTrap)
Endif
kb will then show the corrected stack.
Arguments:
Arg1: 0000000d, EXCEPTION_GP_FAULT
Arg2: 00000000
Arg3: 00000000
Arg4: 00000000

Debugging Details:
------------------

*************************************************************************
***                                                                   ***
***                                                                   ***
***    Your debugger is not using the correct symbols                 ***
***                                                                   ***
***    In order for this command to work properly, your symbol path   ***
***    must point to .pdb files that have full type information.      ***
***                                                                   ***
***    Certain .pdb files (such as the public OS symbols) do not      ***
***    contain the required information.  Contact the group that      ***
***    provided you with these symbols if you need this command to    ***
***    work.                                                          ***
***                                                                   ***
***    Type referenced: kernel32!pNlsUserInfo                         ***
***                                                                   ***
*************************************************************************
*************************************************************************
***                                                                   ***
***                                                                   ***
***    Your debugger is not using the correct symbols                 ***
***                                                                   ***
***    In order for this command to work properly, your symbol path   ***
***    must point to .pdb files that have full type information.      ***
***                                                                   ***
***    Certain .pdb files (such as the public OS symbols) do not      ***
***    contain the required information.  Contact the group that      ***
***    provided you with these symbols if you need this command to    ***
***    work.                                                          ***
***                                                                   ***
***    Type referenced: kernel32!pNlsUserInfo                         ***
***                                                                   ***
*************************************************************************

BUGCHECK_STR:  0x7f_d

DEFAULT_BUCKET_ID:  DRIVER_FAULT

PROCESS_NAME:  MultiThreadTest

LAST_CONTROL_TRANSFER:  from 804f8b9d to 80528bdc

STACK_TEXT:  
ef40b8a4 804f8b9d 00000003 ef40bc00 00000000 nt!RtlpBreakWithStatusInstruction
ef40b8f0 804f978a 00000003 80538f15 02480248 nt!KiBugCheckDebugBreak+0x19
ef40bcd0 80541dff 0000007f 0000000d 00000000 nt!KeBugCheck2+0x574
ef40bcd0 80538f15 0000007f 0000000d 00000000 nt!KiSystemFatalException+0xf
ef40bd8c f898d393 f898f1b4 00000000 1b70c81e nt!_SEH_prolog+0x5
WARNING: Stack unwind information not available. Following frames may be wrong.
ef40bda0 f898d3a0 00000002 0064ffb4 02480248 HelloDDK+0x1393
ef40bddc 80542dd2 efcd893d efcd7fc0 00000000 HelloDDK+0x13a0
ef40bde0 efcd893c efcd7fc0 00000000 0000027f nt!KiThreadStartup+0x16
ef40bdf0 02480000 00000000 00000000 00000000 rdbss!RxInitializeContext+0x132
ef40be04 00000000 02480248 02480248 02480248 0x2480000

STACK_COMMAND:  kb

FOLLOWUP_IP:
HelloDDK+1393
f898d393 83c40c          add     esp,0Ch

SYMBOL_STACK_INDEX:  5

SYMBOL_NAME:  HelloDDK+1393

FOLLOWUP_NAME:  MachineOwner

MODULE_NAME: HelloDDK

IMAGE_NAME:  HelloDDK.sys

DEBUG_FLR_IMAGE_TIMESTAMP:  49d1da6b

FAILURE_BUCKET_ID:  0x7f_d_HelloDDK+1393

BUCKET_ID:  0x7f_d_HelloDDK+1393

Followup: MachineOwner
---------

请问这是为什么呢?
2009-3-31 19:01
0
雪    币: 419
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
把 BIN 发出来,还快点

HelloDDK+1393

应该这地址处的代码有问题
2009-3-31 19:15
0
雪    币: 201
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4
运行EXE后,加载驱动,再按键盘就蓝了!
上传的附件:
2009-4-1 07:45
0
雪    币: 419
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
5
没有出现你说的蓝屏

p3 xp3 下

弄成多线程死循环也一样
2009-4-1 08:19
0
雪    币: 201
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
6
如果是USB键盘的话,HOOK不起作用,就不蓝屏,我是在VMWARE上调的,键盘IDT为0x93,这种情况就蓝屏了
2009-4-1 09:09
0
雪    币: 201
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
7
问题还是没有解决啊,UNEXPECTED_KERNEL_MODE_TRAP (7f)
This means a trap occurred in kernel mode, and it's a trap of a kind
that the kernel isn't allowed to have/catch (bound trap) or that
is always instant death (double fault).  The first number in the
bugcheck params is the number of the trap (8 = double fault, etc)
Consult an Intel x86 family manual to learn more about what these
traps are. Here is a *portion* of those codes:
If kv shows a taskGate
        use .tss on the part before the colon, then kv.
Else if kv shows a trapframe
        use .trap on that value
Else
        .trap on the appropriate frame will show where the trap was taken
        (on x86, this will be the ebp that goes with the procedure KiTrap)
Endif
kb will then show the corrected stack.
Arguments:
Arg1: 0000000d, EXCEPTION_GP_FAULT
Arg2: 00000000
Arg3: 00000000
Arg4: 00000000

是什么意思呢?
2009-4-5 22:29
0
游客
登录 | 注册 方可回帖
返回
//