收集 Microsoft SQL Server 記錄

支援的服務:

本文說明如何使用 Bindplane,將 Microsoft SQL Server 記錄檔擷取至 Google Security Operations。剖析器可處理結構化 (JSON、鍵/值組合) 和半結構化 (syslog) Microsoft SQL Server 伺服器記錄。這個剖析器會擷取欄位、標準化時間戳記、根據 SourceModuleType 和 Message 內容 (包括稽核記錄、登入和資料庫事件) 處理不同的記錄格式,並將這些格式對應至 UDM。此外,這個剖析器也會針對稽核記錄、登入嘗試和資料庫作業執行特定剖析邏輯,並加入其他背景資訊和嚴重性資訊,豐富資料內容。它會使用 syslog 轉送站 (NXLog) 從 Windows 事件記錄收集 SQL Server 稽核和錯誤記錄,並將這些記錄傳送至 BindPlane 代理程式,以便傳送至 Google SecOps。

事前準備

請確認您符合下列必要條件:

  • Google SecOps 執行個體
  • 執行 Microsoft SQL Server 的 Windows Server 2016 以上版本主機
  • 具備管理員權限,可安裝及設定 BindPlane 代理程式和 NXLog
  • 如果是在 Proxy 後方執行,請確認防火牆通訊埠已按照 Bindplane 代理程式規定開啟

取得 Bindplane 代理程式的 Google SecOps 憑證

如要向 Google SecOps 驗證 Bindplane 代理程式,請選擇下列其中一種方法:

  • 新部署作業:使用 Chronicle API (選項 1)。
  • 舊版部署作業:繼續使用擷取驗證檔案 (選項 2),直到 Ingestion API 於 2027 年 7 月 20 日停用。
  1. 登入 Google Cloud 控制台,選取連結至 Google SecOps 執行個體的 Google Cloud 專案。
  2. 依序前往「IAM & Admin」>「Service Accounts」。
  3. 按一下「建立服務帳戶」。
  4. 提供下列設定詳細資料:
    • 「服務帳戶名稱」:輸入帳戶名稱 (例如 bindplane-ingest)。
    • 「Service account description」(服務帳戶說明):輸入說明 (例如 Bindplane agent log ingestion)。
  5. 點按「Create and continue」(建立並繼續)。
  6. 在「將專案存取權授予這個服務帳戶」部分,按一下「選取角色」,然後選取「Chronicle 編輯者」。
  7. 依序點選「繼續」和「完成」。
  8. 按一下您建立的服務帳戶,然後前往「金鑰」分頁。
  9. 依序點選「新增金鑰」>「建立新的金鑰」。
  10. 選取「JSON」,然後點選「建立」。金鑰檔案會下載到您的電腦。
  11. 將金鑰檔案儲存為 Bindplane 收集器目錄中的 ingestion-auth.json (Linux 上的 /opt/observiq-otel-collector/ingestion-auth.json 或 Windows 上的 C:\Program Files\observIQ OpenTelemetry Collector\ingestion-auth.json),或更新 config.yaml 中的 creds_file_path,使其與儲存路徑相符。
  12. 依序前往「IAM 與管理」>「設定」,然後複製「專案編號」。設定匯出工具時會用到。

方法 2:下載擷取驗證檔案 (舊版)

  1. 登入 Google SecOps 控制台。
  2. 依序前往「設定」>「資料管理」>「收集代理程式」。如果使用的是僅限 SIEM 的平台,請依序前往「Settings」>「Collection Agents」。
  3. 下載擷取驗證檔案。
  4. 將檔案安全地儲存在要安裝 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 代理程式,擷取系統記錄並傳送至 Google SecOps

  1. 存取設定檔:
    • 找出 config.yaml 檔案。在 Windows 系統中,通常位於 `C:\Program Files\observIQ\bindplane-agent` 目錄。
    • 使用文字編輯器 (例如 nano、vi 或記事本) 開啟檔案。
  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:
          protocol: https
          # Region of your instance, for example us, europe, asia-southeast1
          location: <LOCATION>
          # Project number of the Google Cloud project linked to the instance
          project: '<PROJECT_NUMBER>'
          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: chronicle.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 位址。
    • 將 <LOCATION> 替換為 Google SecOps 執行個體的區域 (例如 us、europe 或 asia-southeast1)。匯出工具會在這個值前面加上 chronicle.googleapis.com。
    • 將 <PROJECT_NUMBER> 替換為「IAM 與管理」>「設定」中的專案編號。
    • 將 <customer_id> 替換為實際的客戶 ID。
    • 將 /path/to/ingestion-authentication-file.json 更新為服務帳戶金鑰檔案 (選項 1) 的儲存路徑,如「取得 Bindplane 代理程式的 Google SecOps 憑證」一節所述。

舊版 Ingestion API 匯出工具

  • 如果使用選項 2 的擷取驗證檔案,請將 exporters 區塊替換為下列內容。將 creds_file_path 設為擷取驗證檔案的路徑。如果執行個體位於美國境外,請將 malachiteingestion-pa.googleapis.com 替換為區域端點 (例如 europe-malachiteingestion-pa.googleapis.com)。

    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:
    

