收集 Microsoft PowerShell 日志

支持的平台:

本文档介绍了如何使用 Bindplane 代理将 Microsoft PowerShell 日志注入到 Google Security Operations。

Microsoft PowerShell 是 Microsoft 提供的一款任务自动化和配置管理框架,包含命令行 shell 和脚本语言。PowerShell 日志会捕获脚本执行、模块活动和命令调用,从而提供 PowerShell 操作的可见性,以便进行安全监控和取证分析。

准备工作

请确保满足以下前提条件:

  • Google SecOps 实例
  • Windows Server 2016 或更高版本
  • Windows 主机与 Google SecOps 之间的网络连接
  • 如果通过代理运行,请确保防火墙端口已根据 Bindplane 代理要求打开
  • 对 Windows 主机的管理员访问权限,用于配置 PowerShell 日志记录和安装 Bindplane 代理

配置 PowerShell 日志记录

必须先在 Windows 主机上启用 PowerShell 日志记录,然后才能收集日志。默认情况下,PowerShell 日志记录量最少。启用脚本块日志记录功能,以捕获详细的 PowerShell 活动。

使用组策略启用脚本块日志记录

  1. 以管理员身份运行 gpedit.msc,打开本地组策略编辑器
  2. 依次前往计算机配置 > 管理模板 > Windows 组件 > Windows PowerShell
  3. 双击启用 PowerShell 脚本块日志记录
  4. 选择已启用
  5. 您可以选择勾选记录脚本块调用开始 / 停止事件,以捕获每个脚本块的开始和停止事件。请注意,此选项会生成大量日志。
  6. 点击确定
  7. 以管理员身份打开命令提示符,然后运行 gpupdate /force 以立即应用该政策。

使用注册表启用脚本块日志记录

或者,您也可以通过设置以下注册表值来启用脚本块日志记录:

  1. 以管理员身份运行 regedit,打开注册表编辑器
  2. 导航到 HKLM\SOFTWARE\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging
  3. 如果该键不存在,则创建该键。
  4. 创建一个名为 EnableScriptBlockLogging 的新 DWORD(32 位)值,并将其值设置为 1
  5. 重启 PowerShell 会话以使更改生效。

PowerShell 脚本块日志记录会将事件写入 Microsoft-Windows-PowerShell/Operational 事件日志通道,事件 ID 为 4104。

可选:启用模块日志记录

模块日志记录会记录指定模块的流水线执行详情。如需为所有模块启用模块日志记录,请执行以下操作:

  1. 本地组策略编辑器中,依次前往计算机配置 > 管理模板 > Windows 组件 > Windows PowerShell
  2. 双击开启模块日志记录
  3. 选择已启用
  4. 点击模块名称旁边的显示
  5. 输入 * 可记录所有模块。
  6. 模块名称窗口中,点击确定
  7. 模块日志记录窗口中,点击确定
  8. 运行 gpupdate /force 以应用政策。

模块日志记录事件会写入 Windows PowerShell 事件日志,事件 ID 为 4103。

可选:启用转写功能

转写功能会创建所有 PowerShell 会话输入和输出的基于文本的记录。如需启用转写功能,请执行以下操作:

  1. 本地组策略编辑器中,依次前往计算机配置 > 管理模板 > Windows 组件 > Windows PowerShell
  2. 双击开启 PowerShell 转写
  3. 选择已启用
  4. (可选)指定转写输出目录。如果留空,转写内容会保存到每个用户的“文档”文件夹中。
  5. 勾选包含调用标头,以包含时间戳和元数据。
  6. 点击确定
  7. 运行 gpupdate /force 以应用政策。

转写内容会写入名称以 PowerShell_transcript 开头的文本文件。

获取 Google SecOps 注入身份验证文件

  1. 登录 Google SecOps 控制台。
  2. 依次前往 SIEM 设置 > 收集代理
  3. 点击下载以下载提取身份验证文件
  4. 将文件安全地保存在将要安装 Bindplane 代理的 Windows 主机上。

获取 Google SecOps 客户 ID

  1. 登录 Google SecOps 控制台。
  2. 依次前往 SIEM 设置 > 配置文件
  3. 复制并保存组织详细信息部分中的客户 ID

安装 Bindplane 代理

按照以下说明在 Windows 主机上安装 Bindplane 代理。

Windows 安装

  1. 以管理员身份打开命令提示符PowerShell
  2. 运行以下命令:

    msiexec /i "https://github.com/observIQ/bindplane-agent/releases/latest/download/observiq-otel-collector.msi" /quiet
    
  3. 等待安装完成。

  4. 运行以下命令,验证安装是否成功:

    sc query observiq-otel-collector
    

    该服务应显示为 RUNNING

其他安装资源

