Bài 04 · Chuyên đề Hyper-V

Bảo mật & Hardening Hyper-V / Cluster

Hardening 5 lớp: host, bảo vệ VM (Secure Boot/vTPM/Shielded VM), phân quyền RBAC/JEA, bảo mật mạng VM, và bảo mật cụm + Live Migration.

Về trang tổng Hyper-V

Bảo mật & Hardening Hyper-V / Cluster

Host Hyper-V nắm toàn bộ VM — bảo vệ host = bảo vệ cả hạ tầng. Hardening theo 5 lớp:

1 · Hardening Host

  • Cài bản Server Core (ít bề mặt tấn công) cho host production
  • Chỉ cài role cần thiết; không lướt web/email trên host
  • Bật Windows Defender + loại trừ đúng đường dẫn VM/CSV
  • Bật firewall, giới hạn RDP/WinRM theo IP quản trị
  • Secured-core server (TPM 2.0, DRTM, HVCI) nếu phần cứng hỗ trợ

2 · Bảo vệ VM

  • VM Gen2 + Secure Boot + vTPM
  • Shielded VM + Host Guardian Service (HGS): chặn cả admin host độc đọc VM
  • BitLocker mã hoá ổ host & CSV
  • Credential Guard bảo vệ thông tin đăng nhập

3 · Phân quyền (RBAC)

  • Dùng nhóm Hyper-V Administrators, không cấp Domain Admin
  • JEA (Just Enough Administration) cho thao tác hạn chế
  • Mô hình admin tier 0/1/2; tài khoản riêng cho quản trị

4 · Bảo mật mạng VM

  • MAC spoofing OFF, DHCP Guard, Router Guard ON
  • Port ACL + VLAN cô lập từng nhóm VM
  • Tách mạng: Mgmt / Storage / Live Migration / VM riêng

5 · Bảo mật cụm & di chuyển

# vTPM cho VM Gen2 (mã hoá ổ, sẵn sàng Shielded) Set-VMKeyProtector -VMName VM-Web01 -NewLocalKeyProtector Enable-VMTPM -VMName VM-Web01 # Khoá bảo mật vNIC từng VM Set-VMNetworkAdapter -VMName VM-Web01 -MacAddressSpoofing Off -DhcpGuard On -RouterGuard On # Mã hoá Live Migration bằng Kerberos (an toàn hơn CredSSP) Set-VMHost -VirtualMachineMigrationAuthenticationType Kerberos # Patch cả cụm tự động, không downtime (đã giới thiệu) Invoke-CauRun -ClusterName HV-CLUSTER -MaxFailedNodes 0 -Force

Checklist tối thiểu: Server Core · Defender + exclusions · firewall + RDP hạn chế · VM Gen2 + Secure Boot · BitLocker · Hyper-V Admins (không Domain Admin) · MAC spoofing off · Kerberos LM · CAU patching.

Cấu hình bảo mật chi tiết — từng bước

Hướng dẫn cụ thể cho người mới: từng mục A–H kèm lệnh PowerShell thực thi trực tiếp. Áp dụng dần từ cơ bản đến nâng cao trên node H-NODE01/H-NODE02, domain hyperlab.local (HYPERLAB), cụm HV-CLUSTER.

A · Giảm bề mặt tấn công host

Dùng Server Core, gỡ feature thừa, tắt giao thức cũ, và loại trừ Defender đúng đường dẫn/tiến trình Hyper-V để tránh quét nhầm gây hỏng VM.

# Tắt SMBv1 (giao thức cũ, rủi ro) Disable-WindowsOptionalFeature -Online -FeatureName SMB1Protocol # Bật firewall mọi profile Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled True # Loại trừ Defender đúng đường dẫn/tiến trình Hyper-V (tránh quét nhầm, hỏng VM) Add-MpPreference -ExclusionPath "C:\ClusterStorage","C:\ProgramData\Microsoft\Windows\Hyper-V" Add-MpPreference -ExclusionExtension ".vhd",".vhdx",".avhdx" Add-MpPreference -ExclusionProcess "vmms.exe","vmwp.exe"

B · Credential Guard + VBS (chống trộm thông tin đăng nhập)

