收集 AWS WAF 日志

支持的平台:

本文档介绍了如何通过设置 Google 安全运营 Feed 来收集 AWS 网站应用防火墙 (WAF) 日志。解析器会将采用 JSON 格式的原始日志转换为符合 Google SecOps UDM 的结构化格式。它会提取 IP 地址、网址、用户代理和安全规则详细信息等字段,并将其映射到相应的 UDM 字段,以便进行一致的表示和分析。

准备工作

  • 确保您拥有 Google SecOps 实例。
  • 确保您拥有对 AWS 的特权访问权限。

配置 Amazon S3 存储分区

  1. 按照以下用户指南创建 Amazon S3 存储分区创建存储分区
  2. 保存存储分区名称区域,以备日后使用。
  3. 按照以下用户指南创建用户:创建 IAM 用户
  4. 选择创建的用户
  5. 选择安全凭据标签页。
  6. 点击访问密钥部分中的创建访问密钥
  7. 选择第三方服务作为用例
  8. 点击下一步
  9. 可选:添加说明标记。
  10. 点击创建访问密钥
  11. 点击下载 CSV 文件,保存访问密钥密钥以供日后使用。
  12. 点击完成
  13. 选择权限标签页。
  14. 权限政策部分中,点击添加权限
  15. 选择添加权限
  16. 选择直接附加政策
  17. 搜索并选择 AmazonS3FullAccess 政策。
  18. 点击下一步
  19. 点击添加权限

创建 WAF 网站 ACL(访问控制列表)

如果您尚未设置 AWS WAF,则需要创建 WAF Web ACL(访问控制列表)。对于现有设置,您可以跳至下一个步骤。

  1. 在 AWS 控制台中,搜索并选择 AWS WAF & Shield
  2. 点击创建网站 ACL
  3. 提供以下设置:
    • 名称:为 ACL 命名(例如 my-waf-web-acl)。
    • 区域:选择您要应用 WAF 的区域。
    • CloudWatch 指标:启用指标收集功能,以跟踪活动和触发的规则。
  4. 创建后,选择要为其启用日志记录的网站 ACL

配置 AWS WAF 日志记录

  1. AWS WAF 控制台中,前往网站 ACL 的 Logging(日志记录)标签页。
  2. 点击启用日志记录
  3. 选择 Amazon S3 作为日志的目标位置。
  4. 选择之前创建的 S3 存储分区来存储日志。
  5. 可选:配置日志前缀以整理日志(例如 waf-logs/)。
  6. 点击保存

验证 S3 存储分区的权限

确保 S3 存储分区具有适当的权限,以便 AWS WAF 写入日志。

  1. 前往 S3 控制台
  2. 选择日志的存储分区。
  3. 权限标签页中,添加以下存储分区政策,以允许 AWS WAF 写入日志:

    {
      "Version": "2012-10-17",
      "Statement": [
          {
            "Effect": "Allow",
            "Principal": {
                "Service": "wafv2.amazonaws.com"
            },
            "Action": "s3:PutObject",
            "Resource": "arn:aws:s3:::your-log-bucket-name/*"
          }
      ]
    }
    
  1. 点击保存

在 Google SecOps 中配置 Feed 以提取 AWS WAF 日志

  1. 依次前往 SIEM 设置 > Feed
  2. 点击新增
  3. Feed 名称字段中,输入 Feed 的名称(例如 AWS WAF 日志)。
  4. 选择 Amazon S3 作为来源类型
  5. 选择 AWS WAF 作为日志类型
  6. 点击下一步
  7. 为以下输入参数指定值:

    • 区域:Amazon S3 存储分区所在的区域。
    • S3 URI:存储分区 URI。
      • s3://your-log-bucket-name/waf-logs/
        • 替换以下内容:
          • your-log-bucket-name:存储分区的实际名称。
    • URI 是:选择目录包含子目录的目录
    • 来源删除选项:根据您的偏好选择删除选项。
    • 访问密钥 ID:有权访问 S3 存储分区的用户访问密钥。
    • 私有访问密钥:有权访问 S3 存储分区的用户私有密钥。
    • 资源命名空间资源命名空间
    • 提取标签:要应用于此 Feed 中的事件的标签。
  8. 点击下一步

  9. 最终确定界面中查看新的 Feed 配置,然后点击提交

UDM 映射表

