首页
社区
课程
招聘
[原创]提取 ShadowSsdt 原始地址代码
发表于: 2011-8-23 11:24 8427

[原创]提取 ShadowSsdt 原始地址代码

2011-8-23 11:24
8427
comment/*
BOOLEAN  KeAddSystemServiceTable(
          IN  PVOID   ServiceTableBase,
          IN  PVOID   ServiceCounterTableBase,
          IN  ULONG   NumberOfService,
          IN  PVOID   ParamTableBase,
          IN  ULONG   InsertServiceTableIndex
          )

$-18     > 57               push edi
$-17     > 68 10E399BF      push BF99E310
$-12     > FF35 0CE399BF    push dword ptr [BF99E30C]
$-C      > 8935 30899ABF    mov dword ptr [BF9A8930],esi
$-6      > 56               push esi
$-5      > 68 00D699BF      push BF99D600
$ ==>    > FF15 580799BF    call dword ptr [BF990758]

INIT:BF9B3B22                 push    edi          InsertServiceTableIndex
INIT:BF9B3B23                 push    offset unk_BF99E310    ParamTableBase
INIT:BF9B3B28                 push    dword_BF99E30C      NumberOfService
INIT:BF9B3B2E                 mov     dword_BF9A8930, esi
INIT:BF9B3B34                 push    esi          ServiceCounterTableBase
INIT:BF9B3B35                 push    offset off_BF99D600    ServiceTableBase
INIT:BF9B3B3A                 call    ds:KeAddSystemServiceTable
*/
........................映射代码忽略
  assume edi:nothing
  mov edi, BaseAddress
  add edi, [edi].IMAGE_DOS_HEADER.e_lfanew
  movzx eax, [edi].IMAGE_NT_HEADERS.FileHeader.NumberOfSections
  mov Indent, eax
  add edi, sizeof IMAGE_NT_HEADERS
  assume edi:ptr IMAGE_SECTION_HEADER
  mov VirtualSize, 0
  .repeat
    invoke StrCmp,edi,T("INIT")
    .if eax
      m2m VirtualSize, [edi].Misc.VirtualSize
      mov edi, [edi].PointerToRawData
      add edi, BaseAddress
      .break
    .endif
    add edi, sizeof IMAGE_SECTION_HEADER
    dec Indent
  .until Indent == 0
  cmp VirtualSize, 0
  je err
  mov Call_KeAddSystemServiceTable, 0
  mov Indent, 0
  .while TRUE
    invoke DisasmLen,edi,addr hde
    .if hde.len == 6 && hde.opcode == 0FFh && hde.modrm == 15h && hde.disp32
      mov eax, hde.disp32
      sub eax, [esi].OptionalHeader.ImageBase
      invoke RVAToFileMap,BaseAddress,eax
      .if eax == Import_KeAddSystemServiceTable
        mov Call_KeAddSystemServiceTable, edi
        .break
      .endif
    .endif
    mov eax, hde.len
    add edi, eax
    add Indent, eax
    mov eax, Indent
    .break .if eax >= VirtualSize
  .endw
  cmp Call_KeAddSystemServiceTable, 0
  jz err
  m2m ImageBase, [esi].OptionalHeader.ImageBase
  mov edi, Call_KeAddSystemServiceTable
  
  mov eax, DWORD ptr[edi-5+1]
  sub eax, [esi].OptionalHeader.ImageBase
  add eax, BaseAddress
  mov Shadow_ServiceTableBase, eax
  
  mov eax, DWORD ptr[edi-17h+1]
  sub eax, [esi].OptionalHeader.ImageBase
  add eax, BaseAddress
  mov Shadow_ParamTableBase, eax
  
  mov eax, DWORD ptr[edi-12h+2]
  sub eax, [esi].OptionalHeader.ImageBase
  add eax, BaseAddress
  m2m Shadow_NumberOfService, DWORD ptr[eax]
.................................以下代码忽略
运行效果

[课程]Linux pwn 探索篇!

