CloudWatch 또는 Amazon S3에 저장된 AWS WAF 로그를 분석할 수 있는 옵션은 무엇입니까?

6분 분량
0

AWS WAF 로그를 Amazon CloudWatch, Amazon Simple Storage Solution(Amazon S3) 또는 Amazon S3에 Amazon Kinesis Data Firehose 전송 스트림의 대상으로 저장하고 있습니다. AWS WAF 액세스 로그를 분석하려면 어떤 옵션이 있어야 합니까?

해결 방법

특정 로그 요청을 분석하고 필터링하려면 CloudWatch 로그에 대한 Amazon CloudWatch Logs 인사이트를 사용하거나 Amazon S3용 Amazon Athena 로그를 사용합니다.

CloudWatch 로그 인사이트를 사용하여 AWS WAF 액세스 로그 분석

  1. Amazon CloudWatch 콘솔을 엽니다.
  2. 탐색 창에서 [로그(Logs)]를 선택한 다음, [로그 인사이트(Log Insights)]를 선택합니다.
  3. [로그 그룹 선택(Select log group(s))]에서 AWS WAF 액세스 로그로 구성된 쿼리할 로그 그룹을 하나 이상 선택합니다.
  4. (선택 사항) 쿼리할 기간의 시간 범위를 선택합니다.
  5. 쿼리 구문을 사용하여 쿼리를 설계합니다.
  6. [실행(Run)]을 선택하여 로그 그룹에 대한 결과를 봅니다.

다음은 CloudWatch 로그 인사이트에 대한 특정 정보를 필터링하는 데 사용할 수 있는 쿼리의 예입니다.

특정 문자열에서 필터링

특정 문자열을 기준으로 로그를 필터링하려면 다음 쿼리를 실행합니다.
참고: 문자열 {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 액세스 로그 분석

Amazon S3 버킷에 대한 AWS WAF 액세스 로깅을 직접 활성화할 수 있습니다. 또는 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 규칙 정보로 차단된 요청

AWS WAF 규칙을 사용하여 차단된 모든 요청을 나열하려면 다음 Athena 쿼리를 실행합니다.

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

사용자 에이전트 요청

사용자 에이전트를 요청하려면 다음 Athena 쿼리를 실행합니다.
참고: User-AgentUserAgent 값으로 바꿉니다.

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

요청 URI를 확인하려면 다음 Athena 쿼리를 실행합니다.

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

ClientIP에 따라 차단된 요청 수

ClientIP 및 국가를 기준으로 차단된 요청 수를 확인하려면 다음 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 쿼리를 실행합니다.

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년 전