收集 Area 1 記錄
剖析器版本:3.0
本文說明如何使用 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 值區
- 按照這份使用手冊建立 Amazon S3 bucket:建立 bucket
- 登入 AWS 控制台。
- 依序前往「S3」>「Create bucket」。
- 輸入 bucket 名稱 (例如
area1-security-logs)。 - 其他設定保留預設值 (或視需要設定加密和版本管理)。
- 點選「建立」。
- 儲存 bucket 的「名稱」和「區域」,以供日後參考。
- 按照這份使用手冊建立使用者:建立 IAM 使用者。
- 選取建立的使用者。
- 選取「安全憑證」分頁標籤。
- 在「Access Keys」部分,按一下「Create Access Key」。
- 在「用途」部分選取「第三方服務」。
- 點選「下一步」。
- 選用:新增說明標記。
- 按一下「Create access key」。
- 按一下「Download CSV file」,然後儲存「Access Key」和「Secret Access Key」,以供日後參考。
- 按一下「完成」。
- 選取 [權限] 分頁標籤。
- 在「權限政策」中,按一下「新增權限」。
- 選取「直接附加政策」。
- 搜尋 AmazonS3FullAccess 政策。
- 選取政策。
- 點選「下一步」。
- 按一下「Add permissions」。
取得 Area 1 API 憑證
- 登入 Area 1 Security (Cloudflare) 資訊主頁。
- 依序前往「設定」>「API 存取權」。
- 產生 API 金鑰 (權杖)。
- 複製並儲存權杖,妥善保管。
設定必要的 Python 套件
登入記錄收集主機 (例如 AWS VM),然後執行下列指令來設定 AWS 憑證:
pip install boto3 requests aws configure
建立 Area 1 Log Puller 指令碼
輸入
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)儲存並退出
vi:按一下esc,然後輸入:wq。
儲存環境變數
建立安全檔案,將環境變數儲存在
/etc/area1.env(或/home/user/.area1.env) 中export AREA1_API_TOKEN="your_actual_area1_api_token" export AWS_PROFILE="<your_aws_programmatic_username>"請確認檔案安全無虞:
chmod 600 /etc/area1.env
執行及測試指令碼
執行下列指令碼:
python3 area1_to_s3.py如下所示:
Uploaded area1_events_20250701.json to s3://area1-security-logs/logs/
使用 Cron 自動化
執行
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將檔案設為執行檔:
chmod +x /usr/local/bin/run_area1.sh設定為每天 01:00 (世界標準時間) 執行:
crontab -e 0 1 * * * /usr/local/bin/run_area1.sh >> /var/log/area1_to_s3.log 2>&1
設定動態饋給
在 Google SecOps 平台中,有兩個不同的進入點可以設定動態饋給:
- 「設定」>「資料管理」>「動態饋給」>「新增動態饋給」 (在僅限 SIEM 的平台上,依序點選「設定」>「動態饋給」>「新增動態饋給」)
- Content Hub > Content Packs > Get Started
依序前往「設定」>「資料管理」>「動態饋給」設定動態饋給
如要設定動態饋給,請按照下列步驟操作:
- 依序前往「設定」>「資料管理」>「動態饋給」。如果使用的是 SIEM 專用平台,請依序前往「設定」>「動態饋給」。
- 按一下「新增動態饋給」。
- 在下一頁,點按「設定單一動態饋給」。
- 在「Feed name」(動態饋給名稱) 欄位中,輸入動態饋給名稱 (例如
Area1 Logs)。 - 在「Source type」(來源類型) 部分,選取「Amazon S3」。
- 選取「Area1 Security」做為「記錄類型」。
- 點選「下一步」。
指定下列輸入參數的值:
- 區域:Amazon S3 bucket 所在的區域。
- S3 URI:bucket URI (格式應為
s3://<your-log-bucket-name>)。 請替換下列項目:your-log-bucket-name:bucket 的名稱。
- 「URI is a」(URI 為):選取「Directory which includes subdirectories」(包含子目錄的目錄)。
- 來源刪除選項:根據偏好選取刪除選項。
- 存取金鑰 ID:可存取 s3 bucket 的使用者存取金鑰。
- Secret Access Key:可存取 S3 bucket 的使用者私密金鑰。
點選「下一步」。
在「完成」畫面中檢查新的新聞動態消息設定,然後按一下「提交」。
透過內容中心設定動態饋給
為下列欄位指定值:
區域:Amazon S3 bucket 所在的區域。
- S3 URI:bucket URI (格式應為
s3://<your-log-bucket-name>)。 請替換下列項目:your-log-bucket-name:bucket 的名稱。
- 「URI is a」(URI 為):選取「Directory which includes subdirectories」(包含子目錄的目錄)。
- 來源刪除選項:根據偏好選取刪除選項。
- 存取金鑰 ID:可存取 s3 bucket 的使用者存取金鑰。
- 私密存取金鑰:可存取 S3 bucket 的使用者私密金鑰。§
- S3 URI:bucket URI (格式應為
進階選項
- 動態饋給名稱:系統預先填入的值,用於識別動態饋給。
- 來源類型:將記錄收集到 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。 |
|
envelope_to.0" instead of "replyto |
network.email.to |
從變更記錄對應 |
變更記錄
還有其他問題嗎?向社群成員和 Google SecOps 專業人員尋求解答。