AZ-500 LAB 49 ~60 phút Chương 12 Microsoft Sentinel

Sentinel + Azure Activity + Analytics Rule

Triển khai Microsoft Sentinel trên Log Analytics Workspace, kết nối Azure Activity connector, viết KQL truy vấn hoạt động nhạy cảm và tạo scheduled analytics rule tự động sinh incident khi phát hiện thao tác delete.

🎯 Mục Tiêu Lab

Tạo Log Analytics Workspace law-az500-secops

Enable Microsoft Sentinel trên workspace

Kết nối Azure Activity data connector

Thực hiện thao tác test trong Azure để sinh activity log

Viết và chạy KQL query trên bảng AzureActivity

Tạo scheduled analytics rule phát hiện thao tác delete và kiểm tra incident

📋 Chuẩn Bị

Yêu cầu:
  • Azure subscription với quyền Owner hoặc Microsoft Sentinel Contributor
  • Đã đăng nhập Azure CLI: az login
  • Quen thuộc với KQL cơ bản (where, project, summarize)
  • Đã hoàn thành Lab 45 — Defender for Cloud basics
Lưu ý chi phí:
  • Log Analytics: ~$2.76/GB ingested (Pay-as-you-go)
  • Sentinel: ~$2.46/GB bổ sung trên Log Analytics
  • Lab nhỏ (~1-2 GB) ≈ $5–10 tổng cộng
  • Naming: law-az500-secops, region: southeastasia

🏗️ Kịch Bản

SOC team cần xây dựng SIEM cơ bản để giám sát hoạt động Azure. Nhiệm vụ của bạn là triển khai Microsoft Sentinel, thu thập Azure Activity log, và tạo analytics rule tự động phát hiện khi có thao tác xóa tài nguyên (delete operations) — một dấu hiệu có thể là nội gián hoặc tấn công. Mọi sự kiện xóa tài nguyên phải sinh incident để team điều tra.

🧪 Các Bước Thực Hiện

1

Tạo Log Analytics Workspace và Enable Sentinel

Cách 1 — Portal
  1. 1.1Portal → tìm Log Analytics workspaces+ Create
  2. 1.2RG: rg-az500-sentinel, Name: law-az500-secops, Region: Southeast Asia
  3. 1.3Review + Create → Create → chờ deployment
  4. 1.4Portal → tìm Microsoft Sentinel+ Create
  5. 1.5Chọn law-az500-secopsAdd
  6. 1.6Sentinel dashboard mở → xác nhận workspace được gắn thành công
Cách 2 — Azure CLI
Azure CLI— Tạo LAW và enable Sentinel
# Tạo resource group
az group create \
  --name rg-az500-sentinel \
  --location southeastasia \
  --tags "owner=hoatranlab" "env=lab" "module=az500-lab49"

# Tạo Log Analytics Workspace
az monitor log-analytics workspace create \
  --resource-group rg-az500-sentinel \
  --workspace-name law-az500-secops \
  --location southeastasia \
  --sku PerGB2018 \
  --retention-time 30

# Lấy workspace ID
WORKSPACE_ID=$(az monitor log-analytics workspace show \
  --resource-group rg-az500-sentinel \
  --workspace-name law-az500-secops \
  --query id -o tsv)

echo "Workspace ID: $WORKSPACE_ID"

# Enable Microsoft Sentinel (cần extension)
az extension add --name sentinel 2>/dev/null
az sentinel workspace create \
  --resource-group rg-az500-sentinel \
  --workspace-name law-az500-secops \
  --location southeastasia 2>/dev/null || echo "Dùng Portal để enable Sentinel: chọn workspace law-az500-secops"
2

Kết Nối Azure Activity Data Connector

Azure Activity connector đẩy toàn bộ activity log của subscription vào Sentinel để có thể query bằng KQL.

Cách 1 — Portal
  1. 2.1Sentinel → ConfigurationData connectors
  2. 2.2Tìm kiếm "Azure Activity" → click vào connector
  3. 2.3Click "Open connector page"
  4. 2.4Phần Instructions → click "Launch Azure Policy Assignment wizard"
  5. 2.5Scope: chọn subscription → Parameters: chọn law-az500-secops → Review + create
  6. 2.6Chờ 15–30 phút → quay lại connector page → Status = Connected
Cách 2 — Azure CLI
Azure CLI— Kết nối Azure Activity qua Diagnostic Settings
# Lấy subscription ID và workspace ID
SUBSCRIPTION_ID=$(az account show --query id -o tsv)
WORKSPACE_ID=$(az monitor log-analytics workspace show \
  --resource-group rg-az500-sentinel \
  --workspace-name law-az500-secops \
  --query id -o tsv)

