🎯 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ị
- 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
- 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
Tạo Log Analytics Workspace và Enable Sentinel
- 1.1Portal → tìm Log Analytics workspaces → + Create
- 1.2RG:
rg-az500-sentinel, Name:law-az500-secops, Region: Southeast Asia - 1.3Review + Create → Create → chờ deployment
- 1.4Portal → tìm Microsoft Sentinel → + Create
- 1.5Chọn law-az500-secops → Add
- 1.6Sentinel dashboard mở → xác nhận workspace được gắn thành công
# 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"
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.
- 2.1Sentinel → Configuration → Data connectors
- 2.2Tìm kiếm "Azure Activity" → click vào connector
- 2.3Click "Open connector page"
- 2.4Phần Instructions → click "Launch Azure Policy Assignment wizard"
- 2.5Scope: chọn subscription → Parameters: chọn law-az500-secops → Review + create
- 2.6Chờ 15–30 phút → quay lại connector page → Status = Connected
# 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
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.
- 3.1Tạo một resource group test: Portal → Resource groups → + Create →
rg-az500-test-delete - 3.2Sau 5 phút → xóa resource group đó để sinh Delete activity log
- 3.3Sentinel → General → Logs → paste KQL mẫu bên dưới
- 3.4Click Run → xem kết quả trong Results tab
# 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"
AzureActivity
| where TimeGenerated > ago(24h)
| where OperationNameValue has "delete"
| project TimeGenerated, Caller, OperationNameValue, ResourceGroup, ActivityStatusValue
| order by TimeGenerated desc
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
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.
- 4.1Sentinel → Configuration → Analytics → + Create → Scheduled query rule
- 4.2Tab General: Name:
Detect Azure Resource Delete Operations, Severity: Medium - 4.3Tab Set rule logic: paste KQL mẫu → Query scheduling: Every 5 minutes, Lookup data: Last 24 hours
- 4.4Alert threshold: Generate alert when number of query results is greater than 0
- 4.5Tab Incident settings: Create incidents from alerts = Enabled
- 4.6Tab Entity mapping: thêm Account entity → Caller field
- 4.7Review + Create → chờ 5–10 phút → Sentinel → Threat management → Incidents → xem incident mới
# 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
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.
- 5.1Sentinel → Threat management → Incidents → xem incident "Detect Azure Resource Delete Operations"
- 5.2Click vào incident → xem Details: Severity, Alerts count, Entities (account: Caller)
- 5.3Sentinel → Logs → chạy thêm KQL query phân tích hoạt động theo user
// 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
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
law-az500-secops với Sentinel enabled và status = Active
Data connector status = Connected, bảng AzureActivity có data
Query AzureActivity trả về kết quả có delete operations
"Detect Azure Resource Delete Operations" rule active, chạy mỗi 5 phút
Incident xuất hiện trong Sentinel → Incidents với entity Caller mapped
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.
# 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, project và summarize 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