Azure Introduction
Azure Pricing
Azure Threats
Enable Microsoft Defender for Cloud for Virtual Machines
More Info:
Enable Microsoft Defender for Cloud for Virtual Machines
Risk Level
High
Address
Security, Operational Maturity
Compliance Standards
CISAZURE, CBP, HITRUST
Triage and Remediation
Remediation
To remediate the misconfiguration “Enable Microsoft Defender for Cloud for Virtual Machines” for Azure using Azure console, follow the below steps:
- Login to the Azure portal (https://portal.azure.com/)
- Select the Virtual Machine on which you want to enable Microsoft Defender for Cloud
- Under the “Settings” section, select “Security + Compliance”
- Click on “Security Center” to open the Security Center blade
- On the Security Center blade, click on “Recommendations”
- Look for the recommendation “Enable Microsoft Defender for Cloud for Virtual Machines” and click on it
- Click on the “Remediate” button to enable Microsoft Defender for Cloud for the selected Virtual Machine
- Once the remediation is complete, verify that Microsoft Defender for Cloud is enabled for the Virtual Machine by going to the “Security + Compliance” section and checking the status of the Microsoft Defender for Cloud.
Note: It is recommended to enable Microsoft Defender for Cloud for all Virtual Machines in the Azure environment to ensure comprehensive security coverage.
To enable Microsoft Defender for Cloud for Virtual Machines in Azure, follow the below steps using Azure CLI:
-
Open the Azure CLI and login to your Azure account using the command:
az login
-
Once you are logged in, set the subscription to the one you want to work with using the command:
az account set --subscription <subscription_id>
-
Next, enable the Microsoft Defender for Cloud for Virtual Machines using the command:
az security vm enable-defense --name <virtual_machine_name> --resource-group <resource_group_name>
Replace
<virtual_machine_name>
with the name of the virtual machine you want to enable Microsoft Defender for Cloud and<resource_group_name>
with the name of the resource group where the virtual machine is located. -
Wait for a few minutes for the changes to take effect. Once the changes are applied, you can verify the status of Microsoft Defender for Cloud for Virtual Machines using the command:
az security vm show --name <virtual_machine_name> --resource-group <resource_group_name> --query 'defenderStatus.status'
This command will return the status of Microsoft Defender for Cloud for Virtual Machines for the specified virtual machine.
That’s it! You have successfully enabled Microsoft Defender for Cloud for Virtual Machines in Azure using Azure CLI.
To enable Microsoft Defender for Cloud for Virtual Machines in Azure using Python, follow these steps:
- Install the Azure SDK for Python using the following command:
pip install azure-mgmt-compute
-
Authenticate with Azure using the Azure CLI or by providing your credentials directly in the code.
-
Use the following Python code to enable Microsoft Defender for Cloud for Virtual Machines:
from azure.mgmt.compute import ComputeManagementClient
from azure.mgmt.compute.models import VirtualMachineExtension
# Replace the values in the following variables with your own values
subscription_id = '<your-subscription-id>'
resource_group_name = '<your-resource-group-name>'
vm_name = '<your-vm-name>'
location = '<your-vm-location>'
workspace_id = '<your-workspace-id>'
workspace_key = '<your-workspace-key>'
# Create a ComputeManagementClient object
compute_client = ComputeManagementClient(credentials, subscription_id)
# Create a VirtualMachineExtension object
extension = VirtualMachineExtension(
location=location,
publisher='Microsoft.Azure.Security',
virtual_machine_extension_type='IaaSAntimalware',
type_handler_version='1.15',
auto_upgrade_minor_version=True,
settings={
"AntimalwareEnabled": True,
"RealtimeProtectionEnabled": True,
"ScheduledScanSettings": {
"isEnabled": True,
"day": "1",
"time": "120",
"scanType": "Quick"
},
"Exclusions": {
"Extensions": ".log;.bak",
"Paths": "/var/log;/var/lib/docker"
},
"AdvancedThreatProtection": {
"isEnabled": True
}
},
protected_settings={
"storageAccountName": "<your-storage-account-name>",
"storageAccountKey": "<your-storage-account-key>",
"workspaceConfig": {
"workspaceId": workspace_id,
"workspaceKey": workspace_key
}
}
)
# Create the extension on the virtual machine
compute_client.virtual_machine_extensions.create_or_update(
resource_group_name,
vm_name,
'IaaSAntimalware',
extension
)
-
Replace the values in the variables with your own values.
-
Run the Python code to enable Microsoft Defender for Cloud for Virtual Machines in Azure. This will create an extension on the virtual machine that enables Microsoft Defender for Cloud and configures it with the specified settings.