恶意代码分析

发布时间 2023-04-06 22:19:34作者: 201230RookieHacker

恶意代码分析

基础问题回答

  • 如果在工作中怀疑一台主机上有恶意代码,但只是猜想,所以想监控下系统一天天的到底在干些什么。请设计下你想监控的操作有哪些,用什么方法来监控。
    • 监视系统的网络流量

      以识别任何可疑活动。这可以使用网络监控工具(如Wireshark或tcpdump)来完成。

    • 监视系统的文件系统

      以查看是否有任何更改或新文件已添加。这可以使用文件完整性监控工具(如OSSEC或Tripwire)来完成。

    • 监视运行进程和系统日志

      使用Windows系统上的Process Explorer或Sysinternals Suite,或使用Unix-based系统上的内置工具(如ps和syslog)来监视系统的运行进程和系统日志,以查看是否有任何可疑活动。

  • 如果已经确定是某个程序或进程有问题,你有什么工具可以进一步得到它的哪些信息。
    • Process Monitor

      可以监视系统上的进程、文件系统、注册表和网络活动,并提供详细的信息和筛选功能。

    • Process Explorer

      可以显示系统上运行的所有进程,并提供有关每个进程的详细信息,包括打开的文件和注册表项。

    • Windows Task Manager

      可以显示系统上运行的所有进程,并提供有关每个进程的基本信息,如CPU和内存使用情况。

    • lsof

      可以在Unix-based系统上列出打开的文件和网络连接,并提供有关每个进程的详细信息。

实验过程

1.系统运行监控

1.1 使用如计划任务,每隔一分钟记录自己的电脑有哪些程序在联网,连接的外部IP是哪里。

编写计划任务所需执行的脚本

date /t >> D:\wildlinux\netstatlog1206.txt    
time /t >> D:\wildlinux\netstatlog1206.txt 
netstat -bn >> D:\wildlinux\netstatlog1206.txt        

添加任务计划

打开任务计划程序,找到刚刚创建的任务,查看它的属性,在操作中把要执行的 cmd 改成之前写好的 bat 脚本.

然后使用 Excel 分析刚刚脚本产生的数据,建立数据透视图

结果分析,vmware与excel连接居多(当时开着虚拟机联网属于正常),发现serchApp.exe也存在大量连接,查询后发现:searchapp.exe是与Windows搜索功能相关的可执行文件。在以前构建的Windows 10中,SearchApp.exe与Cortana和Windows 10中的搜索功能有关。看来系统没有什么不正常的程序。再看看外网ip


好家伙!!数据包穿过太平洋直接干到了芝加哥。

1.2安装配置 sysinternals 里的sysmon工具,设置合理的配置文件,监控自己主机的重点事可疑行为。

编写配置文件

<Sysmon schemaversion="4.81">
  <!-- Capture all hashes -->
  <HashAlgorithms>*</HashAlgorithms>
  <EventFiltering>
    <!-- Log all drivers except if the signature -->
    <!-- contains Microsoft or Windows -->
    <DriverLoad onmatch="exclude">                       <!-- 驱动加载,除了windows和微软签名过的驱动 -->
      <Signature condition="contains">microsoft</Signature>
      <Signature condition="contains">windows</Signature>
    </DriverLoad>
    <ProcessCreate onmatch="exclude">                    <!-- 进程创建,除了 SLBrowser 都监视 -->
      <Image condition="end with">SLBrowser.exe</Image> 
    </ProcessCreate>
 
    <FileCreateTime onmatch="exclude" >                  <!-- 文件创建时间,除了 SLBrowser 都监视 -->
      <Image condition="end with">SLBrowser.exe</Image>
    </FileCreateTime>
    
    <NetworkConnect onmatch="exclude">                   <!-- 网络连接,除了 SLBrowser,源端口137,本地回环 都监视 -->   
      <Image condition="end with">SLBrowser.exe</Image>
      <SourcePort condition="is">137</SourcePort>    
      <SourceIp condition="is">127.0.0.1</SourceIp>
    </NetworkConnect>
 
    <CreateRemoteThread onmatch="include">               <!--创建远程线程,只监视以下 4 个 -->   
      <TargetImage condition="end with">explorer.exe</TargetImage>
      <TargetImage condition="end with">svchost.exe</TargetImage>
      <TargetImage condition="end with">winlogon.exe</TargetImage>
      <SourceImage condition="end with">powershell.exe</SourceImage>
    </CreateRemoteThread>
  </EventFiltering>