重新啟動 Bindplane 代理程式,套用變更

  • 如要在 Windows 中重新啟動 Bindplane 代理程式,可以使用「Services」(服務) 控制台,或輸入下列指令:

    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 UI 中建立伺服器稽核

  1. 開啟 SQL Server Management Studio (SSMS),並連線至 SQL Server 執行個體。
  2. 在「Object Explorer」中,展開伺服器執行個體。
  3. 展開「Security」資料夾。
  4. 在「稽核」上按一下滑鼠右鍵,然後選取「新增稽核」。
  5. 在「Create Audit」(建立稽核) 對話方塊中,提供下列設定詳細資料:
    • 稽核名稱:輸入 ChronicleAudit。
    • Queue delay (in milliseconds) (佇列延遲時間 (以毫秒為單位)):輸入 1000。
    • 「On audit log failure」(稽核記錄失敗時):選取「Continue」(繼續)。
    • 稽核目的地:選取「應用程式記錄」。
  6. 按一下「OK」建立稽核。
  7. 在「Object Explorer」中,在新建的「ChronicleAudit」上按一下滑鼠右鍵,然後選取「Enable Audit」。

透過 SSMS GUI 建立伺服器稽核規格

  1. 在「Object Explorer」中,展開「Security」。
  2. 在「Server Audit Specifications」上按一下滑鼠右鍵,然後選取「New Server Audit Specification」。
  3. 在「Create Server Audit Specification」(建立伺服器稽核規格) 對話方塊中,提供下列設定詳細資料:
    • 「Name」(名稱):輸入 ChronicleAuditSpec。
    • 稽核:在選單中選取「ChronicleAudit」。
  4. 在「Audit Action Type」(稽核動作類型) 部分,按一下「Add」(新增),然後選取下列稽核動作群組 (每選取一個群組,就按一下「Add」(新增),逐一新增):
    • 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. 按一下「OK」建立稽核規格。
  6. 在「Object Explorer」中,在新建的「ChronicleAuditSpec」上按一下滑鼠右鍵,然後選取「Enable Server Audit Specification」。

驗證稽核設定

  1. 在「Object Explorer」中,依序展開「Security」>「Audits」。
  2. 在「ChronicleAudit」上按一下滑鼠右鍵,然後選取「內容」。
  3. 確認「狀態」顯示為「已啟動」或「已啟用」。
  4. 依序展開「Security」>「Server Audit Specifications」。
  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 Community Edition。
  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>
    
    • 將「Host」目前的值 127.0.0.1 替換為 Bindplane 代理程式 IP 位址。
    • 確認「Port」(通訊埠) 值與先前設定的 Bindplane udplog 接收器通訊埠相符。
  5. 儲存檔案並重新啟動 NXLog 服務:

    net stop nxlog && net start nxlog
    

UDM 對應表

記錄欄位 UDM 對應 邏輯
AccountName principal.user.userid 如果記錄中出現「正在啟動資料庫」或「記錄已備份」等內容,則用於 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 與主機不同,且不是本機或具名管道,則用於主體 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.hostname、observer.hostname 如果不是 IP,則用於主體或觀測器主機名稱。也用於目標主機名稱或 IP,具體取決於是否為 IP。
host.ip principal.ip 已合併至主要 IP。
host.name host 如果存在,則做為主機使用。
Hostname principal.hostname、target.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,則用於主體使用者 ID。
login_result security_result.action 決定安全性結果動作 (ALLOW 或 BLOCK)。
logon_user principal.user.userid 如果登入記錄中存在主體使用者 ID,則用於該 ID。
logstash.process.host intermediary.hostname 對應至中介主機名稱。
Message metadata.description、security_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.ip、principal.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,鍵為「Resource ID」。
schema_name target.resource_ancestors.resource_subtype 如果稽核記錄中存在目標資源上階子類型,則用於該子類型。
security_result.description metadata.description 如果不是稽核事件,則用於事件說明。
security_result.severity security_result.severity 如果存在,則直接對應。KV 記錄設為「LOW」,特定錯誤訊息設為「INFORMATIONAL」,並衍生自 level 或 Severity 欄位。
security_result.severity_details security_result.severity_details 如果存在,則直接對應。
security_result.summary security_result.summary 如果存在,則直接對應。設為「Connection made using Windows authentication」或登入事件的特定原因,或稽核事件的「SQL Server Audit Record」。
security_result_action security_result.action 已合併至 security_result.action。大部分事件設為「ALLOW」,登入事件則衍生自 login_result。
server_instance_name target.hostname 用於目標主機名稱 (如果稽核記錄中有)。
server_principal_name principal.user.userid 如果稽核記錄中有主體使用者 ID,則會使用這個 ID。
server_principal_sid principal.asset_id 用於建構主體資產 ID,前置字串為「server SID:」。
session_id network.session_id 如果稽核記錄中有網路工作階段 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.description、metadata.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 專業人員尋求解答。