Keyhole逆向分析




Keyhole 是 IcedID/Anubis 广泛使用的多功能 VNC/Backconnect 组件。虽然该恶意软件包含以前报告为典型 VNC 和 HDESK 功能的功能,但目前存在的一些扩展功能似乎普遍缺乏技术信息。事实上,我们为 Keyhole 主组件绘制的功能可与 IcedID 本身相媲美:

  • 收集系统信息

  • VNC的

  • HDESK

  • Socks/Backconnect

  • 通过 cmd.exe 或 powershell 引爆控制台命令

  • 多种注射explorer.exe方法

  • LDAP 查询

  • 从受感染的系统中检索文件

  • 劫持浏览器配置文件

  • 删除浏览器配置文件

  • 通过命令行操作降低运行浏览器的安全性

  • 检查网络摄像头是否存在

  • 使用网络摄像头拍照

  • 在注册表中为应用打开麦克风

  • 枚举网络中的服务器和共享

此功能的某些部分分布在多个开源报告中,但在几个值得注意的改进中似乎缺少重要的分析。

155


Keyhole逆向分析


技术概览

初始装载机件:

初始组件涉及一个加载器,该加载器可以处理主组件的 PE 文件或 shellcode 版本;他们还可以使用带有损坏接头的自定义 PE 加载器。最终,加载器负责解码和加载核心模块并正确执行它。

解码核心模块:

核心模块使用 256 字节的交换值数组 (key) 进行编码。找到包含键值的初始 blob 后,将实现分析算法以创建数组。

未解析的密钥 Blob:


Keyhole逆向分析


给出一个整数来决定从未分析的 blob 中拉取多少字节。此整数的大小将加倍,直到该值超过 256。在整数在超过 256 之前可以翻倍的次数上加上 1 将是拉取的字节数。

找到一个整数来决定要拉取多少字节(不是 0)将导致不同的行为。第一次发生这种情况时,将添加适当数量的字节,然后添加一个空字节。直到下一个 0 的所有字节都将被抓取,并且该过程重复,直到密钥 len 为 256。

Python:解析密钥


Keyhole逆向分析


解析密钥/编码核心模块


Keyhole逆向分析


要解码核心模块,编码模块中的每个字节都将用作索引值。该索引处的键中的字节将替换编码的字节。

Python:解码核心模块


Keyhole逆向分析


解码核心模块中的字符串子集

user32.dll
bad pathname
path not found
Default
TOP WND
RtlExitUserProcess
MS Shell Dlg
already exists
explorer.exe
move
test
auth
-err-
runasinvoker
mkdir
disk
busy
__compat_layer
invalid name
hcddir
action not found
Allow
CREATE
AD not found
Value
HIDE
Settings
WINMM.DLL
2500
disk not found
combase.dll
MOVE
divice not readed
mdiclient
f%0.8X
User32.dll
Lucida Console
ntdll.dll
memory alloc
shell32.dll
access denied
open
error
{%0.8X-%0.4X-%0.4X-%0.4X-%0.4X%0.8X}
abcedfikmnopsutw
SelectObject
GetCurrentObject
GetObjectA
CreateCompatibleDC
DeleteDC
CreateDIBSection
CreateCompatibleBitmap
GetViewportOrgEx
BitBlt
NetShareEnum
NetApiBufferFree
NetGetDCName
NETAPI32.dll
RtlLargeIntegerDivide
RtlGetVersion
NtReadVirtualMemory
NtWriteVirtualMemory
NtFlushInstructionCache
NtProtectVirtualMemory
NtAllocateVirtualMemory
LoadCursorA
GetAncestor
CreateDesktopA
GetKeyboardLayoutList
GetKeyboardLayout
VkKeyScanA
VkKeyScanExA
VkKeyScanExW
MapVirtualKeyA
MapVirtualKeyExA
OpenClipboard
CloseClipboard
SetClipboardData
EmptyClipboard
EnumWindows
SetWinEventHook
GetThreadDesktop
RegisterClassExA
GetClipboardData
AddClipboardFormatListener
OpenInputDesktop
VkKeyScanW
SendInput
WinExec
GetPrivateProfileIntW
ACTIVEDS.dll
WS2_32.dll
TRUE
name
Exec
High Definition Audio

主要成分:

Keyhole 的主要组件可以包含编码字符串,真正有趣的部分是使用的算法与我在 2017 年 6 月分析的样本相同:

1cd6f992fbeee0a66e1c329e15db71fe891ae0e845867d6d30df867babe5bed6

旧的 IcedID 字符串解码例程:


Keyhole逆向分析


Keyhole 字符串解码例程:


Keyhole逆向分析


在Keyhole中解码字符串只需要在我的旧IcedID IDA脚本中进行少量编辑:

def gen_key(k):
return(((k << 0x1d) | (k >> 3)) & 0xffffffff)

for addr in XrefsTo(0x322630, flags=0):
addr = addr.frm
addr = idc.PrevHead(addr)
while GetMnem(addr) != "push":
addr = idc.PrevHead(addr)
print(hex(addr))
data_addr = GetOperandValue(addr,0)

xork_init = Dword(data_addr)
data_addr += 4
length_delta = Word(data_addr)
data_addr += 2
length = (xork_init ^ length_delta) & 0xffff
out = ""
xork = xork_init
for i in range(length):
xork = gen_key(xork)
xork += i
out += chr((Byte(data_addr) ^ (xork & 0xFF)) & 0xFF)
data_addr += 1
if out[-2:] == 'x00x00':
print(out.decode('utf16'))
MakeRptCmt(addr, out.decode('utf16').encode('ascii'))
else:
print(out)
MakeRptCmt(addr, out)

Keyhole 的主要组件也期望传递一个参数,这个地址将是来自上一个加载器组件的 shellcode blob。


Keyhole逆向分析


首先,提取一个 DWORD 值,该值最终将用作 XOR 循环的初始种子值:


Keyhole逆向分析


接下来,在拉出 DWORD 并运行 XOR 循环后的每个字节,在该循环中,初始种子值在每次迭代时都会作,我们还可以在下面看到,被解码的 blob 的长度为 0x14e 字节:


Keyhole逆向分析


解码后的 blob 原来是主 Keyhole 组件的配置,因此加载程序组件将配置本身作为参数传递给主组件。解码后,我们有几个值将用于 C2 通信:

['', '', '', '', 'xbbxa2xbdx9ex1fx8bx08x08', 
'', '', '', '', '', '', '', '', '', '', '', '', '', '',
<..snip..>
'', '', '', '', '', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', 'hdesk', '', '', '',
'', '', '', '', '', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '', '', '', '',
'91.238.]50.101', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '', '', '', '', 'x90x1f’]

我们可以看到一些值,尤其是 C2 地址,还有 ‘x1fx8bx08x08’ 的 C2 流量标记和端口0x1f90 8080。

功能性

如前所述,恶意软件将检索有关受感染系统的一些基本信息:


Keyhole逆向分析


它还可以枚举网络中的服务器和共享,并在此过程中利用 LDAP 查询:


Keyhole逆向分析


文件检索的大小限制为大约 33MB:


Keyhole逆向分析


浏览器

对于 Chrome,该模块可以在临时将用户数据复制到新文件夹:


Keyhole逆向分析


除了 ‘C\’ 的参数,我们可以在下面看到文件夹结构将在 temp 下构建:


Keyhole逆向分析


在本例中,如果标志值为 0,我们最终会将配置文件复制到:

%TEMP%DC

浏览器的操作方式与旧银行木马的操作方式类似,该模块包含用于挂钩 NtCreateUserProcess 的代码,然后该代码将查找要生成的浏览器:


Keyhole逆向分析


这允许核心模块操作浏览器的命令行,但是它根据发现要执行的浏览器执行更多操作。

Chrome

- Copies profile data to
- %TEMP%DC
- Modifies command line
- --user-data-dir=”
- " --ash-force-desktop --disable-3d-apis --disable-accelerated-layers --disable-accelerated-plugins --disable-audio --disable-gpu --disable-d3d11 --disable-d3d12 --disable-accelerated-2d-canvas --disable-deadline-scheduling --disable-ui-deadline-scheduling --aura-no-shadows --no-zygote --do-not-de-elevate --mute-audio --disable-renderer-accessibility --disable-direct-compositing --disable-gpu-compositing --disable-renderer-backgrounding --in-process-gpu

FireFox

- Reads default profile path from profiles.ini file- Copies default profile to  - %TEMP%DF- Edits prefs.js  - user_pref("browser.preferences.defaultPerformanceSettings.enabled", false);  - user_pref("layers.acceleration.disabled", true);- Modifies command line  - --no-remote -no-deelevate -profile “


Edge

- Sets registry keys
- SOFTWAREMicrosoftWindows NTCurrentVersionAppCompatFlagsLayers
- C:Program Files (x86)MicrosoftEdgeApplicationmsedge.exe=~ WIN8RTM
- Copies profile data to
- %TEMP%DE
- Modifies command line
- --user-data-dir=”
- " --ash-force-desktop --disable-3d-apis --disable-accelerated-layers --disable-accelerated-plugins --disable-audio --disable-gpu --disable-d3d11 --disable-d3d12 --disable-accelerated-2d-canvas --disable-deadline-scheduling --disable-ui-deadline-scheduling --aura-no-shadows --no-zygote --do-not-de-elevate --mute-audio --disable-renderer-accessibility --disable-direct-compositing --disable-gpu-compositing --disable-renderer-backgrounding --in-process-gpu

IE浏览器

- Modifies registry
- SoftwareMicrosoftInternet ExplorerMain
- NoProtectedModeBanner=1
- TabProcGrowth=0
- SoftwareMicrosoftWindowsCurrentVersionInternet SettingsZones3
- 2500=3
- Modifies command line
- -nomerge -noframemerging -nohome

Keyhole 还可以通过多种方式将注入到新启动的浏览器进程中:


Keyhole逆向分析


对于 BackConnect 命令:


Keyhole逆向分析


对于控制台命令行引爆,powershell 或 cmd 引爆应使用字符串:


Keyhole逆向分析


同样在上面可以看到与麦克风相关的命令,这些命令主要与操作注册表值有关:


Keyhole逆向分析


修改后,资源管理器将重新启动。

  • 软件MicrosoftWindowsCurrentVersionCapabilityAccessManagerConsentStoremicrophoneNonPackaged

  • 软件MicrosoftWindowsCurrentVersionCapabilityAccessManagerConsentStoremicrophone

  • 软件MicrosoftWindowsCurrentVersionExplorerStuckRects3

  • cmd.exe /c taskkill /f /im explorer.exe && 启动 explorer.exe

YARA

rule keyhole_32
{
strings:
$config_decode = {694d0cfd43030081c1c39e2600894d0c}
condition:
all of them
}


rule keyhole_loader
{
strings:
$64exe = {5390 9cbb be0c c453 9d5b 5290}
$64dll = {7809 7407 7305 eb03 3941}
$32exe = {770c 569c c1e6 0ac1 ee09 f7d6}
$32dll = {5781 f7fc 46d8 5083 c728 bf0b}
condition:
any of them
}

IOCS

Sample hash

74aa61cc1157529fb98b757fb879616ffc2b54e4d4ff08c9b9d5b6dcec868c2a

命令行

powershell.exe  -c "[Console]::OutputEncoding = [Console]::InputEncoding = [System.Text.Encoding]::GetEncoding('utf-8'); cd c:; powershell"

cmd.exe /K chcp 65001 && c: && cd c:

cmd.exe /c taskkill /f /im explorer.exe && start explorer.exe

cmd.exe /c start /wait explorer.exe /factory, {75dff2b7-6936-4c06-a8bb-676a7b00b24b}

explorer.exe shell:mycomputerfolder

explorer.exe shell:mycomputerfolder

Browsers with params:
--user-data-dir="

"
--ash-force-desktop --disable-3d-apis --disable-accelerated-layers --disable-accelerated-plugins --disable-audio --disable-gpu --disable-d3d11 --disable-d3d12 --disable-accelerated-2d-canvas --disable-deadline-scheduling --disable-ui-deadline-scheduling --aura-no-shadows --no-zygote --do-not-de-elevate --mute-audio --disable-renderer-accessibility --disable-direct-compositing --disable-gpu-compositing --disable-renderer-backgrounding --in-process-gpu

--no-remote -no-deelevate -profile

文件活动:

%TEMP%DC
%TEMP%DF
%TEMP%DE

引用

  1. https://info.phishlabs.com/blog/the-unrelenting-evolution-of-vawtrak

  2. https://malpedia.caad.fkie.fraunhofer.de/details/win.vawtrak

  3. https://www.justice.gov/usao-sdny/pr/russian-hacker-who-used-neverquest-malware-steal-money-victims-bank-accounts-sentenced

  4. https://securityintelligence.com/new-banking-trojan-icedid-discovered-by-ibm-x-force-research/

  5. https://blog.fox-it.com/2018/08/09/bokbot-the-rebirth-of-a-banker/

  6. https://blog.nviso.eu/2023/03/20/icedids-vnc-backdoors-dark-cat-anubis-keyhole/

  7. https://www.netresec.com/?page=Blog&month=2023-10&post=Forensic-Timeline-of-an-IcedID-Infection

  8. https://svch0st.medium.com/can-you-track-processes-accessing-the-camera-and-microphone-7e6885b37072




  • 进制漏洞课程(更新中)

  • Keyhole逆向分析


  • windows

  • Keyhole逆向分析

  • windows()

  • Keyhole逆向分析

  • USB()

  • Keyhole逆向分析

  • ()

  • Keyhole逆向分析

  • ios

  • Keyhole逆向分析

  • windbg

  • Keyhole逆向分析

  • ()

  • Keyhole逆向分析Keyhole逆向分析Keyhole逆向分析

  • Keyhole逆向分析

  •  

  • Keyhole逆向分析



原文始发于微信公众号(安全狗的自我修养):Keyhole逆向分析

版权声明:admin 发表于 2024年2月15日 上午10:26。
转载请注明:Keyhole逆向分析 | CTF导航

相关文章