5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Linux用 Microsoft Defender for Endpointを使ってリアルタイムスキャン/PUA検知/脆弱性スキャンを実現する

Posted at

はじめに

Linux用MicrosoftDefender for Endpointにはマルウェア対策とエンドポイント検出と応答(EDR)機能が含まれています。今回はこれを試そうと思います。マルウェア検知に関しては、いつもどうするかなーと頭を悩ましているのですが一つの選択肢になりそうです。

今回はこんなことをやっていこうと思います。

  1. Defender for Endpointを有効化
  2. マルウェアのリアルタイムスキャンの有効化&テストウィルスファイルを使って検知させる
  3. PUA検出の有効化&テスト用PUAファイルを使って検知させる
  4. 脆弱性検査

ちなみに大変ややこしいのですが、Defender for Cloudの一つがDefender for Serversとなり、これがDefender for Endpoint for Serversのライセンスを含むことからこの機能を利用できるようです。

Defender for Cloudを有効にする

Defender for Cloudを有効にする

Untitled.png

デフォルトだと全部ONになってしまうので不要なものはオフに設定する

Untitled 1.png

今回はDefender for Endpointが利用したいので、プラン1を選択した

Untitled 2.png

インストール要件を確認

今回はUbuntu20.04を利用することにしました。Redhatなどももちろん利用可能です。

その他ハードウェアの要件についても記載があるので確認します。

接続先のネットワークはこちらを確認。ブロックされていないことを確認する。

mdatpをインストールしていく(Ubuntu20.04の場合)

Linuxサーバ内ではmdatpというデーモンが起動してこれがウィルス検知などの役割を負います。

ドキュメントには色々書いてありますが、以下のコマンドをコピペして貼ってください。

sudo apt update
sudo apt install libplist-utils
curl -o microsoft.list https://packages.microsoft.com/config/ubuntu/22.04/prod.list
sudo mv ./microsoft.list /etc/apt/sources.list.d/microsoft-prod.list
sudo apt install gpg
curl -sSL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/microsoft.gpg > /dev/null
sudo apt install apt-transport-https
sudo apt update
sudo apt install mdatp

サービスの起動を確認しておきます

