Windows应急响应 - 32 Sysmon部署与规则编写

Sysmon部署与规则编写

前置说明

Sysmon(System Monitor)是 Sysinternals 出品的高级系统监控工具,以 Windows 服务 + 驱动的方式运行

它弥补了 Windows 原生事件日志的大量盲区,是 IR/Threat Hunting 的核心数据源

Sysmon 本身不做告警/检测,它只负责高质量的事件生成,检测逻辑由 SIEM/Sigma/Hayabusa 等完成

日志写入:Microsoft-Windows-Sysmon/Operational 通道

关联页面:03-事件日志分析 | 21-WMI事件订阅后门 | 31-Sysinternals套件


一、为什么需要 Sysmon

1.1 Windows 原生日志的盲区

能力 Windows 原生日志 Sysmon
进程创建(含命令行) Security 4688(需开启审计策略) Event ID 1(默认含完整命令行 + hash + 父进程 GUID)
网络连接 Security 5156(Windows Filtering Platform,信息有限) Event ID 3(含源/目 IP:Port、进程、用户)
DLL 加载 无原生日志 Event ID 7(ImageLoaded,含 hash 和签名)
进程注入 无原生日志 Event ID 8(CreateRemoteThread)+ Event ID 10(ProcessAccess)
文件创建 无原生日志 Event ID 11(FileCreate,含 hash)
注册表操作 Security 4657(需开启 SACL) Event ID 12/13/14(无需 SACL 配置)
DNS 查询 DNS Client 日志(需特殊开启) Event ID 22(DNSQuery)
WMI 事件 无原生日志 Event ID 19/20/21
文件流(ADS) 无原生日志 Event ID 15(FileCreateStreamHash)
文件删除 无原生日志 Event ID 23/26(FileDelete)
进程篡改 无原生日志 Event ID 25(ProcessTampering)

结论:没有 Sysmon 的 Windows 系统在 IR 时是”半盲”状态

1.2 Sysmon 的优势

事件中包含 ProcessGUID,可以跨事件关联同一进程的所有行为

事件中包含 文件 hash(MD5/SHA1/SHA256/IMPHASH),直接可对接 IOC

规则驱动:可以精确控制记录什么、不记录什么,平衡覆盖面和性能

持久化为 Windows 服务 + 内核驱动,重启不丢失

日志写入标准 EVTX,可被 SIEM、Hayabusa、Sigma 等工具直接消费


二、安装与基础配置

