我按照这些说明将我的 AWS WAF 数据放入 Athena 表中。
我想查询数据以查找具有 BLOCK 操作的最新请求。此查询有效:
SELECT
from_unixtime(timestamp / 1000e0) AS date,
action,
httprequest.clientip AS ip,
httprequest.uri AS request,
httprequest.country as country,
terminatingruleid,
rulegrouplist
FROM waf_logs
WHERE action='BLOCK'
ORDER BY date DESC
LIMIT 100;
我的问题是清楚地识别“终止规则”——请求被阻止的原因。例如,一个结果有
terminatingrule = AWS-AWSManagedRulesCommonRuleSet
和
rulegrouplist = [
{
"nonterminatingmatchingrules": [],
"rulegroupid": "AWS#AWSManagedRulesAmazonIpReputationList",
"terminatingrule": "null",
"excludedrules": "null"
},
{
"nonterminatingmatchingrules": [],
"rulegroupid": "AWS#AWSManagedRulesKnownBadInputsRuleSet",
"terminatingrule": "null",
"excludedrules": "null"
},
{
"nonterminatingmatchingrules": [],
"rulegroupid": "AWS#AWSManagedRulesLinuxRuleSet",
"terminatingrule": "null",
"excludedrules": "null"
},
{
"nonterminatingmatchingrules": [],
"rulegroupid": "AWS#AWSManagedRulesCommonRuleSet",
"terminatingrule": {
"rulematchdetails": "null",
"action": "BLOCK",
"ruleid": "NoUserAgent_HEADER"
},
"excludedrules":"null"
}
]
我想分成一列的数据是rulegrouplist[terminatingrule].ruleid
它的值NoUserAgent_HEADER
AWS 提供了有关查询嵌套 Athena 数组的有用信息,但我一直无法获得我想要的结果。
我已将此作为一个 AWS 问题进行框定,但由于 Athena 使用 SQL 查询,因此任何具有良好 SQL 技能的人都可以解决这个问题。