如需了解其他安装选项和问题排查信息,请参阅 Bindplane 代理安装指南

配置 Bindplane 代理以收集 PowerShell 日志

找到 Windows 配置文件

  • 按如下方式找到 Windows 配置文件:

    notepad "C:\Program Files\observIQ OpenTelemetry Collector\config.yaml"
    

修改配置文件

  • config.yaml 的全部内容替换为以下配置:

    receivers:
      windowseventlog/powershell:
        channel: Microsoft-Windows-PowerShell/Operational
        max_reads: 100
        poll_interval: 5s
        raw: true
        start_at: end
    
    processors:
      batch:
    
    exporters:
      chronicle/powershell:
        compression: gzip
        creds_file_path: 'C:\Program Files\observIQ OpenTelemetry Collector\ingestion-auth.json'
        customer_id: '<CUSTOMER_ID>'
        endpoint: malachiteingestion-pa.googleapis.com
        log_type: 'POWERSHELL'
        raw_log_field: body
        override_log_type: false
    
    service:
      pipelines:
        logs/powershell:
          receivers:
            - windowseventlog/powershell
          processors:
            - batch
          exporters:
            - chronicle/powershell
    

配置参数

替换以下占位符:

  • 接收器配置

    • channel:要从中收集数据的 Windows 事件日志渠道。对于 PowerShell 脚本块日志记录,请使用 Microsoft-Windows-PowerShell/Operational。对于模块日志记录,请使用 Windows PowerShell
    • raw:设置为 true 可将原始 Windows 事件日志 XML 发送到 Google SecOps。
    • start_at:设置为 end 可仅收集代理启动后的新事件。设置为 beginning 可收集所有现有活动。
  • 导出器配置

    • <CUSTOMER_ID>:替换为上一步中的客户 ID。
    • creds_file_path:提取身份验证文件的完整路径。将下载的身份验证文件复制到此位置。
    • endpoint:区域端点网址。使用 Google SecOps 区域的端点:

      • 美国malachiteingestion-pa.googleapis.com
      • 欧洲europe-malachiteingestion-pa.googleapis.com
      • 亚洲asia-southeast1-malachiteingestion-pa.googleapis.com
      • 如需查看完整列表,请参阅区域级端点
    • log_type:设置为 POWERSHELL 以使用 PowerShell 解析器。

保存配置文件

修改后,依次点击文件> 保存,以保存该文件。

重启 Bindplane 代理以应用更改

Windows

  • 以管理员身份使用命令提示符或 PowerShell:

    net stop observiq-otel-collector && net start observiq-otel-collector
    
  • 或者使用“服务”控制台:

    1. Win+R,输入 services.msc,然后按 Enter 键。
    2. 找到 observIQ OpenTelemetry 收集器
    3. 右键点击并选择重新启动
    4. 验证服务是否正在运行:

      sc query observiq-otel-collector
      
    5. 检查日志是否存在错误:

      type "C:\Program Files\observIQ OpenTelemetry Collector\log\collector.log"
      

验证日志注入

配置 Bindplane 代理并重启服务后,PowerShell 日志应开始流向 Google SecOps。

  1. 登录 Google SecOps 控制台。
  2. 依次前往调查 > 搜索
  3. 运行以下搜索命令,验证 PowerShell 日志是否正在被提取:

    metadata.log_type = "POWERSHELL"
    
  4. 验证事件是否显示最近的时间戳。

PowerShell 脚本块日志记录事件(事件 ID 4104)将显示已执行脚本块的详细信息,包括脚本内容、脚本块 ID 和执行上下文。

UDM 映射表

