CloudWatch または Amazon S3 に保存されている AWS WAF ログを分析するオプションは何ですか?

所要時間4分
0

私の AWS WAF ログを Amazon CloudWatch、Amazon Simple Storage Solution (Amazon S3)、または Amazon S3 に Amazon Kinesis Data Firehose 配信ストリームの送信先として保存しています。AWS WAF アクセスログを分析するにはどのようなオプションがありますか。

解決方法

特定のログリクエストを分析してフィルタリングするには、CloudWatch ログには Amazon CloudWatch Logs Insights を使用し、Amazon S3 ログには Amazon Athena を使用します。

CloudWatch Logs インサイトによる AWS WAF アクセスログの分析

  1. Amazon CloudWatch コンソールを開きます。
  2. 左側のナビゲーションペインで、[ログ] を選択してから、[Log Insights] (ログインサイト) を選択します。
  3. [Select log group(s)] (ロググループの選択) で、AWS WAF アクセスログで構成される、クエリを行うロググループを 1 つ以上選択します。
  4. (オプション) クエリを行いたい期間の時間範囲を選択します。
  5. クエリ構文を使用してクエリを設計します。
  6. [Run] (実行) を選択して、ロググループの結果を表示します。

以下は、CloudWatch Logs Insights の特定の情報をフィルタリングするために使用できるクエリの例です。

特定の文字列でフィルタリング

このクエリを実行して、特定の文字列に基づいてログをフィルタリングします。
注: 文字列 {jndi:ldap. を検索したい文字列に置き換えてください。

fields terminatingRuleId as Rule, action, httpRequest.country as Country, httpRequest.clientIp as ClientIP, httpRequest.httpMethod as Method,httpRequest.uri as URI
| parse @message /\{"name":"[Hh]ost\",\"value":\"(?<Host>[^"}]*)/
| parse @message /\{"name":"[Uu]ser\-[Aa]gent\",\"value\"\:\"(?<UserAgent>[^"}]*)/
| filter @message like "{jndi:ldap"
| sort action, URI desc

ホストでフィルタリング

このクエリを実行して、ホストでフィルタリングします。
注: ホストの値 www.example.com を、検索したいホストに置き換えます。

parse @message /\{"name":"[Hh]ost\",\"value":\"(?<Host>[^"}]*)/
| filter Host = "www.example.com"
| fields terminatingRuleId as Rule, action, httpRequest.country as Country, httpRequest.clientIp as ClientIP, httpRequest.uri as URI

POST リクエストでフィルタリング

このクエリを実行して、すべての POST リクエストを分離します。

parse @message /\{"name":"[Uu]ser\-[Aa]gent\",\"value\"\:\"(?<UserAgent>[^"}]*)/
| parse @message /\{"name":"[Hh]ost\",\"value":\"(?<Host>[^"}]*)/
| fields terminatingRuleId as Rule, action, httpRequest.country as Country, httpRequest.clientIp as ClientIP, httpRequest.httpMethod as Method, httpRequest.uri as URI, httpRequest.requestId as RequestID
| filter httpRequest.httpMethod ="POST"
| display Rule, action, Country, ClientIP, Method, URI, Host, UserAgent, RequestID
| sort Rule, action desc

UserAgent でフィルタリング

このクエリを実行して、UserAgent でフィルタリングします。
注: User-Agent-ValueUserAgent 値に置き換えます**。**

parse @message /\{"name":"[Uu]ser\-[Aa]gent\",\"value\"\:\"(?<UserAgent>[^"}]*)/
| filter UserAgent like "<User-Agent-Value>"
| fields terminatingRuleId as Rule, action, httpRequest.country as Country, httpRequest.clientIp as ClientIP, httpRequest.uri as URI

国から発信されていないリクエストをフィルタリング

このクエリを実行して、特定の国から発信されたものではないリクエストをフィルタリングします。

fields terminatingRuleId as Rule, action, httpRequest.country as Country, httpRequest.clientIp as ClientIP, httpRequest.uri as URI
| parse @message /\{"name":"[Hh]ost\",\"value":\"(?<Host>[^"}]*)/
| parse @message /\{"name":"[Uu]ser\-[Aa]gent\",\"value\"\:\"(?<UserAgent>[^"}]*)/
| filter Country != "US"
| sort Country, action desc

クロスサイトスクリプティングまたは SQL インジェクションのフィルタリング

このクエリを実行して、クロスサイトスクリプティングまたは SQL インジェクションをフィルタリングします。

fields @timestamp, terminatingRuleId, action, httpRequest.clientIp as ClientIP, httpRequest.country as Country, terminatingRuleMatchDetails.0.conditionType as ConditionType, terminatingRuleMatchDetails.0.location as Location, terminatingRuleMatchDetails.0.matchedData.0 as MatchedData
| filter ConditionType in["XSS","SQL_INJECTION"]

終了ルールに基づく時系列

このクエリを実行して、終了ルールに基づいて時系列をフィルタリングします。

#Time Series by Terminating Rule
filter terminatingRuleId = "AWS-AWSManagedRulesCommonRuleSet"
| stats count(*) as requestCount by bin(30m)

ClientIP、国、URI、およびルールによりブロックされたリクエストを要約

このクエリを実行して、ClientIP、国、URI、およびルールによりブロックされたリクエストを要約します。

fields httpRequest.clientIp as ClientIP, httpRequest.country as Country, httpRequest.uri as URI, terminatingRuleId as Rule
| filter action = "BLOCK"
| stats count(*) as RequestCount by Country, ClientIP, URI, Rule
| sort RequestCount desc

上位のクライアント IP

このクエリを実行して、上位のクライアント IP をカウントします。

