sysmon

14 分钟

Sysmon

Sysmon(System monitor)微软提供的轻量级的系统监控工具,能根据自定义编写配置文件监控并记录进程创建、网络连接、文件操作、驱动情况等等详细信息,相关的详细信息会写入到事件查看器——应用程序和服务日志——Windows——Sysmon日志事件里面去,从功能上来看,Sysmon类似于HIDS,依托于Windows内核态注册回调并通过ETW存储展示Windows日志

Windows系统主要分为用户态(ring3)内核态(ring0)

  • ring3:普通应用程序层级,权限低,不能直接操作系统底层资源(比如进程创建、文件读写),适合做数据收集、解析、展示非底层操作。
  • ring0:驱动程序运行的层级,能直接访问系统内核资源,能监控所有底层操作(比如进程创建、文件底层读写),但风险高(写得不好会导致系统蓝屏),适合做底层数据采集。

Sysmon也分成这样的两层,通过内核驱动捞底层原始数据,用户态负责补全数据并将原始数据翻译成易懂的日志

层级 运行的组件 核心职责 依赖
ring3 用户态 Sysmon 服务(exe 程序) 1. 收集网络数据;2. 解析驱动传来的原始数据 ETW(事件跟踪)、EventLog(事件日志)
内核态驱动 Minifilter 文件过滤驱动 1. 收集进程 / 线程 / 模块信息;2. 记录文件 / 注册表访问 进程回调、Minifilter、注册表回调

ring3:

  • Sysmon的用户态程序会订阅 Windows 的 “网络相关 ETW(Event Tracing for Windows) 事件(比如网络连接、端口监听、数据发送接收等),直接从系统层面捕获网络数据。
  • 驱动会把收集到的进程 / 文件 / 注册表原始数据,通过内核态→用户态的通信机制(比如事件对象、共享内存)传给Sysmon用户态程序;用户态程序通过 EventLog的规范,把这些原始数据 翻译成结构化日志 —— 比如把PID对应到进程名、把内存地址转成实际的文件路径 / 注册表路径,最终生成包含时间戳、进程信息、操作对象、操作类型、结果的清晰日志。

ring1:

内核允许驱动注册回调,当系统中任何进程发生创建、退出或者进程加载了新模块(比如 DLL 文件),内核会立刻通知驱动,驱动就能捕获到关键信息:

  • 进程信息:PID、进程名、父进程 PID、进程路径、创建时间、退出时间;
  • 线程信息:线程 ID、所属进程 PID、线程创建 / 退出时间;
  • 模块信息:加载的 DLL/EXE 路径、模块名、加载时间、所属进程。

基于Minifilter,驱动能拦截所有进程的文件操作,记录:

  • 操作进程:哪个进程在操作文件;
  • 操作对象:文件的完整路径;
  • 操作类型:创建、读取、写入、删除、重命名等;
  • 操作结果:成功 / 失败(比如权限不足导致删除失败)。

内核支持注册表回调,驱动注册后,能拦截所有注册表操作:

  • 操作进程:哪个进程在操作注册表;
  • 操作对象:注册表的完整路径(比如 HKEY_LOCAL_MACHINE\SOFTWARE\XXX);
  • 操作类型:创建、读取、写入、删除等;
  • 操作结果:成功 / 失败。

总的来说,Sysmon是两层架构的协作流程:

  1. 驱动采集底层数据:通过进程回调 + Minifilter + 注册表回调,收集原始数据。
  2. 数据传递给用户态:通过内核->用户态的通信通道,传给Sysmon服务
  3. 用户态补充+解析:通过ETW补充采集网络数据,同时接收驱动传来的二进制数据,并解析EventLog
  4. 生成最终的日志:整合以上的数据,写入日志库中供用户查看

Sysmon语法字段

Sysmon事件对象:

事件 ID 事件名称 核心监控内容
1 ProcessCreate 进程创建(记录完整命令行、父进程 ID、进程路径、哈希值等)
2 ProcessCreateEx 进程创建扩展信息(包含进程创建时的环境变量、令牌信息等详细数据)
3 NetworkConnect 网络连接建立(记录源 IP / 端口、目标 IP / 端口、协议、进程信息等)
4 ServiceConfigurationChange 服务配置变更(记录服务的创建、修改、删除或启动类型变更)
5 ProcessTerminate 进程终止(记录进程 ID、名称及终止时间)
6 DriverLoad 驱动加载(记录驱动路径、哈希值、签名信息,用于检测恶意驱动)
7 ImageLoad 镜像加载(记录进程加载的 DLL 等模块路径、哈希值,检测 DLL 注入)
8 RemoteThreadCreate 远程线程创建(记录跨进程创建线程的行为,常用于检测进程注入)
9 NetworkDisconnect 网络连接断开(记录连接断开的进程、IP / 端口信息)
10 ProcessAccess 进程访问(记录一个进程打开另一个进程的行为,如读取敏感进程内存)
11 FileCreate 文件创建 / 覆盖(记录新建文件或覆盖已有文件的路径、进程信息)
12 RegistryEvent (CreateKey) 注册表项创建(记录新建注册表项的路径、操作进程)
13 RegistryEvent (SetValue) 注册表值修改(记录注册表值的修改操作,含键路径、新旧值)
14 RegistryEvent (DeleteKey) 注册表项删除(记录删除注册表项的路径、操作进程)
15 FileCreateTime 文件时间戳修改(记录文件创建时间、最后修改时间等被手动篡改的行为)
16 ServiceConfigurationChange (旧版) 服务配置变更(部分旧版 Sysmon 使用,新版建议用 ID 4)
17 PipeEvent (Create) 命名管道创建(记录进程创建的命名管道,用于检测进程间隐蔽通信)
18 PipeEvent (Connect) 命名管道连接(记录进程连接到命名管道的行为)
19 WmiEvent (Filter) WMI 筛选器创建(记录 WMI 筛选器的创建,检测通过 WMI 的持久化恶意行为)
20 WmiEvent (Consumer) WMI 消费者创建(记录 WMI 消费者的创建,常与恶意持久化相关)
21 WmiEvent (Binding) WMI 绑定(记录 WMI 筛选器与消费者的绑定,用于检测 WMI 触发的恶意逻辑)
22 DNSQuery DNS 查询(记录进程发起的 DNS 解析请求,含域名、查询结果 IP)
23 FileDelete 文件删除(记录文件被删除的路径、操作进程)
24 FileDeleteDetected 文件删除检测(通常由反病毒软件触发,记录被删除的恶意文件)
25 FileStreamCreate 文件流创建(记录 NTFS 备用数据流的创建,用于检测隐藏在数据流中的恶意内容)
26 IntegrityCheck 完整性检查(记录 Sysmon 配置或自身文件被修改的行为,检测工具被篡改)
27 PipeEvent (Disconnect) 命名管道断开(记录命名管道连接的断开行为)
28 LoadImage 镜像加载(与 ID 7 类似,部分版本中用于记录驱动或模块加载的扩展信息)
29 CreateRemoteThread 远程线程创建(与 ID 8 类似,部分版本中细化远程线程创建的监控)

condition语法:

条件 描述
is 默认值,值相等
is any 字段是用分号分隔的值中的一个
is not 值不同
contains 字段包含此值
contains any 字段包含用分号分隔的值中的任意一个
contains all 字段包含用分号分隔的所有值
excludes 字段不包含此值
excludes any 字段不包含用分号分隔的值中的一个或多个
excludes all 字段不包含用分号分隔的任何值
begin with 字段以此值开头
end with 字段以此值结尾
not begin with 字段不以此值开头
not end with 字段不以此值结尾
less than 字典序比较结果小于零(即按字典顺序,字段值小于目标值)
more than 字典序比较结果大于零(即按字典顺序,字段值大于目标值)
image 匹配镜像路径(完整路径或仅镜像名称)。例如:lsass.exe 会匹配 c:\windows\system32\lsass.exe

