收集 Area 1 記錄

支援的國家/地區:

本文說明如何使用 AWS S3,將 Area 1 Email Security (由 Cloudflare 提供) 記錄檔擷取至 Google Security Operations。剖析器會處理 JSON 格式的記錄。這項功能會從巢狀 JSON 結構中擷取相關欄位,將這些欄位對應至統一資料模型 (UDM),並使用地理資訊和安全性詳細資料 (例如附件雜湊和處置) 擴充資料。

事前準備

請確認您已完成下列事前準備事項:

  • Google SecOps 執行個體
  • Windows 2016 以上版本,或搭載 systemd 的 Linux 主機
  • 如果透過 Proxy 執行,防火牆通訊埠已開啟
  • Area 1 Email Security (由 Cloudflare 提供) 的特殊存取權

設定 AWS IAM 和 S3 值區

  1. 按照這份使用者指南建立 Amazon S3 值區建立值區
  2. 登入 AWS Console
  3. 依序前往「S3」>「建立 bucket」
  4. 輸入 bucket 的名稱 (例如 area1-security-logs)。
  5. 保留其他預設值 (或視需要設定加密和版本控管)。
  6. 點選「建立」
  7. 儲存 bucket 的「Name」(名稱) 和「Region」(區域),以供日後參考。
  8. 請按照這份使用者指南建立使用者建立 IAM 使用者
  9. 選取建立的「使用者」
  10. 選取「安全憑證」分頁標籤。
  11. 在「Access Keys」部分中,按一下「Create Access Key」
  12. 選取「第三方服務」做為「用途」
  13. 點選「下一步」
  14. 選用:新增說明標記。
  15. 按一下「建立存取金鑰」
  16. 按一下「下載 CSV 檔案」,然後儲存「存取金鑰」和「存取金鑰密碼」,以供日後參考。
  17. 按一下 [完成]
  18. 選取 [權限] 分頁標籤。
  19. 在「權限政策」中,按一下「新增權限」
  20. 選取「直接附加政策」
  21. 搜尋「AmazonS3FullAccess」AmazonS3FullAccess政策。
  22. 選取政策。
  23. 點選「下一步」
  24. 按一下「新增權限」

取得 Area 1 API 憑證

  1. 登入 Area 1 Security (Cloudflare) 資訊主頁。
  2. 依序前往「設定」>「API 存取權」
  3. 產生 API 金鑰 (權杖)。
  4. 複製儲存權杖,存放在安全的地方。

設定必要的 Python 套件

  1. 登入記錄收集主機 (例如 AWS VM),然後執行下列指令來設定 AWS 憑證:

    pip install boto3 requests
    aws configure
    

建立 Area 1 Log Puller 指令碼

  1. 輸入 sudo vi area1_to_s3.py 建立下列檔案,然後複製下列程式碼:

    • 調整下列項目:
    #!/usr/bin/env python3
    import os
    import requests
    import boto3
    import datetime
    import json
    
    # Configuration
    AREA1_API_TOKEN = os.environ.get("AREA1_API_TOKEN")  # Load securely from env
    AWS_PROFILE = os.environ.get("AWS_PROFILE", None)    # Optional, for named profiles
    S3_BUCKET_NAME = "area1-security-logs"
    LOG_TYPE = "events"
    
    # Time range
    end_time = datetime.datetime.utcnow()
    start_time = end_time - datetime.timedelta(days=1)
    
    def fetch_area1_logs():
        url = f"https://api.area1security.com/v1/{LOG_TYPE}"
        headers = {
            "Authorization": f"Bearer {AREA1_API_TOKEN}",
            "Accept": "application/json"
        }
        params = {
            "startDate": start_time.strftime("%Y-%m-%dT%H:%M:%SZ"),
            "endDate": end_time.strftime("%Y-%m-%dT%H:%M:%SZ")
        }
        response = requests.get(url, headers=headers, params=params)
        response.raise_for_status()
        return response.json()
    
    def upload_to_s3(data):
        filename = f"area1_{LOG_TYPE}_{start_time.strftime('%Y%m%d')}.json"
    
        session = boto3.Session(profile_name=AWS_PROFILE) if AWS_PROFILE else boto3.Session()
        s3 = session.client("s3")
    
        s3.put_object(
            Bucket=S3_BUCKET_NAME,
            Key=f"logs/{filename}",
            Body=json.dumps(data).encode("utf-8"),
            ContentType="application/json"
        )
        print(f"[✓] Uploaded {filename} to s3://{S3_BUCKET_NAME}/logs/")
    
    if __name__ == "__main__":
        logs = fetch_area1_logs()
        upload_to_s3(logs)
    
  2. 儲存並結束 vi:依序點選 esc:wq

儲存環境變數

  1. 建立安全檔案,在 /etc/area1.env (或 /home/user/.area1.env) 中儲存環境變數

    export AREA1_API_TOKEN="your_actual_area1_api_token"
    export AWS_PROFILE="<your_aws_programmatic_username>"
    
  2. 確保檔案安全無虞:

    chmod 600 /etc/area1.env
    

執行及測試指令碼

  1. 執行下列指令碼:

    python3 area1_to_s3.py
    
  2. 畫面上會顯示下列訊息:

    Uploaded area1_events_20250701.json to s3://area1-security-logs/logs/
    

