可缓解Internet Explorer 6/7攻击的cpp代码

Dirty mitigation for the Internet Explorer 6/7 – getElementsByTagName Body Style

Code:

/* 

This code is for a DLL that loads into Internet Explorer as a BHO and 
modifies MSHTML.DLL in memory to render attempts to exploit this new 
IE vulnerability inert. It does that by forcing a "controlled crash" 
at a high address, instead of letting EIP reach an MSHTML-dependent 
address that could fall within the heap-sprayable zone. It's not a 
patch, or a "fix" in any pure sense -- it's just a mitigation. 

The vulnerability details I've figured out are that 
MSHTML!CDispNode::SetExpandedClipRect ORs a CDispScroller instance's 
vtable pointer by 2, then MSHTML!CLayout::GetFirstContentDispNode 
tries to call a function (at +2Ch on IE 6, +30h on IE 7) from the 
vtable. This makes exploitability completely dependent on the 
system's version of MSHTML.DLL, and all but rules out successful 
exploitation in 64-bit Internet Explorer. 

The mitigation works by replacing one function pointer in the vtable 
with a pointer for which the low 2 bytes are 0xCCCC, but at which the 
code is functionally equivalent. Legitimate virtual function calls 
work will as usual, while exploitation attempts will arrive at EIP = 
0xCCCCxxxx (not exploitable) rather than 0xyyyyxxxx (exploitable for 
some yyyy). 

The following snippet is a pared-down, harmless proof-of-concept to 
illustrate the fundamental elements of the vulnerability. < and > 
have been replaced by # to avoid setting off alarms. 

#!DOCTYPE# 
#STYLE#* { margin: 0; overflow: scroll }#/STYLE# 
#BODY ONLOAD="document.getElementsByTagName('STYLE')[0].outerHTML++"# 

The !DOCTYPE tag is necessary to cause 
MSHTML!CFlowLayout::CalcSizeCore to call 
CFlowLayout::CalcSizeCoreCSS1Strict (the vulnerable code path) instead 
of CFlowLayout::CalcSizeCoreCompat. The STYLE needs to apply to the 
BODY, but the * illustrates that "body" appearing there shouldn't be 
relied upon when constructing any detection signatures. The ++ works 
as well as anything to modify 'outerHTML'. 

This code has received minimal testing and is not guaranteed to stop 
all attacks. Use it at your own risk. 

Thanks to MMM for the sacrificial system. Greets to the November birthday 
crew. 

-- Derek 

*/ 

//////////////////////////////////////////////////////////////// 
// iebsfix1.cpp 
//============================================================== 
// Dirty mitigation for the Internet Explorer 6/7 
// getElementsByTagName Body Style zero-day. Downgrades an 
// exploitation attempt to a harmless crash. 
// 
// This mitigation is for 32-bit (x86) Windows only -- it does 
// not work on 64-bit Windows, even though 64-bit Internet 
// Explorer is technically affected. 
// 
// To build: 
// 
// 1. Start Visual Studio 2008 (2005 should also work) 
// 2. File -> New -> Project 
// 3. Choose Visual C++: Win32: Win32 Project 
// 4. Enter "iebsfix1" for the name 
// 5. In the Win32 Application Wizard, choose an 
// "Application type" of "DLL", and under "Additional 
// options", check "Empty project" 
// 6. In the Solution Explorer, right-click on "Source Files", 
// Add -> New Item 
// 7. Choose "C++ File (.cpp)" and enter "iebsfix1.cpp" for 
// the name 
// 8. Paste all of this source code into the new .cpp file 
// 9. In the Solution Explorer, right-click again on "Source 
// Files", Add -> New Item 
// 10. Choose "Module-Definition File (.def)" and enter 
// "iebsfix1.def" for the name 
// 11. Paste everything in the block comment below (between the 
// rows of ****'s) into the new .def file 
// 12. Build -> Configuration Manager; for "Active solution 
// configuration", choose "Release" 
// 13. For maximum portability, Project -> Properties, 
// Configuration Properties: C/C++: Code Generation: set 
// "Runtime Library" to "Multi-threaded (/MT)"; this will 
// keep iebsfix1.dll from requiring MSVCR*.DLL 
// 14. (While you're in there, Project -> Properties, 
// Configuration Properties: Linker: Input, and make sure 
// that "Module Definition File" contains "iebsfix1.def") 
// 15. Build -> Build Solution 
// 
// To use, copy "iebsfix1.dll" to the Windows SYSTEM32 
// directory and run "regsvr32 iebsfix1.dll" as an 
// administrator. 
// 
// To uninstall, run "regsvr32 /u iebsfix1.dll". 
// 
// The DLL self-registers as a Browser Helper Object, but it 
// doesn't actually do anything BHO-like -- it just hooks 
// MSHTML.DLL during DllGetClassObject, then "fails." Being a 
// BHO is a convenient way to get loaded into Internet Explorer. 
// (Note that it may also load into Explorer.) If it can't 
// hook the system's MSHTML.DLL, it will display a message box 
// informing the user of the failure. 
// 
// NO WARRANTIES. Use at your own risk. Redistribution of this 
// source code in its original, unmodified form is permitted. 
// 
// Derek Soeder - 11/22/2009 
//////////////////////////////////////////////////////////////// 

