• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            S.l.e!ep.¢%

            像打了激速一樣,以四倍的速度運(yùn)轉(zhuǎn),開(kāi)心的工作
            簡(jiǎn)單、開(kāi)放、平等的公司文化;尊重個(gè)性、自由與個(gè)人價(jià)值;
            posts - 1098, comments - 335, trackbacks - 0, articles - 1
              C++博客 :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

            hook未導(dǎo)出native api的好辦法

            Posted on 2009-11-04 11:39 S.l.e!ep.¢% 閱讀(400) 評(píng)論(0)  編輯 收藏 引用 所屬分類: RootKit
            				
            						昨天寫(xiě)的那個(gè) 
            hook?ssdt的驅(qū)動(dòng),用的是硬編碼的辦法,這樣在不同的系統(tǒng)中由于NtShutdownSystem的服務(wù)號(hào)都不相同,所以在不同的操作系統(tǒng)上代碼都要做修改,這個(gè)比較不爽.今天聽(tīng)老大PJF說(shuō)有避免硬編碼的方法,google了下,發(fā)現(xiàn)下面的文章,代碼稍微改了改,用在我的驅(qū)動(dòng)中,果然好使.文章貼在下面:
            -------------------------------------------------------------------------------------------
            from?http://www.rootkit.com

            Hardcoding?the?positions?seems?a?poor?solution,?since?it?means?after?a?new?service?pack,?the?rootkit?may?no?longer?work?and?become?discovered.

            As?I?have?found?the?code?on?this?site?extremely?helpful,?I?think?it?is?only?fair?that?I?return?the?favour?;-)

            I?have?implemented?the?method?described?in?previous?posts,?whereby?I?have?mapped?a?view?of?ntdll.dll?into?the?process?space?of?whoever?loads?the?driver?initially,?and?then?retrieve?the?required?function?positions?directly?from?the?dll.

            This?was?relatively?simple?to?do,?and?only?requires?knowledge?of?the?pe?file?format,?and?a?few?undocumented?apis.

            Using?the?function?pasted?below,?when?hooking?you?simply?do?as?follows:


            RtlInitUnicodeString(&dllName,?L"\\Device\\HarddiskVolume1\\Windows\\System32\\ntdll.dll");
            functionAddress?=?GetDllFunctionAddress(functionName,?&dllName);
            position?=?*((WORD*)(functionAddress+1));
            ????
            g_OriginalZwCreateProcessEx?=?(ZWCREATEPROCESSEX)(KeServiceDescriptorTable.ServiceTableBase[position]);


            and?here's?the?function?GetDllFunctionAddress:


            DWORD?GetDllFunctionAddress(char*?lpFunctionName,?PUNICODE_STRING?pDllName)?
            {
            ????HANDLE?hThread,?hSection,?hFile,?hMod;
            ????SECTION_IMAGE_INFORMATION?sii;
            ????IMAGE_DOS_HEADER*?dosheader;
            ????IMAGE_OPTIONAL_HEADER*?opthdr;
            ????IMAGE_EXPORT_DIRECTORY*?pExportTable;
            ????DWORD*?arrayOfFunctionAddresses;
            ????DWORD*?arrayOfFunctionNames;
            ????WORD*?arrayOfFunctionOrdinals;
            ????DWORD?functionOrdinal;
            ????DWORD?Base,?x,?functionAddress;
            ????char*?functionName;
            ????STRING?ntFunctionName,?ntFunctionNameSearch;
            ????PVOID?BaseAddress?=?NULL;
            ????SIZE_T?size=0;

            ????OBJECT_ATTRIBUTES?oa?=?{sizeof?oa,?0,?pDllName,?OBJ_CASE_INSENSITIVE};

            ????IO_STATUS_BLOCK?iosb;

            ????//_asm?int?3;
            ????ZwOpenFile(&hFile,?FILE_EXECUTE?|?SYNCHRONIZE,?&oa,?&iosb,?FILE_SHARE_READ,?FILE_SYNCHRONOUS_IO_NONALERT);

            ????oa.ObjectName?=?0;

            ????ZwCreateSection(&hSection,?SECTION_ALL_ACCESS,?&oa,?0,PAGE_EXECUTE,?SEC_IMAGE,?hFile);
            ????
            ????ZwMapViewOfSection(hSection,?NtCurrentProcess(),?&BaseAddress,?0,?1000,?0,?&size,?(SECTION_INHERIT)1,?MEM_TOP_DOWN,?PAGE_READWRITE);?
            ????
            ????ZwClose(hFile);
            ????
            ????hMod?=?BaseAddress;
            ????
            ????dosheader?=?(IMAGE_DOS_HEADER?*)hMod;
            ????
            ????opthdr?=(IMAGE_OPTIONAL_HEADER?*)?((BYTE*)hMod+dosheader->e_lfanew+24);

            ????pExportTable?=(IMAGE_EXPORT_DIRECTORY*)((BYTE*)?hMod?+?opthdr->DataDirectory[?IMAGE_DIRECTORY_ENTRY_EXPORT].?VirtualAddress);

            ????//?now?we?can?get?the?exported?functions,?but?note?we?convert?from?RVA?to?address
            ????arrayOfFunctionAddresses?=?(DWORD*)(?(BYTE*)hMod?+?pExportTable->AddressOfFunctions);

            ????arrayOfFunctionNames?=?(DWORD*)(?(BYTE*)hMod?+?pExportTable->AddressOfNames);

            ????arrayOfFunctionOrdinals?=?(WORD*)(?(BYTE*)hMod?+?pExportTable->AddressOfNameOrdinals);

            ????Base?=?pExportTable->Base;

            ????RtlInitString(&ntFunctionNameSearch,?lpFunctionName);

            ????for(x?=?0;?x?<?pExportTable->NumberOfFunctions;?x++)
            ????{
            ????????functionName?=?(char*)(?(BYTE*)hMod?+?arrayOfFunctionNames[x]);

            ????????RtlInitString(&ntFunctionName,?functionName);

            ????????functionOrdinal?=?arrayOfFunctionOrdinals[x]?+?Base?-?1;?//?always?need?to?add?base,?-1?as?array?counts?from?0
            ????????//?this?is?the?funny?bit.??you?would?expect?the?function?pointer?to?simply?be?arrayOfFunctionAddresses[x]...
            ????????//?oh?no...?thats?too?simple.??it?is?actually?arrayOfFunctionAddresses[functionOrdinal]!!
            ????????functionAddress?=?(DWORD)(?(BYTE*)hMod?+?arrayOfFunctionAddresses[functionOrdinal]);
            ????????if?(RtlCompareString(&ntFunctionName,?&ntFunctionNameSearch,?TRUE)?==?0)?
            ????????{
            ????????????ZwClose(hSection);
            ????????????return?functionAddress;
            ????????}
            ????}

            ????ZwClose(hSection);
            ????return?0;
            }
            国产精品视频久久| 久久久久人妻一区二区三区 | 久久婷婷五月综合97色一本一本| 久久精品综合网| 久久99久久99精品免视看动漫| 天天爽天天爽天天片a久久网| 精品久久久久久国产| 欧美激情精品久久久久久久九九九| 亚洲国产精品成人久久| 久久久久国产成人精品亚洲午夜| 午夜福利91久久福利| 狠狠狠色丁香婷婷综合久久俺| 一级女性全黄久久生活片免费 | 一日本道伊人久久综合影| 国产精品久久久久国产A级| 久久人人爽人人爽人人片AV麻豆| 少妇熟女久久综合网色欲| 日本精品久久久中文字幕| 久久精品国产日本波多野结衣| 久久久久国产亚洲AV麻豆| 国产精品久久久久久| 久久久久人妻一区精品色| 狠狠色丁香久久婷婷综合图片| 久久天堂电影网| 97精品伊人久久大香线蕉app| 久久伊人精品一区二区三区| 国产精品美女久久久久av爽| 国产精品美女久久久m| 久久棈精品久久久久久噜噜| 99久久国产宗和精品1上映 | 色综合久久夜色精品国产| 久久99久久无码毛片一区二区| 久久99精品国产一区二区三区| 麻豆一区二区99久久久久| 色综合久久无码中文字幕| 亚洲欧美国产精品专区久久| 久久天天躁狠狠躁夜夜av浪潮| 久久精品无码免费不卡| 久久成人国产精品一区二区| 久久被窝电影亚洲爽爽爽| 人人狠狠综合久久亚洲婷婷|