Azure Microsoft 맬웨어 방지를 사용하도록 설정하고 구성하는 코드 샘플

이 문서에서는 다음과 같은 다양한 Azure 서비스에 대해 Microsoft 맬웨어 방지 프로그램을 사용하도록 설정하고 구성하는 PowerShell 코드 샘플을 제공합니다.

  • Azure Resource Manager VM
  • Azure Service Fabric 클러스터
  • Azure Cloud Services(추가 지원)
  • Azure Arc 사용 가능 서버

이 샘플들을 활용해 Microsoft Antimalware 확장 프로그램을 Azure 환경에 배포하고 설정하세요.

Azure Resource Manager VM에 Microsoft 맬웨어 방지 프로그램 배포

비고

이 코드 샘플을 실행하기 전에 변수의 주석 처리를 해제하고 적절한 값을 지정하세요.

경고

이 확장을 배포하거나 업데이트하면 제외를 포함하여 기존 Microsoft Defender 바이러스 백신 설정이 대체됩니다. 설정을 유지하려면 확장 구성에서 설정을 지정합니다. 자세한 내용은 기본 및 사용자 지정 맬웨어 방지 구성을 참조하세요.

# Script to add Microsoft Antimalware extension to Azure Resource Manager VMs
# Specify your subscription ID
$subscriptionId= " SUBSCRIPTION ID HERE "
# Specify location, resource group, and VM for the extension
$location = " LOCATION HERE " # For example, "Southeast Asia" or "Central US"
$resourceGroupName = " RESOURCE GROUP NAME HERE "
$vmName = " VM NAME HERE "

# Enable Antimalware with default policies
$settingString = '{"AntimalwareEnabled": true}'
# Enable Antimalware with custom policies
# $settingString = '{
# "AntimalwareEnabled": true,
# "RealtimeProtectionEnabled": true,
# "ScheduledScanSettings": {
#                             "isEnabled": true,
#                             "day": 0,
#                             "time": 120,
#                             "scanType": "Quick"
#                             },
# "Exclusions": {
#            "Extensions": ".ext1,.ext2",
#                  "Paths":"",
#                  "Processes":"sampl1e1.exe, sample2.exe"
#             },
# "SignatureUpdates": {
#                               "FileSharesSources": "",
#                               "FallbackOrder": "",
#                               "ScheduleDay": 0,
#                               "UpdateInterval": 0,
#                       },
# "CloudProtection": true
#
# }'
# Sign in to Azure and select the subscription to use
Connect-AzAccount

Set-AzContext -SubscriptionId $subscriptionId
# Retrieve the most recent version number of the extension
$allVersions = (Get-AzVMExtensionImage -Location $location -PublisherName "Microsoft.Azure.Security" -Type "IaaSAntimalware").Version
$versionString = $allVersions[($allVersions.Count)-1].Split(".")[0] + "." + $allVersions[($allVersions.Count)-1].Split(".")[1]
# Set the extension by using prepared values
Set-AzVMExtension -ResourceGroupName $resourceGroupName -Location $location -VMName $vmName -Name "IaaSAntimalware" -Publisher "Microsoft.Azure.Security" -ExtensionType "IaaSAntimalware" -TypeHandlerVersion $versionString -SettingString $settingString

Azure Service Fabric 클러스터에 Microsoft Antimalware 추가

Azure Service Fabric은 Azure 가상 머신 스케일 세트를 사용하여 Service Fabric 클러스터를 생성합니다. Service Fabric 클러스터를 생성하는 가상 머신 스케일 세트 템플릿은 Antimalware 확장 프로그램에서는 활성화되지 않습니다. 스케일 세트에서 안티멀웨어를 별도로 활성화하세요. 스케일 세트에서 활성화하면, 가상 머신 스케일 셋 하에서 생성된 모든 노드가 자동으로 확장 기능을 상속하고 받습니다.