# Tạo Diagnostic Settings để gửi Activity Log vào LAW
az monitor diagnostic-settings create \
  --name "sentinel-activity-connector" \
  --resource "/subscriptions/${SUBSCRIPTION_ID}" \
  --workspace "$WORKSPACE_ID" \
  --logs '[
    {
      "category": "Administrative",
      "enabled": true
    },
    {
      "category": "Security",
      "enabled": true
    },
    {
      "category": "ServiceHealth",
      "enabled": true
    },
    {
      "category": "Alert",
      "enabled": true
    },
    {
      "category": "Policy",
      "enabled": true
    }
  ]'

echo "Azure Activity connector configured successfully"

# Xác nhận diagnostic settings đã tạo
az monitor diagnostic-settings show \
  --name "sentinel-activity-connector" \
  --resource "/subscriptions/${SUBSCRIPTION_ID}" \
  --query "{name:name, workspaceId:workspaceId}" -o table
3

Sinh Activity Log Test và Query KQL

Thực hiện thao tác trong Azure để sinh activity log, sau đó dùng KQL để truy vấn bảng AzureActivity.

Cách 1 — Portal
  1. 3.1Tạo một resource group test: Portal → Resource groups → + Create → rg-az500-test-delete
  2. 3.2Sau 5 phút → xóa resource group đó để sinh Delete activity log
  3. 3.3Sentinel → GeneralLogs → paste KQL mẫu bên dưới
  4. 3.4Click Run → xem kết quả trong Results tab
Cách 2 — Azure CLI
Azure CLI— Sinh activity log test bằng tạo/xóa resource group
# Tạo resource group test (sinh Create activity log)
az group create \
  --name rg-az500-test-delete \
  --location southeastasia

# Chờ 2 phút rồi xóa (sinh Delete activity log)
sleep 120
az group delete \
  --name rg-az500-test-delete \
  --yes \
  --no-wait

echo "Delete operation initiated — activity log will appear in Sentinel in ~15 minutes"

# Query KQL từ CLI (thay WORKSPACE_ID)
WORKSPACE_ID=$(az monitor log-analytics workspace show \
  --resource-group rg-az500-sentinel \
  --workspace-name law-az500-secops \
  --query id -o tsv)

# Chạy KQL query từ CLI
az monitor log-analytics query \
  --workspace "$WORKSPACE_ID" \
  --analytics-query "AzureActivity | where TimeGenerated > ago(1h) | where OperationNameValue has 'delete' | project TimeGenerated, Caller, OperationNameValue, ResourceGroup, ActivityStatusValue | order by TimeGenerated desc | limit 10" \
  -o table 2>/dev/null || echo "Chạy KQL trực tiếp trong Sentinel → Logs sau 15-30 phút"
KQL— Query mẫu Lab 49: Phát hiện thao tác delete trong 24 giờ
AzureActivity
| where TimeGenerated > ago(24h)
| where OperationNameValue has "delete"
| project TimeGenerated, Caller, OperationNameValue, ResourceGroup, ActivityStatusValue
| order by TimeGenerated desc
Kết quả mong đợi (Results)
TimeGenerated          Caller                          OperationNameValue                            ResourceGroup              ActivityStatusValue
2026-05-21 10:30:15    [email protected]   MICROSOFT.RESOURCES/RESOURCEGROUPS/DELETE     rg-az500-test-delete       Succeeded
2026-05-21 10:28:02    [email protected]   MICROSOFT.STORAGE/STORAGEACCOUNTS/DELETE      rg-az500-storage-sec       Succeeded
4

Tạo Scheduled Analytics Rule

Tạo rule chạy định kỳ với KQL mẫu, tự động tạo incident khi phát hiện thao tác delete.

Cách 1 — Portal
  1. 4.1Sentinel → ConfigurationAnalytics+ CreateScheduled query rule
  2. 4.2Tab General: Name: Detect Azure Resource Delete Operations, Severity: Medium
  3. 4.3Tab Set rule logic: paste KQL mẫu → Query scheduling: Every 5 minutes, Lookup data: Last 24 hours
  4. 4.4Alert threshold: Generate alert when number of query results is greater than 0
  5. 4.5Tab Incident settings: Create incidents from alerts = Enabled
  6. 4.6Tab Entity mapping: thêm Account entity → Caller field
  7. 4.7Review + Create → chờ 5–10 phút → Sentinel → Threat managementIncidents → xem incident mới
Cách 2 — Azure CLI
Azure CLI— Tạo analytics rule qua REST API / az sentinel
# Tạo analytics rule qua az sentinel (nếu extension hỗ trợ)
az sentinel alert-rule create \
  --resource-group rg-az500-sentinel \
  --workspace-name law-az500-secops \
  --rule-id "detect-delete-operations" \
  --etag '"*"' \
  --kind "Scheduled" \
  --display-name "Detect Azure Resource Delete Operations" \
  --enabled true \
  --query-text "AzureActivity | where TimeGenerated > ago(24h) | where OperationNameValue has 'delete' | project TimeGenerated, Caller, OperationNameValue, ResourceGroup, ActivityStatusValue | order by TimeGenerated desc" \
  --query-frequency "PT5M" \
  --query-period "P1D" \
  --severity "Medium" \
  --trigger-operator "GreaterThan" \
  --trigger-threshold 0 \
  --incident-configuration '{"createIncident":true,"groupingConfiguration":{"enabled":false}}' \
  2>/dev/null || echo "Dùng Portal để tạo Scheduled Query Rule — az sentinel extension có thể cần cập nhật"

