Exp4 恶意代码分析

实践目标

1.监控你自己系统的运行状态,看有没有可疑的程序在运行。
2.分析一个恶意软件,就分析Exp2或Exp3中生成后门软件;分析工具尽量使用原生指令或sysinternals,systracer套件。
3.假定将来工作中你觉得自己的主机有问题,就可以用实验中的这个思路,先整个系统监控看能不能找到可疑对象,再对可疑对象进行进一步分析,好确认其具体的行为与性质。

实践内容

系统内容监控

使用计划任务

1、使用以下命令创建计划任务netstat5219。

schtasks /create /TN netstat5219 /sc MINUTE /MO 5 /TR "cmd /c netstat -bn > c:
etstatlog.txt"

2、在c盘下创建一个netstatlog5219.bat文件,写入以下内容,用作批处理。

date /t > c:
etstatlog5219.txt
time /t > c:
etstatlog5219.txt
netstat -bn > c:
etstatlog5219.txt

3、修改计划任务的脚本为批处理脚本,过一段过一段时间再打开netstatlog5219.txt文件即可查看有那些程序在连接网络。(注意将计划任务设置为以最高权限运行,因为监控信息重定向至c: etstatlog5219.txt,而在c下创建文件需要管理员权限)

使用sysmon工具

sysmon参数

可选事件过滤器

    ProcessCreate  进程创建
    FileCreateTime 进程创建时间
    NetworkConnect 网络链接
    ProcessTermina 进程结束
    DriverLoad    驱动加载
    ImageLoad     镜像加载
    CreateRemoteTh 远程线程创建
    RawAccessRead  驱动器读取
    ProcessAccess  进程访问
    FileCreate    文件创建
    RegistryEvent  注册表事件
    FileCreateStre 文件流创建

标签说明

使用onmacth标记配置文件中 过滤器规则 include exclude
include:
     仅包含include的规则配置 
exclude: 
     除去该规则配置, 其他全包含 
PS: 
     例如,此规则将丢弃进程创建中 IntegrityLevel 为中等的任何流程事件
      <ProcessCreate onmatch="exclude">
          <IntegrityLevel>Medium</IntegrityLevel>
     </ProcessCreate>

过滤器标签的字段

字段如下:
     is             默认值, 等于
     is not         不等于 
     contains       包含
     excludes       不包含
     begin with     以此字段开始
     end with       以此字段结束
     less than      小于
     more than      大于 
     image          匹配镜像路径(完整路径或仅镜像名称) 
     例如:lsass.exe将匹配c:windowssystem32lsass.exe

xml配置文件

给出我的xml配置文件(主要是监控443、80端口的网络连接,以及windows自带的与系统安全有关的exe)

<Sysmon schemaversion="4.23">
  <!-- Capture all hashes -->
  <HashAlgorithms>*</HashAlgorithms>

  <EventFiltering>
    <!-- Log all drivers except if the signature -->
    <!-- contains Microsoft or Windows -->
    <DriverLoad onmatch="exclude">
      <Signature condition="contains">Microsoft</Signature>
      <Signature condition="contains">Windows</Signature>
    </DriverLoad>

    <ProcessTerminate onmatch="include" >
      <Image condition="end with">MsMpEng.exe</Image>
    </ProcessTerminate>

    <!-- Log network connection if the destination port equal 443 -->
    <!-- or 80, and process isn't InternetExplorer -->
    <!--NetworkConnect onmatch="include">
      <DestinationPort>443</DestinationPort>
      <DestinationPort>80</DestinationPort >
    </NetworkConnect -->

    <FileCreateTime onmatch="exclude" >
      <Image condition="end with">chrome.exe</Image>
    </FileCreateTime>

    <ImageLoad onmatch="include">
      <Signed condition="is">false</Signed>
    </ImageLoad>

    <!-- Log access rights for lsass.exe or winlogon.exe is not PROCESS_QUERY_INFORMATION -->
    <ProcessAccess onmatch="exclude">
      <GrantedAccess condition="is">0x1400</GrantedAccess>
    </ProcessAccess>

    <ProcessAccess onmatch="include">
      <TargetImage condition="end with">lsass.exe</TargetImage>
      <TargetImage condition="end with">winlogon.exe</TargetImage>
    </ProcessAccess>

    <NetworkConnect onmatch="exclude">
      <Image condition="end with">chrome.exe</Image>
      <SourcePort condition="is">137</SourcePort>
      <SourcePortName condition="is">llmnr</SourcePortName>
      <DestinationPortName condition="is">llmnr</DestinationPortName>
    </NetworkConnect>

    <CreateRemoteThread onmatch="include">
      <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>