常见的配置

监控网络连接

  • 监控常见exe软件发起的网络连接
  • 监控常见端口的网络连接
  • 排查杀毒软件、回环地址、某些官方域名的网络连接
<Sysmon schemaversion="4.90">
  <HashAlgorithms>*</HashAlgorithms>
  <EventFiltering>
    <RuleGroup name="networkmonitor" groupRelation="or">
       <NetworkConnect onmatch="include">
           <Image name="user" condition="begin with">C:\Users</Image>
           <Image condition="begin with">C:\ProgramData</Image>
           <Image condition="begin with">C:\Windows\Temp</Image>
           <Image condition="end with">dll</Image>
           <Image condition="image">java.exe</Image>
           <Image condition="image">javaws.exe</Image>
           <Image condition="image">python.exe</Image>
           <Image condition="image">curl.exe</Image>
           <Image condition="image">ncat.exe</Image>
           <Image condition="image">nc.exe</Image>
           <Image condition="image">cmd.exe</Image>
           <Image condition="image">nslookup.exe</Image>
           <Image condition="image">sc.exe</Image>
           <Image condition="image">at.exe</Image>
           <Image condition="image">certutil.exe</Image>
           <Image condition="image">dsquery.exe</Image>
           <Image condition="image">powershell.exe</Image>
          <Image condition="image">powershell_ise.exe</Image>
           <Image condition="image">wmic.exe</Image>
           <Image condition="image">wscript.exe</Image>
           <DestinationPort name="FTP" condition="is">21</DestinationPort>
           <DestinationPort name="SSH" condition="is">22</DestinationPort>
           <DestinationPort name="IMAP" condition="is">25</DestinationPort>
           <DestinationPort name="POP" condition="is">110</DestinationPort>
           <DestinationPort name="SMB" condition="is">445</DestinationPort>
           <DestinationPort name="RDP" condition="is">3389</DestinationPort>
        </NetworkConnect>
        <NetworkConnect onmatch="exclude">
           <Image name="defender" condition="begin with">C:\ProgramData\Microsoft\Windows Defender\</Image>
           <Image name="360" condition="is">360safe.exe</Image>
           <DestinationHostname condition="end with">.microsoft.com</DestinationHostname>
           <DestinationIp condition="is">127.0.0.1</DestinationIp> 
        </NetworkConnect>
  </EventFiltering>
</Sysmon>

image-20251020152003938

监控文件更改

  • 监控用户目录、系统目录的文件
  • 监控exe、dll文件的删除,排查临时文件缓存
  • 排除系统wps、word等常用办公软件产生的文件监控
<Sysmon schemaversion="4.90">
  <HashAlgorithms>*</HashAlgorithms>
  <EventFiltering>
    <RuleGroup name="filemonitor" groupRelation="or">
        <FileCreate onmatch="include">
          <TargetFilename condition="contains">C:\Users\</TargetFilename> 
          <TargetFilename condition="contains">C:\ProgramData\</TargetFilename>
          <TargetFilename condition="contains">C:\Windows\System32\</TargetFilename>
        </FileCreate>
        <FileCreateTime onmatch="include">
        </FileCreateTime>
        <FileDelete onmatch="include">
          <TargetFilename condition="end with">.exe</TargetFilename>
          <TargetFilename condition="end with">.dll</TargetFilename>
        </FileDelete>
        <FileStreamCreate onmatch="include">
        </FileStreamCreate>
        <FileCreate onmatch="exclude">
          <Image condition="end with">svchost.exe</Image>
          <Image condition="end with">lsass.exe</Image>
        </FileCreate>
        <FileDelete onmatch="exclude">
          <Image condition="end with">cleanmgr.exe</Image>
          <TargetFilename condition="contains">AppData\Local\Temp\</TargetFilename>
        </FileDelete>
        <FileCreate onmatch="exclude">
          <Image condition="end with">notepad.exe</Image>
          <Image condition="end with">word.exe</Image>
          <Image condition="end with">wps.exe</Image>
        </FileCreate>
      </RuleGroup>
  </EventFiltering>
