0
0

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.

Microsoft Sentinel分析ルールの紐解き(Account Created and Deleted in Short Timeframe)

Posted at

Microsoft Sentinelにおいてもともと準備されている分析ルールについてクエリの中身や注意点等を紐解いていく。

このルールは利用環境によっては過検知が多発するためチューニングが必要である。
例えば

  • 情シス部門のユーザーかつ条件付きアクセスで許可されたロケーションからの操作は検知除外する
  • 作成/削除後に別ドメインで作成し削除がない場合は検知除外する(対象ドメイン間違いというシナリオ)

である

1. ルール概要

項目 説明
重大度
ルール名 Account Created and Deleted in Short Timeframe
ルールの種類 Scheduled
ルールの頻度 1時間ごとにクエリを実行
ルールの期間 過去1日のデータ
バージョン 1.0.2
説明 ユーザー・プリンシパル・ネーム(UPN)イベントを検索します。作成された後、24時間以内に削除されたアカウントを探す。攻撃者は、自分用にアカウントを作成し、不要になった時点で削除することがあります。。(by DeepL)
Ref https://docs.microsoft.com/azure/active-directory/fundamentals/security-operations-user-accounts#short-lived-account

2. 活用するテーブル

テーブル名 概要 参考URL
AuditLogs Azure ADの監査ログ https://learn.microsoft.com/ja-jp/azure/azure-monitor/reference/tables/auditlogs

3. クエリ解説

Account Created and Deleted in Short Timeframe / version1.0.2
// 削除に関するログ調査の時間を1時間に設定する
let queryfrequency = 1h;
// 作成に関するログ調査の時間を1日に設定する
let queryperiod = 1d;
// AzureADの監査ログを対象とする
AuditLogs
// ログの生成日時が1時間以内のものに絞り込む
| where TimeGenerated > ago(queryfrequency)
// 操作名が大文字小文字問わずユーザー削除を示すログに絞り込む
| where OperationName =~ "Delete user"
//extend UserPrincipalName = tostring(TargetResources[0].userPrincipalName)
// UPNを文字列型フィールドに展開する(UPNにGUIDが含まれることがあるため、正規表現でGUIDあった場合ない場合を加味して処理している)
| extend UserPrincipalName = extract(@'([a-f0-9]{32})?(.*)', 2, tostring(TargetResources[0].userPrincipalName))
// 削除したユーザーおよび削除したユーザーのIPアドレスを文字列型フィールドにそれぞれ展開する
| extend DeletedByUser = tostring(InitiatedBy.user.userPrincipalName), DeletedByIPAddress = tostring(InitiatedBy.user.ipAddress)
// 削除したときのアプリの表示名を文字列型フィールドに展開する
| extend DeletedByApp = tostring(InitiatedBy.app.displayName)
// 削除した日時、UPN、削除したユーザー、削除したユーザーのIPアドレス、削除した際のアプリ表示名、削除した際の詳細情報等のフィールドに並び変える
| project Deletion_TimeGenerated = TimeGenerated, UserPrincipalName, DeletedByUser, DeletedByIPAddress, DeletedByApp, Deletion_AdditionalDetails = AdditionalDetails, Deletion_InitiatedBy = InitiatedBy, Deletion_TargetResources = TargetResources
// メインクエリとサブクエリの主キー(結合キー)が重複するもののみ残す
| join kind=inner (
    // AzureADの監査ログを対象とする
    AuditLogs
    // ログの生成日時が過去1日以内のものに絞り込む
    | where TimeGenerated > ago(queryperiod)
    // 操作名が大文字小文字問わずユーザー作成を示すログに絞り込む
    | where OperationName =~ "Add user"
    // UPNを文字列型フィールドに展開する
    | extend UserPrincipalName = tostring(TargetResources[0].userPrincipalName)
    // ログの日時をリネームする
    | project-rename Creation_TimeGenerated = TimeGenerated
// 結合キーをUPNに設定する
) on UserPrincipalName
// 削除から作成までの時間差を算出する
| extend TimeDelta = Deletion_TimeGenerated - Creation_TimeGenerated
// 時間差が0秒~1日以内のもののみに絞り込む
| where  TimeDelta between (time(0s) .. queryperiod)
// 作成したユーザーおよび削除したユーザーのIPアドレスを文字列型フィールドにそれぞれ展開する
| extend CreatedByUser = tostring(InitiatedBy.user.userPrincipalName), CreatedByIPAddress = tostring(InitiatedBy.user.ipAddress)
// 作成したときのアプリの表示名を文字列型フィールドに展開する
| extend CreatedByApp = tostring(InitiatedBy.app.displayName)
// 表示するフィールドを並び変える
| project Creation_TimeGenerated, Deletion_TimeGenerated, TimeDelta, UserPrincipalName, DeletedByUser, DeletedByIPAddress, DeletedByApp, CreatedByUser, CreatedByIPAddress, CreatedByApp, Creation_AdditionalDetails = AdditionalDetails, Creation_InitiatedBy = InitiatedBy, Creation_TargetResources = TargetResources, Deletion_AdditionalDetails, Deletion_InitiatedBy, Deletion_TargetResources
// エンティティに作成日時、UPN、削除した時のIPアドレスを設定する
| extend timestamp = Deletion_TimeGenerated, CustomAccountEntity = UserPrincipalName, IPCustomEntity = DeletedByIPAddress
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?