Bật bảo mật dựa trên ảo hoá (VBS) + Credential Guard trên host để bảo vệ thông tin đăng nhập khỏi bị trích xuất.

# Bật qua registry rồi reboot (yêu cầu CPU ảo hoá + Secure Boot) reg add "HKLM\SYSTEM\CurrentControlSet\Control\DeviceGuard" /v EnableVirtualizationBasedSecurity /t REG_DWORD /d 1 /f reg add "HKLM\SYSTEM\CurrentControlSet\Control\DeviceGuard" /v RequirePlatformSecurityFeatures /t REG_DWORD /d 1 /f reg add "HKLM\SYSTEM\CurrentControlSet\Control\LSA" /v LsaCfgFlags /t REG_DWORD /d 1 /f # Kiểm tra sau reboot: msinfo32 → "Credential Guard ... Running"

Cách GUI: gpedit.msc → Computer Configuration → Administrative Templates → System → Device Guard → "Turn On Virtualization Based Security" → Credential Guard: "Enabled with UEFI lock".

C · BitLocker mã hoá ổ host & CSV (advanced)

Mã hoá ổ đĩa host và CSV để bảo vệ dữ liệu VM khi ổ bị đánh cắp vật lý.

# Cài tính năng trên MỌI node Install-WindowsFeature BitLocker -IncludeAllSubFeature -IncludeManagementTools -Restart # Mã hoá CSV bằng key protector của tài khoản cụm (CSV tạm offline khi bật) Enable-BitLocker -MountPoint "C:\ClusterStorage\Volume1" -EncryptionMethod XtsAes256 -UsedSpaceOnly -RecoveryPasswordProtector Add-BitLockerKeyProtector -MountPoint "C:\ClusterStorage\Volume1" -ADAccountOrGroupProtector -ADAccountOrGroup "HYPERLAB\HV-CLUSTER$"

BitLocker trên CSV là nâng cao — cần TPM/recovery key lưu nơi an toàn; thử ở lab trước.

D · Shielded VM + Host Guardian Service (HGS) (advanced)

Bảo vệ VM khỏi cả admin host độc hại; cần 1 server HGS riêng làm cơ quan chứng thực & giữ khoá.

# Trên server HGS riêng Install-WindowsFeature HostGuardianServiceRole -IncludeManagementTools -Restart Install-HgsServer -HgsDomainName "hgs.hyperlab.local" -SafeModeAdministratorPassword (Read-Host -AsSecureString) -Restart # Lab: dùng AD-trusted attestation cho đơn giản Initialize-HgsServer -LogDirectory C:\ -HgsServiceName "hgs" -TrustActiveDirectory # Trên host Hyper-V (guarded host) Set-HgsClientConfiguration -AttestationServerUrl "http://hgs.hyperlab.local/Attestation" -KeyProtectionServerUrl "http://hgs.hyperlab.local/KeyProtection"

Sau đó tạo VM Gen2 + vTPM và áp shielding data (.pdk). Đây là tính năng nâng cao cho môi trường bảo mật cao.

E · Bảo mật mạng cho VM (Port ACL + VLAN)

Dùng Port ACL chặn lưu lượng ngoài ý muốn và VLAN cô lập card mạng VM theo từng phân vùng.

# Chỉ cho VM ra subnet nội bộ, chặn còn lại Add-VMNetworkAdapterAcl -VMName VM-Web01 -RemoteIPAddress 10.100.20.0/24 -Direction Outbound -Action Allow Add-VMNetworkAdapterAcl -VMName VM-Web01 -RemoteIPAddress ANY -Direction Outbound -Action Deny # Cô lập VLAN cho card mạng VM Set-VMNetworkAdapterVlan -VMName VM-Web01 -Access -VlanId 20

F · JEA — uỷ quyền tối thiểu (vận hành không cần full admin)

Cấu hình JEA để operator chỉ chạy được vài lệnh VM qua virtual account, không cần quyền admin đầy đủ.