上传的附件:
收藏
免费 6
支持
分享
最新回复 (10)
雪    币: 2362
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
标题栏是不是应该是antiprotector
2011-8-23 11:33
0
雪    币: 34
活跃值: (10)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
3
AntiRootkit = Protector
AntiProtector = AntiAntiRootkit = Rootkit
2011-8-23 12:40
0
雪    币: 170
活跃值: (90)
能力值: ( LV12,RANK:210 )
在线值:
发帖
回帖
粉丝
4
老代码吧。。。。各种省略。。。
2011-8-23 13:46
0
雪    币: 8865
活跃值: (2379)
能力值: ( LV12,RANK:760 )
在线值:
发帖
回帖
粉丝
5
简单一点吧~reload后读取就行鸟~
BOOL GetOriginalW32pTable(PVOID ImageBase,PSERVICE_DESCRIPTOR_TABLE W32pTable,DWORD Win32kBase)
{
        BOOL bRet=FALSE;
        PIMAGE_NT_HEADERS NtHeaders;
        ULONG_PTR EntryPoint;
        DWORD dwKeAddSystemServiceTable;
        dwKeAddSystemServiceTable= (DWORD)MiFindExportedRoutine((PVOID)RealKernelBase,TRUE,"KeAddSystemServiceTable",0);
        NtHeaders = RtlImageNtHeader(ImageBase);
        if (NtHeaders)
        {
                DWORD dwEntryPoint;
                DWORD dwCurAddress;
                EntryPoint = NtHeaders->OptionalHeader.AddressOfEntryPoint;
                EntryPoint += (ULONG_PTR)ImageBase;
                dwEntryPoint=(DWORD)EntryPoint;
                /*IDA反汇编结果:
                68 80 A2 99 BF          push    offset off_BF99A280
                FF 15 58 D4 98 BF       call    ds:KeAddSystemServiceTable
                */
                //通过call    ds:KeAddSystemServiceTable的定位,该定位应该比较准确
                for(dwCurAddress = dwEntryPoint; dwCurAddress < dwEntryPoint + 0x1000; dwCurAddress++)
                {
                        if(*(WORD *)dwCurAddress == 0x15ff )
                        {  
                                //计算出加载后的ds:KeAddSystemServiceTable地址,然后该地址中存放的即是KeAddSystemServiceTable真实入口地址
                                DWORD dwFunAddress = *(PDWORD)(*(PDWORD)(dwCurAddress + 2)-Win32kBase+(DWORD)ImageBase);
                                if(dwKeAddSystemServiceTable == dwFunAddress)
                                {
                                        //将该地址结合内核中Win32k的加载地址进行重定位
                                        W32pTable->ServiceTable =(PDWORD) (*(PDWORD)(dwCurAddress - 4) - Win32kBase + (DWORD)ImageBase);
                                        bRet=TRUE;
                                        break;
                                }
                        }
                }
        }
        return bRet;
}
2011-8-23 13:55
0
雪    币: 343
活跃值: (40)
能力值: ( LV5,RANK:60 )
在线值:
发帖
回帖
粉丝
6
怎么不来个开源的
2011-8-23 13:55
0
雪    币: 298
活跃值: (75)
能力值: ( LV5,RANK:70 )
在线值:
发帖
回帖
粉丝
7
我是为了提取原始参数而已,才写了这个,什么老代码,,前面忽略的是简单才忽略,既然你没能力看懂,那就全部放出来好了

ShadowSsdt proc uses esi edi
       
        local hde:hde32s
        local pSSDT,pSSPT,Indent
        local pKERNEL_MODULE:KERNEL_MODULE
        local Shadow_ServiceTableBase
        local Shadow_NumberOfService
        local Shadow_ParamTableBase
        local Win32Path[MAX_PATH+1]:BYTE
        local ImageBase,Win32Ring0,dwdelta
        local szKeAddSystemServiceTable[30]:BYTE
        local hFile,FileSize,hFileMap,BaseAddress
        local Import_KeAddSystemServiceTable,Call_KeAddSystemServiceTable
        local ShadowSsdtName,VirtualSize
       
        xor eax, eax
        mov pSSDT, eax
        mov pSSPT, eax
        mov Indent, eax
        mov BaseAddress, eax
        mov hFile, eax
        mov hFileMap, eax
        m2m ShadowSsdtName, ShadowName
        invoke GetSystemDirectory,addr Win32Path,MAX_PATH
        invoke StrLen,addr Win32Path
        mov WORD ptr Win32Path[eax], "\"
        invoke StrCat,addr Win32Path,offset szWin32ksys
        invoke CreateFile,addr Win32Path,GENERIC_READ,FILE_SHARE_READ+FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL
        .if eax == INVALID_HANDLE_VALUE
                open_err:
                invoke wsprintf,offset TempBuf,offset szScanInline_Open,offset szWin32ksys
                invoke SetWindowText,hStausBar,offset TempBuf
                jmp err
        .endif
        mov hFile, eax
        invoke GetFileSize,eax,NULL
        mov FileSize, eax
        invoke CreateFileMapping,hFile,NULL,PAGE_READONLY,NULL,NULL,NULL
        or eax, eax
        jz open_err
        mov hFileMap, eax
        invoke MapViewOfFile,hFileMap,FILE_MAP_READ,NULL,NULL,NULL
        or eax, eax
        jz open_err
        mov BaseAddress, eax
        lea eax, szKeAddSystemServiceTable
        mov DWORD ptr[eax+00000000], 06441654Bh
        mov DWORD ptr[eax+00000004], 073795364h
        mov DWORD ptr[eax+00000008], 0536D6574h
        mov DWORD ptr[eax+00000012], 069767265h
        mov DWORD ptr[eax+00000016], 061546563h
        mov DWORD ptr[eax+00000020], 000656C62h
        invoke FindImport,BaseAddress,0,eax
        or eax, eax
        jz err
        mov Import_KeAddSystemServiceTable, eax
        mov esi, BaseAddress
        assume esi:ptr IMAGE_DOS_HEADER
        add esi, [esi].e_lfanew
        assume esi:ptr IMAGE_NT_HEADERS
        mov Call_KeAddSystemServiceTable, 0
        mov Indent, 0
       
