AzureのAntimalware対応

ちょっと前にAzure用Microsoft AntimalwareがGAしました。ので今日はその辺さらっと見ておきます。

Microsoft Antimalwareはそのまんま名前の通りOSをウィルスだったり不正なアプリから保護してくれるアプリです。Azure対応ということで、クラウドサービスと仮想マシンで使うことができます。

詳細はこちらのホワイトペーパーをどうぞ(直リン) → Microsoft Antimalware white paper

GA当初(10月3日)、ホワイトペーパーをざっとみてクラウドサービスの場合はSDK使うのかなー(と図を見て)と思ったのですがそんなことはなかったです。結局、クラウドサービスも仮想マシンもAzure PowerShellを使って構成する感じでした。

Microsoft Antimalwareの構成

クラウドサービス、仮想マシンともに何も指定しなければ既定の設定が利用されます。設定内容については以下の表を参照。

 

設定 オプション 既定値 詳細
AntimalwareEnabled true / false none trueの場合有効。falseはノンサポート(何それ)
Exclusions Extensions extension1,extension2,… none スキャンから除外する拡張子(.logなど)を記述
Exclusions Paths path1,path2 none スキャンから除外するファイル・フォルダのパス
Exclusions Processes process1,process2,… none スキャンから除外するプロセス(のパス)。指定したプロセスが触るファイル等はスキャン対象から除外されます
Monitoring On/Off none Onの場合Azure診断v1.1を使ってマルウェア対策の監視が有効
StorageAccountName ストレージアカウント名 none Antimalware関連のヘルスとイベント情報を指定したAzure StorageアカウントのTableにキャプチャする
RealtimeProtectionEnabled true / false true trueの場合リアルタイムスキャンする
ScheduledScanSettings isEnabled true / false none trueの場合スケジュールスキャンする
ScheduledScanSettings Day 0 – 8 7 0…毎日, 1…日曜日 ,, 7…土曜日, 8…無効
指定曜日にスケジュールスキャンする(スケジュールスキャンが有効な場合)
ScheduledScanSettings Time 0 – 1440 120 スケジュールスキャンする時刻
60 … AM1:00
120 … AM2:00
1380 … PM11:00
scanType Quick / Full Quick スケジュールスキャンする場合の種類

カスタム構成にするにはXMLファイルを作成して後述のCmdletで指定してあげます。

例:

<AntimalwareConfig>
<!--    AntimalwareEnabled: true/false. Note - This is a required parameter: 
        Values: true = Enable. false = Error out as false is not a supported value. 
        Note: true/false values are case sensitive and must be lowercase -->
    <AntimalwareEnabled>true</AntimalwareEnabled> 

<!--    RealtimeProtectionEnabled: true/false. Default is true.
        Values: true = Enable. false = Disable. 
        Note: true/false values are case sensitive and must be lowercase-->
    <RealtimeProtectionEnabled>true</RealtimeProtectionEnabled>     
    
<!--    ScheduledScanSettings: By Default, ScheduledScan is Disabled
        Values: isEnabled="true/false" Note: true/false values are case sensitive and must be lowercase
        day="0-8" [0-daily, 1-Sunday, 2-Monday, ...., 7-Saturday, 8-Disabled]
        time="0-1440" (measured in minutes after midnight)
        scanType="Quick/Full" (Default is Quick - values are case sensitive and first letter must be uppercase). 
        If isEnabled="true" is the only setting provided, the following defaults are set - day="7" (Saturday), time="120" (2 AM), scanType="Quick" -->
    <ScheduledScanSettings isEnabled="false" day="8" time="0" scanType="Quick" /> 
<!--    Exclusions: If no Exclusions are specified below, then the existing exclusions, if any, are overwritten by blank on the system. By Default, there are NO Exclusions -->
    <Exclusions> 
        <Extensions>
<!-- Specify Extension exclusions as .txt, .log etc. Each excluded file extension should be added as a separate row element value-->
<Extension>.log</Extension> 
<Extension>.txt</Extension> 
        </Extensions>
        <Paths>
<!-- Specify Path exclusions as E:\, F:\ etc. Each excluded path should be added as a separate row element value -->
<Path></Path> 
        </Paths>
        <Processes>
<!-- Specify Process exclusions as foo.exe etc. Each excluded path should be added as a separate row element value -->
<Process></Process> 
        </Processes>
    </Exclusions>
<!--    Monitoring: ON/OFF. Antimalware monitoring can be specified here or as a cmdlet parameter to the antimalware PowerShell cmdlet if you wish to enable antimalware monitoring. By default, monitoring is OFF
        Values: ON = Antimalware monitoring is turned ON to collect events into user storage. OFF = Antimalware monitoring is turned OFF &amp; events are not collected -->
    <Monitoring>ON</Monitoring> 
<!--    Storage account name must be specified here or as a cmdlet parameter to the antimalware PowerShell cmdlet to enable antimalware monitoring-->
    <StorageAccountName></StorageAccountName>