2.1 安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 下载 Sysmon
Invoke-WebRequest -Uri "https://download.sysinternals.com/files/Sysmon.zip" `
-OutFile "$env:TEMP\Sysmon.zip"
Expand-Archive -Path "$env:TEMP\Sysmon.zip" -DestinationPath "C:\Tools\Sysmon"

# 基础安装(无配置文件,记录所有事件 — 仅用于测试)
C:\Tools\Sysmon\Sysmon64.exe -accepteula -i

# 使用配置文件安装(推荐)
C:\Tools\Sysmon\Sysmon64.exe -accepteula -i C:\Tools\Sysmon\sysmonconfig.xml

# 常用安装参数
# -i <config.xml> 安装并应用配置
# -c <config.xml> 更新已安装 Sysmon 的配置
# -u 卸载
# -u force 强制卸载(配置损坏时使用)
# -h md5,sha256,imphash 指定 hash 算法
# -l 记录 DLL 加载事件(也可在配置中控制)
# -n 记录网络连接事件(也可在配置中控制)

2.2 验证安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 检查 Sysmon 服务状态
Get-Service Sysmon64
# Status: Running

# 检查 Sysmon 驱动
fltmc | findstr /i sysmon
# SysmonDrv ...

# 检查当前配置
Sysmon64.exe -c

# 查看 Sysmon 版本
Sysmon64.exe

# 测试日志是否正常写入
Get-WinEvent -LogName "Microsoft-Windows-Sysmon/Operational" -MaxEvents 5 |
Select-Object TimeCreated, Id, Message

2.3 更新配置

1
2
3
4
5
6
7
# 更新配置(不需要重新安装)
Sysmon64.exe -c C:\Tools\Sysmon\sysmonconfig_updated.xml

# 恢复默认配置(记录所有事件)
Sysmon64.exe -c --

# 注意:更新配置不需要重启服务,立即生效

三、Sysmon 事件 ID 详解

3.1 进程相关事件

Event ID 1 — ProcessCreate(进程创建)

IR 价值:最高 — 记录每个进程的创建,含完整命令行

关键字段:

ProcessGuid: 全局唯一标识,用于跨事件关联

ProcessId: PID

Image: 进程完整路径

CommandLine: 完整命令行参数(核心信息

ParentProcessGuid / ParentProcessId / ParentImage / ParentCommandLine: 父进程信息

User: 运行用户

Hashes: 文件 hash

IntegrityLevel: 完整性级别(Low/Medium/High/System)

示例告警场景:

cmd.exe 的父进程是 winword.exe(钓鱼)

powershell.exe -enc <base64>(编码命令执行)

C:\Windows\Temp\*.exe 执行(临时目录中的可执行文件)

Event ID 5 — ProcessTerminate(进程终止)

IR 价值:中 — 结合 Event ID 1 计算进程运行时长

Event ID 8 — CreateRemoteThread(远程线程创建)

IR 价值:最高 — 进程注入的关键指标

关键字段:

SourceImage: 创建线程的进程

TargetImage: 被注入的目标进程

StartAddress / StartModule / StartFunction: 线程起始信息

典型告警:任何进程对 lsass.exe 创建远程线程

Event ID 10 — ProcessAccess(进程访问)

IR 价值:最高 — 检测 Mimikatz 等凭据提取工具

关键字段:

SourceImage: 发起访问的进程

TargetImage: 被访问的目标进程

GrantedAccess: 请求的访问权限

Mimikatz 典型模式:

GrantedAccess 包含 0x10100x1410(PROCESS_QUERY_LIMITED_INFORMATION + PROCESS_VM_READ)

TargetImagelsass.exe

Event ID 25 — ProcessTampering(进程篡改)

IR 价值: — 检测 Process Hollowing / Process Herpaderping

当进程映像被修改或替换时触发

3.2 网络相关事件

Event ID 3 — NetworkConnect(网络连接)

IR 价值: — 记录进程级别的网络活动

关键字段:

Image: 发起连接的进程

User: 用户

Protocol: TCP/UDP

SourceIp / SourcePort: 源地址

DestinationIp / DestinationPort / DestinationHostname: 目标地址

Initiated: true(出站)/ false(入站)

注意:高流量环境下此事件量极大,需要精细 Filter

Event ID 22 — DNSQuery(DNS 查询)

IR 价值: — 记录进程的 DNS 解析请求

关键字段:

Image: 发起查询的进程

QueryName: 查询的域名

QueryResults: 解析结果

典型告警:

非浏览器进程查询动态 DNS(*.duckdns.org*.no-ip.com

异常长的子域名(可能是 DNS tunneling)

powershell.exerundll32.exe 的 DNS 查询

3.3 文件相关事件

Event ID 11 — FileCreate(文件创建)

IR 价值: — 追踪文件投放

关键字段:

Image: 创建文件的进程

TargetFilename: 被创建的文件完整路径

监控重点:

C:\Windows\System32\ 中的新 DLL

C:\Windows\Temp\ 中的 EXE

Startup 目录中的新文件

用户 profile 中的可执行文件

Event ID 15 — FileCreateStreamHash(文件流/ADS 创建)

IR 价值: — 检测 Alternate Data Stream 隐藏

当文件被创建且带有 ADS 时触发

攻击者可能在 ADS 中隐藏恶意 payload

Event ID 23 — FileDelete(文件删除,含归档)

IR 价值: — Sysmon 可以在文件被删除前归档保存

配置 ArchiveDirectory 后,Sysmon 会将被删除的文件保存到指定目录

这对恶意软件的自删除行为极为有价值

Event ID 26 — FileDeleteDetected(文件删除记录)

仅记录删除事件,不归档文件(比 Event ID 23 轻量)

3.4 注册表相关事件

Event ID 12 — RegistryEvent (Object create/delete)

Event ID 13 — RegistryEvent (Value Set)

Event ID 14 — RegistryEvent (Key/Value Rename)

关键字段:

Image: 操作注册表的进程

EventType: CreateKey / DeleteKey / SetValue / RenameKey

TargetObject: 注册表路径

Details: 设置的值(Event ID 13)

监控重点路径:

HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

HKLM\SYSTEM\CurrentControlSet\Services

HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options

HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon

3.5 DLL 加载与 WMI 事件

Event ID 7 — ImageLoaded(DLL 加载)

IR 价值: — 检测 DLL 劫持/侧加载

关键字段:

Image: 加载 DLL 的进程

ImageLoaded: DLL 完整路径

Hashes: DLL 的 hash

Signed / Signature / SignatureStatus: 签名信息

注意:此事件量极大,必须配合精确的 Filter 使用

Event ID 19/20/21 — WMI 事件

Event ID 19: WmiEventFilter(事件过滤器创建)

Event ID 20: WmiEventConsumer(事件消费者创建)

Event ID 21: WmiEventConsumerToFilter(绑定关系创建)

IR 价值: — 检测 WMI 持久化后门

参见 21-WMI事件订阅后门

3.6 Event ID 完整速查表

ID 事件名 IR 价值 事件量
1 ProcessCreate 最高
2 FileCreateTime
3 NetworkConnect 极大
4 Sysmon Service State 极小
5 ProcessTerminate
6 DriverLoad
7 ImageLoaded (DLL) 极大
8 CreateRemoteThread 最高
9 RawAccessRead
10 ProcessAccess 最高 极大
11 FileCreate
12 RegistryCreate/Delete
13 RegistryValueSet
14 RegistryRename
15 FileCreateStreamHash
16 Sysmon Config Change 极小
17 PipeCreated
18 PipeConnected
19 WmiFilterCreate 极小
20 WmiConsumerCreate 极小
21 WmiConsumerBind 极小
22 DNSQuery
23 FileDelete (archive)
24 ClipboardChange
25 ProcessTampering 极小
26 FileDeleteDetected
27 FileBlockExecutable
28 FileBlockShredding
29 FileExecutableDetected

四、配置文件结构

4.1 XML 配置基本结构

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<Sysmon schemaversion="4.90">
<!-- Hash 算法配置 -->
<HashAlgorithms>md5,sha256,IMPHASH</HashAlgorithms>

<!-- DNS 查询缓存(设为 true 不记录缓存命中的查询) -->
<DnsLookup>false</DnsLookup>

<!-- 文件删除归档目录 -->
<ArchiveDirectory>C:\SysmonArchive</ArchiveDirectory>

<!-- 事件过滤规则 -->
<EventFiltering>

<!-- RuleGroup 支持 AND/OR 逻辑 -->
<RuleGroup name="Process Creation Rules" groupRelation="or">
<ProcessCreate onmatch="include">
<!-- 规则条目 -->
</ProcessCreate>
</RuleGroup>

<RuleGroup name="Network Rules" groupRelation="or">
<NetworkConnect onmatch="exclude">
<!-- 排除的网络事件 -->
</NetworkConnect>
</RuleGroup>

</EventFiltering>
</Sysmon>

4.2 Include vs Exclude 逻辑

**onmatch="include"**:只记录匹配规则的事件(白名单模式)

匹配 → 记录

不匹配 → 丢弃

**onmatch="exclude"**:记录所有事件,除了匹配规则的(黑名单模式)

匹配 → 丢弃

不匹配 → 记录

最佳实践:

大多数事件类型使用 exclude(记录一切,排除已知噪音)

高容量事件(Event ID 7 ImageLoaded、Event ID 10 ProcessAccess)使用 include(只记录关心的)

如果同时有 include 和 exclude RuleGroup(不同 RuleGroup),处理顺序:

Sysmon 15+ 版本支持在同一事件类型中使用多个 RuleGroup

include 先处理,exclude 后处理

4.3 条件匹配操作符

操作符 说明 示例
is 精确匹配 <Image condition="is">C:\Windows\System32\cmd.exe</Image>
is not 不等于 <Image condition="is not">...</Image>
contains 包含 <CommandLine condition="contains">-enc</CommandLine>
contains any 包含任意一个(; 分隔) <CommandLine condition="contains any">-enc;-nop;-w hidden</CommandLine>
contains all 包含所有 <CommandLine condition="contains all">net;user;/add</CommandLine>
excludes 不包含 <Image condition="excludes">System32</Image>
excludes any 不包含任意一个 <Image condition="excludes any">System32;SysWOW64</Image>
excludes all 不包含所有 <Image condition="excludes all">...</Image>
begin with 以…开头 <TargetFilename condition="begin with">C:\Windows\</TargetFilename>
end with 以…结尾 <TargetFilename condition="end with">.exe</TargetFilename>
image 匹配路径中的文件名部分 <Image condition="image">cmd.exe</Image>

4.4 RuleGroup 与 groupRelation

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<!-- OR 关系:任一条件匹配即触发(默认) -->
<RuleGroup name="Suspicious Process" groupRelation="or">
<ProcessCreate onmatch="include">
<Image condition="end with">.ps1</Image> <!-- 条件 A -->
<Image condition="end with">.vbs</Image> <!-- 条件 B -->
<!-- A 或 B 匹配 → 记录 -->
</ProcessCreate>
</RuleGroup>

<!-- AND 关系:所有条件都匹配才触发 -->
<RuleGroup name="Mimikatz Detection" groupRelation="and">
<ProcessAccess onmatch="include">
<TargetImage condition="is">C:\Windows\system32\lsass.exe</TargetImage> <!-- 条件 A -->
<GrantedAccess condition="is">0x1010</GrantedAccess> <!-- 条件 B -->
<!-- A 和 B 同时匹配 → 记录 -->
</ProcessAccess>
</RuleGroup>

五、推荐配置方案

5.1 SwiftOnSecurity/sysmon-config

GitHub: https://github.com/SwiftOnSecurity/sysmon-config

特点:

最广泛使用的 Sysmon 配置

以 exclude 模式为主,记录大量事件并排除已知噪音

详细的注释说明每条规则的原因

适合作为起始配置,在此基础上定制

1
2
3
4
# 下载并应用
Invoke-WebRequest -Uri "https://raw.githubusercontent.com/SwiftOnSecurity/sysmon-config/master/sysmonconfig-export.xml" `
-OutFile "C:\Tools\Sysmon\sysmonconfig-swift.xml"
Sysmon64.exe -c C:\Tools\Sysmon\sysmonconfig-swift.xml