# Tạo Role Capability chỉ cho phép vài lệnh VM New-Item "C:\Program Files\WindowsPowerShell\Modules\HVOps\RoleCapabilities" -ItemType Directory -Force New-PSRoleCapabilityFile -Path "C:\Program Files\WindowsPowerShell\Modules\HVOps\RoleCapabilities\HVOps.psrc" -VisibleCmdlets "Get-VM","Start-VM","Stop-VM","Get-VMHost" # Session config gắn role cho nhóm operator, chạy bằng virtual account New-PSSessionConfigurationFile -Path .\HVJEA.pssc -SessionType RestrictedRemoteServer -RunAsVirtualAccount -RoleDefinitions @{ "HYPERLAB\HV-Operators" = @{ RoleCapabilities = "HVOps" } } Register-PSSessionConfiguration -Name HVOps -Path .\HVJEA.pssc -Force # Operator dùng: Enter-PSSession -ComputerName H-NODE01 -ConfigurationName HVOps -Credential HYPERLAB\op.hyperv

G · Hạn chế truy cập quản trị (RDP/WinRM theo subnet)

Chỉ cho phép RDP/WinRM từ subnet quản lý, giảm rủi ro truy cập trái phép từ mạng khác.

# Chỉ cho RDP từ subnet quản lý 10.100.10.0/24 Set-NetFirewallRule -DisplayGroup "Remote Desktop" -RemoteAddress 10.100.10.0/24 # Giới hạn WinRM tương tự nếu cần

H · Mã hoá Live Migration & lưu trữ

Dùng Kerberos cho Live Migration và bật mã hoá SMB cho lưu trữ để bảo vệ dữ liệu trên đường truyền.

# Live Migration dùng Kerberos (an toàn hơn CredSSP) — làm trên cả 2 host Set-VMHost -VirtualMachineMigrationAuthenticationType Kerberos # Mã hoá lưu lượng SMB (storage SOFS) Set-SmbServerConfiguration -EncryptData $true -Force

Áp dụng theo mức độ: A–B–E–G–H là cơ bản nên làm; C, D, F là nâng cao cho môi trường yêu cầu bảo mật cao.

🧪 LAB thực hành — Hardening 1 VM & uỷ quyền

Mục tiêu: siết bảo mật cho VM-Lab01 + host H-NODE01: bật vTPM, khoá vNIC, mã hoá Live Migration bằng Kerberos, uỷ quyền vận hành không cần Domain Admin.

1

Bật vTPM (VM Gen2) — mã hoá & sẵn sàng Shielded

Set-VMKeyProtector -VMName VM-Lab01 -NewLocalKeyProtector Enable-VMTPM -VMName VM-Lab01

Cách GUI: Hyper-V Manager → chuột phải VM-Lab01 → Settings → Security → tick "Enable Trusted Platform Module" và "Enable Secure Boot".

2

Khoá bảo mật card mạng VM

Set-VMNetworkAdapter -VMName VM-Lab01 ` -MacAddressSpoofing Off -DhcpGuard On -RouterGuard On

Cách GUI: VM Settings → Network Adapter → Advanced Features → bỏ tick "Enable MAC address spoofing"; tick "Enable DHCP guard" và "Enable router advertisement guard".

3

Mã hoá Live Migration bằng Kerberos (cả 2 host)

Set-VMHost -VirtualMachineMigrationAuthenticationType Kerberos

Cách GUI: Hyper-V Manager → Hyper-V Settings… → Live Migrations → Advanced Features → Authentication protocol: chọn "Use Kerberos". Làm trên cả 2 host.

4

Uỷ quyền vận hành — KHÔNG dùng Domain Admin

# Cấp quyền quản trị Hyper-V cho 1 tài khoản nghiệp vụ Add-LocalGroupMember -Group "Hyper-V Administrators" -Member "HYPERLAB\op.hyperv"

Cách GUI: mở lusrmgr.msc (hoặc Computer Management → Local Users and Groups) → Groups → "Hyper-V Administrators" → Add → HYPERLAB\op.hyperv (KHÔNG dùng Domain Admin).

Kiểm chứng: Get-VMSecurity -VMName VM-Lab01 → TpmEnabled = True; Get-VMNetworkAdapter -VMName VM-Lab01 | fl MacAddressSpoofing,DhcpGuard,RouterGuard đúng như cấu hình.