收集 Microsoft SQL Server 日志

支持的平台:

本文档介绍了如何使用 Bindplane 将 Microsoft SQL Server 日志注入到 Google Security Operations。该解析器可处理结构化(JSON、键值对)和半结构化 (syslog) Microsoft SQL Server 日志。它会提取字段、对时间戳进行标准化处理、根据 SourceModuleTypeMessage 内容(包括审核、登录和数据库事件)处理不同的日志格式,并将它们映射到 UDM。它还针对审核记录、登录尝试和数据库操作执行特定的解析逻辑,通过添加更多上下文和严重程度信息来丰富数据。它使用 syslog 转发器 (NXLog) 从 Windows 事件日志中收集 SQL Server 审核日志和错误日志,并将这些日志发送到 BindPlane 代理,以便将它们传递给 Google SecOps。

准备工作

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

  • Google SecOps 实例
  • 运行 Microsoft SQL Server 的 Windows Server 2016 或更高版本的主机
  • 拥有管理员访问权限,可安装和配置 BindPlane 代理和 NXLog
  • 如果通过代理运行,请确保防火墙端口已根据 Bindplane 代理要求打开

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

  1. 登录 Google SecOps 控制台。
  2. 依次前往 SIEM 设置 > 收集代理
  3. 下载注入身份验证文件。将该文件安全地保存在将要安装 Bindplane 的系统上。

获取 Google SecOps 客户 ID

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

安装 Bindplane 代理

按照以下说明在 Windows 或 Linux 操作系统上安装 Bindplane 代理。

Windows 安装

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

    msiexec /i "https://github.com/observIQ/bindplane-agent/releases/latest/download/observiq-otel-collector.msi" /quiet
    

其他安装资源

如需了解其他安装选项,请参阅安装指南

配置 Bindplane 代理以注入 Syslog 并将其发送到 Google SecOps

  1. 访问配置文件:
    • 找到 config.yaml 文件。在 Windows 上,该文件通常位于 `C:\Program Files\observIQ\bindplane-agent` 目录中。
    • 使用文本编辑器(例如 nanovi 或记事本)打开该文件。
  2. 按如下方式修改 config.yaml 文件:

      receivers:
      udplog:
         # Replace the port and IP address as required
         listen_address: "0.0.0.0:1514"
    
      exporters:
      chronicle/chronicle_w_labels:
         compression: gzip
         # Adjust the path to the credentials file you downloaded in Step 1
         creds_file_path: '/path/to/ingestion-authentication-file.json'
         # Replace with your actual customer ID from Step 2
         customer_id: <YOUR_CUSTOMER_ID>
         endpoint: malachiteingestion-pa.googleapis.com
         # Add optional ingestion labels for better organization
         log_type: 'MICROSOFT_SQL'
         raw_log_field: body
         ingestion_labels:
    
      service:
      pipelines:
         logs/source0__chronicle_w_labels-0:
            receivers:
            - udplog
            exporters:
            - chronicle/chronicle_w_labels
    
    • 根据基础架构的需要替换端口和 IP 地址。
    • <customer_id> 替换为实际的客户 ID。
    • /path/to/ingestion-authentication-file.json 更新为获取 Google SecOps 提取身份验证文件部分中保存身份验证文件的路径。

重启 Bindplane 代理以应用更改

  • 如需在 Windows 中重启 Bindplane 代理,您可以使用服务控制台,也可以输入以下命令:

    net stop BindPlaneAgent && net start BindPlaneAgent
    

在 Windows 事件日志中启用 SQL Server 审核

您可以使用 SQL Server Management Studio (SSMS) GUI 或 T-SQL 命令来启用 SQL Server 审核。请选择最适合您环境的选项。

选项 1:通过 SSMS GUI 启用 SQL Server 审核

在 SQL Server Management Studio 界面中创建服务器审核

  1. 打开 SQL Server Management Studio (SSMS) 并连接到 SQL Server 实例。
  2. 对象资源管理器中,展开服务器实例。
  3. 展开安全文件夹。
  4. 右键点击审核,然后选择新建审核
  5. 创建审核对话框中,提供以下配置详细信息:
    • 审核名称:输入 ChronicleAudit
    • 队列延迟时间(以毫秒为单位):输入 1000
    • 审核日志失败时:选择继续
    • 审核目标位置:选择应用日志
  6. 点击确定以创建审核。
  7. 对象资源管理器中,右键点击新创建的 ChronicleAudit,然后选择启用审核