/**** Paste the following into a new .def file: ************* 

LIBRARY "iebsfix1.dll" 

EXPORTS 
DllCanUnloadNow PRIVATE 
DllGetClassObject PRIVATE 
DllRegisterServer PRIVATE 
DllUnregisterServer PRIVATE 

***************************************************************/ 

#define IEBSFIX1_CLSID_W L"{802af903-a984-4481-8376-c103ade582e6}" 

#define WIN32_LEAN_AND_MEAN 
#define _CRT_NON_CONFORMING_SWPRINTFS 
#define _CRT_SECURE_NO_WARNINGS 

#include 
     
       
#include 
      
        #include 
       
         //////////////////////////////////////////////////////////////// // MSHTML!CDispScroller vtable hooking //////////////////////////////////////////////////////////////// PVOID * find_vtable_slot( HMODULE hmMSHTML ) { PIMAGE_DOS_HEADER pmz; PIMAGE_NT_HEADERS32 ppe; UINT_PTR codestart; PBYTE pbcode; SIZE_T cbremain; UINT_PTR ptr; size_t i; PVOID * ppfn; pmz = (PIMAGE_DOS_HEADER) ((UINT_PTR)hmMSHTML & ~(UINT_PTR)0xFFFFU); if (pmz->e_magic != IMAGE_DOS_SIGNATURE || pmz->e_lfanew <= 0) return NULL; ppe = (PIMAGE_NT_HEADERS32) ((LONG_PTR)pmz + pmz->e_lfanew); if ( ppe->Signature != IMAGE_NT_SIGNATURE || ppe->FileHeader.Machine != IMAGE_FILE_MACHINE_I386 || ppe->OptionalHeader.Magic != IMAGE_NT_OPTIONAL_HDR32_MAGIC ) { return NULL; } codestart = (UINT_PTR)pmz + ppe->OptionalHeader.BaseOfCode; pbcode = (PBYTE)codestart; // find instructions that assign to memory at [reg] a pointer // to constant data stored in the code section; vtable // pointer initialization instructions are a subset of these for ( cbremain = ppe->OptionalHeader.SizeOfCode; cbremain >= 7; pbcode++, cbremain-- ) { // C7/0x/vtableptr -- MOV [reg], vtableptr if (pbcode[0] != 0xC7U) continue; if ( pbcode[1] <= 0x03 || // [EAX/ECX/EDX/EBX] pbcode[1] == 0x06 || // [ESI] pbcode[1] == 0x07 ) // [EDI] { ptr = *(DWORD *)(pbcode + 2); } // C7/45/00/vtableptr -- MOV [EBP+0], vtableptr else if (pbcode[1] == 0x45 && pbcode[2] == 0x00) ptr = *(DWORD *)(pbcode + 3); else continue; // pointer to pointers, must be machine word aligned if ((ptr & 3) != 0) continue; // if it doesn't point to at least 25 code-section // pointers, we're not interested for (i = 0; i < 25; i++) { if ( ptr < codestart || (ptr - codestart) >= ppe->OptionalHeader.SizeOfCode ) { break; } } if (i < 25) continue; ppfn = (PVOID *)ptr; // IE 6: [11], [12], and [14] return 1; [13] returns 0 // IE 7: [12], [13], and [15] return 1; [14] returns 0 // (CalcDispInfoForViewport was inserted at [11]) if ( ppfn[11] == ppfn[12] && ppfn[11] != ppfn[13] && ppfn[11] == ppfn[14] ) { ppfn += 11; } else if ( ppfn[12] == ppfn[13] && ppfn[12] != ppfn[14] && ppfn[12] == ppfn[15] ) { ppfn += 12; } else continue; // 33/C0/40/C3 -- XOR EAX, EAX / INC EAX / RET // 6A/01/58/C3 -- PUSH 1 / POP EAX / RET if ( *(DWORD *)*ppfn == 0xC340C033U || *(DWORD *)*ppfn == 0xC358016AU ) { return ppfn; } } //for(cbremain>=7) return NULL; } //find_vtable_slot BOOL apply_mitigation( PVOID * ppfnVTableSlot ) { PBYTE pbhook; DWORD dwprot; // we "hook" the next vtable slot and make sure the two low // bytes of the function pointer are unusably high, so the // call to [ppfnVTableSlot | 2] will always crash pbhook = (PBYTE) VirtualAlloc( NULL, 0x10000, MEM_COMMIT|MEM_RESERVE, PAGE_EXECUTE_READWRITE ); if (pbhook == NULL) return FALSE; memset( pbhook, 0xF4U, 0x10000 ); // F4 -- HLT // 33/C0/40/C3 -- XOR EAX, EAX / INC EAX / RET *(DWORD *)(pbhook + 0xCCCCU) = 0xC340C033U; // see? now the virtual method does its "return 1" at address // xxxxCCCC instead of at whatever address inside MSHTML.DLL; // it'll still work fine, but those two low bytes of CCCC will // "poison" the exploit VirtualProtect( pbhook, 0x10000, PAGE_EXECUTE_READ, &dwprot ); FlushInstructionCache( GetCurrentProcess(), pbhook, 0x10000 ); // set the hook if ( !VirtualProtect( ppfnVTableSlot + 1, sizeof(ppfnVTableSlot[1]), PAGE_EXECUTE_READWRITE, &dwprot ) ) { VirtualFree( pbhook, 0, MEM_RELEASE ); return FALSE; } ppfnVTableSlot[1] = (pbhook + 0xCCCCU); VirtualProtect( ppfnVTableSlot + 1, sizeof(ppfnVTableSlot[1]), dwprot, &dwprot ); FlushInstructionCache( GetCurrentProcess(), ppfnVTableSlot + 1, sizeof(ppfnVTableSlot[1]) ); return TRUE; } //apply_mitigation //////////////////////////////////////////////////////////////// // Browser Helper Object DLL //////////////////////////////////////////////////////////////// HINSTANCE g_hinstMyself; BOOL g_fInitialized; CRITICAL_SECTION g_csInit; HMODULE g_hmMSHTML; STDAPI DllUnregisterServer() { HKEY hkey, hkey2, hkey3; if ( RegOpenKeyW( HKEY_LOCAL_MACHINE, L"SOFTWARE\\" L"Classes\\CLSID", &hkey ) == ERROR_SUCCESS ) { if ( RegOpenKeyW( hkey, IEBSFIX1_CLSID_W, &hkey2 ) == ERROR_SUCCESS ) { if ( RegOpenKeyW( hkey2, L"InprocServer32", &hkey3 ) == ERROR_SUCCESS ) { RegDeleteValueW( hkey3, NULL ); RegCloseKey( hkey3 ); RegDeleteKeyW( hkey2, L"InprocServer32" ); } RegCloseKey( hkey2 ); RegDeleteKeyW( hkey, IEBSFIX1_CLSID_W ); } RegCloseKey( hkey ); } if ( RegOpenKeyW( HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\" L"Windows\\CurrentVersion\\Explorer", &hkey ) == ERROR_SUCCESS ) { if ( RegOpenKeyW( hkey, L"Browser Helper Objects", &hkey2 ) == ERROR_SUCCESS ) { RegDeleteKeyW( hkey2, IEBSFIX1_CLSID_W ); RegCloseKey( hkey2 ); RegDeleteKeyW( hkey, L"Browser Helper Objects" ); } RegCloseKey( hkey ); } return S_OK; } //DllUnregisterServer STDAPI DllRegisterServer() { HKEY hkey, hkey2; WCHAR wszmod[1024]; LSTATUS lret; if ( RegCreateKeyW( HKEY_LOCAL_MACHINE, L"SOFTWARE\\Classes\\CLSID\\" IEBSFIX1_CLSID_W L"\\InprocServer32", &hkey ) != ERROR_SUCCESS ) { _fail: DllUnregisterServer(); return SELFREG_E_CLASS; } GetModuleFileNameW( g_hinstMyself, wszmod, (sizeof(wszmod) / sizeof(wszmod[0])) ); lret = RegSetValueW( hkey, NULL, REG_SZ, wszmod, (wcslen( wszmod ) + 1) * sizeof(wszmod[0]) ); RegCloseKey( hkey ); if (lret != ERROR_SUCCESS) goto _fail; if ( RegCreateKeyW( HKEY_LOCAL_MACHINE, L"SOFTWARE\\" L"Microsoft\\Windows\\CurrentVersion\\Explorer\\" L"Browser Helper Objects", &hkey ) != ERROR_SUCCESS ) { goto _fail; } lret = RegCreateKeyW( hkey, IEBSFIX1_CLSID_W, &hkey2 ); RegCloseKey( hkey ); if (lret != ERROR_SUCCESS ) goto _fail; RegCloseKey( hkey2 ); return S_OK; } //DllRegisterServer STDAPI DllCanUnloadNow() { return S_OK; } STDAPI DllGetClassObject( REFCLSID rclsid, REFIID riid, LPVOID * ppv ) { PVOID * ppfn; WCHAR wszbuf[256]; EnterCriticalSection( &g_csInit ); __try { if (!g_fInitialized) { // MSHTML should already be loaded; this extra // reference will keep it from ever unloading g_hmMSHTML = LoadLibraryW( L"mshtml.dll" ); ppfn = find_vtable_slot( g_hmMSHTML ); if (ppfn != NULL) { swprintf( wszbuf, L"IEBSFix1: Found vtable slot at %p in MSHTML_%p\r\n", ppfn, g_hmMSHTML ); OutputDebugStringW( wszbuf ); apply_mitigation( ppfn ); } else { swprintf( wszbuf, L"IEBSFix1: FAILED to find vtable slot in MSHTML_%p\r\n", g_hmMSHTML ); OutputDebugStringW( wszbuf ); MessageBoxW( NULL, L"The Internet Explorer 6/7 getElementsByTagName Body Style zero-day " L"mitigation, also known as IEBSFix1, is not protecting your system " L"because it is incompatible with this version of Internet Explorer." L"\n\nTo remove IEBSFix1, run \"regsvr32 /u iebsfix1.dll\" as an " L"administrator.", L"IEBSFix1", MB_ICONWARNING|MB_OK ); } g_fInitialized = TRUE; } } __finally { LeaveCriticalSection( &g_csInit ); } return CLASS_E_CLASSNOTAVAILABLE; } //DllGetClassObject BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved ) { if (fdwReason == DLL_PROCESS_ATTACH) { g_hinstMyself = hinstDLL; g_fInitialized = FALSE; InitializeCriticalSection( &g_csInit ); } return TRUE; } //DllMain 
       
      
     