</AntimalwareConfig>

まぁコメントみればわかるでしょう。

 

クラウドサービスの場合

クラウドサービスの場合はデプロイ後に Set-AzureServiceAntimalwareExtension を使って設定します。

※前述の設定を使う場合、XmlDocumentで指定する必要があるので読み込んでおきます。

 $antimalwareconfig = [xml](Get-Content "config.xml")

使い方は簡単です。サービス名とか必要に応じてスロット(Production/Staging)とかロール名とかも指定します。※Get-Helpしてね

実行例:設定とストレージ(モニタリングの吐き出し用)を指定する場合

> $antimalwareconfig = [xml](Get-Content ".\config.xml")
> $key = Get-AzureStorageKey -StorageAccountName ストレージ名
> $storagecontext = New-AzureStorageContext -StorageAccountName ストレージ名 -StorageAccountKey $key.Primary
> Set-AzureServiceAntimalwareExtension -ServiceName サービス名 -StorageContext $storagecontext -AntimalwareConfiguration $antimalwareconfig

OperationDescription          OperationId                  OperationStatus
--------------------          -----------                  ---------------
Set-AzureServiceAntimalwar... ad58afa2-5057-1bdf-8b4d-9... Succeeded

実行するとデプロイがビジーになる感じです。(設定終わるまでcmdletも終わりません)

Get-AzureServiceAntimalwareConfig すると設定している内容が見えます。

C:\bin\Console2> Get-AzureServiceAntimalwareConfig -ServiceName クラウドサービス名


Role                 : Default
Extension            : PaaSAntimalware
ProviderNameSpace    : Microsoft.Azure.Security
Version              :
Id                   : Default-PaaSAntimalware-Production-Ext-0
PublicConfiguration  : <AntimalwareConfig><AntimalwareEnabled>true</AntimalwareEnabled>
                       <RealtimeProtectionEnabled>true</RealtimeProtectionEnabled><Sche
                       duledScanSettings isEnabled="false" day="8" time="0" scanType="Q
                       uick" /><Exclusions><Extensions><Extension>.log</Extension><Exte
                       nsion>.txt</Extension></Extensions><Paths><Path></Path></Paths><
                       Processes><Process></Process></Processes></Exclusions></Antimalw
                       areConfig>
OperationDescription : Get-AzureServiceAntimalwareConfig
OperationId          : 3b53a61c-8768-131b-a4b3-d4fe6953d37e
OperationStatus      : Succeeded

Role                 : Default
Extension            : PaaSDiagnostics
ProviderNameSpace    : Microsoft.Azure.Diagnostics
Version              :
Id                   : Default-PaaSDiagnostics-Production-Ext-0
PublicConfiguration  : <PublicConfig xmlns="http://schemas.microsoft.com/ServiceHosting
                       /2010/10/DiagnosticsConfiguration">
                         <WadCfg>
                           <DiagnosticMonitorConfiguration>
                             <WindowsEventLog scheduledTransferPeriod="PT1M">
                               <DataSource name="System!*[System[Provider[@Name='Micros
                       oft Antimalware']]]" />
                             </WindowsEventLog>
                           </DiagnosticMonitorConfiguration>
                         </WadCfg>
                         <StorageAccount>azselfstudy01</StorageAccount>
                       </PublicConfig>
OperationDescription : Get-AzureServiceAntimalwareConfig
OperationId          : 3b53a61c-8768-131b-a4b3-d4fe6953d37e
OperationStatus      : Succeeded

インスタンス上でみてもちゃんとインストールされていますね

image

さてさてテストですが例によってEICARテストファイルを使います。

適当に.cmdファイルとか作って中身を貼り付けて保存すると…ファイルがきえました。Microsoft Antimalwareの動作はイベントログに出るので見てみましょう。

image

ばっちりですね。AzureストレージTableにも転送するように設定したので、ちゃんとTableのWADWindowsEventLogsTableにも出力されています。

image

クラウドサービスの場合、パッケージに含める感じでは無いのでデプロイと一緒にMicrosoft Antimalwareが構成されるようにPowerShellなりでスクリプト組んじゃうのがいいでしょう。もうちょっとお手軽になることを期待したいところ。

仮想マシンの場合

仮想マシンの場合、既定値でよければポータル上のウィザードで作成する際にMicrosoft Antimalwareの拡張機能にチェックを付けるだけです。

image

拡張機能となっているので、Azure PowerShellで指定する場合も Set-AzureVMExtension Set-AzureVMMicrosoftAntimalwareExtension で指定するだけのお手軽さです。

仮想マシンへのMS Antimalwareを追加する場合は今のところWordのドキュメント見るより、以下のCmdletの説明みたほうがいいかも

こちらのCmdletを使います。パラメーターでもろもろ指定できますが、クラウドサービスの時のXMLのようにJSON形式でカスタム設定を指定することもできます。