通过 SSMS GUI 创建服务器审核规范

  1. Object Explorer 中,展开 Security
  2. 右键点击服务器审核规范,然后选择新建服务器审核规范
  3. 创建服务器审核规范对话框中,提供以下配置详细信息:
    • 名称:输入 ChronicleAuditSpec
    • 审核:从菜单中选择 ChronicleAudit
  4. 审核操作类型部分,点击添加,然后选择以下审核操作组(选择每个组后,点击添加,逐个添加):
    • FAILED_LOGIN_GROUP
    • SUCCESSFUL_LOGIN_GROUP
    • LOGOUT_GROUP
    • SERVER_ROLE_MEMBER_CHANGE_GROUP
    • DATABASE_OBJECT_CHANGE_GROUP
    • DATABASE_PRINCIPAL_CHANGE_GROUP
    • SCHEMA_OBJECT_CHANGE_GROUP
    • DATABASE_PERMISSION_CHANGE_GROUP
  5. 点击确定以创建审核规范。
  6. 对象资源管理器中,右键点击新创建的 ChronicleAuditSpec,然后选择启用服务器审核规范

验证审核配置

  1. 对象资源管理器中,依次展开安全性 > 审核
  2. 右键点击 ChronicleAudit,然后选择属性
  3. 验证状态是否显示为已启动已启用
  4. 依次展开安全性> 服务器审核规范
  5. 右键点击 ChronicleAuditSpec,然后选择属性
  6. 验证是否列出了所有八个审核操作组,并且规范已启用。

方法 2:使用 T-SQL 启用 SQL Server 审核

  1. 打开 SQL Server Management Studio (SSMS) 并连接到 SQL Server 实例。
  2. 执行以下 T-SQL 命令,以创建写入 Windows 应用日志的服务器审核:

    USE master;
    GO
    
    CREATE SERVER AUDIT ChronicleAudit
    TO APPLICATION_LOG
    WITH (QUEUE_DELAY = 1000, ON_FAILURE = CONTINUE);
    GO
    
    ALTER SERVER AUDIT ChronicleAudit WITH (STATE = ON);
    GO
    
  3. 创建审核规范以捕获相关的安全事件:

    CREATE SERVER AUDIT SPECIFICATION ChronicleAuditSpec
    FOR SERVER AUDIT ChronicleAudit
    ADD (FAILED_LOGIN_GROUP),
    ADD (SUCCESSFUL_LOGIN_GROUP),
    ADD (LOGOUT_GROUP),
    ADD (SERVER_ROLE_MEMBER_CHANGE_GROUP),
    ADD (DATABASE_OBJECT_CHANGE_GROUP),
    ADD (DATABASE_PRINCIPAL_CHANGE_GROUP),
    ADD (SCHEMA_OBJECT_CHANGE_GROUP),
    ADD (DATABASE_PERMISSION_CHANGE_GROUP);
    GO
    
    ALTER SERVER AUDIT SPECIFICATION ChronicleAuditSpec WITH (STATE = ON);
    GO
    

此配置可确保将身份验证事件、权限更改和对象修改记录到 Windows 事件日志中。

安装并配置 NXLog 以将事件转发到 Bindplane

  1. nxlog.co/downloads 下载 NXLog 社区版
  2. 运行安装程序并完成安装向导。
  3. 打开位于以下位置的 NXLog 配置文件:

    C:\Program Files\nxlog\conf\nxlog.conf
    
  4. 将内容替换为以下配置:

    define ROOT C:\Program Files\nxlog
    Moduledir %ROOT%\modules
    CacheDir %ROOT%\data
    Pidfile %ROOT%\data\nxlog.pid
    SpoolDir %ROOT%\data
    LogFile %ROOT%\data\nxlog.log
    
    <Extension _json>
       Module      xm_json
    </Extension>
    
    <Input in_eventlog>
       Module      im_msvistalog
       Query       <QueryList>\
                      <Query Id="0">\
                            <Select Path="Application">*[System[Provider[@Name='MSSQLSERVER']]]</Select>\
                      </Query>\
                   </QueryList>
    </Input>
    
    <Output out_syslog>
       Module      om_udp
       Host        127.0.0.1
       Port        1514
       Exec        to_json();
    </Output>
    
    <Route r1>
       Path        in_eventlog => out_syslog
    </Route>
    
    • 主机的当前值 127.0.0.1 替换为 Bindplane 代理的 IP 地址。
    • 确保 Port 值与之前配置的 Bindplane udplog 接收器端口一致。
  5. 保存文件并重启 NXLog 服务:

    net stop nxlog && net start nxlog
    

UDM 映射表