</Sysmon>

初始化(安装) Sysmon

打开日志:打开事件查看器(win+R运行eventvwr.msc)—> 应用程序和服务日志 -> Microsoft -> Windows -> Sysmon -> Operational

捕捉到的事件太多,不利于发现恶意软件。
进一步改进 XML 配置文件,把捕捉到的合法的操作都放过去。

<Sysmon schemaversion="4.81">
  <!-- Capture all hashes -->
  <HashAlgorithms>*</HashAlgorithms>
  <EventFiltering>
    <!-- Log all drivers except if the signature -->
    <!-- contains Microsoft or Windows -->
    <ProcessCreate onmatch="exclude">                    <!-- 进程创建 -->
      <Image condition="end with">SLBrowser.exe</Image>
	  <Image condition="end with">SLBAgent.exe</Image>
	  <Image condition="end with">SLBAgent.exe</Image>
	  <Image condition="end with">LeAppOM.exe</Image>
	  <Image condition="end with">conhost.exe</Image>
	  <Image condition="end with">dllhost.exe</Image>
	  <Image condition="end with">LeASPac.exe</Image>
	  <Image condition="end with">dwe.exe</Image>
	  <Image condition="end with">Taskmgr.exe</Image>
	  <Image condition="end with">perfmon.exe</Image>
	  <Image condition="is">C:\Windows\System32\TokenBrokerCookies.exe</Image>
	  <Image condition="is">C:\Windows\System32\plasrv.exe</Image> 
	  <Image condition="is">C:\Windows\System32\wifitask.exe</Image> 
	  <Image condition="is">C:\Windows\system32\CompatTelRunner.exe</Image> 
	  <Image condition="is">C:\Windows\system32\PrintIsolationHost.exe</Image> 
	  <Image condition="is">C:\Windows\system32\SppExtComObj.Exe</Image> 
	  <Image condition="is">C:\Windows\system32\audiodg.exe</Image> 
	  <Image condition="is">C:\Windows\system32\conhost.exe</Image> 
	  <Image condition="is">C:\Windows\system32\mobsync.exe</Image> 
	  <Image condition="is">C:\Windows\system32\musNotification.exe</Image> 
	  <Image condition="is">C:\Windows\system32\musNotificationUx.exe</Image> 
	  <Image condition="is">C:\Windows\system32\powercfg.exe</Image> 
	  <Image condition="is">C:\Windows\system32\sndVol.exe</Image> 
	  <Image condition="is">C:\Windows\system32\sppsvc.exe</Image> 
	  <Image condition="contains">SLBrowser</Image>
	  <Image condition="contains">LockScreen</Image>
	  <Product condition="contains">Windows</Product>
	  <Product condition="contains">Microsoft</Product>	  
    </ProcessCreate>
 
    <FileCreate onmatch="exclude" >                  <!-- 文件创建 -->
      <Image condition="end with">SLBrowser.exe</Image>
	  <Image condition="end with">backgroundTaskHost.exe</Image>
	  <Image condition="end with">LockScreenPlayer.exe</Image>
	  <Image condition="end with">svchost.exe</Image>
	  <Image condition="end with">SogouCloud.exe</Image>
    </FileCreate>
    
    <NetworkConnect onmatch="exclude">                   <!-- 网络连接 -->   
      <Image condition="end with">SLBrowser.exe</Image>
	  <Image condition="end with">SogouCloud.exe</Image>
	  <Image condition="end with">svchost.exe</Image>
	  <Image condition="end with">wpscloudsvr.exe</Image>
	  <Image condition="end with">LenovoAppupdate.exe</Image>
      <SourcePort condition="is">137</SourcePort>
	  <SourcePortName condition="is">netbios-ns</SourcePortName>
      <SourceIp condition="is">127.0.0.1</SourceIp>
	  <DestinationIp condition="is">127.0.0.1</DestinationIp>
    </NetworkConnect>
 
    <CreateRemoteThread onmatch="exclude">               <!--创建远程线程 -->   
      <TargetImage condition="end with">explorer.exe</TargetImage>
      <TargetImage condition="end with">svchost.exe</TargetImage>
      <TargetImage condition="end with">winlogon.exe</TargetImage>
      <SourceImage condition="end with">powershell.exe</SourceImage>
    </CreateRemoteThread>
  </EventFiltering>