日志字段 UDM 映射 逻辑
操作 security_result.action 如果操作为 ALLOW,请将 security_result.action 设置为 ALLOW,并将 security_result.severity 设置为 INFORMATIONAL。如果操作为“屏蔽”,请将 security_result.action 设置为“屏蔽”。如果 action 为 CAPTCHA 且 captchaResponse.responseCode 为 405,请将 security_result.action 设置为 BLOCK,并将 security_result.action_details 设置为“CAPTCHA {captchaResponse.failureReason}”。
captchaResponse.failureReason security_result.action_details 与 action 和 captchaResponse.responseCode 结合使用,用于确定 security_result.action_details。
captchaResponse.responseCode security_result.action_details 与 action 和 captchaResponse.failureReason 结合使用,用于确定 security_result.action_details。
httpRequest.clientIp principal.ip、principal.asset.ip 直接映射到 principal.ip 和 principal.asset.ip。
httpRequest.headers target.hostname、target.asset.hostname、network.http.user_agent、network.http.parsed_user_agent、network.http.referral_url、target.location.country_or_region、target.resource.attribute.labels、target.user.userid 迭代 httpRequest.headers 中的每个标头。如果标头名称为“host”或“Host”,则该值会映射到 target.hostname 和 target.asset.hostname。如果标头名称为“User-Agent”或“user-agent”,则该值会映射到 network.http.user_agent 并解析为 network.http.parsed_user_agent。如果标头名称为“Referer”或“referer”,则该值会映射到 network.http.referral_url。如果标头名称为“(?i)time-zone”,则该值会映射到 target.location.country_or_region。如果标头名称为“authorization”,系统会对值进行解码,提取用户名并将其映射到 target.user.userid。所有其他标头都会作为键值对添加到 target.resource.attribute.labels。
httpRequest.httpMethod network.http.method 直接映射到 network.http.method。
httpRequest.requestId network.session_id 直接映射到 network.session_id。
httpRequest.uri target.url 直接映射到 target.url。
httpSourceId target.resource.name 直接映射到 target.resource.name。
httpSourceName metadata.product_event_type 直接映射到 metadata.product_event_type。
标签 security_result.rule_labels 迭代标签中的每个标签。如果标签名称不为空,则会作为键值对添加到 security_result.rule_labels。
nonTerminatingMatchingRules security_result.action_details、security_result.rule_labels 迭代 nonTerminatingMatchingRules 中的每条规则。如果操作为“允许”且规则操作为“CAPTCHA”,请将 security_result.action_details 设置为“CAPTCHA SUCCESSFUL”,并将规则 ID 添加到 security_result.rule_labels,键为“nonTerminatingCaptchaRuleName”。如果操作为“屏蔽”或“允许”,并且规则操作为“计数”,请将 security_result.action_details 设置为“计数规则”,并将规则 ID 添加到 security_result.rule_labels,键为“nonTerminatingCountRuleName”。如果操作为 BLOCK 或 ALLOW,并且规则操作为 CHALLENGE,请将 security_result.action_details 设置为“COUNT RULE”,并将规则 ID 添加到 security_result.rule_labels,键为“nonTerminatingChallengeRuleName”。
rateBasedRuleList security_result.rule_id、security_result.rule_name、security_result.description 如果 terminatingRuleType 为“RATE_BASED”,则迭代 rateBasedRuleList 中的每条规则。如果 terminatingRuleId 与规则名称匹配,则规则 ID、规则名称和说明分别映射到 security_result.rule_id、security_result.rule_name 和 security_result.description。
responseCodeSent network.http.response_code 直接映射到 network.http.response_code 并转换为整数。
ruleGroupList intermediary.labels、security_result.rule_id、security_result.rule_name、security_result.description、security_result.detection_fields 迭代 ruleGroupList 中的每个规则组。规则组 ID 会作为键值对添加到 intermediary.labels。如果 terminatingRuleType 为“MANAGED_RULE_GROUP”且 terminatingRuleId 与规则组 ID 匹配,则规则 ID、规则名称和说明分别映射到 security_result.rule_id、security_result.rule_name 和 security_result.description。如果 terminatingRuleType 为“GROUP”,系统会提取终止规则 ID 并将其映射到 security_result.rule_name 和 security_result.description。终止规则组 ID 会添加到 security_result.rule_labels 中,键为“terminatingRuleGroupName”。如果 terminatingRuleType 为“REGULAR”,系统会提取终止规则操作,并将其添加到 security_result.detection字段(键为“terminatingRuleAction{index}”)。
terminatingRuleId security_result.rule_id、security_result.rule_name、security_result.description 如果 terminatingRuleType 为“RATE_BASED”“MANAGED_RULE_GROUP”或“REGULAR”,terminatingRuleId 会映射到 security_result.rule_id、security_result.rule_name,并用于构建 security_result.description。
terminatingRuleMatchDetails security_result.description、security_result.category_details、security_result.detection_fields 迭代 terminatingRuleMatchDetails 中的每个匹配项。将 security_result.description 设置为“Terminating Rule”。如果条件类型不为空,则会添加到 security_result.category_details。如果位置信息不为空,则会添加到 security_result.detection_fields 中,键为“location”。对于每个匹配的数据元素,系统会将其添加到 security_result.detection_fields 中,并使用键“matchedData”。
terminatingRuleType security_result.rule_type 直接映射到 security_result.rule_type。
时间戳 metadata.event_timestamp 转换为时间戳并映射到 metadata.event_timestamp。
webaclId intermediary.resource.name 直接映射到 intermediary.resource.name。
metadata.vendor_name 设置为“AMAZON”。
metadata.product_name 设置为“AWS Web 应用防火墙”。
metadata.log_type 设置为“AWS_WAF”。
network.application_protocol 设置为“HTTP”。
metadata.event_type 如果 httpRequest.headers 包含“host”或“Host”标头,则设置为“NETWORK_HTTP”。否则,请设置为“STATUS_UPDATE”。

变化

2024-03-14

  • 改进了对日志消息中无效转义字符的处理,以确保 JSON 格式正确无误。

2023-12-29

  • 对“user-agent”信息与相应 UDM 字段的映射进行了标准化。
  • 从 HTTP 请求中的“authorization”标头中提取用户 ID。

2023-12-08

  • 修复了与主机名映射、目标网址提取和规则处理相关的多个 bug。
  • 改进了解析器的特定部分中的错误处理。

2023-12-11

  • 通过引入新的 Grok 模式,添加了对新日志格式的支持。

2023-08-16

  • 改进了安全规则操作与检测字段的 UDM 字段之间的映射。

2022-12-16

  • 优化了日期过滤逻辑,改进了对无效 JSON 数据的处理方式。
  • 将 HTTP 标头中的用户代理信息映射到专用 UDM 字段。

2022-12-11

  • 移除了处理 CSV 和 SYSLOG 消息日志的多余逻辑。

2022-07-22

  • 这标志着解析器的初始创建。

需要更多帮助?向社区成员和 Google SecOps 专业人士寻求解答。