日志字段 UDM 映射 逻辑
AccountName principal.user.userid 如果日志中存在“Starting up database”或“Log was backed up”等信息,则用于 principal.user.userid
AgentDevice additional.fields 以键值对的形式添加到 additional.fields,键为“AgentDevice”。
AgentLogFile additional.fields 以键值对的形式添加到 additional.fields,键为“AgentLogFile”。
agent.hostname observer.asset.hostname 映射到观测者主机名。
agent.id observer.asset_id agent.type 串联以形成 observer.asset_id
agent.type observer.asset_id agent.id 串联以形成 observer.asset_id
agent.version observer.platform_version 映射到观测器平台版本。
ApplicationName principal.application 映射到主应用。
application_name target.application 映射到目标应用。
client_address principal.ip 如果与主机不同且不是本地或命名管道,则用于主账号 IP。
client_ip principal.ip 映射到主账号 IP。
computer_name about.hostname 映射到有关主机名。
correlationId security_result.detection_fields 以键值对的形式添加到 security_result.detection_fields,键为“correlationId”。
Date metadata.event_timestamp Time 结合使用以创建活动时间戳。
database_name target.resource_ancestors.name 如果审核日志中存在,则用于目标资源祖先名称。
durationMs network.session_duration.seconds 从毫秒转换为秒并进行映射。
ecs.version metadata.product_version 映射到产品版本。
error security_result.detection_fields 以键值对的形式添加到 security_result.detection_fields 中,键为“error”。
err_msg security_result.description 映射到安全结果说明。
EventID metadata.product_event_type 用于在其他字段不可用时构建商品事件类型,以“EventID: ”为前缀。
event.action Source 如果存在,则用作来源。
event.code metadata.product_event_type event.provider 结合形成 metadata.product_event_type
event.provider metadata.product_event_type event.code 结合形成 metadata.product_event_type
EventReceivedTime metadata.ingested_timestamp 解析并用作提取时间戳。
event_time metadata.event_timestamp 已解析并用作事件时间戳。
file_name principal.process.file.full_path 映射到主进程文件完整路径。
file_path target.file.full_path 如果备份日志中找到了目标文件的完整路径,则使用该路径。
first_lsn target.resource.attribute.labels 以键值对的形式添加到 target.resource.attribute.labels 中,键为“First LSN”。
host principal.hostnameobserver.hostname 用于主账号或观测器主机名(如果不是 IP)。还用于目标主机名或 IP(具体取决于是否为 IP)。
host.ip principal.ip 已合并到主 IP 地址。
host.name host 用作主机(如果存在)。
Hostname principal.hostnametarget.hostname 用于主账号或目标主机名(如果存在)。
hostinfo.architecture principal.asset.hardware.cpu_platform 映射到主要资产硬件 CPU 平台。
hostinfo.os.build additional.fields 以键值对的形式添加到 additional.fields 中,键为“os_build”。
hostinfo.os.kernel principal.platform_patch_level 映射到主平台补丁级别。
hostinfo.os.name additional.fields 以键值对的形式添加到 additional.fields 中,键为“os_name”。
hostinfo.os.platform principal.platform 采用大写形式,并映射到主要平台。
hostinfo.os.version principal.platform_version 映射到主要平台版本。
last_lsn target.resource.attribute.labels 以键值对的形式添加到 target.resource.attribute.labels 中,键为“Last LSN”。
level security_result.severity 如果为“Informational”,则将 security_result.severity 设置为“INFORMATIONAL”。
log.level security_result.severity_details 映射到安全结果严重程度详细信息。
LoginName principal.user.userid 如果 KV 日志中存在,则用于主用户 ID。
login_result security_result.action 确定安全结果操作(允许或屏蔽)。
logon_user principal.user.userid 用于登录日志中存在的主用户 ID。
logstash.process.host intermediary.hostname 映射到中间主机名。
Message metadata.descriptionsecurity_result.description 用于事件说明或安全结果说明,具体取决于日志类型。
msg metadata.description 用于活动说明(如果有)。
ObjectName target.resource.name 映射到目标资源名称。
object_name target.resource.name 用于审核日志中存在的目标资源名称。
ObjectType target.resource.type 映射到目标资源类型。
operationId security_result.detection_fields 以键值对的形式添加到 security_result.detection_fields 中,键为“operationId”。
operationName metadata.product_event_type 映射到产品事件类型。
operationVersion additional.fields 以键值对的形式添加到 additional.fields 中,键为“operationVersion”。
ProcessInfo additional.fields 以键值对的形式添加到 additional.fields,键为“ProcessInfo”。
properties.apiVersion metadata.product_version 映射到产品版本。
properties.appId target.resource.product_object_id 映射到目标资源商品对象 ID。
properties.clientAuthMethod extensions.auth.auth_details 用于确定身份验证详细信息。
properties.clientRequestId additional.fields 以键值对的形式添加到 additional.fields 中,键为“clientRequestId”。
properties.durationMs network.session_duration.seconds 转换为秒并进行映射。
properties.identityProvider security_result.detection_fields 以键值对的形式添加到 security_result.detection_fields 中,键为“identityProvider”。
properties.ipAddress principal.ipprincipal.asset.ip 已解析为 IP,并合并到主要 IP 和主要资产 IP 中。
properties.location principal.location.name 映射到主要位置名称。
properties.operationId security_result.detection_fields 以键值对的形式添加到 security_result.detection_fields 中,键为“operationId”。
properties.requestId metadata.product_log_id 映射到产品日志 ID。
properties.requestMethod network.http.method 映射到网络 HTTP 方法。
properties.requestUri target.url 映射到目标网址。
properties.responseSizeBytes network.received_bytes 转换为无符号整数并进行映射。
properties.responseStatusCode network.http.response_code 转换为整数并进行映射。
properties.roles additional.fields 以键值对的形式添加到 additional.fields 中,键为“roles”。
properties.servicePrincipalId principal.user.userid 如果不存在 properties.userId,则用于主用户 ID。
properties.signInActivityId network.session_id 映射到网络会话 ID。
properties.tenantId metadata.product_deployment_id 映射到商品部署 ID。
properties.tokenIssuedAt additional.fields 以键值对的形式添加到 additional.fields,键为“tokenIssuedAt”。
properties.userAgent network.http.user_agent 映射到网络 HTTP 用户代理。
properties.userId principal.user.userid 用于主用户 ID(如果存在)。
properties.wids security_result.detection_fields 以键值对的形式添加到 security_result.detection_fields 中,键为“wids”。
reason security_result.summary 用于登录事件中的安全结果摘要。
resourceId target.resource.attribute.labels 以键值对的形式添加到 target.resource.attribute.labels,键为“资源 ID”。
schema_name target.resource_ancestors.resource_subtype 如果审核日志中存在,则用于目标资源祖先子类型。
security_result.description metadata.description 用于事件说明(如果不是审核事件)。
security_result.severity security_result.severity 如果存在,则直接映射。对于 KV 日志,设置为“LOW”;对于某些错误消息,设置为“INFORMATIONAL”;从 levelSeverity 字段派生而来。
security_result.severity_details security_result.severity_details 如果存在,则直接映射。
security_result.summary security_result.summary 如果存在,则直接映射。设置为“使用 Windows 身份验证建立的连接”或登录事件中的特定原因,对于审核事件,则设置为“SQL Server 审核记录”。
security_result_action security_result.action 已合并到 security_result.action。对于大多数事件,设置为“ALLOW”;对于登录事件,则派生自 login_result
server_instance_name target.hostname 用于审核日志中存在的目标主机名。
server_principal_name principal.user.userid 用于主账号用户 ID(如果审核日志中存在)。
server_principal_sid principal.asset_id 用于构建主素材资源 ID,以“服务器 SID:”为前缀。
session_id network.session_id 用于审核日志中存在的网络会话 ID。
sev security_result.severity 用于确定安全性结果的严重程度。
Severity security_result.severity 用于确定安全性结果的严重程度。
Source additional.fields 以键值对的形式添加到 additional.fields 中,键为“Source”。
source principal.resource.attribute.labels 以键值对的形式添加到 principal.resource.attribute.labels 中,键为“source”。
SourceModuleType observer.application 映射到观测器应用。
SourceModuleName additional.fields 以键值对的形式添加到 additional.fields 中,键为“SourceModuleName”。
source_module_name observer.labels 以键值对的形式添加到 observer.labels 中,键为“SourceModuleName”。
source_module_type observer.application 映射到观测器应用。
SPID network.session_id 映射到网络会话 ID。
statement target.process.command_line 用于审核日志中存在的目标进程命令行。
TextData security_result.descriptionmetadata.description 用于安全结果说明(如果不是登录事件)或事件说明(如果是登录事件)。
time metadata.event_timestamp 已解析并用作事件时间戳。
Time metadata.event_timestamp Date 结合使用以创建活动时间戳。
transaction_id target.resource.attribute.labels 以键值对的形式添加到 target.resource.attribute.labels,键为“transaction_id”。
UserID principal.user.windows_sid 用于主用户的 Windows SID(如果存在且格式正确)。
user_id principal.user.userid 用于主用户 ID(如果存在)。
metadata.log_type metadata.log_type 硬编码为“MICROSOFT_SQL”。
metadata.vendor_name metadata.vendor_name 硬编码为“Microsoft”。
metadata.product_name metadata.product_name 硬编码为“SQL Server”。
metadata.event_type metadata.event_type 根据日志内容设置为各种值,包括“USER_LOGIN”“USER_LOGOUT”“STATUS_STARTUP”“STATUS_SHUTDOWN”“NETWORK_HTTP”“GENERIC_EVENT”和默认值“STATUS_UNCATEGORIZED”。
extensions.auth.type extensions.auth.type 对于登录和退出登录事件,请设置为“MACHINE”。

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