LoginSignup
1
0

GuardDutyの通知設定

Last updated at Posted at 2024-05-12

自己紹介

はじめまして、クラウドの領域に入って4~5年目のよちよちは終わったかなぐらいのエンジニアです。
今回はとある新規案件でGuardDuty周りの設定を行いましたので備忘としてこちらに投稿します。

GuardDutyとは

Amazon Web Services, Incが提供するクラウドサービスの一つ

どういったもの?

  • アカウント内での異常な操作を特定、分析し連携が可能なサービス

異常な操作って?

  • 今までアクセスしてこなかったユーザが急にs3バケットにアクセスする操作
  • CloudTrailのログ記録を無効にする操作
  • 悪意のある既知のIPとの通信
  • 通常ではないリージョンでのインフラストラクチャのデプロイ

などなど、考えただけでもちょっと寒気しますね、、、

今回は上記のような操作があった場合にメールにて連携する仕組みを設計し構築していきます。

使用するAWSサービス

  • Amazon GuardDuty
  • Amazon Simple Notification Service
  • Amazon EventBridge
  • AWS Identity and Access Management
  • AWS CloudShell

構築の流れ

以下の流れで構築をしていきます。
1.権限周りの設定
2.SNSの設定
3.EventBridgeの設定
4.GuardDutyの有効化
5.検知テスト

構成図

awsguardduty.png

AWS構築手順

1.イベントバスの作成

EventBridgeのサービスメニューからイベントバスの作成を押下します。
image.png

eventbuss名を入力し作成
image.png

この時にeventbussのARNをメモ帳に控えておきましょう

2.IAMの設定

以下の権限でポリシーを作成

ポリシー
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Action": [
                "events:PutEvents"
            ],
            "Resource": [
                "コピーしたeventbussのArn"
            ],
            "Effect": "Allow"
        }
    ]
}

以下のエンティティで作成し上記のポリシーをアタッチする

信頼されたエンティティ
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "Service": "events.amazonaws.com"
            },
            "Action": "sts:AssumeRole"
        }
    ]
}

3.SNSの設定

以下の項目を入力しトピックを作成(表示名は任意)
・タイプ:スタンダート
・名前:任意のトピックの名前
・表示名:任意のトピックの表示名
image.png

以下項目を入力しトピックを作成
・トピックARN:上記で作成したARN
・プロトコル:Eメール
・エンドポイント:通知を受信するメールアドレス
image.png

サブスクリプションを作成したら設定した受信するメールアドレスに確認メールが飛んできているはずなのでそちらからサブスクリプションを確認

4.EventBridge集約ルールの設定

以下項目を入力し次へ
・eventルールの名前:任意の名前
・説明:任意の説明
・イベントバス:上記で作成したイベントバスを選択
image.png

以下の項目を入力して次へ
・イベントソース:AWSイベントまたはEventBridgeパートナーイベント
・イベントソース:AWSのサービス
・イベントのサービス:GuardDuty
・イベントタイプ:GuardDuty Finding

image.png

以下の項目を入力して入力トランスフォーマーを設定を押下
・ターゲットタイプ:AWSのサービス
・ターゲットを選択:SNSトピック
・トピック:上記で作成したSNSトピックを選択
・ターゲット入力を設定:入力トランスフォーマー

image.png

以下項目を入力しルールを作成

入力パス
{"Account_ID":"$.detail.accountId","Finding_ID":"$.detail.id","Finding_Type":"$.detail.type","Finding_description":"$.detail.description","Resource_Type":"$.detail.resource.resourceType","region":"$.region","severity":"$.detail.severity"}
テンプレート
"AWS <Account_ID> has a severity <severity> GuardDuty finding type <Finding_Type> in the <region> region."
"Resource_Type:<Resource_Type>"
"Finding Description:"
"<Finding_description>. "
"For more details open the GuardDuty console at https://<region>.console.aws.amazon.com/guardduty/home?region=<region>#/findings?search=id%3D<Finding_ID>&macros=current"

image.png

5.EventBridge検知ルールの設定

以下項目を入力し次へ
・eventルールの名前:任意の名前
・説明:任意の説明
・イベントバス:defaultを選択
image.png

以下の項目を入力して次へ
・イベントソース:AWSイベントまたはEventBridgeパートナーイベント
・イベントソース:AWSのサービス
・イベントのサービス:GuardDuty
・イベントタイプ:GuardDuty Finding

image.png

以下項目を入力してルールを作成
・ターゲットタイプ:EventBridgeのイベントバス
・ターゲットタイプ:同じアカウントとリージョン内のイベントバス
・ターゲットとしてのイベントバス:上記で作成しているイベントバスを選択
・実行ロール:既存のロールを使用
・ロール名:上記で作成しているロールを選択

image.png

6.GuardDutyの有効化

GuardDutyのサービスページに移動し今すぐ有効化を押下
image.png

GuardDutyを有効化するを押下
image.png

7.検知テスト

CloudShellに以下コマンドを投入

AWS CLI
aws guardduty create-sample-findings \
  --detector-id $(aws guardduty list-detectors --query 'DetectorIds[0]' --output text) \
  --finding-types "Backdoor:EC2/DenialOfService.Dns"

以下のメールが届けば完了

mail
"AWS ACCOUNT NUMBER has a severity 8 GuardDuty finding type Backdoor:EC2/DenialOfService.Dns in the ap-northeast-1 region."
"Resource_Type:Instance"
"Finding Description:"
"The EC2 instance i-99999999 is behaving in a manner that may indicate it is being used to perform a Denial of Service (DoS) attack using the DNS protocol.. "
"For more details open the GuardDuty console at https://ap-northeast-1.console.aws.amazon.com/guardduty/home?region=ap-northeast-1#/findings?search=XXXXXXXXXXXXXXXXXXXXXXXXX"

8.IaCについて

別の記事にてアップします。

以下参考

https://docs.aws.amazon.com/ja_jp/guardduty/latest/ug/what-is-guardduty.html
https://dev.classmethod.jp/articles/create-a-single-sample-findings-in-guardduty/

1
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
1
0