🔖

【初心者向け】Aamazon GuardDuty 入門!完全ガイド

2024/01/24に公開

Amazon GuardDuty

☘️ はじめに

本ページは、AWS に関する個人の勉強および勉強会で使用することを目的に、AWS ドキュメントなどを参照し作成しておりますが、記載の誤り等が含まれる場合がございます。

最新の情報については、AWS 公式ドキュメントをご参照ください。

👀 Contents

Duration: 00:01:00

GuardDuty とは

Duration: 0:46:52

AWS 環境のセキュリティを継続的にチェックしてくれるサービスです。

【AWS Black Belt Online Seminar】Amazon GuardDuty(YouTube)(0:46:52)

blackbelt-guardduty

【AWS Black Belt Online Seminar】Amazon GuardDuty Malware Protection(YouTube)(0:43:53)

blackbelt-guardduty-malware

Amazon GuardDuty サービス概要

Amazon GuardDuty ドキュメント

Amazon GuardDuty よくある質問

Amazon GuardDuty の料金

GuardDuty が必要な理由

Duration: 0:01:30

Well-Architected フレームワークという考え方のうち、「セキュリティの柱」に、「発見的統制」というものがあります。

これは、セキュリティインシデントが発生しても通知するようにしておき対応する、というものです。

自力で検知を組み込むのは大変な事ですが、これを自動的に検知して通知してくれるのが Amazon GuardDuty ですので、有効化しておくとよいです。

特徴

Duration: 0:00:30

  • 30 日間は無料
  • AWS アカウントレベルで検出
  • GuardDuty はリージョンサービス
  • 全てのリージョンで有効化することを推奨
    • 全リージョンで有効化するには、CLI や CDK などで効率化する

全リージョンで有効化するには

AWS CLI を使う場合

#!/usr/bin/sh
# リージョン一覧の取得
REGIONS=$( \
    aws ec2 describe-regions \
        --all-regions \
        --query "Regions[].RegionName" \
        --output text \
        --profile ${profileName} \
    )
for region in ${REGIONS[@]}; do
  # 有効化の確認
  DETECTOR=$( ¥
        aws guardduty list-detectors \
        --region "${REGION}" \
        --query DetectorIds \
        --output text \
        )
  if [ "${#DETECTOR}" -ne "0" ] ; then
      # 既に有効化されている
      echo "GuardDuty is already enabled. ${REGION}:${DETECTOR}"
  else
      # finding-publishing-frequency は指定しないとデフォルト 6h
      aws guardduty create-detector \
        --region "${REGION}" \
        --finding-publishing-frequency FIFTEEN_MINUTES \
        --enable \
        --profile ${profileName}
  fi
done

AWS CDK を使う場合

# YAML のパラメータファイルに以下を定義
# import * as yaml from 'js-yaml'; で読み込んでいます。
# ---------
# ForceEnabled : true # それぞれの設定に関係なく強制的に有効化する場合 true
# RegionConfigs :
#  -  { Region: 'us-east-1' , isEnabled: false } # 米国東部(バージニア北部)
#  -  { Region: 'us-east-2' , isEnabled: false } # 米国東部 (オハイオ)
#  -  { Region: 'us-west-1' , isEnabled: false } # 米国西部 (北カリフォルニア)
#  :