JSONファイルの例:

{
	"AntimalwareEnabled": true, 
	"RealtimeProtectionEnabled": true, 
	"ScheduledScanSettings": {
		"isEnabled": false, 
		"day": 8, 
		"time": 0, 
		"scanType": "Quick"
	},
	"Exclusions": {
		"Extensions": ".log;.txt"
	}
}

実行例:

(Get-AzureVM -ServiceName サービス名 -Name インスタンス名) | Set-AzureVMMicrosoftAntimalwareExtension -AntimalwareConfigFile '.\config.json' | Update-AzureVM

JSONの文字列のまま渡す場合は ?AntimalwareConfiguration に渡します。他もろもろあるので詳細はMSDNのドキュメントみてください。

しばらくするとインスタンスへMS Antimalware拡張がインストールされます。ポータルで見ても準備完了ですね。

image

 

※2014/10/08 追記。間違ってたので以下は削除。

クラウドサービスの場合と違う点としてはXMLの設定ファイルの取り扱いと、AzureストレージTableにログを吐き出す場合、追加でDiagnosticsの拡張機能も有効化する必要があるぐらいでしょうか。

Set-AzureVMExtensionで設定を渡す場合、Base64でエンコードした文字列にする必要があります。(このへん統一感があまりない)
こんな感じで。

$ms_antimalware_xml_config = Get-Content ".\config.xml"
$ms_antimalware_b64_config = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($ms_antimalware_xml_config))
$ms_antimalware_public_config = [string]::Format("{{""xmlCfg"":""{0}""}}",$ms_antimalware_b64_config)

$ms_antimalware_public_config をSet-AzureVMExtension のPublicConfigurationパラメーターに渡します。

ちなみにExtension名とかはこんな感じです

Publisher                   : Microsoft.Azure.Security
ExtensionName               : IaaSAntimalware
Version                     : 1.1
Label                       : Microsoft Antimalware
Description                 : Microsoft Antimalware
PublicConfigurationSchema   :
PrivateConfigurationSchema  :
IsInternalExtension         : False
SampleConfig                : {"PublicConfig":"{\"AntimalwareEnabled\":true}","PrivateC
                              onfig":null}
ReplicationCompleted        : True
Eula                        : http://azure.microsoft.com/en-us/support/legal/subscripti
                              on-agreement/
PrivacyUri                  : http://azure.microsoft.com/en-us/support/legal/privacy-st
                              atement/
HomepageUri                 : http://go.microsoft.com/fwlink/?LinkId=398023
IsJsonExtension             : True
DisallowMajorVersionUpgrade : False
SupportedOS                 :
PublishedDate               : 2014/09/12 11:10:17
CompanyName                 : Microsoft Corporation

バージョン変わったりすると面倒なのでこんな感じでExtension取得してからSet-AzureVMExtensionにつっこめばいいんじゃないでしょうか。

$antimalwareextension = Get-AzureVMAvailableExtension -Publisher "Microsoft.Azure.Security" -ExtensionName "IaaSAntimalware"
Set-AzureVMExtension -ExtensionName $antimalwareextension.ExtensionName -Publisher $antimalwareextension.Publisher -Version $antimalwareextension.Version

まとめるとこんな感じでVM取得して最後にUpdate-VMする感じです。新規の時でも他のExtensionと同じように指定できると思います。

 

(Get-AzureVM -ServiceName サービス名 -Name マシン名) | Set-AzureVMExtension -ExtensionName $antimalwareextension.ExtensionName -Publisher $antimalwareextension.Publisher -Version $antimalwareextension.Version -PublicConfiguration $ms_antimalware_public_config | Update-AzureVM

 

めでたしめでたし!と思ったら、何やってもAntimalwareEnabledにtrueが指定されていませんとかいうエラーが出て動かないです。謎。設定が悪いのかなと思ってあれこれ試してみたりしましたが、なんかまともに見てくれてない様子。。。仮想マシンはカスタムの設定なしでとりあえず構成しとくのが無難な気がします。

 

まとめ

とりあえずクラウドサービスや仮想マシンを何かしら保護したい場合はいいかもしれません。3rd PartyのDeepSecurityとかもありますが追加料金いりませんし。

Webアプリの場合でユーザーからファイルを受け取る場合は、一度ファイルシステム上にファイルを保存すればリアルタイムスキャンしてくれるのでより安全にできるかと思います。(ただいきなり消えるので消えたことを検知したり、厳密にはイベントログで削除されたのを確認したほうがいいですが)

コメントを残す

以下に詳細を記入するか、アイコンをクリックしてログインしてください。

WordPress.com ロゴ

WordPress.com アカウントを使ってコメントしています。 ログアウト /  変更 )

Facebook の写真

Facebook アカウントを使ってコメントしています。 ログアウト /  変更 )

%s と連携中