</Sysmon>

重启 sysmon ,更新配置文件

运行一个后门软件试试

捕捉到了操作信息。


2.恶意软件分析

假设前面的监控发现了可疑软件backdoor.exe,下面进一步分析,它想要对我们的电脑干什么,有什么功能。
主要考虑三个方面:

  • 修改文件(改写注册表、启动项,删除重要数据...)
  • 网络连接(反弹shell,开启端口监听,向外部IP发送了什么数据...)
  • 进程(进程迁移、进程注入、进程提权...)

2.1静态分析

  • Virus Total 行为分析
    可以看到分析信息


  • PEiD 分析
    PEiD(PEIdentifier)是一款著名的查壳工具,其功能强大,几乎可以侦测出所有的壳,其数量已超过470种PE文档的加壳类型和签名。
    正常扫描模式:可在PE文档的入口点扫描所有记录的签名
    深度扫描模式:可深入扫描所有记录的签名,这种模式要比上一种的扫描范围更广、更深入
    核心扫描模式:可完整地扫描整个PE文档,PEiD内置有差错控制的技术,所以一般能确保扫描结果的准确性

    PE文件未加壳
  • kali strings命令
    strings 在二进制文件中查找可打印的字符串。

    发现一长字符串,猜测为缓冲区溢出做跳转使用;

    果然发现有网络连接部分,但看不出连接IP及端口。
  • IDA pro 反汇编 和 反编译

    还不会用,暂时在研究。。。

2.2动态分析

  • 沙盒


    后门连接前后,注册表没有明显发生变化,但是在 C 盘根目录多了两个隐藏文件 pagefile.sys 虚拟内存页面文件。同时检测到应用软件 backdoor.exe 的状态变化,多次建立 TCP 连接,并打开的多个句柄。
  • wireshark 网络流量分析

    通过ip可知以太网4是虚拟攻击机网关,选其并开始抓包。

    可见,恶意软件 从 192.168.144.1:30725 连向 192.168.144.141:1206
    再用 wireshark 分析一下流量



    综上分析可知:发起连接 从 192.168.178.1:66 连向 192.168.178.130:1206,使用 TLS/SSL 协议,使用了密码套件,对数据进行了加密处理。
  • Process Explorer 进程分析
    在沙盒中运行可疑程序,可以看到进程的详细情况

    进程的基本信息



    最后kill这个进程

实验体会

此次实验难点不仅仅难在发现恶意程序,更难在分析整个程序的功能。由于后门程序的种类繁多,外加各种加壳等辅助性工具的加持,单一的分析方法很难安全地研究出程序的功能以做出防护措施,甚至可能很难发现都说不准。在系统监控的环节中,产生的日志消息是很多的。如何从减少无用的日志信息,并从大量的日志信息中提取中有用的信息,并最终发现异常,在本次实验中我发现这并不容易。尤其是在第一次 sysmon 监控系统的时候,小小的配置文件,导致了大量的无用数据,而要从大量的数据中找到恶意程序的数据,要人工手工,简直是不可能。通过此次实验,让我对后面程序的检测以及防范有了更深的理解,不再仅仅是断网苦苦寻找或者重新装机。