</Sysmon>

image-20251020151946140

进程监控

监控所有的进程创建,排除关键的系统核心进程

<Sysmon schemaversion="4.90">
  <HashAlgorithms>*</HashAlgorithms>
  <EventFiltering>
        <RuleGroup name="processmonitor" groupRelation="or">
            <ProcessCreate onmatch="include">
                <!--不填写默认监控所有-->
            </ProcessCreate>
            <ProcessCreate onmatch="exclude">
              <Image condition="contains">C:\Windows\System32\</Image>
              <Image condition="contains">C:\Windows\SysWOW64\</Image>
              <Image condition="contains">C:\Windows\WinSxS\</Image>
              <Image condition="contains">C:\Windows\Microsoft.NET\</Image>
              <Image condition="end with">svchost.exe</Image>       <!-- 系统服务宿主 -->
              <Image condition="end with">lsass.exe</Image>         <!-- 安全账户管理器 -->
              <Image condition="end with">services.exe</Image>      <!-- 服务控制管理器 -->
              <Image condition="end with">winlogon.exe</Image>      <!-- 登录进程 -->
              <Image condition="end with">explorer.exe</Image>      <!-- 资源管理器 -->
              <Image condition="end with">taskhostw.exe</Image>     <!-- 任务宿主(现代应用) -->
              <Image condition="end with">csrss.exe</Image>         <!-- 客户端服务器运行时进程 -->
              <Image condition="end with">smss.exe</Image>          <!-- 会话管理器 -->
              <Image condition="end with">wininit.exe</Image>       <!-- 系统初始化进程 -->
              <Image condition="end with">SearchIndexer.exe</Image> <!-- 搜索索引进程 -->
            </ProcessCreate>
            <ProcessTerminate onmatch="include">
            <Image condition="begin with">C:\Users</Image>
            <Image condition="begin with">\</Image>
           </ProcessTerminate>
      </RuleGroup>
  </EventFiltering>
</Sysmon>

image-20251020152021622

DNS解析监控

排除一些官方网站的dns解析

<Sysmon schemaversion="4.90">
  <HashAlgorithms>*</HashAlgorithms>
  <EventFiltering>
        <RuleGroup name="dnsmonitor" groupRelation="or">
            <QueryName condition="end with">.bing.com</QueryName>
            <QueryName condition="end with">.baidu.com</QueryName>
            <QueryName condition="end with">.google.com</QueryName>
            <QueryName condition="is">localhost</QueryName>
            <QueryName condition="end with">.windowsupdate.com</QueryName>
            <QueryName condition="end with">.mozilla.com</QueryName>
            <QueryName condition="end with">.mozilla.net</QueryName>
            <QueryName condition="end with">.mozilla.org</QueryName>
      </RuleGroup>
  </EventFiltering>
</Sysmon>

image-20251020152658424

注册表监控

  • 监控自启动项、安全相关的注册表路径
  • 监控自启动值、UAC开关值的修改
  • 监控安全软件、系统关键配置项的删除
  • 排除正常的系统进程