5.2 Olaf Hartong / sysmon-modular

GitHub: https://github.com/olafhartong/sysmon-modular

特点:

模块化配置,每个 Event ID 有独立的配置文件

使用 merge-sysmonconfig.ps1 合并为最终配置

更容易维护和定制

与 MITRE ATT&CK 映射

1
2
3
4
5
6
7
8
9
10
# 克隆仓库
git clone https://github.com/olafhartong/sysmon-modular.git
cd sysmon-modular

# 合并配置
.\Merge-SysmonXml.ps1 -Path . -AsHashTable |
Out-File sysmonconfig-merged.xml -Encoding UTF8

# 应用
Sysmon64.exe -c sysmonconfig-merged.xml

5.3 配置选择建议

场景 推荐配置 原因
快速部署 SwiftOnSecurity 开箱即用、社区验证
企业定制 sysmon-modular 模块化便于按需增减
最大覆盖 自定义 exclude-all 配置 最全面但日志量大
性能敏感 精简 include 配置 只监控高价值事件

六、自定义规则编写实战

6.1 检测 PowerShell Download Cradle

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<!-- 检测 PowerShell 下载行为 -->
<RuleGroup name="PowerShell Download Cradle" groupRelation="or">
<ProcessCreate onmatch="include">
<CommandLine condition="contains any">
Invoke-WebRequest;IWR;Invoke-RestMethod;IRM;
wget;curl;DownloadString;DownloadFile;
DownloadData;Net.WebClient;Start-BitsTransfer;
BitsTransfer;Invoke-Expression;IEX
</CommandLine>
<ParentImage condition="image">powershell.exe</ParentImage>
</ProcessCreate>
</RuleGroup>

