🎯 Mục Tiêu Lab
Bật Defender for Storage trên Storage Account lab
Cấu hình malware scanning trên upload (on-upload scanning)
Upload file test (EICAR test file) để kích hoạt malware alert
Xem security alerts và recommendations trong Defender for Cloud
Cấu hình Event Grid notification hoặc workflow automation cơ bản
Hiểu sự khác biệt giữa activity monitoring và malware scanning
📋 Chuẩn Bị
- Azure subscription với quyền Owner hoặc Security Admin
- Defender for Cloud đã enabled (Lab 45)
- Azure CLI:
az login - Azure Storage Explorer hoặc trình duyệt để upload file test
- Defender for Storage: ~$10/tháng/storage account
- Malware scanning: $0.15/GB scanned (tháng đầu có free tier)
- EICAR test file là file vô hại, chỉ dùng để test AV detection
- Region: southeastasia, RG:
rg-az500-storage-sec
🏗️ Kịch Bản
Công ty sử dụng Azure Blob Storage làm nơi nhận file upload từ đối tác và khách hàng. Để ngăn ransomware và malware lây lan qua storage, bạn cần bật Defender for Storage với malware scanning. Khi có file độc hại được upload, hệ thống phải tự động cảnh báo security team và có thể tự động xóa file nguy hiểm qua workflow automation.
🧪 Các Bước Thực Hiện
Tạo Storage Account và Bật Defender for Storage
Tạo Storage Account lab và bật Defender for Storage kèm malware scanning.
- 1.1Portal → Storage accounts → + Create
- 1.2RG:
rg-az500-storage-sec, Name:staz500lab48[random], Region: Southeast Asia - 1.3Tab Advanced → Microsoft Defender for Storage → tick Enable
- 1.4Bật Malware scanning → giữ mức cap mặc định (5000 GB/month)
- 1.5Review + Create → Create → chờ deployment hoàn tất
- 1.6Vào Storage Account → Microsoft Defender for Cloud (menu trái) → xác nhận Defender = On
# Tạo resource group
az group create \
--name rg-az500-storage-sec \
--location southeastasia \
--tags "owner=hoatranlab" "env=lab" "module=az500-lab48"
# Tạo storage account (tên phải unique globally)
STORAGE_NAME="staz500lab48$(date +%s | tail -c 6)"
az storage account create \
--name $STORAGE_NAME \
--resource-group rg-az500-storage-sec \
--location southeastasia \
--sku Standard_LRS \
--kind StorageV2 \
--allow-blob-public-access false
# Bật Defender for Storage với malware scanning
az security defender for-storage show \
--resource-group rg-az500-storage-sec \
--storage-account $STORAGE_NAME 2>/dev/null || echo "Dùng Portal để bật Defender for Storage với malware scanning"
# Xem storage account vừa tạo
az storage account show \
--name $STORAGE_NAME \
--resource-group rg-az500-storage-sec \
--query "{name:name, location:location, kind:kind}" -o table
echo "Storage account name: $STORAGE_NAME"
Cấu Hình Malware Scanning và Tạo Container
Cấu hình chi tiết malware scanning và tạo Blob container để test.
- 2.1Defender for Cloud → Environment settings → subscription → tìm Storage → On
- 2.2Click Settings bên cạnh Storage → kiểm tra On-upload malware scanning = On
- 2.3Cấu hình Scanning result send to → bật Event Grid topic nếu muốn automation
- 2.4Save → vào Storage Account → Containers → + Container
- 2.5Name:
uploads, Access level: Private → Create
# Thay YOUR_STORAGE_NAME bằng tên storage account vừa tạo
STORAGE_NAME="YOUR_STORAGE_NAME"
# Lấy connection string
CONN_STR=$(az storage account show-connection-string \
--name $STORAGE_NAME \
--resource-group rg-az500-storage-sec \
--query connectionString -o tsv)
# Tạo container "uploads"
az storage container create \
--name uploads \
--connection-string "$CONN_STR" \
--public-access off
# Tạo file test bình thường
echo "This is a test file for lab 48" > test-normal.txt
az storage blob upload \
--container-name uploads \
--file test-normal.txt \
--name test-normal.txt \
--connection-string "$CONN_STR"
# Xác nhận blob được upload
az storage blob list \
--container-name uploads \
--connection-string "$CONN_STR" \
--query "[].{name:name, size:properties.contentLength}" \
-o table
Upload EICAR Test File để Kích Hoạt Malware Alert
- 3.1Tạo file
eicar-test.txttrên máy local với nội dung chính xác như trong CLI bên dưới - 3.2Portal → Storage Account → Containers → uploads → Upload
- 3.3Chọn file
eicar-test.txt→ Upload - 3.4Chờ 5–10 phút → Defender for Cloud → Security alerts → xem alert "Malware uploaded to storage"
- 3.5Click vào alert → xem chi tiết: storage account, container, blob name, scan result
# Tạo EICAR test file (chuỗi chuẩn EICAR — hoàn toàn vô hại)
printf 'X5O!P%%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*' > eicar-test.txt
# Kiểm tra file đã tạo đúng
cat eicar-test.txt
# Upload EICAR test file lên storage
STORAGE_NAME="YOUR_STORAGE_NAME"
CONN_STR=$(az storage account show-connection-string \
--name $STORAGE_NAME \
--resource-group rg-az500-storage-sec \
--query connectionString -o tsv)
az storage blob upload \
--container-name uploads \
--file eicar-test.txt \
--name eicar-test.txt \
--connection-string "$CONN_STR"
echo "EICAR file uploaded. Check Defender for Cloud alerts in 5-10 minutes."
# Xem alerts sau khi chờ (nếu CLI hỗ trợ)
az security alert list \
--query "[?contains(alertDisplayName,'Malware') || contains(alertDisplayName,'storage')].{name:alertDisplayName, severity:severity, time:timeGeneratedUtc}" \
-o table
Alert: "Malware uploaded to a storage blob container"
Severity: High
Description: Azure Defender for Storage detected a malware upload.
Affected resource: staz500lab48xxxxx/uploads/eicar-test.txt
Scan verdict: Malicious
EICAR signature: EICAR-Test-File (not a virus)
Xem Alerts và Cấu Hình Workflow Automation
Phân tích alert và cấu hình notification tự động khi có malware được phát hiện.
- 4.1Defender for Cloud → Security alerts → click alert malware storage
- 4.2Xem tab Take action → đọc suggested remediation steps
- 4.3Defender for Cloud → Workflow automation → + Add workflow automation
- 4.4Trigger: Security alert, Condition: Severity = High, Alert type chứa "storage"
- 4.5Action: chọn Logic App (nếu có) hoặc ghi nhận cấu hình mà không tạo để tiết kiệm chi phí
- 4.6Xem Email notifications: Defender for Cloud → Environment settings → Email notifications
# Xem tất cả security alerts
az security alert list \
--query "[].{name:alertDisplayName, severity:severity, state:status, time:timeGeneratedUtc}" \
-o table
# Xem chi tiết alert (nếu có malware alert)
az security alert list \
--query "[?severity=='High'].{name:alertDisplayName, description:description}" \
-o json | head -50
# Kiểm tra email notification settings
az security contact list \
--query "[].{email:email, phone:phone, alertNotifications:alertNotifications, alertsToAdmins:alertsToAdmins}" \
-o table
# Cấu hình email notification (thay YOUR_EMAIL)
az security contact create \
--email "[email protected]" \
--phone "+84917516878" \
--alert-notifications On \
--alerts-to-admins On \
--name "secops-contact"
echo "Email notification configured"
Xem Recommendations và Blob Index Tags
Defender for Storage tự động thêm metadata (index tag) vào blob sau khi scan để đánh dấu trạng thái.
- 5.1Storage Account → Containers → uploads → click vào eicar-test.txt
- 5.2Xem tab Index tags → tìm tag
Malware Scanning Verdict=Malicious - 5.3Defender for Cloud → Recommendations → lọc Resource type: Storage accounts
- 5.4Xem các recommendations liên quan đến storage security (public access, HTTPS only, v.v.)
# Xem blob properties (bao gồm metadata) sau khi scan
STORAGE_NAME="YOUR_STORAGE_NAME"
CONN_STR=$(az storage account show-connection-string \
--name $STORAGE_NAME \
--resource-group rg-az500-storage-sec \
--query connectionString -o tsv)
# Xem metadata của blob eicar test
az storage blob show \
--container-name uploads \
--name eicar-test.txt \
--connection-string "$CONN_STR" \
--query "{name:name, metadata:metadata, tags:tags}" \
-o json
# Xem tất cả blobs với metadata
az storage blob list \
--container-name uploads \
--connection-string "$CONN_STR" \
--include m \
--query "[].{name:name, metadata:metadata}" \
-o json
# Xem recommendations cho storage accounts
az security assessment list \
--resource-group rg-az500-storage-sec \
--query "[?status.code=='Unhealthy'].{name:displayName, severity:metadata.severity}" \
-o table
📊 Kết Quả Đầu Ra Lab 48
Storage account hiển thị Defender status = On trong Portal
On-upload malware scanning = On trong Defender settings
Alert "Malware uploaded to storage" xuất hiện trong Security alerts
eicar-test.txt có tag "Malware Scanning Verdict" = "Malicious"
Security contact với email alert đã được cấu hình
Đã xem và ghi nhận các recommendations cho storage security
🧹 Dọn Dẹp Tài Nguyên
# Xóa resource group
az group delete \
--name rg-az500-storage-sec \
--yes \
--no-wait
# Tắt Defender for Storage plan (optional — tiết kiệm chi phí)
az security pricing create \
--name StorageAccounts \
--tier Free
# Xóa file EICAR local
rm -f eicar-test.txt test-normal.txt
echo "Lab 48 cleanup complete"
❓ Câu Hỏi Ôn Tập
1. Defender for Storage có hai tính năng chính: Activity monitoring và Malware scanning. Sự khác biệt là gì?
Gợi ý: Activity monitoring phát hiện hành vi bất thường (anonymous access, unusual geolocation); Malware scanning quét nội dung file upload để phát hiện virus/malware thực sự
2. Sau khi Defender for Storage scan một blob và phát hiện malware, điều gì xảy ra với file đó?
Gợi ý: File KHÔNG tự động bị xóa — Defender chỉ sinh alert và gắn index tag "Malicious". Việc xóa/quarantine phải được thực hiện qua automation rule (Logic App) hoặc thủ công
3. EICAR test file có phải là malware thật không? Tại sao nó được dùng để test?
Gợi ý: Không, hoàn toàn vô hại. Là chuỗi ASCII 68 ký tự được EICAR chuẩn hóa — tất cả AV engines đều nhận dạng nó mà không cần dùng malware thật, đảm bảo an toàn cho môi trường lab/production
4. Blob index tag "Malware Scanning Verdict" có giá trị nào? Dùng để làm gì?
Gợi ý: Giá trị: "No threats found", "Malicious", "No scan" (file quá lớn/không được scan). Tag này cho phép dùng Lifecycle policy hoặc Logic App tự động xóa blob có tag = Malicious
5. Khi nào nên bật Defender for Storage ở cấp subscription vs. từng storage account?
Gợi ý: Subscription-level: tự động bảo vệ mọi storage account mới tạo, dễ quản lý nhưng tốn chi phí nhiều hơn; Account-level: kiểm soát chi phí từng storage account, phù hợp khi chỉ một số account cần bảo vệ cao