使用 Cron 自動執行作業

  1. 執行 sudo vi /usr/local/bin/run_area1.sh 建立 Cron 的包裝函式指令碼,然後複製下列程式碼:

    #!/usr/bin/env bash
    set -euo pipefail
    
    source /etc/area1.env
    /usr/bin/python3 /opt/scripts/area1_to_s3.py
    
  2. 將檔案設為可執行檔:

    chmod +x /usr/local/bin/run_area1.sh
    
  3. 設為每天在世界標準時間 01:00 執行:

    crontab -e
    0 1 * * * /usr/local/bin/run_area1.sh >> /var/log/area1_to_s3.log 2>&1
    

設定動態饋給

在 Google SecOps 平台中,有兩種不同的進入點可設定動態饋給:

  • 「SIEM 設定」>「動態消息」
  • 內容中心 > 內容包

依序前往「SIEM 設定」>「動態消息」,設定動態消息

如要設定動態消息,請按照下列步驟操作:

  1. 依序前往「SIEM 設定」>「動態饋給」
  2. 按一下「新增動態消息」
  3. 在下一個頁面中,按一下「設定單一動態饋給」
  4. 在「動態饋給名稱」欄位中輸入動態饋給名稱 (例如 Area1 Logs)。
  5. 選取「Amazon S3」做為「來源類型」
  6. 選取「Area1 Security」做為「記錄類型」
  7. 點選「下一步」
  8. 指定下列輸入參數的值:

    • 區域:Amazon S3 值區所在的區域。
    • S3 URI:值區 URI (格式應為 s3://<your-log-bucket-name>)。 取代下列項目:
      • your-log-bucket-name:值區名稱。
    • URI 是:選取「包含子目錄的目錄」
    • 來源刪除選項:根據偏好設定選取刪除選項。
    • 存取金鑰 ID:具有 S3 bucket 存取權的使用者存取金鑰。
    • 存取密鑰:具有 S3 bucket 存取權的使用者私密金鑰。
  9. 點選「下一步」

  10. 在「Finalize」畫面上檢查新的動態饋給設定,然後按一下「Submit」

從內容中心設定動態饋給

為下列欄位指定值:

  • 區域:Amazon S3 值區所在的區域。

    • S3 URI:值區 URI (格式應為 s3://<your-log-bucket-name>)。 取代下列項目:
      • your-log-bucket-name:值區名稱。
    • URI 是:選取「包含子目錄的目錄」
    • 來源刪除選項:根據偏好設定選取刪除選項。
    • 存取金鑰 ID:具有 S3 bucket 存取權的使用者存取金鑰。
    • 存取密鑰:具有 S3 bucket 存取權的使用者私密金鑰。§

進階選項

  • 動態饋給名稱:系統預先填入的值,用於識別動態饋給。
  • 來源類型:將記錄收集到 Google SecOps 的方法。
  • 資產命名空間:與動態饋給相關聯的命名空間。
  • 擷取標籤:套用至這個動態饋給所有事件的標籤。

UDM 對應表

記錄欄位 UDM 對應 邏輯
alert_id security_result.rule_id 這個值取自 alert_id 欄位。
alert_reasons security_result.description 這個值取自 alert_reasons 欄位。
attachments.att_size security_result.about.file.size 這個值取自 attachments.att_size 欄位,並轉換為無正負號整數。
attachments.disposition security_result.about.user.attribute.labels.value 這個值取自 attachments.disposition 欄位。
attachments.extension security_result.about.file.mime_type 這個值取自 attachments.extension 欄位。
attachments.md5 security_result.about.file.md5 這個值取自 attachments.md5 欄位。
attachments.name security_result.about.file.full_path 這個值取自 attachments.name 欄位。
attachments.sha1 security_result.about.file.sha1 這個值取自 attachments.sha1 欄位。
attachments.sha256 security_result.about.file.sha256 這個值取自 attachments.sha256 欄位。
attachments.ssdeep security_result.about.file.ssdeep 這個值取自 attachments.ssdeep 欄位。
delivery_mode security_result.detection_fields.value 這個值取自 delivery_mode 欄位。
envelope_from principal.user.email_addresses、network.email.from 這個值取自 envelope_from 欄位。
envelope_to network.email.to、target.user.email_addresses 這個值取自 envelope_to 欄位。
final_disposition security_result.category_details 這個值取自 final_disposition 欄位。
message_id metadata.product_log_id 系統會從 message_id 欄位中擷取值,並移除「<」和「>」字元。
replyto network.email.bounce_address 這個值取自 replyto 欄位。
smtp_helo_server_ip principal.ip 這個值取自 smtp_helo_server_ip 欄位。
smtp_helo_server_ip_as_name principal.location.name 這個值取自 smtp_helo_server_ip_as_name 欄位。
smtp_helo_server_ip_as_number principal.asset_id 這個值取自 smtp_helo_server_ip_as_number 欄位,並在前面加上 asset_id:
smtp_helo_server_ip_geo principal.location.country_or_region、principal.location.state、principal.location.city 系統會使用 Grok 模式從 smtp_helo_server_ip_geo 欄位擷取值。
smtp_helo_server_name principal.administrative_domain 這個值取自 smtp_helo_server_name 欄位。
來源 metadata.vendor_name 這個值取自 source 欄位。如果欄位空白,系統會將值設為 area1security
主旨 network.email.subject 這個值取自 subject 欄位。
時間 metadata.event_timestamp 這個值取自 time 欄位,並會轉換為時間戳記。
metadata.event_type 值會設為 EMAIL_TRANSACTION
metadata.product_name 值會設為 AREA1
metadata.log_type 值會設為 AREA1
security_result.about.user.attribute.labels.key 值會設為 disposition
security_result.category 值會設為 SOFTWARE_MALICIOUS
security_result.detection_fields.key 值會設為 delivery_mode

還有其他問題嗎?向社群成員和 Google SecOps 專業人員尋求答案。