stats count(*) as RequestCount by httpRequest.clientIp as ClientIP
| sort RequestCount desc

上位の国

このクエリを実行して、上位の国を数えます。

stats count(*) as RequestCount by httpRequest.country as Country
| sort RequestCount desc

上位のホスト

このクエリを実行して、上位のホストを数えます。

parse @message /\{"name":"[Hh]ost\",\"value":\"(?<Host>[^"}]*)/
| stats count(*) as RequestCount by Host
| sort RequestCount desc

上位のメソッド

このクエリを実行して、上位のメソッドを数えます。

stats count(*)as RequestCount by httpRequest.httpMethod as Method
| sort RequestCount desc

上位の終了ルール

このクエリを実行して、上位の終了ルールを数えます。

stats count(*) as RequestCount by terminatingRuleId
| sort RequestCount desc

上位の UserAgents

このクエリを実行して、上位の UserAgents をカウントします。

parse @message /\{"name":"[Uu]ser\-[Aa]gent\",\"value\"\:\"(?<UserAgent>[^"}]*)/
| stats count(*) as RequestCount by UserAgent
| sort RequestCount desc

リクエストが Default_Action またはアクション ALLOW のルールによって終了されていない

このクエリを実行して、Default_Action によって終了されていないリクエスト、または ALLOW アクションを含むルールでフィルタリングします。

fields @timestamp, terminatingRuleId, action, @message
| filter terminatingRuleId != 'Default_Action' and action != 'ALLOW'
| sort @timestamp desc

無効な Captcha トークンを含むリクエスト

このクエリを実行して、無効な Captcha トークンを含むリクエストでフィルタリングします。

fields @timestamp, httpRequest.clientIp, httpRequest.requestId, captchaResponse.failureReason, @message
|filter captchaResponse.failureReason ='TOKEN_MISSING'
| sort @timestamp desc

レートベースのルールによるリクエストブロック

このクエリを実行して、レートベースのルールによってブロックされたリクエストでフィルタリングします。

fields @timestamp, httpRequest.clientIp, terminatingRuleId, httpRequest.country,@message
| filter terminatingRuleType ="RATE_BASED" ## and webaclId = "arn:aws:wafv2:us-east-1:xxxxxxxx:regional/webacl/waf-test/abcdefghijkl" ## uncomment to filter for specific WebACL
| sort requestCount desc

AWS Bot Control (ABC) によって検出されたすべてのリクエストをフィルタリング

このクエリを実行して、ABC によって検出されたすべてのリクエストをフィルタリングします。

fields @timestamp, @message
|filter @message like 'awswaf:managed:aws:bot-control'
| parse @message '"labels":[*]' as Labels
| sort @timestamp desc

Amazon Athena で AWS WAF アクセスログを分析する

AWS WAF アクセスログ記録を Amazon S3 バケットに対して直接オンにすることができます。または、Amazon Kinesis Data Firehose デリバリーストリームを使用して、AWS WAF アクセスログを Amazon S3 バケットに配信することもできます。Amazon S3 にログを保存するには、Amazon S3 にログを保存するように AWS WAF の包括的なログ記録を設定する方法を教えてくださいを参照してください。

アクセスログが Amazon S3 バケットにある場合は、AWS WAF テーブルを作成して、Amazon Athena を使用してログにクエリを行い、さまざまな詳細をフィルタリングします。

これらのクエリは、Athena で AWS WAF ログをクエリするために使用できる例です。

AWS WAF ルール情報を含むブロックされたリクエスト

この Athena クエリを実行して、AWS WAF ルールでブロックされたすべてのリクエストを一覧表示します。

SELECT timestamp,
    action,
    httpsourcename,
    httpsourceid,
    httprequest.requestID,
    httprequest.clientip,
    webaclid,
    terminatingruleid,
    terminatingruletype,
    rulegrouplist,
    terminatingrulematchdetails
FROM "wafv2"."waf_logs"
WHERE ("action" LIKE 'BLOCK')

ユーザーエージェントをリクエスト

この Athena クエリを実行して、ユーザーエージェントをリクエストします。
注: User-Agent をお客様の UserAgent 値に置き換えます。

select n.value, count(n.value) as count
from waf_logs
cross join
unnest(
  cast(
    httprequest.headers as ARRAY(ROW(name VARCHAR, value VARCHAR))
    )
  ) as x(n)
where n.name = 'User-Agent'
group by n.value
ORDER BY count(n.value) DESC

リクエスト URI

この Athena クエリを実行して、リクエスト URI を確認します。

SELECT
"httprequest"."uri"
, "count"(*) "count"
FROM
  waf_logs
WHERE ("action" LIKE 'BLOCK')
GROUP BY "httprequest"."uri"
ORDER BY "count" DESC

ClientIP に基づいてブロックされたリクエストをカウント

この Athena クエリを実行して、ClientIP と国に基づいてブロックされたリクエストの数を表示します。

SELECT
  "httprequest"."clientip"
, "count"(*) "count"
, "httprequest"."country"
FROM
waf_logs
WHERE ("action" LIKE 'BLOCK')
GROUP BY "httprequest"."clientip", "httprequest"."country"
ORDER BY "count" DESC

リクエスト数を表示

この Athena クエリを実行して、リクエスト数を表示します。

SELECT 
  "httprequest"."clientip"
, "count"(*) "count"
,"httprequest"."country"
FROM
 waf_logs
WHERE ("action" LIKE
'BLOCK')
GROUP BY
"httprequest"."clientip", "httprequest"."country"
ORDER BY "count" DESC

その他の Athena クエリの例については、「AWS WAF ログのクエリ例」を参照してください。


AWS公式
AWS公式更新しました 2年前