首页
社区
课程
招聘
[求助]如何获取ShadowSSDT的系统调用号?
2009-6-17 21:55 6562

[求助]如何获取ShadowSSDT的系统调用号?

2009-6-17 21:55
6562
诸如NtUserSetWindowHookEx之类的函数,请教如何获取他们的系统调用号?

[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

收藏
点赞0
打赏
分享
最新回复 (12)
雪    币: 203
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
fmicromath 2009-6-17 22:57
2
0
/*
this routine is to help get system sevices number
by specified service name
*/
NTSTATUS
IhkGetSystemServicesNumber(
        IN        PCHAR                                ServiceName,        //ZwXxx   or NtXxx
        OUT        PULONG                                ServiceNumber
        )
{
        UNICODE_STRING                                usModuleName;
        HANDLE                                                moduleFileHandle;
        NTSTATUS                                        status;
        OBJECT_ATTRIBUTES                        objectAttrib;
        IO_STATUS_BLOCK                                ioStatus;
        HANDLE                                                sectionHandle;
        PUCHAR                                                baseAddress = NULL;
        SIZE_T                                                size = 0;
        PIMAGE_OPTIONAL_HEADER                optHeader;
        PIMAGE_EXPORT_DIRECTORY                exprotTable;
        PULONG                                                routineAddrs;
        PULONG                                                routineNames;
        PSHORT                                                routineOrdinals;
        ULONG                                                i;
        PCHAR                                                name;
        ULONG                                                index;
        PVOID                                                addr;

        //ntdll.dll
        // note : we use ntdll.dll because the routine it exports is
        // more than ntoskrnl and
        // the header  ZwXxx  or NtXxx  in it is all start as
        //  mov eax, <services number>(32bit)
        //  
        RtlInitUnicodeString (&usModuleName, L"\\SystemRoot\\system32\\ntdll.dll");

        InitializeObjectAttributes (&objectAttrib,
                &usModuleName,
                OBJ_CASE_INSENSITIVE ,
                NULL,
                NULL
                );

        //open file
        status = ZwCreateFile(&moduleFileHandle,
                FILE_EXECUTE,
                &objectAttrib,
                &ioStatus,
                NULL,
                FILE_ATTRIBUTE_NORMAL,
                FILE_SHARE_READ,
                FILE_OPEN,
                FILE_SYNCHRONOUS_IO_NONALERT,
                NULL,
                0
                );

        if(!NT_SUCCESS(status)){

                return status;
        }

        objectAttrib.ObjectName  = NULL;

        //map file
        status = ZwCreateSection(
                §ionHandle,
                SECTION_ALL_ACCESS,
                &objectAttrib,
                0,
                PAGE_EXECUTE,
                SEC_IMAGE,
                moduleFileHandle);

        if(!NT_SUCCESS(status)){

                ZwClose(moduleFileHandle);
                return status;
        }

        status = ZwMapViewOfSection(
                sectionHandle,
                NtCurrentProcess(),
                &baseAddress,
                0,
                0x1000,
                NULL,
                &size,
                ViewShare ,
                MEM_TOP_DOWN,
                PAGE_READWRITE
                );

        if(!NT_SUCCESS(status)){

                ZwClose(moduleFileHandle);
                ZwClose(sectionHandle);
                return status;
        }

        ZwClose(moduleFileHandle);

        //get export table
        optHeader  = &((PIMAGE_NT_HEADERS )( baseAddress +
                ((PIMAGE_DOS_HEADER )baseAddress)->e_lfanew))->OptionalHeader ;

        exprotTable = (PIMAGE_EXPORT_DIRECTORY)(baseAddress +
                optHeader->DataDirectory [ IMAGE_DIRECTORY_ENTRY_EXPORT]. VirtualAddress);

        // now we can get the exported functions, but note we convert from RVA to address
        routineAddrs = (PULONG)( baseAddress + exprotTable ->AddressOfFunctions );

        routineNames = (PULONG)( baseAddress + exprotTable->AddressOfNames);

        routineOrdinals = (PSHORT)( baseAddress + exprotTable->AddressOfNameOrdinals);

        //search
        for(i = 0; i < exprotTable ->NumberOfFunctions ; i++){

                name = (PCHAR)(baseAddress + routineNames [i]);

                if(!strcmp(name, ServiceName )){
                        //found
                       
                        // always need to add base, -1 as array counts from 0
                        index = routineOrdinals [i] + exprotTable ->Base  - 1;

                        // this is the funny bit.  you would expect the function pointer to
                        // simply be routineAddrs[i]...
                        // oh no... thats too simple.  it is actually routineAddrs[index]!!
                        addr = (PVOID)(baseAddress + routineAddrs [index]);

                        //get the index of serviecs in ZwXxx's  or NtXxx's header
                        *ServiceNumber = *(PULONG)((PUCHAR)addr + 1);

                        ZwClose(sectionHandle);

                        return STATUS_SUCCESS ;
                }
        }

        ZwUnmapViewOfSection (NtCurrentProcess(), baseAddress);

        ZwClose(sectionHandle);

        return STATUS_NOT_FOUND ;
}
雪    币: 375
活跃值: (12)
能力值: ( LV8,RANK:130 )
在线值:
发帖
回帖
粉丝
xPLK 3 2009-6-17 23:23
3
0
楼上的
ntdll啊?
雪    币: 203
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
fmicromath 2009-6-17 23:41
4
0
是啊 。。。。。。。。。
雪    币: 722
活跃值: (123)
能力值: ( LV12,RANK:300 )
在线值:
发帖
回帖
粉丝
轩辕小聪 7 2009-6-18 03:46
5
0
晕倒,ShadowSSDT的win32k.sys的函数,其R3 stub不是在ntdll.dll里的,是在其他与图形界面和消息驱动有关的DLL如user32.dll里的,而且其服务号在函数代码中的位置,也不是像ntdll.dll里的那么容易找的……
雪    币: 290
活跃值: (20)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
cschenhui 2009-6-18 09:28
6
0
使用符号可以解决
雪    币: 375
活跃值: (12)
能力值: ( LV8,RANK:130 )
在线值:
发帖
回帖
粉丝
xPLK 3 2009-6-18 10:41
7
0
硬编码。
雪    币: 118
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
chenyeyws 2009-6-18 13:08
8
0
雪    币: 118
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
chenyeyws 2009-6-18 13:12
9
0
不好意思,发错了~~
雪    币: 254
活跃值: (30)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
margen 1 2009-6-18 18:29
10
0
貌似User32.dll里的函数,在很深才会有一个sysenter或int 2e,是不是可以借助反汇编引擎去动态获取这个调用号?
雪    币: 183
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
yeliangang 2009-6-18 19:36
11
0
windbg跟不出来么?
雪    币: 254
活跃值: (30)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
margen 1 2009-6-18 19:47
12
0
貌似也不对,IDA看了下,貌似大部分R3的User32函数,都会以11B3h号进入内核……
雪    币: 203
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
fmicromath 2009-6-18 23:12
13
0
不好意思,看成ssdt了
游客
登录 | 注册 方可回帖
返回