comment/*
BOOLEAN  KeAddSystemServiceTable(
          IN  PVOID   ServiceTableBase,
          IN  PVOID   ServiceCounterTableBase,
          IN  ULONG   NumberOfService,
          IN  PVOID   ParamTableBase,
          IN  ULONG   InsertServiceTableIndex
          )

BF9B3B3A - BF800380 = 1B37BA
014B3B22   57               push edi
014B3B23   68 10E399BF      push BF99E310                                ParamTableBase
014B3B28   FF35 0CE399BF    push dword ptr [BF99E30C]                NumberOfService
014B3B2E   8935 30899ABF    mov dword ptr [BF9A8930],esi
014B3B34   56               push esi                                        ServiceCounterTableBase
014B3B35   68 00D699BF      push BF99D600                                ServiceTableBase
014B3B3A   FF15 580799BF    call dword ptr [BF990758]

$-18     > 57               push edi
$-17     > 68 10E399BF      push BF99E310
$-12     > FF35 0CE399BF    push dword ptr [BF99E30C]
$-C      > 8935 30899ABF    mov dword ptr [BF9A8930],esi
$-6      > 56               push esi
$-5      > 68 00D699BF      push BF99D600
$ ==>    > FF15 580799BF    call dword ptr [BF990758]

INIT:BF9B3B22                 push    edi                                        InsertServiceTableIndex
INIT:BF9B3B23                 push    offset unk_BF99E310                ParamTableBase
INIT:BF9B3B28                 push    dword_BF99E30C                        NumberOfService
INIT:BF9B3B2E                 mov     dword_BF9A8930, esi
INIT:BF9B3B34                 push    esi                                        ServiceCounterTableBase
INIT:BF9B3B35                 push    offset off_BF99D600                ServiceTableBase
INIT:BF9B3B3A                 call    ds:KeAddSystemServiceTable
*/
        assume edi:nothing
        mov edi, BaseAddress
        add edi, [edi].IMAGE_DOS_HEADER.e_lfanew
        movzx eax, [edi].IMAGE_NT_HEADERS.FileHeader.NumberOfSections
        mov Indent, eax
        add edi, sizeof IMAGE_NT_HEADERS
        assume edi:ptr IMAGE_SECTION_HEADER
        mov VirtualSize, 0
        .repeat
                invoke StrCmp,edi,T("INIT")
                .if eax
                        m2m VirtualSize, [edi].Misc.VirtualSize
                        mov edi, [edi].PointerToRawData
                        add edi, BaseAddress
                        .break
                .endif
                add edi, sizeof IMAGE_SECTION_HEADER
                dec Indent
        .until Indent == 0
        cmp VirtualSize, 0
        je err
        mov Call_KeAddSystemServiceTable, 0
        mov Indent, 0
        .while TRUE
                invoke DisasmLen,edi,addr hde
                .if hde.len == 6 && hde.opcode == 0FFh && hde.modrm == 15h && hde.disp32
                        mov eax, hde.disp32
                        sub eax, [esi].OptionalHeader.ImageBase
                        invoke RVAToFileMap,BaseAddress,eax
                        .if eax == Import_KeAddSystemServiceTable
                                mov Call_KeAddSystemServiceTable, edi
                                .break
                        .endif
                .endif
                mov eax, hde.len
                add edi, eax
                add Indent, eax
                mov eax, Indent
                .break .if eax >= VirtualSize
        .endw
        cmp Call_KeAddSystemServiceTable, 0
        jz err
        m2m ImageBase, [esi].OptionalHeader.ImageBase
        mov edi, Call_KeAddSystemServiceTable
       
        mov eax, DWORD ptr[edi-5+1]
        sub eax, [esi].OptionalHeader.ImageBase
        add eax, BaseAddress
        mov Shadow_ServiceTableBase, eax
       
        mov eax, DWORD ptr[edi-17h+1]
        sub eax, [esi].OptionalHeader.ImageBase
        add eax, BaseAddress
        mov Shadow_ParamTableBase, eax
       
        mov eax, DWORD ptr[edi-12h+2]
        sub eax, [esi].OptionalHeader.ImageBase
        add eax, BaseAddress
        m2m Shadow_NumberOfService, DWORD ptr[eax]
       
        invoke DumpKernelModule
        or eax, eax
        jz err
        mov esi, offset KernelModule
        assume esi:ptr KERNEL_MODULE
        .while [esi].BaseAddress
                invoke StrRChr,addr [esi].ImageName,"\"
                .if eax
                        inc eax
                .else
                        lea eax, [esi].ImageName
                .endif
                invoke strnicmp,eax,offset szWin32ksys
                .if eax
                        mov eax, [esi].BaseAddress
                        mov Win32Ring0, eax
                       
                        sub eax, ImageBase
                        mov dwdelta, eax
                        .break
                .endif
                add esi, sizeof KERNEL_MODULE
        .endw
       
       
        imul eax, Shadow_NumberOfService, 4
        invoke GlobalAlloc,GPTR,eax
        or eax, eax
        jz err
        mov pSSDT, eax
        imul eax, Shadow_NumberOfService, 4
        invoke Communications,IOCTL_DumpShadowSsdt,NULL,NULL,pSSDT,eax
        or eax, eax
        jz err
       
        invoke GlobalAlloc,GPTR,Shadow_NumberOfService
        or eax, eax
        jz err
        mov pSSPT, eax
        invoke Communications,IOCTL_DumpShadowSspt,NULL,NULL,pSSPT,Shadow_NumberOfService
        or eax, eax
        jz err
       
        mov esi, pSSDT
        mov edi, Shadow_ServiceTableBase
        mov Indent, 0
        .repeat
                ;; 序号
                invoke wsprintf,offset TempBuf,offset szD,Indent
                invoke ListView_AddItemEx,hMianDlg,92,NULL,Indent,0,offset TempBuf
                ;; 当前地址
                invoke wsprintf,offset TempBuf,offset sz08X,DWORD ptr[esi]
                invoke ListView_AddItemEx,hMianDlg,92,NULL,Indent,1,offset TempBuf
                ;; 原始地址
                mov eax, DWORD ptr[edi]
                add eax, dwdelta
                invoke wsprintf,offset TempBuf,offset sz08X,eax
                invoke ListView_AddItemEx,hMianDlg,92,NULL,Indent,2,offset TempBuf
                ;; 当前参数
                mov eax, Indent
                add eax, pSSPT
                movzx eax, BYTE ptr[eax]
                invoke wsprintf,offset TempBuf,offset szD,eax
                invoke ListView_AddItemEx,hMianDlg,92,NULL,Indent,3,offset TempBuf
                ;; 原始参数
                mov eax, Indent
                add eax, Shadow_ParamTableBase
                movzx eax, BYTE ptr[eax]
                invoke wsprintf,offset TempBuf,offset szD,eax
                invoke ListView_AddItemEx,hMianDlg,92,NULL,Indent,4,offset TempBuf
                ;; 名称
                .if ShadowSsdtName
                        mov eax, ShadowSsdtName
                        invoke ListView_AddItemEx,hMianDlg,92,NULL,Indent,5,DWORD ptr[eax]
                        add ShadowSsdtName, 4
                .endif
                ;; 所属模块
                invoke GetBelongsSys,DWORD ptr[esi]
                .if eax
                        mov ecx, eax
                        invoke ListView_AddItemEx,hMianDlg,92,0,Indent,6,addr [ecx].KERNEL_MODULE.ImageName
                .endif
                add esi, 4
                add edi, 4
                inc Indent
                mov eax, Indent
        .until eax == Shadow_NumberOfService
        err:
        .if pSSDT
                invoke GlobalFree,pSSDT
        .endif
        .if pSSPT
                invoke GlobalFree,pSSPT
        .endif
        .if BaseAddress
                invoke UnmapViewOfFile,BaseAddress
        .endif
        .if hFile
                invoke ZwClose,hFile
        .endif
        .if hFileMap
                invoke ZwClose,hFileMap
        .endif
        ret
       
ShadowSsdt endp
2011-8-23 14:17
0
雪    币: 170
活跃值: (90)
能力值: ( LV12,RANK:210 )
在线值:
发帖
回帖
粉丝
8
汇编写  太强大啊
2011-8-26 11:56
0
雪    币: 116
活跃值: (48)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
9
MARK下·
2011-8-27 00:54
0
雪    币: 27
活跃值: (90)
能力值: ( LV8,RANK:120 )
在线值:
发帖
回帖
粉丝
10
我喜欢向老V学习 :)
2011-8-27 02:41
0
雪    币: 220
活跃值: (15)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
11
呵呵 这个得强烈支持一下
2011-8-27 02:46
0
游客
登录 | 注册 方可回帖
返回
//