<!-- 检测编码的 PowerShell 命令 -->
<RuleGroup name="Encoded PowerShell" groupRelation="or">
<ProcessCreate onmatch="include">
<CommandLine condition="contains any">
-enc;-encodedcommand;-e JAB;-e SQBFAF;-e SQBuAH;-e SABFAF;
-e cwBhA;-e aQBmA;-e aQBlA;-e dgBhAH;-e bgBhAG0A
</CommandLine>
</ProcessCreate>
</RuleGroup>

6.2 检测 LSASS 凭据提取(Mimikatz)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<!-- 检测对 LSASS 的可疑访问 — Mimikatz 检测 -->
<RuleGroup name="LSASS Access Detection" groupRelation="and">
<ProcessAccess onmatch="include">
<TargetImage condition="is">C:\Windows\system32\lsass.exe</TargetImage>
<GrantedAccess condition="is any">
0x1010;0x1410;0x1438;0x143a;0x1fffff;0x1010;0x40
</GrantedAccess>
</ProcessAccess>
</RuleGroup>

<!-- 排除已知合法的 LSASS 访问 -->
<RuleGroup name="LSASS Access Exclusion" groupRelation="or">
<ProcessAccess onmatch="exclude">
<SourceImage condition="is">C:\Windows\system32\wbem\wmiprvse.exe</SourceImage>
<SourceImage condition="is">C:\Windows\system32\svchost.exe</SourceImage>
<SourceImage condition="is">C:\Windows\system32\lsass.exe</SourceImage>
<SourceImage condition="is">C:\Windows\system32\csrss.exe</SourceImage>
<SourceImage condition="begin with">C:\Program Files\Windows Defender\</SourceImage>
<SourceImage condition="begin with">C:\ProgramData\Microsoft\Windows Defender\</SourceImage>
</ProcessAccess>
</RuleGroup>

