Detecting fileless attacks on endpoints

From killvxk/cybersecurity-skills-zh · View interactive version

Detecting fileless attacks on endpoints is an AI agent skill from the GitHub repository killvxk/cybersecurity-skills-zh. 检测完全在内存(RAM)中执行、不向磁盘写入持久文件的无文件恶意软件和内存攻击, 规避传统杀毒软件。适用于为 PowerShell 攻击、反射式 DLL 注入、WMI 持久化和注册表驻留恶意软件 构建检测规则的场景。

How to use this skill

Skill file

检测端点上的无文件攻击

使用场景

在以下情况下使用本技能:

不适用于检测基于文件的恶意软件或进行恶意软件逆向工程。

前置条件

操作流程

步骤 1:启用所需遥测

# 启用 PowerShell 脚本块日志记录(GPO 或注册表)
New-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging" `
  -Name EnableScriptBlockLogging -Value 1 -PropertyType DWORD -Force

# 启用 PowerShell 模块日志记录
New-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\ModuleLogging" `
  -Name EnableModuleLogging -Value 1 -PropertyType DWORD -Force

# 启用 PowerShell 转录
New-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\Transcription" `
  -Name EnableTranscripting -Value 1 -PropertyType DWORD -Force

# 用于无文件检测的 Sysmon 配置(关键事件):
# 事件 ID 1:进程创建(捕获 CommandLine)
# 事件 ID 7:镜像加载(DLL 加载)
# 事件 ID 8:CreateRemoteThread(注入)
# 事件 ID 10:进程访问(LSASS 访问)
# 事件 ID 19/20/21:WMI 事件

步骤 2:检测基于 PowerShell 的攻击

# 恶意 PowerShell 的指标:

# 编码命令执行
EventID: 1
CommandLine 包含:"powershell" 且 ("-enc" 或 "-e " 或 "-encodedcommand" 或 "FromBase64String")

# 下载摇篮(Download Cradle)模式
CommandLine 包含:"IEX" 且 ("Net.WebClient" 或 "DownloadString" 或 "Invoke-WebRequest")
CommandLine 包含:"Invoke-Expression" 且 "New-Object"

# AMSI 绕过尝试(事件 ID 4104 - 脚本块)
ScriptBlock 包含:"AmsiUtils" 或 "amsiInitFailed" 或 "SetValue.*amsi"

# 可疑 PowerShell 的 Splunk 查询:
index=windows source="WinEventLog:Microsoft-Windows-PowerShell/Operational" EventCode=4104
| where match(ScriptBlockText, "(?i)(iex|invoke-expression|downloadstring|net\.webclient|frombase64|bypass|amsiutils)")
| table _time host ScriptBlockText

步骤 3:检测进程注入技术

# 反射式 DLL 注入 - 从内存加载 DLL 而不接触磁盘
# 检测:Sysmon 事件 7(ImageLoaded)其中镜像路径异常
EventID: 7
ImageLoaded 不以 "C:\Windows\" 开头 且不以 "C:\Program Files" 开头

# 进程空洞 - 创建挂起状态的进程,替换内存
# 检测:进程创建后紧接着内存写入
EventID: 1 + 10 关联
# 进程被创建然后以 PROCESS_VM_WRITE 访问

# APC 注入 - 将代码排队到线程的异步过程调用队列
# 检测:来自非系统进程的 Sysmon CreateRemoteThread
EventID: 8
SourceImage 不在 (已知合法来源) 中

# MDE KQL:
DeviceEvents
| where ActionType in ("CreateRemoteThreadApiCall", "NtAllocateVirtualMemoryApiCall")
| where InitiatingProcessFileName !in ("MsMpEng.exe", "svchost.exe")
| project Timestamp, DeviceName, ActionType, InitiatingProcessFileName,
    InitiatingProcessCommandLine, FileName

步骤 4:检测基于 WMI 的持久化

# WMI 事件的 Sysmon 事件 ID 19/20/21
EventID: 19  # 检测到 WmiEventFilter 活动
EventID: 20  # 检测到 WmiEventConsumer 活动
EventID: 21  # 检测到 WmiEventConsumerToFilter 活动

# 除非预期,否则任何 WMI 事件订阅创建都是可疑的
# 常见恶意 WMI 持久化:
Consumer 包含:"CommandLineEventConsumer" 或 "ActiveScriptEventConsumer"

# 通过 osquery 或 PowerShell 查询 WMI 订阅:
Get-WMIObject -Namespace root\Subscription -Class __EventFilter
Get-WMIObject -Namespace root\Subscription -Class __EventConsumer
Get-WMIObject -Namespace root\Subscription -Class __FilterToConsumerBinding

步骤 5:检测基于注册表的执行

# 存储在注册表值中并通过 PowerShell 执行的恶意软件
# Sysmon 事件 13 - 设置了含编码内容的注册表值
EventID: 13
TargetObject 包含:"CurrentVersion\Run"
Details:异常长的值或 Base64 编码内容

# 检测查询:
index=sysmon EventCode=13
| where match(Details, "[A-Za-z0-9+/=]{100,}")
| table _time host TargetObject Details Image

关键概念

| 术语 | 定义 |

|------|------|

| 无文件恶意软件 | 完全在内存中运行、不向磁盘写入可执行文件的恶意软件 |

| AMSI | 反恶意软件扫描接口(Antimalware Scan Interface),允许安全产品在执行前检查脚本内容的 Windows API |

| 反射式 DLL 注入 | 从内存而非磁盘加载 DLL,避免基于文件的检测 |

| 进程空洞(Process Hollowing) | 创建合法进程的挂起状态,并用恶意代码替换其内存 |

| 脚本块日志记录 | 捕获反混淆脚本内容的 PowerShell 日志功能(事件 ID 4104) |

工具与系统

常见误区

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.