s</Sysmon>

启动sysmon

Sysmon.exe -i sysmon5219.xml

在事件查看器的“应用程序和服务日志/Microsoft/Windows/Sysmon/Operational”目录下可以查看日志信息。

恶意代码分析

静态分析

就拿我们实验二中最简单的backdoor分析

PEID

很明显没有加壳

IDA

观察流程调用,逆向难度有些大,那我们就从字符串入手

发现程序中有几个动态链接库

  • MSVCRT.dll:c语言运行库执行文件,提供了printf,malloc,strcpy等C语言库函数的具体运行实现,并且为使用C/C++(Vc)编译的程序提供了初始化(如获取命令行参数)以及退出等功能。
  • KERNEL32.dll:内核级文件,控制系统的内存管理、数据的输入输出操作和中断处理。
  • advapi32.dll:一个高级API应用程序接口服务库的一部分,包含的函数与对象的安全性,注册表的操控以及事件日志有关。
  • WSOCK32.dll:Windows Sockets应用程序接口,用于支持很多Internet和网络应用程序。
  • ws2_32.dll:Windows Sockets应用程序接口, 用于支持Internet和网络应用程序。
  • ntdll.dll:重要的Windows NT内核级文件。描述了windows本地NTAPI的接口。

据此我猜测,backdoor程序是基于c编写的,通过一系列的系统调用实现提权,并可能更改操控注册表以及事件日志有关信息,通过网络回连攻击机。

字符串中有一段很有趣的部分

这是web压力测试工具apache benchmark的命令,难道回连还要测攻击机的web性能?(搞不懂哦)

动态分析

SYSMON

首先修改sysmon的xml文件,把backdoor文件加入白名单中,并且改为监听443、80以外的端口。
我们可以看到后门程序进程创建。

以及网络连接

可以看到攻击机的ip以及监听端口。

wireshark

抓包后门回连时的情况

可以看到7、8、9是tcp的三次握手,后面一直重复12、13、14的过程,感觉是用来保持回连状态。由于wireshark的data无法导出分析,所以只能猜测13、14是攻击机向受害机发送shellode?

systracer

可以看到后门启动情况。

的确新增了注册表,不过没有分析出来是干什么用的。

实践问题回答

(1)如果在工作中怀疑一台主机上有恶意代码,但只是猜想,所有想监控下系统一天天的到底在干些什么。请设计下你想监控的操作有哪些,用什么方法来监控。
答:1、监控每个程序的行为,并与恶意代码特有行为特征进行比对。
2、监控网络流量,过滤敏感字符。
3、监控端口,看是否有异常端口开启。
4、监控注册表、dll库、键值等。
(2)如果已经确定是某个程序或进程有问题,你有什么工具可以进一步得到它的哪些信息
答:1、ida静态分析,获得程序调用图、关键字符串等信息,甚至可以逆向出病毒运行逻辑。
2、PEID,分析文件是否加壳。
3、沙箱测试,比对程序作出了什么异常操作、对系统有什么危害。

参考

关于sysmon的基本使用(1)
使用轻量级工具Sysmon监视你的系统

原文地址:https://www.cnblogs.com/luoleqi/p/12705569.html