다음 코드 샘플은 Az.Compute PowerShell cmdlet을 사용하여 IaaS 안티멀웨어 확장 기능을 활성화하는 방법을 보여줍니다.

비고

이 코드 샘플을 실행하기 전에 변수의 주석 처리를 해제하고 적절한 값을 지정하세요.

경고

이 확장을 배포하거나 업데이트하면 제외를 포함하여 기존 Microsoft Defender 바이러스 백신 설정이 대체됩니다. 설정을 유지하려면 확장 구성에서 설정을 지정합니다. 자세한 내용은 기본 및 사용자 지정 맬웨어 방지 구성을 참조하세요.

# Script to add Microsoft Antimalware extension to a virtual machine scale set (VMSS) and Service Fabric cluster
# Sign in to Azure and select the subscription to use
Connect-AzAccount
# Specify your subscription ID
$subscriptionId="SUBSCRIPTION ID HERE"
Set-AzContext -SubscriptionId $subscriptionId
# Specify location, resource group, and VMSS for the extension
$location = "LOCATION HERE" # For example, "West US", "Southeast Asia", or "Central US"
$resourceGroupName = "RESOURCE GROUP NAME HERE"
$vmScaleSetName = "YOUR VM SCALE SET NAME"

# Customize the configuration.json configuration file according to the documentation: https://msdn.microsoft.com/library/dn771716.aspx
$settingString = '{"AntimalwareEnabled": true}'
# Enable Antimalware with custom policies
# $settingString = '{
# "AntimalwareEnabled": true,
# "RealtimeProtectionEnabled": true,
# "ScheduledScanSettings": {
#                             "isEnabled": true,
#                             "day": 0,
#                             "time": 120,
#                             "scanType": "Quick"
#                             },
# "Exclusions": {
#            "Extensions": ".ext1,.ext2",
#                  "Paths":"",
#                  "Processes":"sampl1e1.exe, sample2.exe"
#             } ,
# "SignatureUpdates": {
#                               "FileSharesSources": "",
#                               "FallbackOrder": "",
#                               "ScheduleDay": 0,
#                               "UpdateInterval": 0,
#                       },
# "CloudProtection": true
# }'

# Retrieve the most recent version number of the extension
$allVersions = (Get-AzVMExtensionImage -Location $location -PublisherName "Microsoft.Azure.Security" -Type "IaaSAntimalware").Version
$versionString = $allVersions[($allVersions.Count)-1].Split(".")[0] + "." + $allVersions[($allVersions.Count)-1].Split(".")[1]
$vmss = Get-AzVmss -ResourceGroupName $resourceGroupName -VMScaleSetName $vmScaleSetName
Add-AzVmssExtension -VirtualMachineScaleSet $vmss -Name "IaaSAntimalware" -Publisher "Microsoft.Azure.Security" -Type "IaaSAntimalware" -TypeHandlerVersion $versionString -Setting $settingString
Update-AzVmss -ResourceGroupName $resourceGroupName -VMScaleSetName $vmScaleSetName -VirtualMachineScaleSet $vmss

확장 지원을 통해 Microsoft Antimalware를 Azure Cloud Services에 추가하세요

다음 코드 샘플에서는 PowerShell cmdlet을 사용하여 확장 지원을 통해 Azure Cloud Services에 Microsoft 맬웨어 방지를 추가하거나 구성하는 방법을 보여줍니다.

비고

이 코드 샘플을 실행하기 전에 변수의 주석 처리를 해제하고 적절한 값을 지정하세요.

경고

이 확장을 배포하거나 업데이트하면 제외를 포함하여 기존 Microsoft Defender 바이러스 백신 설정이 대체됩니다. 설정을 유지하려면 확장 구성에서 설정을 지정합니다. 자세한 내용은 기본 및 사용자 지정 맬웨어 방지 구성을 참조하세요.