$ sudo service mdatp status
● mdatp.service - Microsoft Defender
     Loaded: loaded (/lib/systemd/system/mdatp.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2023-02-06 06:18:59 UTC; 1 day 18h ago
   Main PID: 3612 (wdavdaemon)
      Tasks: 159 (limit: 4095)
     Memory: 539.9M
     CGroup: /system.slice/mdatp.service
             ├─  3612 /opt/microsoft/mdatp/sbin/wdavdaemon
             ├─  3636 /opt/microsoft/mdatp/sbin/wdavdaemon edr 10 9 --log_level info
             ├─179408 /opt/microsoft/mdatp/sbin/wdavdaemon unprivileged 62 64 66 68 19 --log_level info
             └─200556 /opt/microsoft/mdatp/sbin/telemetryd_v2 33"

Feb 06 06:18:59 vm-plat-ubuntu2004 systemd[1]: mdatp.service: Succeeded.
Feb 06 06:18:59 vm-plat-ubuntu2004 systemd[1]: Stopped Microsoft Defender.
Feb 06 06:18:59 vm-plat-ubuntu2004 systemd[1]: Started Microsoft Defender.
Feb 07 22:42:13 vm-plat-ubuntu2004 wdavdaemon[3636]: avc:  could not determine enforcing mode: No such file or directory

オンボーディング

mdatp healthコマンドを実行するとライセンスがない旨出力されると思います。

これを解消するには、DefenderポータルにあるPythonスクリプトをダウンロードして実行してライセンスを付与する必要があります。これをオンボーディングと言います。

$ mdatp health --field healthy
false

まずはDefenderポータルを開く

Sign in to your account

[設定] [エンドポイント] > [デバイス管理>] [オンボード] >の順に移動

Untitled 3.png

スクリプトをダウンロードして実行します。

$ sudo python MicrosoftDefenderATPOnboardingLinuxServer.py
Generating /etc/opt/microsoft/mdatp/mdatp_onboard.json ...

IDが取得できることを確認する

$ mdatp health --field org_id
"aacebf9a-98bf-4f22-8a66-dfc3c8b61c3c"

healthyもtrueになることを確認する

$ mdatp health --field healthy
true

これで準備はOKです。早速動作確認していきます。

動作確認

リアルタイムスキャンがどうなっているか確認します。

mdatp health --field real_time_protection_enabled

falseが表示されている場合は有効化します。

mdatp config real-time-protection --value enabled

この状態で脅威がないことを確認する

$ mdatp threat list
No threats.

テスト用のファイルをダウンロード

  • EICARというファイルはテスト用のウィルスファイルです(安全です)
$ curl -o /tmp/eicar.com.txt https://www.eicar.org/download/eicar.com.txt
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    68  100    68    0     0     53      0  0:00:01  0:00:01 --:--:--    53

すぐ脅威が検出可能

$ mdatp threat list
Id: "60194780-0aaf-49c3-8aba-8b709aea9c75"
Name: Virus:DOS/EICAR_Test_File
Type: "virus"
Detection time: Tue Feb  7 08:26:49 2023
Status: "quarantined"

Defenderポータルにもデバイスが表示される

Untitled 4.png

アラートタブを見ると先ほどのEICARが表示されてる!

Untitled 5.png

通知するには?

Defenderポータル→設定→エンドポイントから設定します。

Untitled 6.png

もういちどEICARをダウンロードして、検知させてみるとメールが飛んでくることが確認できると思います。

Untitled 7.png

更新

Linux用のDefender for Endpointの各バージョンには有効期限があり、Updateする必要がある。更新されないと止まってしまうので注意が必要です。

有効期限を調べるには以下のコマンドを実行する

$ mdatp health --field product_expiration
Sep 16, 2023 at 05:17:54 PM

Updateはコマンド一発(今回は最新だったので更新されなかった模様)

$ sudo apt install --only-upgrade mdatp
Reading package lists... Done
Building dependency tree       
Reading state information... Done
mdatp is already the newest version (101.94.13).
0 upgraded, 0 newly installed, 0 to remove and 9 not upgraded.

ご丁寧にcronの設定方法まで記載されていました。ただ、失敗時の対応が書かれていませんのでログの監視や有効期限の監視は行っておいたほうがよさそうです。

推奨される構成プロファイル

mdatpには設定ファイルがあり、これを修正することで様々な機能を利用することができます

設定ファイルを修正した場合、デーモンの再起動は必要ないようです。(参考

$ sudo cat /etc/opt/microsoft/mdatp/managed/mdatp_managed.json
{
   "antivirusEngine":{
      "enforcementLevel":"real_time",
      "threatTypeSettings":[
         {
            "key":"potentially_unwanted_application",
            "value":"block"
         },
         {
            "key":"archive_bomb",
            "value":"audit"
         }
      ]
   },
   "cloudService":{
      "automaticDefinitionUpdateEnabled":true,
      "automaticSampleSubmissionConsent":"safe",
      "enabled":true
   }
}

推奨される構成プロファイルはこちらに記載がありました

PUA保護(potentially_unwanted_application)

ウイルス、マルウェア、またはその他の種類の脅威とは見なされませんが、パフォーマンスや使用に悪影響を与える可能性があるアプリケーションをブロックしたりできます。

既定では何もしませんが、推奨される構成プロファイルではブロックされているのでこれの動作検証をしていきます。

セキュリティ製品のテスト標準化団体 AMSTO (Anti-Malware Testing Standards Organization)がテスト用のファイルを配布しているのでこちらから入手します。

PUA保護が有効になっているVMでwgetしてみましょう

wget http://amtso.eicar.org/PotentiallyUnwanted.exe

ちゃんとPUAとして検知されました。

$ mdatp threat list
Id: "4a6d516c-5e18-46b5-b890-517fc3a4d568"
Name: PUA:Win32/EICAR_Test_File
Type: "potentially_unwanted_application"
Detection time: Wed Feb  8 01:49:39 2023
Status: "quarantined"

脆弱性検知

なんと脆弱性検知もできます・・・。mdatpをインストール後しばらくたつと在庫というところでパッケージのリストが表示されました。

Untitled 8.png

しばらくたつと「弱点」というところに脆弱性の一覧が表示されました。CVSSのスコアなんかも表示されます。

Untitled 9.png

ちなみにこれも設定→エンドポイント→メール通知から通知の設定を行うことができます。すっご・・・。

届いたメールがこちら

Untitled 10.png

View recommendationsを選択すると何をしたらよいか教えてくれます

Untitled 11.png

ついでにパッケージを更新してみます。まずはupgradeできるか確認します

おお。。。ドンピシャ。

$ sudo apt list --upgradable
Listing... Done
libssl1.1/focal-updates,focal-security 1.1.1f-1ubuntu2.17 amd64 [upgradable from: 1.1.1f-1ubuntu2.16]
openssl/focal-updates,focal-security 1.1.1f-1ubuntu2.17 amd64 [upgradable from: 1.1.1f-1ubuntu2.16]

ということでアップグレードしてみます

$ sudo apt upgrade
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
The following packages will be upgraded:
  libssl1.1 openssl
2 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
2 standard LTS security updates
Need to get 1944 kB of archives.
After this operation, 4096 B of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://azure.archive.ubuntu.com/ubuntu focal-updates/main amd64 libssl1.1 amd64 1.1.1f-1ubuntu2.17 [1322 kB]
Get:2 http://azure.archive.ubuntu.com/ubuntu focal-updates/main amd64 openssl amd64 1.1.1f-1ubuntu2.17 [622 kB]
Fetched 1944 kB in 0s (29.1 MB/s)
Preconfiguring packages ...
(Reading database ... 68954 files and directories currently installed.)
Preparing to unpack .../libssl1.1_1.1.1f-1ubuntu2.17_amd64.deb ...
Unpacking libssl1.1:amd64 (1.1.1f-1ubuntu2.17) over (1.1.1f-1ubuntu2.16) ...
Preparing to unpack .../openssl_1.1.1f-1ubuntu2.17_amd64.deb ...
Unpacking openssl (1.1.1f-1ubuntu2.17) over (1.1.1f-1ubuntu2.16) ...
Setting up libssl1.1:amd64 (1.1.1f-1ubuntu2.17) ...
Setting up openssl (1.1.1f-1ubuntu2.17) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.9) ...

しばらくすると脆弱性の推奨事項からも消えました。

推奨事項の一覧から修正を依頼したりすることもできるようで至れり尽くせりでした。

その他

Plan2独自の機能も存在するようです。プランの比較はこちらをどうぞ

5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?