利用Delphi加壳器来实现病毒免杀
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;margin:0pt 0pt 18pt;text-align:left;"><br />
</p>
<p class="p" style="margin-left:0pt;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;">
<br />
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;margin:0pt 0pt 18pt;text-align:left;">
简介
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;border-bottom:1pt solid #DDDDDD;margin:11.25pt 0pt;padding:0pt;text-align:justify;">
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;margin:0pt 0pt 18pt;text-align:left;">
为了绕过静态和动态分析,威胁组织经常为恶意程序采取"加壳"或"加密"措施,并且这种做法非常流行。实际上,免杀和查杀是一个军备竞赛,因此,在这场持久战中,各种新技术会不断涌现,并被迅速采用。例如,据我们观察,许多加密服务都是由地下论坛提供的,他们声称能够绕过反病毒技术、沙箱和其他端点解决方案,任何恶意软件只要采用了他们的服务,就能够实现“完全无法检测(Fully Undetectable,FUD)”的效果。我们还发现,越来越多的威胁组织正在设法模拟正常的用户行为,并将其作为基于恶意软件指纹分析技术的有效对策。
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;margin:0pt 0pt 18pt;text-align:left;">
恶意软件的保护神:Delphi代码
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;border-bottom:1pt solid #DDDDDD;margin:11.25pt 0pt;padding:0pt;text-align:justify;">
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;margin:0pt 0pt 18pt;text-align:left;">
在这里,我们所考察的样本具有Delphi签名(见图1),并且与使用IDR(Interactive Delphi Reconstructor)分析时看到的Delphi代码构造完全一致。
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;margin:0pt 0pt 18pt;text-align:left;">
<img width="693" height="504" src="https://www.9kb.org/content/uploadfile/201809/24/423e7736a4924cf2b29625751ab03462.jpg" />
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;margin:0pt 0pt 18pt;text-align:left;">
图1:样本中的Delphi签名
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;margin:0pt 0pt 18pt;text-align:left;">
对于基于Windows API函数的应用程序和程序来说,Delphi是一种简单易用的编程语言。事实上,一些组织会故意将某些默认库包含进恶意软件中,以此转移静态分析人员的注意力,并能让应用程序在进行动态分析时“看起来很正常”。图2显示的地下论坛帖子,就是在讨论这些技术。
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;margin:0pt 0pt 18pt;text-align:left;">
<img width="2543" height="1022" src="https://www.9kb.org/content/uploadfile/201809/24/f3aa98a38fb849909bab0af6f825e327.jpg" />
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;margin:0pt 0pt 18pt;text-align:left;">
图2:地下论坛中的免杀技术帖
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;margin:0pt 0pt 18pt;text-align:left;">
有效载荷的投递
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;border-bottom:1pt solid #DDDDDD;margin:11.25pt 0pt;padding:0pt;text-align:justify;">
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;margin:0pt 0pt 18pt;text-align:left;">
我们发现,许多攻击组织都曾利用这种有效载荷进行加壳处理,然后通过垃圾邮件进行分发,当然,针对不同的人群,他们会使用不同的邮件主题。
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;margin:0pt 0pt 18pt;text-align:left;">
一个样本是与电汇有关的垃圾邮件,它将一个文档文件作为邮件附件(哈希值:71cd5df89e3936bb39790010d6d52a2d),其作用是利用恶意宏来投递有效载荷。该垃圾邮件如图3所示。
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;margin:0pt 0pt 18pt;text-align:left;">
<img width="2500" height="1608" src="https://www.9kb.org/content/uploadfile/201809/24/6ca42a55a9ce4cc8a346870e37d68212.jpg" />
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;margin:0pt 0pt 18pt;text-align:left;">
图3:垃圾邮件样本1
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;margin:0pt 0pt 18pt;text-align:left;">
另一个例子是报价方面的垃圾邮件,它将一个漏洞利用文档文件作为附件(哈希值:0543e266012d9a3e33a9688a95fce358),其作用是利用公式编辑器漏洞来投递有效载荷(图4)。
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;margin:0pt 0pt 18pt;text-align:left;">
<img width="2500" height="1612" src="https://www.9kb.org/content/uploadfile/201809/24/472c78742d4042739e0c7415587e6925.jpg" />
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;margin:0pt 0pt 18pt;text-align:left;">
图4:垃圾邮件样本2
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;margin:0pt 0pt 18pt;text-align:left;">
样本中的文档会从<a href="http://5.152.203.115/win32.exe%E4%B8%8B%E8%BD%BD%E6%9C%89%E6%95%88%E8%BD%BD%E8%8D%B7%EF%BC%8C%E5%85%B6%E5%AE%9E%EF%BC%8C%E5%B0%B1%E6%98%AFLokibot%E6%81%B6%E6%84%8F%E8%BD%AF%E4%BB%B6%E3%80%82">http://5.152.203.115/win32.exe下载有效载荷,其实,就是Lokibot恶意软件。</a>
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;margin:0pt 0pt 18pt;text-align:left;">
用户行为检测
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;border-bottom:1pt solid #DDDDDD;margin:11.25pt 0pt;padding:0pt;text-align:justify;">
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;margin:0pt 0pt 18pt;text-align:left;">
这个加壳器会尽力确保自己不在安全分析环境中运行。对于普通用户来说,通常会在一定时间内切换多个应用程序窗口。该加壳器的第一个变体,会使用GetForegroundWindow API来检测用户切换窗口的次数,准确来说,只有切换三次之后,它才会继续执行其他代码。如果它没有检测到窗户的变化,就会自动进入无限期的睡眠状态,具体代码如图5所示。有趣的是,尽管这种技术非常简单,却能检测到多种常用的沙箱。
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;margin:0pt 0pt 18pt;text-align:left;">
<img width="493" height="370" src="https://www.9kb.org/content/uploadfile/201809/24/5e4ae21289ed452cbdc61945903a836b.jpg" />
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;margin:0pt 0pt 18pt;text-align:left;">
图5:检测窗口的变化情况
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;margin:0pt 0pt 18pt;text-align:left;">
为了对用户活动进行印证,加壳器的第二个变体使用GetCursorPos和Sleep API来检查鼠标和光标的移动情况,而第三个变体则使用GetLastInputInfo和GetTickCount API来检查系统的空闲状态。
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;margin:0pt 0pt 18pt;text-align:left;">
从PE资源中提取实际有效载荷
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;border-bottom:1pt solid #DDDDDD;margin:11.25pt 0pt;padding:0pt;text-align:justify;">
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;margin:0pt 0pt 18pt;text-align:left;">
原始的有效载荷被拆分为多个二进制代码段,并分别存储在资源目录内的不同位置,如图6所示。
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;margin:0pt 0pt 18pt;text-align:left;">
<img width="1168" height="849" src="https://www.9kb.org/content/uploadfile/201809/24/f388e8c427fe4088b503451595bb1caf.jpg" />
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;margin:0pt 0pt 18pt;text-align:left;">
图6:具有加密内容的位图资源
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;margin:0pt 0pt 18pt;text-align:left;">
为了定位和组装实际有效载荷的代码字节,该加壳器首先会从资源部分内硬编码的资源ID中读取相应的内容。其中,前16个字节用于生成一个XOR密钥,用于通过滚动XOR方法来解密其余字节。解密后的字节内容,实际上就是一些内部数据结构,具体如图7所示,供加壳器用于引用各种资源ID对应的缓冲区,注意,这些缓冲区都经过了相应的加密和混淆处理。
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;margin:0pt 0pt 18pt;text-align:left;">
<img width="527" height="350" src="https://www.9kb.org/content/uploadfile/201809/24/c4835a49c4ba4d4c8b5dd34add3ed70e.jpg" />
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;margin:0pt 0pt 18pt;text-align:left;">
图7:展示加密文件信息的数据结构
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;margin:0pt 0pt 18pt;text-align:left;">
之后,该加壳器就会从加密缓冲区读取相应的值,从dwStartResourceId开始,直到dwStartResourceId+dwNumberOfResources为止;并通过读取dwChunkSize块信息将其放到一个地方。一旦准备好最终数据缓冲区,就会通过前面讲过的滚动XOR算法和上述结构中的新密钥对其进行解密,从而生成有效载荷可执行文件。这个脚本可用于<a href="https://www.fireeye.com/content/dam/fireeye-www/blog/pdfs/script.pdf" title="静态提取实际有效载荷">静态提取实际有效载荷</a>。
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;margin:0pt 0pt 18pt;text-align:left;">
恶意软件的家族分布
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;border-bottom:1pt solid #DDDDDD;margin:11.25pt 0pt;padding:0pt;text-align:justify;">
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;margin:0pt 0pt 18pt;text-align:left;">
根据我们从样本集中提取的许多未加壳的二进制文件来看,它们都属于Lokibot恶意软件家族。此外,我们还能够识别Pony、IRStealer、Nanocore、Netwire、Remcos和nJRAT恶意软件家族,以及挖矿恶意软件家族,等等。使用该加壳器的恶意软件家族的分布如图8所示。不难看出,这里出现了多种恶意软件家族,这意味着许多威胁组织正在使用这种“加密”服务/工具进行免杀处理,并且很可能是从开发人员本身那里购买的。
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;margin:0pt 0pt 18pt;text-align:left;">
<img width="856" height="645" src="https://www.9kb.org/content/uploadfile/201809/24/e320fb7b2ac3426aa2cdc7b7a74eaceb.jpg" />
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;margin:0pt 0pt 18pt;text-align:left;">
图8:使用该加壳器的恶意软件家族分布情况
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;margin:0pt 0pt 18pt;text-align:left;">
小结
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;border-bottom:1pt solid #DDDDDD;margin:11.25pt 0pt;padding:0pt;text-align:justify;">
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;margin:0pt 0pt 18pt;text-align:left;">
自从有了加壳和加密服务之后,威胁组织就可以直接将有效载荷的免杀工作外包出去,一方面是简单省事,另一方面,还能提高免杀效果。而且,这些免杀服务的提供者经常会找到基于安全分析对抗技术的沙箱环境绕过方法;因此,利用模拟真实用户行为的沙箱环境来“引爆”恶意软件样本的方法已经不再可靠了。
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;margin:0pt 0pt 18pt;text-align:left;">
IOC
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;border-bottom:1pt solid #DDDDDD;margin:11.25pt 0pt;padding:0pt;text-align:justify;">
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;margin:0pt 0pt 18pt;padding:0pt;text-align:left;word-break:break-all;">
853bed3ad5cc4b1471e959bfd0ea7c7c
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;margin:0pt 0pt 18pt;padding:0pt;text-align:left;word-break:break-all;">
e3c421d404c08809dd8ee3365552e305
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;margin:0pt 0pt 18pt;padding:0pt;text-align:left;word-break:break-all;">
14e5326c5da90cd6619b7fe1bc4a97e1
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;margin:0pt 0pt 18pt;padding:0pt;text-align:left;word-break:break-all;">
dc999a1a2c5e796e450c0a6a61950e3f
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;margin:0pt 0pt 18pt;padding:0pt;text-align:left;word-break:break-all;">
3ad781934e67a8b84739866b0b55544b
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;margin:0pt 0pt 18pt;padding:0pt;text-align:left;word-break:break-all;">
b4f5e691b264103b9c4fb04fa3429f1e
</p>
<p>
<br />
</p>
<p>
<br />
</p>
<p style="background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;margin:0pt 0pt 18pt;padding:0pt;text-align:left;word-break:break-all;">
<br />
</p>
页:
[1]