Changeset 52739 in vbox for trunk/src/VBox/HostDrivers/Support/win
- Timestamp:
- Sep 13, 2014 11:16:58 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/Support/win/SUPR3HardenedMain-win.cpp
r52709 r52739 228 228 * thread creation in this process. */ 229 229 static uint8_t g_abLdrInitThunkSelfBackup[16]; 230 231 /** Mask of adversaries that we've detected (SUPHARDNT_ADVERSARY_XXX). */ 232 static uint32_t g_fSupAdversaries = 0; 233 /** @name SUPHARDNT_ADVERSARY_XXX - Adversaries 234 * @{ */ 235 /** Symantec endpoint protection or similar including SysPlant.sys. */ 236 #define SUPHARDNT_ADVERSARY_SYMANTEC_SYSPLANT RT_BIT_32(0) 237 /** Avast! */ 238 #define SUPHARDNT_ADVERSARY_AVAST RT_BIT_32(1) 239 /** Unknown adversary detected while waiting on child. */ 240 #define SUPHARDNT_ADVERSARY_UNKNOWN RT_BIT_32(31) 241 /** @} */ 230 242 231 243 … … 3449 3461 * process asynchronously. 3450 3462 */ 3451 DWORD dwStart = GetTickCount(); 3452 NtYieldExecution(); 3453 3454 LARGE_INTEGER Time; 3455 Time.QuadPart = -8000000 / 100; /* 8ms in 100ns units, relative time. */ 3456 NtDelayExecution(FALSE, &Time); 3457 3458 NtYieldExecution(); 3459 3460 Time.QuadPart = -8000000 / 100; /* 8ms in 100ns units, relative time. */ 3461 NtDelayExecution(FALSE, &Time); 3462 3463 NtYieldExecution(); 3463 DWORD dwStart = GetTickCount(); 3464 uint32_t cMsKludge = (g_fSupAdversaries & SUPHARDNT_ADVERSARY_SYMANTEC_SYSPLANT) ? 256 : g_fSupAdversaries ? 64 : 16; 3465 do 3466 { 3467 NtYieldExecution(); 3468 LARGE_INTEGER Time; 3469 Time.QuadPart = -8000000 / 100; /* 8ms in 100ns units, relative time. */ 3470 NtDelayExecution(FALSE, &Time); 3471 } while (GetTickCount() - dwStart < cMsKludge); 3464 3472 SUP_DPRINTF(("supR3HardNtPuChTriggerInitialImageEvents: Startup delay kludge #1: %u ms\n", GetTickCount() - dwStart)); 3465 3473 3466 3474 /* 3467 3475 * Unmap the image we mapped into the guest above. 3468 */ 3469 supR3HardNtPuChUnmapDllFromChild(pThis, pvKernel32, "kernel32.dll"); 3470 supR3HardNtPuChUnmapDllFromChild(pThis, pvKernelBase, "KernelBase.dll"); 3476 * Experiment: Don't unmap for avast. 3477 */ 3478 if (!(g_fSupAdversaries & SUPHARDNT_ADVERSARY_AVAST)) 3479 { 3480 supR3HardNtPuChUnmapDllFromChild(pThis, pvKernel32, "kernel32.dll"); 3481 supR3HardNtPuChUnmapDllFromChild(pThis, pvKernelBase, "KernelBase.dll"); 3482 } 3471 3483 supR3HardNtPuChUnmapDllFromChild(pThis, pvNtDll2, "ntdll.dll[2nd]"); 3472 3484 supR3HardNtPuChUnmapDllFromChild(pThis, pvExe2, "executable[2nd]"); … … 4386 4398 * This is unfortunately kind of fragile. 4387 4399 */ 4388 uint32_t iLoop = 0;4400 uint32_t cMsFudge = g_fSupAdversaries ? 512 : 128; 4389 4401 uint32_t cFixes; 4390 do4402 for (uint32_t iLoop = 0; iLoop < 16; iLoop++) 4391 4403 { 4392 4404 uint32_t cSleeps = 0; … … 4399 4411 NtDelayExecution(FALSE, &Time); 4400 4412 cSleeps++; 4401 } while ( GetTickCount() - dwStart <= 804413 } while ( GetTickCount() - dwStart <= cMsFudge 4402 4414 || cSleeps < 8); 4403 4415 SUP_DPRINTF(("supR3HardenedWinInit: Startup delay kludge #2/%u: %u ms, %u sleeps\n", … … 4407 4419 rc = supHardenedWinVerifyProcess(NtCurrentProcess(), NtCurrentThread(), SUPHARDNTVPKIND_SELF_PURIFICATION, 4408 4420 &cFixes, NULL /*pErrInfo*/); 4409 } while ( RT_SUCCESS(rc) 4410 && cFixes > 0 4411 && ++iLoop < 8); 4421 if (RT_FAILURE(rc) || cFixes == 0) 4422 break; 4423 4424 if (!g_fSupAdversaries) 4425 g_fSupAdversaries |= SUPHARDNT_ADVERSARY_UNKNOWN; 4426 cMsFudge = 512; 4427 SUP_DPRINTF(("supR3HardenedWinInit: cFixes=%u g_fSupAdversaries=%#x\n", cFixes, g_fSupAdversaries)); 4428 } 4412 4429 4413 4430 /* … … 4520 4537 4521 4538 4539 /** 4540 * Scans the Driver directory for drivers which may invade our processes. 4541 * 4542 * @returns Mask of SUPHARDNT_ADVERSARY_XXX flags. 4543 */ 4544 static uint32_t supR3HardenedWinFindAdversaries(void) 4545 { 4546 /* 4547 * Open the driver object directory. 4548 */ 4549 UNICODE_STRING NtDirName = RTNT_CONSTANT_UNISTR(L"\\Driver"); 4550 4551 OBJECT_ATTRIBUTES ObjAttr; 4552 InitializeObjectAttributes(&ObjAttr, &NtDirName, OBJ_CASE_INSENSITIVE, NULL /*hRootDir*/, NULL /*pSecDesc*/); 4553 4554 HANDLE hDir; 4555 NTSTATUS rcNt = NtOpenDirectoryObject(&hDir, DIRECTORY_QUERY | FILE_LIST_DIRECTORY, &ObjAttr); 4556 #ifdef VBOX_STRICT 4557 SUPR3HARDENED_ASSERT_NT_SUCCESS(rcNt); 4558 #endif 4559 if (!NT_SUCCESS(rcNt)) 4560 return 0; 4561 4562 /* 4563 * Enumerate it, looking for the driver. 4564 */ 4565 uint32_t fFound = 0; 4566 ULONG uObjDirCtx = 0; 4567 for (;;) 4568 { 4569 uint32_t abBuffer[_64K + _1K]; 4570 ULONG cbActual; 4571 rcNt = NtQueryDirectoryObject(hDir, 4572 abBuffer, 4573 sizeof(abBuffer) - 4, /* minus four for string terminator space. */ 4574 FALSE /*ReturnSingleEntry */, 4575 FALSE /*RestartScan*/, 4576 &uObjDirCtx, 4577 &cbActual); 4578 if (!NT_SUCCESS(rcNt) || cbActual < sizeof(OBJECT_DIRECTORY_INFORMATION)) 4579 break; 4580 4581 POBJECT_DIRECTORY_INFORMATION pObjDir = (POBJECT_DIRECTORY_INFORMATION)abBuffer; 4582 while (pObjDir->Name.Length != 0) 4583 { 4584 WCHAR wcSaved = pObjDir->Name.Buffer[pObjDir->Name.Length / sizeof(WCHAR)]; 4585 pObjDir->Name.Buffer[pObjDir->Name.Length / sizeof(WCHAR)] = '\0'; 4586 4587 #define IS_MATCH(a_Str) ( pObjDir->Name.Length == sizeof(L##a_Str) - sizeof(WCHAR) \ 4588 && RTUtf16ICmpAscii(pObjDir->Name.Buffer, a_Str) == 0) 4589 if (IS_MATCH("sysplant")) 4590 fFound |= SUPHARDNT_ADVERSARY_SYMANTEC_SYSPLANT; 4591 else if (IS_MATCH("aswHwid")) 4592 fFound |= SUPHARDNT_ADVERSARY_AVAST; 4593 else if (IS_MATCH("aswMonFlt")) 4594 fFound |= SUPHARDNT_ADVERSARY_AVAST; 4595 else if (IS_MATCH("aswRdr2")) 4596 fFound |= SUPHARDNT_ADVERSARY_AVAST; 4597 else if (IS_MATCH("aswRvrt")) 4598 fFound |= SUPHARDNT_ADVERSARY_AVAST; 4599 else if (IS_MATCH("aswSnx")) 4600 fFound |= SUPHARDNT_ADVERSARY_AVAST; 4601 else if (IS_MATCH("aswsp")) 4602 fFound |= SUPHARDNT_ADVERSARY_AVAST; 4603 else if (IS_MATCH("aswStm")) 4604 fFound |= SUPHARDNT_ADVERSARY_AVAST; 4605 else if (IS_MATCH("aswVmm")) 4606 fFound |= SUPHARDNT_ADVERSARY_AVAST; 4607 #undef IS_MATCH 4608 pObjDir->Name.Buffer[pObjDir->Name.Length / sizeof(WCHAR)] = wcSaved; 4609 4610 /* Next directory entry. */ 4611 pObjDir++; 4612 } 4613 } 4614 4615 /* 4616 * Clean up and return. 4617 */ 4618 NtClose(hDir); 4619 4620 return fFound; 4621 } 4622 4623 4522 4624 extern "C" int main(int argc, char **argv, char **envp); 4523 4625 … … 4563 4665 4564 4666 supR3HardenedOpenLog(&cArgs, papszArgs); 4667 4668 /* 4669 * Scan the system for adversaries. 4670 */ 4671 g_fSupAdversaries = supR3HardenedWinFindAdversaries(); 4672 SUP_DPRINTF(("g_fSupAdversaries=%#x\n", g_fSupAdversaries)); 4565 4673 4566 4674 /*
Note:
See TracChangeset
for help on using the changeset viewer.