日志字段 UDM 映射 逻辑
HostId principal.resource.product_object_id 与主资源关联的商品对象的唯一标识符
System.Version metadata.product_version 生成相应事件的产品的版本
System.EventId、EventID、winlog.event_id metadata.product_event_type 产品定义的事件类型
计算机、System.Computer、计算机、winlog.computer_name principal.hostname 主实体的主机名
计算机、System.Computer、计算机、winlog.computer_name principal.asset.hostname 与正文相关联的资产的主机名
System.EventRecordID、RecordNumber、winlog.record_id metadata.product_log_id 商品日志记录系统内日志条目的唯一标识符
System.Opcode、opcode、winlog.opcode metadata.description 活动说明或其他背景信息
ProviderGuid, winlog.provider_guid metadata.product_deployment_id 商品的部署的唯一标识符
System.ProcessID、ProcessID、ExecutionProcessID、execution.process_id、winlog.process.pid principal.process.pid 主进程的进程 ID
SourceModuleName principal.resource.name 与正文关联的资源的名称
SourceModuleType principal.resource.resource_subtype 与正文关联的资源的子类型
security.user_id、UserID、winlog.user.identifier principal.user.windows_sid 主用户的 Windows 安全标识符 (SID)
metadata.event_type 事件类型(例如 USER_LOGIN、NETWORK_CONNECTION)
SourceName, winlog.provider_name metadata.product_name 生成相应事件的产品的名称
AccountName、Username、UserName、winlog.user.name principal.user.userid 主用户的用户 ID
网域,winlog.user.domain principal.administrative_domain 委托人的管理网域
Path、target_file、ScriptName、script_name、ContextInfo_Script Name、file_path target.process.file.full_path 与目标进程关联的文件的完整路径
HostName、powershell.Host Name、ContextInfo_Host Name target.hostname 目标实体的主机名
HostName、powershell.Host Name、ContextInfo_Host Name target.asset.hostname 与目标相关联的资产的主机名
主机 ID、HostID、ContextInfo_Host ID target.asset.asset_id 目标资源的唯一标识符
Nombre_de_comando, ContextInfo_Command Name, CommandName target.application 与目标相关联的应用的名称
HostApplication、ContextInfo_Host Application target.process.command_line 用于启动目标进程的命令行
ScriptBlockText target.process.command_line 用于启动目标进程的命令行
MessageSourceAddress principal.ip 主账号的 IP 地址
MessageSourceAddress principal.asset.ip 与正文相关联的资产的 IP 地址
Nombre_de_host principal.application 与正文关联的应用的名称
Version_de_host principal.platform_version 与正文关联的平台版本
Id_de_host principal.resource.id 主账号资源的唯一标识符
Application_host principal.process.file.full_path 与主进程关联的文件的完整路径
HostApplication principal.process.command_line 用于启动主进程的命令行
Usuario, admin_domain principal.user.userid 主用户的用户 ID
Usuario, admin_domain principal.administrative_domain 委托人的管理网域
CommandLine principal.process.command_line 用于启动主进程的命令行
设备,machine_id principal.asset.asset_id 主要资产的唯一标识符
机器,platform_software principal.asset.platform_software.platform 相应资产的平台类型(例如 WINDOWS、LINUX)
机器,platform_software principal.asset.platform_software.platform_version 资产上平台软件的版本
MessageSourceAddress intermediary.ip 中介实体的 IP 地址
MessageSourceAddress、Hostname intermediary.hostname 中介实体的主机名
MessageSourceAddress、Hostname intermediary.asset.hostname 与中介相关联的资产的主机名
MessageSourceAddress intermediary.port 中介使用的端口号
HostApplication target.process.command_line 用于启动目标进程的命令行
HostId target.asset.asset_id 目标资源的唯一标识符
SequenceNumber、ContextInfo_Sequence Number、Sequence Number security_result.detection_fields 其他检测信息的键值对
ProviderName principal.resource.attribute.labels 与主账号资源相关联的标签或属性
NewEngineState additional.fields 标准 UDM 架构未涵盖的其他自定义字段
PreviousEngineState additional.fields 标准 UDM 架构未涵盖的其他自定义字段
ScriptName additional.fields 标准 UDM 架构未涵盖的其他自定义字段
ManagementGroupName additional.fields 标准 UDM 架构未涵盖的其他自定义字段
来源 additional.fields 标准 UDM 架构未涵盖的其他自定义字段
RenderedDescription security_result.description 安全性结果或采取的操作的说明
TenantId additional.fields 标准 UDM 架构未涵盖的其他自定义字段
用户名 principal.user.userid 主用户的用户 ID
ActivityID security_result.detection_fields 其他检测信息的键值对
ExecutionThreadID、execution.thread_id、winlog.process.thread.id security_result.detection_fields 其他检测信息的键值对
输出 security_result.detection_fields 其他检测信息的键值对
数据 security_result.detection_fields 其他检测信息的键值对
Data_1 additional.fields 标准 UDM 架构未涵盖的其他自定义字段
data_1 security_result.detection_fields 其他检测信息的键值对
Data_2 security_result.detection_fields 其他检测信息的键值对
winlog.activity_id security_result.detection_fields 其他检测信息的键值对
winlog.api additional.fields 标准 UDM 架构未涵盖的其他自定义字段
winlog.channel principal.resource.attribute.labels 与主账号资源相关联的标签或属性
偏移值 additional.fields 标准 UDM 架构未涵盖的其他自定义字段
SeverityValue security_result.detection_fields 其他检测信息的键值对
中介 中介 与活动相关的中介实体的详细信息
security_result security_result 总体安全结果,包括操作、严重程度和检测结果
metadata.vendor_name 生成相应活动的供应商的名称
SourceName metadata.product_name 生成相应事件的产品的名称

需要更多帮助?获得社区成员和 Google SecOps 专业人士的解答。