# Create an Antimalware extension object, where file is AntimalwareSettings
$xmlconfig = [IO.File]::ReadAllText("C:\path\to\file.xml")
$extension = New-AzCloudServiceExtensionObject -Name "AntimalwareExtension" -Type "PaaSAntimalware" -Publisher "Microsoft.Azure.Security" -Setting $xmlconfig -TypeHandlerVersion "1.5" -AutoUpgradeMinorVersion $true

# Get existing Cloud Service
$cloudService = Get-AzCloudService -ResourceGroup "ContosOrg" -CloudServiceName "ContosoCS"

# Add Antimalware extension to existing Cloud Service extension object
$cloudService.ExtensionProfile.Extension = $cloudService.ExtensionProfile.Extension + $extension

# Update Cloud Service
$cloudService | Update-AzCloudService

다음은 개인 설정 XML 파일의 예시입니다:

<?xml version="1.0" encoding="utf-8"?>
<AntimalwareConfig
    xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
    <AntimalwareEnabled>true</AntimalwareEnabled>
    <RealtimeProtectionEnabled>true</RealtimeProtectionEnabled>
    <ScheduledScanSettings isEnabled="true" day="1" time="120" scanType="Full" />
    <Exclusions>
        <Extensions>
            <Extension>.ext1</Extension>
            <Extension>.ext2</Extension>
        </Extensions>
        <Paths>
            <Path>c:\excluded-path-1</Path>
            <Path>c:\excluded-path-2</Path>
        </Paths>
        <Processes>
            <Process>excludedproc1.exe</Process>
            <Process>excludedproc2.exe</Process>
        </Processes>
    </Exclusions>
</AntimalwareConfig>

Azure Arc 지원 서버용 Microsoft 맬웨어 방지 프로그램 추가

다음 코드 샘플은 PowerShell cmdlet을 통해 Microsoft Antimalware for Azure Arc 지원 서버를 추가하는 방법을 보여줍니다.

비고

이 코드 샘플을 실행하기 전에 변수의 주석 처리를 해제하고 적절한 값을 지정하세요.

# Before you use Azure PowerShell to manage VM extensions on your hybrid server managed by Azure Arc-enabled servers, install the Az.ConnectedMachine module. Run the following command on your Azure Arc-enabled server:
# If Az.ConnectedMachine is installed, ensure the version is at least 0.4.0
Install-Module -Name Az.ConnectedMachine
Import-Module -Name Az.ConnectedMachine

# Specify location, resource group, and machine for the extension
$subscriptionid =" SUBSCRIPTION ID HERE "
$location = " LOCATION HERE " # For example, "Southeast Asia" or "Central US"
$resourceGroupName = " RESOURCE GROUP NAME HERE "
$machineName = "MACHINE NAME HERE "

# Enable Antimalware with default policies
$setting = @{"AntimalwareEnabled"=$true}
# Enable Antimalware with custom policies
$setting2 = @{
"AntimalwareEnabled"=$true;
"RealtimeProtectionEnabled"=$true;
"ScheduledScanSettings"= @{
                            "isEnabled"=$true;
                            "day"=0;
                            "time"=120;
                            "scanType"="Quick"
                            };
"Exclusions"= @{
           "Extensions"=".ext1, .ext2";
                 "Paths"="";
                 "Processes"="sampl1e1.exe, sample2.exe"
            };
"SignatureUpdates"= @{
                              "FileSharesSources"="";
                              "FallbackOrder"="";
                              "ScheduleDay"=0;
                              "UpdateInterval"=0;
                      };
"CloudProtection"=$true
}
# Sign in to Azure
Connect-AzAccount
# Enable Antimalware with the policies
New-AzConnectedMachineExtension -Name "IaaSAntimalware" -ResourceGroupName $resourceGroupName -MachineName $machineName -Location $location -SubscriptionId $subscriptionid -Publisher "Microsoft.Azure.Security" -Settings $setting -ExtensionType "IaaSAntimalware"

다음 단계