<Sysmon schemaversion="4.90">
  <HashAlgorithms>*</HashAlgorithms>
  <EventFiltering>
       <RuleGroup name="registrymonitor" groupRelation="or">
       <RegistryEvent onmatch="include" eventType="CreateKey">>
          <TargetObject condition="contains">HKLM\Software\Microsoft\Windows\CurrentVersion\Run</TargetObject>
          <TargetObject condition="contains">HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnce</TargetObject>
          <TargetObject condition="contains">HKCU\Software\Microsoft\Windows\CurrentVersion\Run</TargetObject>
          <TargetObject condition="contains">HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon</TargetObject>
          <TargetObject condition="contains">HKLM\Software\Microsoft\Windows Defender</TargetObject>
        </RegistryEvent>
        <RegistryEvent onmatch="include" eventType="SetValue">
          <TargetObject condition="contains">HKLM\Software\Microsoft\Windows\CurrentVersion\Run\</TargetObject>
          <TargetObject condition="contains">HKCU\Software\Microsoft\Windows\CurrentVersion\Run\</TargetObject>
          <TargetObject condition="contains">HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System\EnableLUA</TargetObject>
        </RegistryEvent>
        <RegistryEvent onmatch="include" eventType="DeleteKey">
          <TargetObject condition="contains">HKLM\Software\Microsoft\Windows Defender</TargetObject>
          <TargetObject condition="contains">HKLM\Software\Microsoft\Windows\CurrentVersion\Run</TargetObject>
        </RegistryEvent>
        <RegistryEvent onmatch="exclude">
          <Image condition="end with">svchost.exe</Image>
          <Image condition="end with">wuauclt.exe</Image>
          <Image condition="end with">msiexec.exe</Image>
          <TargetObject condition="contains">HKLM\Software\Microsoft\Windows\CurrentVersion\Installer\</TargetObject>
          <TargetObject condition="contains">HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\</TargetObject>
          <CommandLine condition="is">C:\Windows\system32\wermgr.exe -upload</CommandLine>
          <ParentCommandLine condition="is">C:\windows\system32\wermgr.exe -queuereporting</ParentCommandLine>
         <ParentImage condition="is">C:\Windows\system32\SearchIndexer.exe</ParentImage>
        </RegistryEvent>
    </RuleGroup>
  </EventFiltering>
</Sysmon>

image-20251020160218950

更全面的配置文件可以看:https://github.com/SwiftOnSecurity/sysmon-config

Winlogbeat

可以通过WinlogbeatSysmon的日志发送至SIEM平台中,这里以splunk为例。

Winlogbeat下载地址:https://www.elastic.co/cn/downloads/beats/winlogbeat

1、在splunk中配置HTTP事件接收器,以接收Winlogbeat发送的日志

image-20251020162553561

2、编辑C:\Program Files\Winlogbeat\winlogbeat.yml文件,以发送到splunk

############################# Winlogbeat ######################################

winlogbeat.event_logs:
  - name: Microsoft-Windows-Sysmon/Operational
    ignore_older: 24h
    #event_id: 1,2

# ====================== Output to Splunk HEC ===============================

output.http:
  hosts: ["https://host:port/services/collector"]
  headers:
    Authorization: Splunk token
  index: "win_sysmon"
  ssl.verification_mode: "none"

# ======================== Processors ======================================

processors:
  - add_host_metadata: ~
  #云环境- add_cloud_metadata: ~
  #docker环境- add_docker_metadata: ~

# ======================== Logging ==========================================

logging.level: info
logging.to_files: true
logging.files:
  path: C:\Program Files\Winlogbeat\logs

定义Winlogbeat-event_logs要发送的日志类型为Microsoft-Windows-Sysmon/Operational并忽略24 小时前的旧日志,配置为http的方式用于splunk接收日志,并通过processors加入自定义字段,如add_host_metadata加入主机的IP、主机名等信息作区分,并把Winlogbeat日志写入到C:\Program Files\Winlogbeat\logs文件当中。

总结

SysmonWinlogbeat的组合,可为办公终端构建一套轻量微型HIDS,通过实时获取HIDS的网络连接、进程、文件操作日志等到splunk中,再在splunk根据日志构建基础日志检测规则,实时发现在办公终端上的恶意行为,Sysmon低成本高性价、高细粒度、高自定义极有优势,与传统的商业EDR结合,能形成更为安全的互补。

~  ~  The   End  ~  ~


 赏 
承蒙厚爱,倍感珍贵,我会继续努力哒!
logo图像
tips
文章二维码 分类标签:安全安全
文章标题:sysmon
文章链接:https://aiwin.net.cn/index.php/archives/4523/
最后编辑:2025 年 10 月 20 日 17:25 By Aiwin
许可协议: 署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)
(*) 8 + 4 =
快来做第一个评论的人吧~