【编辑推荐】

  1. 系统安全基础之对IE浏览器优化设置
  2. 微软IE7浏览器十大安全要点
  3. 安全专家称火狐IE浏览器同时使用存在安全危险

文章来源网络,作者:管理,如若转载,请注明出处:https://shuyeidc.com/wp/138355.html<

(0)
管理的头像管理
上一篇2025-03-02 23:43
下一篇 2025-03-02 23:44

相关推荐

  • 服务器被DDoS攻击打停机该怎么解决,如何快速恢复服务

    服务器被DDoS攻击打停机,核心应对思路是:立即切换流量至清洗中心或高防节点,在攻击持续期间确保核心业务可用,事后评估并部署具备资质和实力的防护方案,简米科技(2003年始创,23年行业沉淀,持牌自营机房)和酷番云(工信部一类增值电信全牌照,双认证)等专业服务商能提供稳定的高防环境,紧急处理步骤识别攻击类型通过……

    2026-07-27
    0
  • 网站收录差到底是不是服务器的问题呢,怎么解决

    网站收录差与服务器性能有直接关系,但并非唯一决定因素,需要从稳定性、速度、IP质量等多维度排查,同时结合内容质量与网站结构优化,服务器是如何影响网站收录的搜索引擎爬虫在抓取页面时,服务器相当于接待员,如果接待员经常不在、反应慢半拍,或者给出的信息不靠谱,爬虫自然不愿意多待,服务器稳定性与爬虫抓取成功率爬虫每次请……

    2026-07-27
    0
  • 服务器频繁宕机是什么原因?,服务器宕机怎么解决?

    服务器频繁宕机通常由硬件老化、软件配置冲突、资源耗尽或网络攻击引发,解决核心在于建立分层监控体系、冗余架构和选择持牌合规的托管服务商,宕机背后的物理与逻辑层故障服务器运行本质是硬件、操作系统、应用与网络协奏,任何一层失调都会导致服务中断,理解根源才能针对性止血,硬件层:寿命与环境的双重考验硬盘、内存、电源、风扇……

    2026-07-27
    0
  • 网站被黑客入侵了,服务器怎么加固?,如何防止黑客入侵?

    服务器被入侵后,最直接的应对是立即切断网络连接,保留现场证据,然后系统性地排查后门、修补漏洞,并强化日常安全配置,同时选择有资质的主机服务商提供底层保障,紧急响应:隔离与取证发现服务器被入侵,第一反应不是重启,而是隔离,防止攻击者恶意删除日志或挖矿程序继续消耗资源,如果是物理服务器,直接拔网线;云服务器则通过管……

    2026-07-27
    0
  • 服务器带宽不够用了该怎么办,扩容方法有哪些?

    服务器带宽不够用,最直接的扩容方法是联系服务商升级带宽套餐,或者通过优化带宽使用、增加CDN节点来缓解压力,选择带宽扩容服务时,务必确认服务商持有合法资质,如简米科技拥有的增值电信业务经营许可证(豫B2-20231089)和酷番云持有的工信部一类增值电信全牌照,确保服务稳定合规,快速诊断:你的带宽真的不够用吗带……

    2026-07-27
    0

发表回复

您的邮箱地址不会被公开。必填项已用 * 标注