6.3 检测 DLL 注入(CreateRemoteThread)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<!-- 检测远程线程注入 -->
<RuleGroup name="Remote Thread Injection" groupRelation="or">
<CreateRemoteThread onmatch="exclude">
<!-- 排除已知合法的远程线程创建 -->
<SourceImage condition="is">C:\Windows\system32\csrss.exe</SourceImage>
<SourceImage condition="is">C:\Windows\system32\wininit.exe</SourceImage>
<SourceImage condition="is">C:\Windows\system32\winlogon.exe</SourceImage>
<SourceImage condition="is">C:\Windows\system32\services.exe</SourceImage>
<SourceImage condition="begin with">C:\Program Files\</SourceImage>
<SourceImage condition="begin with">C:\Program Files (x86)\</SourceImage>
</CreateRemoteThread>
</RuleGroup>

<!-- 高优先级:任何进程对 lsass 创建远程线程 -->
<RuleGroup name="LSASS Thread Injection" groupRelation="or">
<CreateRemoteThread onmatch="include">
<TargetImage condition="is">C:\Windows\system32\lsass.exe</TargetImage>
</CreateRemoteThread>
</RuleGroup>

6.4 检测可疑 DNS 查询

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<!-- 检测可疑的 DNS 查询 -->
<RuleGroup name="Suspicious DNS" groupRelation="or">
<DnsQuery onmatch="include">
<!-- 动态 DNS 服务 -->
<QueryName condition="end with">.duckdns.org</QueryName>
<QueryName condition="end with">.no-ip.com</QueryName>
<QueryName condition="end with">.no-ip.org</QueryName>
<QueryName condition="end with">.ddns.net</QueryName>
<QueryName condition="end with">.hopto.org</QueryName>
<QueryName condition="end with">.zapto.org</QueryName>
<QueryName condition="end with">.serveftp.com</QueryName>
<!-- Pastebin 等常见 C2 中转 -->
<QueryName condition="contains">pastebin.com</QueryName>
<QueryName condition="contains">raw.githubusercontent.com</QueryName>
<!-- Tor 相关 -->
<QueryName condition="end with">.onion</QueryName>
<QueryName condition="end with">.tor2web.org</QueryName>
</DnsQuery>
</RuleGroup>

<!-- 非浏览器进程的 DNS 查询(可选,量大) -->
<RuleGroup name="Non-Browser DNS" groupRelation="or">
<DnsQuery onmatch="include">
<Image condition="image">powershell.exe</Image>
<Image condition="image">cmd.exe</Image>
<Image condition="image">rundll32.exe</Image>
<Image condition="image">regsvr32.exe</Image>
<Image condition="image">mshta.exe</Image>
<Image condition="image">wscript.exe</Image>
<Image condition="image">cscript.exe</Image>
</DnsQuery>
</RuleGroup>

6.5 检测 WMI 持久化

1
2
3
4
5
6
<!-- 记录所有 WMI 事件订阅活动 -->
<RuleGroup name="WMI Persistence" groupRelation="or">
<WmiEvent onmatch="exclude">
<!-- 几乎不排除任何 WMI 事件,因为它们非常少且非常重要 -->
</WmiEvent>
</RuleGroup>

