首页
社区
课程
招聘
[旧帖] 搜内核未导出的函数地址,特征对了正常,如果特征码不对就蓝屏。谁帮我看下代码 0.00雪花
发表于: 2012-11-9 12:52 4556

[旧帖] 搜内核未导出的函数地址,特征对了正常,如果特征码不对就蓝屏。谁帮我看下代码 0.00雪花

2012-11-9 12:52
4556
DWORD i;//循环找
  DWORD Count;
  DWORD Count1;
  NTSTATUS status;
  ULONG len;
  PVOID p_Buffer;
  PRTL_PROCESS_MODULES Mode_data;

  DWORD BaseAddr;
  DWORD u_addr;
  BYTE* _bp;
  

  status=ZwQuerySystemInformation((SYSTEM_INFORMATION_CLASS)11,NULL,0,&len);
  p_Buffer=ExAllocatePool(NonPagedPool,len);
  if(p_Buffer==NULL)
  {
    KdPrint(("分配内存出错!\r\n"));
    return ;
  }
  status=ZwQuerySystemInformation((SYSTEM_INFORMATION_CLASS)11,p_Buffer,len,0);
  Mode_data=(PRTL_PROCESS_MODULES)p_Buffer;

  BaseAddr=(DWORD)Mode_data->Modules[0].ImageBase;
  Count = (DWORD)Mode_data->Modules[0].ImageSize;

  KdPrint(("BaseAddr地址为:%x , ImageSize大小为:%x\r\n",BaseAddr,Count));

  ExFreePool(p_Buffer);
  
  return ;
  u_addr = BaseAddr;
  while(1)
  {
    if (GetValue_b(u_addr)==0x64
      &&GetValue_b(u_addr+6)==0x8B
      &&GetValue_b(u_addr+9)==0x39
      &&GetValue_b(u_addr+0xa)==0xB8
      &&GetValue_b(u_addr+0xb)==0xbc)
  
    {
      str_debugport.KiDispatchException=(ULONG)u_addr+0xb;
      KdPrint(("KiDispatchException的地址为:%x\r\n",KiDispatchException));
      break;
    }

    u_addr++;
  }
  


如果上面的特征对的上。查找到了。就不会蓝屏。请问一下。是否是因为越界了。可以用
ImageSize 来判断吗?但是我判断了还是会蓝。

[课程]Linux pwn 探索篇!

收藏
免费 0
支持
分享
最新回复 (5)
雪    币: 28961
活跃值: (7448)
能力值: ( LV15,RANK:3306 )
在线值:
发帖
回帖
粉丝
2
按区段搜索吧
2012-11-9 14:10
0
雪    币: 219
活跃值: (738)
能力值: (RANK:290 )
在线值:
发帖
回帖
粉丝
3
http://bbs.pediy.com/showthread.php?t=151311
2012-11-9 16:55
0
雪    币: 124
活跃值: (54)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4
  这个代码不全,像GetFunctionIndexByName我都不知道怎么实现的。有完整的这个函数的例子吗?有的话发我学习一下。谢谢了
2012-11-10 13:58
0
雪    币: 100
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
5
3L给出的代码是A盾中的。LZ可以看看A盾代码 我把GetFunctionIndexByName代码贴出来。