# Xem danh sách analytics rules đã tạo
az sentinel alert-rule list \
  --resource-group rg-az500-sentinel \
  --workspace-name law-az500-secops \
  --query "[].{name:displayName, kind:kind, enabled:enabled}" \
  -o table 2>/dev/null
5

Kiểm Tra Incident và KQL Nâng Cao

Xem incident được tạo từ rule và chạy thêm KQL queries để phân tích.

Cách 1 — Portal
  1. 5.1Sentinel → Threat managementIncidents → xem incident "Detect Azure Resource Delete Operations"
  2. 5.2Click vào incident → xem Details: Severity, Alerts count, Entities (account: Caller)
  3. 5.3Sentinel → Logs → chạy thêm KQL query phân tích hoạt động theo user
KQL— Query bổ sung: Phân tích các operation categories
// Tóm tắt hoạt động theo loại operation và caller
AzureActivity
| where TimeGenerated > ago(24h)
| summarize OperationCount = count() by Caller, OperationNameValue, ActivityStatusValue
| order by OperationCount desc
| limit 20
KQL— Query failed operations (có thể chỉ dấu tấn công thất bại)
AzureActivity
| where TimeGenerated > ago(24h)
| where ActivityStatusValue in ("Failed", "Failure")
| project TimeGenerated, Caller, OperationNameValue, ResourceGroup, ActivityStatusValue, Properties
| order by TimeGenerated desc

📊 Kết Quả Đầu Ra Lab 49

Sentinel Deployed

law-az500-secops với Sentinel enabled và status = Active

Azure Activity Connected

Data connector status = Connected, bảng AzureActivity có data

KQL Query Chạy Thành Công

Query AzureActivity trả về kết quả có delete operations

Analytics Rule Created

"Detect Azure Resource Delete Operations" rule active, chạy mỗi 5 phút

Incident Generated

Incident xuất hiện trong Sentinel → Incidents với entity Caller mapped

KQL Cơ Bản Thành Thạo

Biết dùng where, project, order by, summarize, limit trong KQL

🧹 Dọn Dẹp Tài Nguyên

Lưu ý: GIỮ workspace law-az500-secops nếu bạn sẽ làm Lab 50 tiếp theo. Lab 50 cần incident từ lab này.

Azure CLI— Chỉ xóa sau khi hoàn thành Lab 50
# CHỈ chạy sau khi hoàn thành Lab 50
# Xóa toàn bộ Sentinel + LAW
az group delete \
  --name rg-az500-sentinel \
  --yes \
  --no-wait

echo "Sentinel and Log Analytics Workspace will be deleted"

❓ Câu Hỏi Ôn Tập

1. Microsoft Sentinel là SIEM hay SOAR? Sự khác biệt giữa hai khái niệm này?

Gợi ý: Sentinel là cả hai — SIEM (Security Information and Event Management): thu thập và phân tích log; SOAR (Security Orchestration, Automation and Response): tự động hóa phản ứng qua Playbook/Logic App

2. Tại sao Azure Activity connector cần được cấu hình qua Azure Policy chứ không phải trực tiếp?

Gợi ý: Azure Policy đảm bảo mọi subscription (kể cả mới tạo sau) đều tự động gửi activity log vào Sentinel workspace chỉ định — không cần cấu hình thủ công từng subscription

3. Trong KQL, sự khác biệt giữa where, projectsummarize là gì?

Gợi ý: where = lọc hàng theo điều kiện; project = chọn/đổi tên cột; summarize = tổng hợp/nhóm dữ liệu (tương tự GROUP BY trong SQL)

4. Scheduled Query Rule khác Microsoft Security Rule ở chỗ nào?

Gợi ý: Scheduled: bạn tự viết KQL, tùy chỉnh hoàn toàn, chạy theo lịch; Microsoft Security Rule: tự động import alerts từ Defender for Cloud/Defender 365 — không cần viết query, không thể tùy chỉnh logic

5. Entity mapping trong analytics rule dùng để làm gì?

Gợi ý: Map field trong query result với Sentinel entity types (Account, IP, Host...) để investigation graph hoạt động, hunting query được, và UEBA (User Entity Behavior Analytics) có thể phân tích entity

Lab 48: Defender for Storage Thư viện Labs Lab 50: Incident Investigation
Zalo