WMI 事件订阅(Event ID 19/20/21)在正常系统中极为罕见

任何 WMI 事件订阅的创建都应当被视为高优先级告警

6.6 检测可疑文件创建

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<!-- 监控关键目录的文件创建 -->
<RuleGroup name="Suspicious File Creation" groupRelation="or">
<FileCreate onmatch="include">
<!-- Startup 目录 -->
<TargetFilename condition="contains">\Start Menu\Programs\Startup\</TargetFilename>
<!-- 系统目录中的新 EXE/DLL -->
<TargetFilename condition="begin with">C:\Windows\System32\</TargetFilename>
<TargetFilename condition="begin with">C:\Windows\SysWOW64\</TargetFilename>
<!-- Temp 目录中的可执行文件 -->
<TargetFilename condition="contains">\Temp\</TargetFilename>
<!-- 可疑扩展名 -->
<TargetFilename condition="end with">.exe</TargetFilename>
<TargetFilename condition="end with">.dll</TargetFilename>
<TargetFilename condition="end with">.bat</TargetFilename>
<TargetFilename condition="end with">.ps1</TargetFilename>
<TargetFilename condition="end with">.vbs</TargetFilename>
<TargetFilename condition="end with">.hta</TargetFilename>
<TargetFilename condition="end with">.scr</TargetFilename>
</FileCreate>
</RuleGroup>

七、Sysmon 作为取证制品源

7.1 使用 PowerShell 查询 Sysmon 日志

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 查询所有进程创建事件
Get-WinEvent -LogName "Microsoft-Windows-Sysmon/Operational" -FilterXPath "*[System[EventID=1]]" -MaxEvents 50 |
ForEach-Object {
$xml = [xml]$_.ToXml()
[PSCustomObject]@{
Time = $_.TimeCreated
Image = ($xml.Event.EventData.Data | Where-Object Name -eq 'Image').'#text'
CommandLine = ($xml.Event.EventData.Data | Where-Object Name -eq 'CommandLine').'#text'
ParentImage = ($xml.Event.EventData.Data | Where-Object Name -eq 'ParentImage').'#text'
User = ($xml.Event.EventData.Data | Where-Object Name -eq 'User').'#text'
}
} | Format-Table -AutoSize

# 查询网络连接事件
Get-WinEvent -LogName "Microsoft-Windows-Sysmon/Operational" -FilterXPath "*[System[EventID=3]]" -MaxEvents 50 |
ForEach-Object {
$xml = [xml]$_.ToXml()
[PSCustomObject]@{
Time = $_.TimeCreated
Image = ($xml.Event.EventData.Data | Where-Object Name -eq 'Image').'#text'
DestIP = ($xml.Event.EventData.Data | Where-Object Name -eq 'DestinationIp').'#text'
DestPort = ($xml.Event.EventData.Data | Where-Object Name -eq 'DestinationPort').'#text'
}
} | Format-Table -AutoSize

# 查询 DNS 查询事件
Get-WinEvent -LogName "Microsoft-Windows-Sysmon/Operational" -FilterXPath "*[System[EventID=22]]" -MaxEvents 50 |
ForEach-Object {
$xml = [xml]$_.ToXml()
[PSCustomObject]@{
Time = $_.TimeCreated
Image = ($xml.Event.EventData.Data | Where-Object Name -eq 'Image').'#text'
QueryName = ($xml.Event.EventData.Data | Where-Object Name -eq 'QueryName').'#text'
}
} | Format-Table -AutoSize

7.2 离线分析 Sysmon EVTX

1
2
3
4
5
6
7
8
# 使用 EvtxECmd 解析 Sysmon 日志
EvtxECmd.exe -f "C:\Evidence\Microsoft-Windows-Sysmon%4Operational.evtx" --csv C:\Evidence\parsed\ --csvf sysmon_parsed.csv

# 使用 Hayabusa 对 Sysmon 日志进行威胁狩猎
hayabusa.exe csv-timeline -f "C:\Evidence\Microsoft-Windows-Sysmon%4Operational.evtx" -o C:\Evidence\sysmon_timeline.csv

# 使用 Chainsaw 扫描
chainsaw hunt "C:\Evidence\Microsoft-Windows-Sysmon%4Operational.evtx" -s sigma_rules/ --mapping mappings/sigma-event-logs-all.yml