BOOL GetFunctionIndexByName(CHAR *lpszFunctionName,int *Index)
{
        UNICODE_STRING wsNtDllString;

        HANDLE hNtSection;
        ULONG ulNtDllModuleBase;
        PIMAGE_DOS_HEADER pDosHeader;
        PIMAGE_NT_HEADERS NtDllHeader;

        IMAGE_OPTIONAL_HEADER opthdr;
        DWORD* arrayOfFunctionAddresses;
        DWORD* arrayOfFunctionNames;
        WORD* arrayOfFunctionOrdinals;
        DWORD functionOrdinal;
        DWORD Base, x, functionAddress,position;
        char* functionName;
        IMAGE_EXPORT_DIRECTORY *pExportTable;
        BOOL bRetOK = FALSE;
        BOOL bInit = FALSE;

        STRING lpszSearchFunction;
        STRING lpszFunction;

        __try
        {
                RRtlInitUnicodeString = ReLoadNtosCALL(L"RtlInitUnicodeString",SystemKernelModuleBase,ImageModuleBase);
                RZwClose = ReLoadNtosCALL(L"ZwClose",SystemKernelModuleBase,ImageModuleBase);
                if (RRtlInitUnicodeString &&
                        RZwClose)
                {
                        bInit = TRUE;
                }
                if (!bInit)
                        return NULL;

                RRtlInitUnicodeString(&wsNtDllString,L"\\SystemRoot\\System32\\ntdll.dll");
                hNtSection = MapFileAsSection(&wsNtDllString,&ulNtDllModuleBase);  //载入到内存
                if (!hNtSection)
                {
                        return bRetOK;
                }
                RZwClose(hNtSection);

                //NtDllHeader=(PIMAGE_NT_HEADERS)GetPeHead((ULONG)ulNtDllModuleBase);
                pDosHeader=(PIMAGE_DOS_HEADER)ulNtDllModuleBase;
                if (pDosHeader->e_magic!=IMAGE_DOS_SIGNATURE)
                {
                        if (DebugOn)
                                KdPrint(("failed to find NtHeader\r\n"));
                        return bRetOK;
                }
                NtDllHeader=(PIMAGE_NT_HEADERS)(ULONG)((ULONG)pDosHeader+pDosHeader->e_lfanew);
                if (NtDllHeader->Signature!=IMAGE_NT_SIGNATURE)
                {
                        if (DebugOn)
                                KdPrint(("failed to find NtHeader\r\n"));
                        return bRetOK;
                }
                opthdr = NtDllHeader->OptionalHeader;
                pExportTable =(IMAGE_EXPORT_DIRECTORY*)((BYTE*)ulNtDllModuleBase + opthdr.DataDirectory[ IMAGE_DIRECTORY_ENTRY_EXPORT]. VirtualAddress); //得到导出表
                arrayOfFunctionAddresses = (DWORD*)( (BYTE*)ulNtDllModuleBase + pExportTable->AddressOfFunctions);  //地址表
                arrayOfFunctionNames = (DWORD*)((BYTE*)ulNtDllModuleBase + pExportTable->AddressOfNames);         //函数名表
                arrayOfFunctionOrdinals = (WORD*)( (BYTE*)ulNtDllModuleBase + pExportTable->AddressOfNameOrdinals);

                Base = pExportTable->Base;

                for(x = 0; x < pExportTable->NumberOfFunctions; x++) //在整个导出表里扫描
                {
                        functionName = (char*)( (BYTE*)ulNtDllModuleBase + arrayOfFunctionNames[x]);
                        functionOrdinal = arrayOfFunctionOrdinals[x] + Base - 1;
                        functionAddress = (DWORD)((BYTE*)ulNtDllModuleBase + arrayOfFunctionAddresses[functionOrdinal]);
                        position  = *((WORD*)(functionAddress + 1));  //得到服务号

                        RtlInitString(&lpszSearchFunction,functionName);
                        RtlInitString(&lpszFunction,lpszFunctionName);
                        if (RtlCompareString(&lpszSearchFunction,&lpszFunction,TRUE) == 0)
                        {
                                if (DebugOn)
                                        KdPrint(("Find FunctionName:%s\r\nposition:%d\r\n",functionName,position));
                                *Index = position;
                                bRetOK = TRUE;
                                break;
                        }
                }

        }__except(EXCEPTION_EXECUTE_HANDLER){

        }
        return bRetOK;
}
2012-11-10 14:15
0
雪    币: 59
活跃值: (17)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
6
楼上说的很好……
2012-11-15 12:26
0
游客
登录 | 注册 方可回帖
返回
//