首页
社区
课程
招聘
[求助]纠结了谁给帮忙解决下
发表于: 2010-12-3 20:42 4532

[求助]纠结了谁给帮忙解决下

2010-12-3 20:42
4532
今天hook ZwCreateSection 这个函数 搞了半天,老是蓝屏,纠结的我一天没吃饭,哪位高人给看看为啥蓝屏啊?应该咋该啊?

#include "NTDDK.H"

ULONG g_uCr0;

VOID WpOff()
{
        ULONG uAttr;
        _asm
        {       
                push eax
                mov eax,cr0
                mov uAttr,eax
                and eax,0xfffeffff
                mov cr0,eax
                pop eax
        }

        g_uCr0=uAttr;
}

VOID WpOn()
{
        _asm
        {
                push eax
                mov eax,g_uCr0
                mov cr0,eax
                pop eax

        }

}

_declspec(naked) my_Function()
{

        _asm
        {
          mov     eax,32h
                  lea     edx,[esp+4]

        _emit 0xEA
        _emit 0xAA
        _emit 0xAA
        _emit 0xAA
        _emit 0xAA
        _emit 0x08
        _emit 0x00
        }       

       
}

VOID Hook_Function()
{
        int i;
        KIRQL oldIrql;
        char *non_page_memory;
        PULONG old_Function;
        ULONG fan_Address;
        UNICODE_STRING functionName;
        UCHAR new_code[]={0xEA,0x00,0x00,0x00,0x00,0x08,0x00,0x90,0x90};
        RtlInitUnicodeString(&functionName,L"ZwCreateSection");
        old_Function=MmGetSystemRoutineAddress(&functionName);
        if(!old_Function)
        {
                return NULL;
        }       
        fan_Address=(ULONG)old_Function+9;
        non_page_memory=ExAllocatePool(NonPagedPool,256);
        for(i=0;i<256;i++)
        {
                ((unsigned *)non_page_memory)[i]=((unsigned *)my_Function)[i];
        }
        *((PULONG)(&new_code[1]))=(ULONG)non_page_memory;
        for(i=0;i<256;i++)
        {
                if((PUCHAR)non_page_memory[i]==0xAA &&
                        (PUCHAR)non_page_memory[i+1]==0xAA &&
                        (PUCHAR)non_page_memory[i+2]==0xAA &&
                        (PUCHAR)non_page_memory[i+3]==0xAA )
                {
                        *((PULONG)(&non_page_memory[i]))=fan_Address;
                }
        }

        oldIrql = KeRaiseIrqlToDpcLevel();
        WpOff();
        for(i=0;i<9;i++)
        {
                old_Function[i]=new_code[i];
        }
        WpOn();
        KeLowerIrql(oldIrql);

}

my_Unload(PDRIVER_OBJECT pDriverObject)
{
        KdPrint(("enter DriverUnload\n"));
}
NTSTATUS DriverEntry(PDRIVER_OBJECT pDriverObject,PUNICODE_STRING pRegistryPath)
{
       
       
        pDriverObject->DriverUnload=my_Unload;
        Hook_Function();
        return STATUS_SUCCESS;
}

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

收藏
免费 0
支持
分享
最新回复 (7)
雪    币: 72
活跃值: (52)
能力值: ( LV3,RANK:30 )
在线值:
发帖
回帖
粉丝
2
纠结啊,谁给说下哪错了啊,今天晚上又睡不着了。
2010-12-3 22:56
0
雪    币: 18
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
_declspec(naked) MyFunc()
{
        __asm
        {
                        mov     eax,32h
                        mov                ebx,ZwCreateSection
                        add                ebx,5
                        jmp                ebx
        }
}

VOID Hook()
{
        DWORD        ZwCreateSectionAdd        =        (DWORD)ZwCreateSection;

        _asm
        {
                        cli
                        mov eax,cr0
                        and eax,not 10000h
                        mov cr0,eax   
        };

        *(PUCHAR)ZwCreateSectionAdd                        =        0xE9;
        *(PULONG)(ZwCreateSectionAdd+1)                =        (ULONG)MyFunc - ZwCreateSectionAdd - 5;

        _asm
        {
                        mov eax,cr0
                        or  eax,10000h
                        mov cr0,eax
                        sti            
        };
}
2010-12-5 00:14
0
雪    币: 72
活跃值: (52)
能力值: ( LV3,RANK:30 )
在线值:
发帖
回帖
粉丝
4
谢谢指点   能不能给我说说我那个方法哪里不对了  我感觉应该对啊 可一测试就蓝
2010-12-5 00:46
0
雪    币: 72
活跃值: (52)
能力值: ( LV3,RANK:30 )
在线值:
发帖
回帖
粉丝
5
运行前这个函数时这样的
nt!ZwCreateSection:
804ff180 b832000000      mov     eax,32h
804ff185 8d542404        lea     edx,[esp+4]
804ff189 9c              pushfd
804ff18a 6a08            push    8
804ff18c e8f0f20300      call    nt!KiSystemService (8053e481)
804ff191 c21c00          ret     1Ch
运行后
nt!ZwCreateSection:
804ff180 ea906dbd810800  jmp     0008:81BD6D90
804ff187 90              nop
804ff188 90              nop
804ff189 9c              pushfd
804ff18a 6a08            push    8
804ff18c e8f0f20300      call    nt!KiSystemService (8053e481)
804ff191 c21c00          ret     1Ch

0008:81BD6D90的内容是
bf7a50 681007f3f9      push    offset driver! ?? ::FNODOBFM::`string' (f9f30710)
81bf7a55 e816020000      call    81bf7c70
81bf7a5a 83c404          add     esp,4
81bf7a5d b832000000      mov     eax,32h
81bf7a62 8d542404        lea     edx,[esp+4]
81bf7a66 ea89f14f800800  jmp     0008:804FF189

看样子hook成功了,可为什么运行几秒后还是蓝屏呢???
2010-12-6 17:23
0
雪    币: 6092
活跃值: (654)
能力值: ( LV4,RANK:45 )
在线值:
发帖
回帖
粉丝
6
感觉 硬件编码的问题
还有 为什么不获取ssdt的原地址 并且保存方便处理
既然是hook 应该是把函数地址拿来 给自己的函数  然后自己进行对函数的处理

然后返回给内核
我不明白你写这个hook是什么 目的 又是硬编码  又是汇编
而且没有采用 自旋锁 来处理多个 请求时的 系统死锁
我自己也是菜鸟
只是感觉你的写法不规范 而且不兼容
有问题多交流吧
2010-12-6 18:10
0
雪    币: 72
活跃值: (52)
能力值: ( LV3,RANK:30 )
在线值:
发帖
回帖
粉丝
7
谢谢楼上的兄弟,我是菜的不能在菜了,得加把劲儿学习啊,像你们看齐,能否交个朋友,加个q411794169。
2010-12-6 18:52
0
雪    币: 4
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
8
我看不懂额~~~~~~~
2010-12-10 13:56
0
游客
登录 | 注册 方可回帖
返回
//