参见 33-事件日志分析工具 获取更多工具详情


八、性能调优

8.1 高容量事件的处理策略

事件 策略 原因
Event ID 7 (ImageLoaded) 使用 include,只监控特定路径 DLL 加载量极大
Event ID 10 (ProcessAccess) 使用 include + exclude 结合 进程间访问频繁
Event ID 3 (NetworkConnect) 排除已知高频合法连接 网络活动量大
Event ID 12/13 (Registry) 排除已知系统噪音路径 注册表操作频繁
Event ID 11 (FileCreate) 排除临时文件、日志文件 文件创建频繁

8.2 监控 Sysmon 自身性能

1
2
3
4
5
6
7
8
9
10
11
12
# 检查 Sysmon 日志的事件生成速率
$sysmonLog = Get-WinEvent -LogName "Microsoft-Windows-Sysmon/Operational" -MaxEvents 1000
$timeSpan = $sysmonLog[0].TimeCreated - $sysmonLog[-1].TimeCreated
$eventsPerSecond = 1000 / $timeSpan.TotalSeconds
Write-Host "Sysmon events per second: $([math]::Round($eventsPerSecond, 2))"

# 检查日志文件大小
Get-Item "C:\Windows\System32\winevt\Logs\Microsoft-Windows-Sysmon%4Operational.evtx" |
Select-Object Name, @{N='SizeMB';E={[math]::Round($_.Length/1MB,2)}}

# 检查是否有事件丢失(Event ID 4 = Sysmon Service State)
Get-WinEvent -LogName "Microsoft-Windows-Sysmon/Operational" -FilterXPath "*[System[EventID=4]]" -MaxEvents 10

8.3 日志大小配置

1
2
3
4
5
6
7
8
# 增大 Sysmon 日志容量(默认 64 MB 可能不够)
wevtutil sl "Microsoft-Windows-Sysmon/Operational" /ms:536870912
# /ms: 最大大小(字节),上例为 512 MB

# 建议值:
# 小型环境: 256 MB
# 中型环境: 512 MB - 1 GB
# 大型环境: 配置日志转发到 SIEM,本地保留 256 MB

九、Sysmon 规避与对策

9.1 攻击者如何规避 Sysmon

卸载 Sysmon: 需要管理员权限,但获得权限后可以 Sysmon64.exe -u

停止 Sysmon 服务: sc stop Sysmon64 / net stop Sysmon64

清空 Sysmon 日志: wevtutil cl Microsoft-Windows-Sysmon/Operational

卸载 Sysmon 驱动: fltmc unload SysmonDrv

修改 Sysmon 配置: 替换为空配置,不记录任何事件

内核级绕过: Patch Sysmon 驱动的回调函数

9.2 检测 Sysmon 被篡改

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 监控 Sysmon 服务状态变化
# Sysmon Event ID 4 记录服务状态变化
# Sysmon Event ID 16 记录配置变化

# 在 SIEM 中创建告警:
# - Sysmon 服务停止
# - Sysmon 配置变更
# - Sysmon 日志被清空(Security Event ID 1102)
# - SysmonDrv 驱动被卸载

# PowerShell 监控脚本
$lastState = (Get-Service Sysmon64).Status
while ($true) {
Start-Sleep -Seconds 30
$currentState = (Get-Service Sysmon64).Status
if ($currentState -ne $lastState) {
Write-Warning "Sysmon service state changed: $lastState -> $currentState"
# 发送告警
$lastState = $currentState
}
}

9.3 加固 Sysmon

使用 -d 参数自定义驱动名称(避免被简单搜索发现)

1
2
# 自定义驱动名称安装
Sysmon64.exe -i sysmonconfig.xml -d MyCustomDriver

使用 ACL 保护 Sysmon 配置文件和服务

将 Sysmon 日志实时转发到 SIEM,即使本地被清除也有副本


参考链接

Sysmon 官方文档

SwiftOnSecurity/sysmon-config

olafhartong/sysmon-modular

TrustedSec Sysmon Community Guide

Sysmon - DFIR (SANS)

关联页面:03-事件日志分析 | 21-WMI事件订阅后门 | 33-事件日志分析工具


上一章 目录 下一章
31-Sysinternals套件 Windows应急响应 33-事件日志分析工具