RegionConfigs.forEach((x) => {
  if (x.isEnabled || isForceEnabled) {
    new GuardDutyStack(app, `GuardDutyStack${x.Region}`, {
      :
      :
      env : {
        account: process.env.CDK_DEFAULT_ACCOUNT,
        region: x.Region,
      }
    }
  }
}

脅威検出

Duration: 0:01:00

ログなどから脅威を検出する機能です。検出する機能なので、通知するには EventBridge と SNS を利用する必要があります。(GuardDuty の検出結果を通知する CloudWatch Events ルールの作成

検出結果
result
result-detail

EventBridge のイベントパターン指定例
event-pattern

検出結果タイプ

Duration: 0:01:30

GuardDuty を有効化したときにデフォルトで次のログを検査します。CloudTrail の有効化や VPC Flow logs や DNS ログの設定がされていなくても GuardDuty によって個別に取得されます。
ただし、調査などの理由から各サービスのログも有効化しておくのを推奨します。

これ以外に、個別のサービスに対するモニタリングを有効/無効にすることができます。詳細は 検出結果タイプ を参照してください。

  • EKS Protection
  • Lambda Protection
  • RDS Protection
  • S3 Protection

plan

信頼および脅威 IP アドレスリスト

信頼できる IP リストと 脅威リストの使用

IP アドレスまたは CIDR によって脅威の検出を制御できます。

  • 信頼されている IP リスト(Trusted IP lists)
    • このリストに指定したものを脅威として検出しなくなります。セキュリティテストを行うサーバの IP を指定しておくといったケースが考えられます。
  • 脅威 IP リスト(Threat IP lists)
    • 既にある AWS の脅威リストを補完するもので、ユーザーが個別に指定できます。

ip-list

信頼と脅威に同じものを指定した場合は、信頼リストのほうの判定が優先され、脅威対象と見なされなくなるので注意が必要です。

マルウェア検知

Duration: 0:03:00

インスタンスで動作しているマルウェアを検出できます。
通常、サードパーティ製のマルウェア検知ソフトの場合、インスタンスにエージェントをインストールしなければならないが、GuardDuty を使えばエージェントレスでマルウェアを検知できます。
チェック対象の EC2 にアタッチされた EBS はスナップショットが取得され、そのスナップショットから、DuardDuty が動作する 別の AWS アカウントに EBS が複製され、チェックを実行する  EC2 にアタッチされて検査されます。

malware-scan

このため、チェック対象のインスタンスにエージェントのインストールが不要になります。

スキャンの方法は 2 種類あります。

注意事項

  • 現時点では「スキャンはするが保護、隔離などは実施しない」ので、簡易的なチェックです。Deep Security や Cloud One などのように予防的な対策を行ってくれるものではありません。
  • スキャン実施時に、一時的とはいえ別の AWS アカウントに EBS が複製されます。スキャン対象の EBS に機密データが含まれるような場合、利用可否をしっかり検討してください。

検出結果通知

Duration: 0:05:00

検出結果通知は、GuardDuty から Amazon EventBridge に発信されるイベントを検出し、SNS と連携することで実現できます。

GuardDuty から 発信される 検出結果の詳細 は次のようになります。

        {
         "version": "0",
         "id": "cd2d702e-ab31-411b-9344-793ce56b1bc7",
         "detail-type": "GuardDuty Finding",
         "source": "aws.guardduty",
         "account": "111122223333",
         "time": "1970-01-01T00:00:00Z",
         "region": "us-east-1",
         "resources": [],
         "detail": {GUARDDUTY_FINDING_JSON_OBJECT}
        }

上記のようなイベントを検出できるように、EventBridge のイベントパターンを定義します。定義の雛形は次のとおりです。

{
  "source": [
    "aws.guardduty"
  ],
  "detail-type": [
    "GuardDuty Finding"
  ],
  "detail": {
    "severity": [
      :
    ]
  }
}

通知対象を限定せずに設定を行うと大量のメールが送信される可能性があるため注意が必要です。

[Medium] (中)〜[High] (高) を検出するイベントパターンの例は次のとおりです。

{
  "source": ["aws.guardduty"],
  "detail-type": ["GuardDuty Finding"],
  "detail": {
    "severity": [
      4, 4.0, 4.1, 4.2, 4.3, 4.4, 4.5, 4.6, 4.7, 4.8, 4.9, 5, 5.0, 5.1, 5.2,
      5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 5.9, 6, 6.0, 6.1, 6.2, 6.3, 6.4, 6.5, 6.6,
      6.7, 6.8, 6.9, 7, 7.0, 7.1, 7.2, 7.3, 7.4, 7.5, 7.6, 7.7, 7.8, 7.9, 8,
      8.0, 8.1, 8.2, 8.3, 8.4, 8.5, 8.6, 8.7, 8.8, 8.9
    ]
  }
}

severity は GuardDuty で定義されている重要度レベルを示しており、数値と重要度は以下の通りです。

  • 高: 7.0〜8.9 の範囲
  • 中: 4.0〜6.9 の範囲
  • 低: 0.1〜3.9 の範囲

または、次のようにも定義できます。

{
  "source": ["aws.guardduty"],
  "detail-type": ["GuardDuty Finding"],
  "detail": {
    "severity": [{ "numeric": [">=", 4] }]
  }
}

このまま通知すると、JSON 形式の可読性の低いものになりますので、インプットトランスフォーマー機能をつかって、整形します。

transform-target-input

”入力パス” で定義する項目は、次を参考にします。

入力パス

{
  "severity": "$.detail.severity",
  "Account_ID": "$.detail.accountId",
  "Finding_ID": "$.detail.id",
  "Finding_Type": "$.detail.type",
  "region": "$.region",
  "Finding_description": "$.detail.description"
}

入力テンプレート

"AWS <Account_ID> has a severity <severity> GuardDuty finding type <Finding_Type> in the <region> region."
"Finding Description:"
"<Finding_description>. "
"For more details open the GuardDuty console at https://console.aws.amazon.com/guardduty/home?region=<region>#/findings?search=id%3D<Finding_ID>"

検出結果の確認

通知のテストを行うために、サンプルイベントの発行機能があります。GuardDuty のコンソールから実行することでサンプルイベントを発行できます。

GuardDuty のサンプルの検出結果生成

result-sample

サンプルが簡単に生成できるのは便利ですが、様々な検出結果タイプのサンプルイベントを生成するため、通知が大量に配信されます。

AWS CLI を使うことで 1 件ずつイベントを発行できます。

# 重要度「高」
# EC2 インスタンスが、TCP ポートで UDP プロトコルを使用したサービス拒否 (DoS) 攻撃の実行に利用されている可能性があります。
# https://docs.aws.amazon.com/ja_jp/guardduty/latest/ug/guardduty_finding-types-ec2.html#backdoor-ec2-denialofserviceudpontcpports
aws guardduty create-sample-findings \
--detector-id $(aws guardduty list-detectors --query 'DetectorIds' --output text) \
--finding-types Backdoor:EC2/DenialOfService.UdpOnTcpPorts
# 重要度「中」
# EC2 インスタンスがポート 25 でリモートホストと通信して異常な動作を示しています
# https://docs.aws.amazon.com/ja_jp/guardduty/latest/ug/guardduty_finding-types-ec2.html#backdoor-ec2-spambot
aws guardduty create-sample-findings \
  --detector-id $(aws guardduty list-detectors --query 'DetectorIds[0]' --output text) \
  --finding-types "Backdoor:EC2/Spambot"
# 重要度「低」
# EC2 インスタンスが SSH ブルートフォース攻撃に巻き込まれています。
# https://docs.aws.amazon.com/ja_jp/guardduty/latest/ug/guardduty_finding-types-ec2.html#unauthorizedaccess-ec2-sshbruteforce
aws guardduty create-sample-findings \
  --detector-id $(aws guardduty list-detectors --query 'DetectorIds[0]' --output text) \
  --finding-types "UnauthorizedAccess:EC2/SSHBruteForce"

全てのリージョンの場合は、リージョンのリストを取得してから実施します。

aws ec2 describe-regions --query "Regions[].[RegionName]" --output text \
| while read region; do
aws guardduty create-sample-findings \
  --detector-id $(aws guardduty list-detectors --region ${region} --query 'DetectorIds[0]' --output text) \
  --finding-types "UnauthorizedAccess:EC2/SSHBruteForce"
done

複数アカウントの管理

Duration: 0:01:30

Amazon GuardDuty での複数のアカウントの管理

結果を集約したい管理者アカウントでメンバーアカウントを招待することで、権威結果を表示することができます。

メンバーアカウントの管理は次の2つがあります。

account

メンバーアカウントを追加した場合、EventBridge が次のような設定だと管理者アカウントとメンバーアカウントの両方の検出結果が通知されます。

{
  "source": ["aws.guardduty"],
  "detail-type": ["GuardDuty Finding"],
  "detail": {
    "severity": [{ "numeric": [">=", 4] }]
  }
}

メンバーアカウントのアカウント ID を追加することでフィルタリングすることができます。

{
  "source": ["aws.guardduty"],
  "detail-type": ["GuardDuty Finding"],
  "detail": {
    "accountId": ["123456789012"],
    "severity": [{ "numeric": [">=", 4] }]
  }
}

📖 まとめ

guardduty

GitHubで編集を提案

Discussion