为 Network Fire AWS wall 自定义亚马逊 CloudWatch 提醒 - AWS Prescriptive Guidance

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

为 Network Fire AWS wall 自定义亚马逊 CloudWatch 提醒

由杰森·欧文斯创作 () AWS

摘要

该模式可帮助您自定义 Amazon Web Services (AWS) Network Firewall 生成的亚马逊 CloudWatch 警报。您可以使用预定义的规则或创建自定义规则来确定警报的消息、元数据和严重性。然后,您可以根据这些提醒采取行动,或者由其他亚马逊服务(例如亚马逊)自动回复 EventBridge。

在此模式中,您将生成与 Suricata 兼容的防火墙规则。Suricata 是一个开源威胁检测引擎。您首先创建简单的规则,然后对其进行测试以确认 CloudWatch 警报已生成并记录在案。成功测试规则后,您可以修改它们以定义自定义消息、元数据和严重性,然后再次测试以确认更新。

先决条件和限制

先决条件

  • 一个活动的 AWS 账户。

  • AWS在 Linux、macOS 或 Windows 工作站上安装和配置命令行界面 (AWSCLI)。有关更多信息,请参阅安装或更新最新版本的AWSCLI

  • AWSNetwork Firewall 已安装并配置为使用 CloudWatch 日志。有关更多信息,请参阅记录来自 Network Firewall 的AWS网络流量

  • 位于受网络防火墙保护的虚拟私有云 (EC2) 的私有子网中的亚马逊弹性计算云 (AmazonVPC) 实例。

产品版本

  • 对于的版本 1 AWSCLI,请使用 1.18.180 或更高版本。对于的版本 2 AWSCLI,请使用 2.1.2 或更高版本。

  • Suricata 版本 5.0.2 中的 classification.config 文件。有关此配置文件的副本,请参阅其他信息部分。

架构

目标技术堆栈

  • Network Firewall

  • Amazon CloudWatch 日志

目标架构

EC2实例请求会在 Network Firewall 中生成警报,网络防火墙会将警报转发到 CloudWatch

架构图显示了以下工作流程:

  1. 私有子网中的EC2实例使用 curlW get 发出请求。

  2. Network Firewall 处理流量并生成警报。

  3. Network Firewall 将记录的警报发送到 CloudWatch 日志。

工具

AWS 服务

  • Amazon CloudWatch 可帮助您实时监控您的AWS资源和运行的应用程序AWS的指标。

  • Amazon CloudWatch Lo gs 可帮助您集中管理所有系统、应用程序和AWS服务的日志,以便您可以对其进行监控并安全地存档。

  • AWSCommand Line Interface (AWSCLI) 是一个开源工具,可帮助您通过命令行外壳中的命令与AWS服务进行交互。

  • AWSNetwork Fire wall 是一项针对云AWS端虚拟私有云 (VPCs) 的状态托管网络防火墙以及入侵检测和防御服务。 

其他工具和服务

  • curl – curl 是一个开源命令行工具和库。

  • Wget — GNU Wget 是一个免费的命令行工具。

操作说明

任务描述所需技能
创建规则。
  1. 在文本编辑器中,创建要添加到防火墙的规则列表。每个规则必须位于单独的行上。classtype 参数中的值来自默认的 Suricata 分类配置文件。有关完整的配置文件内容,请参阅其他信息部分。以下是规则的两个示例。

    alert http any any -> any any (content:"badstuff"; classtype:misc-activity; sid:3; rev:1;) alert http any any -> any any (content:"morebadstuff"; classtype:bad-unknown; sid:4; rev:1;)
  2. 将规则保存在名为 custom.rules 的文件中。

AWS系统管理员、网络管理员
创建规则组。

在中 AWSCLI,输入以下命令。这将创建规则组。

❯ aws network-firewall create-rule-group \         --rule-group-name custom --type STATEFUL \         --capacity 10 --rules file://custom.rules \         --tags Key=environment,Value=development

下面是一个示例输出。记下 RuleGroupArn,在后面的步骤中需要用到它。

{     "UpdateToken": "4f998d72-973c-490a-bed2-fc3460547e23",     "RuleGroupResponse": {         "RuleGroupArn": "arn:aws:network-firewall:us-east-2:1234567890:stateful-rulegroup/custom",         "RuleGroupName": "custom",         "RuleGroupId": "238a8259-9eaf-48bb-90af-5e690cf8c48b",         "Type": "STATEFUL",         "Capacity": 10,         "RuleGroupStatus": "ACTIVE",         "Tags": [             {                 "Key": "environment",                 "Value": "development"             }         ]     }
AWS系统管理员
任务描述所需技能
获取防火墙策略。ARN

在中 AWSCLI,输入以下命令。这将返回防火墙策略的 Amazon 资源名称 (ARN)。记录下来ARN,以便稍后在此模式中使用。

❯ aws network-firewall describe-firewall \     --firewall-name aws-network-firewall-anfw \     --query 'Firewall.FirewallPolicyArn'

以下是此命令返回ARN的示例。

"arn:aws:network-firewall:us-east-2:1234567890:firewall-policy/firewall-policy-anfw"
AWS系统管理员
更新防火墙策略。

在文本编辑器中,复制并粘贴以下代码。将 <RuleGroupArn> 替换为在上一个长篇故事中记录的值。将该文件保存为 firewall-policy-anfw.json

{     "StatelessDefaultActions": [         "aws:forward_to_sfe"     ],     "StatelessFragmentDefaultActions": [         "aws:forward_to_sfe"     ],     "StatefulRuleGroupReferences": [         {             "ResourceArn": "<RuleGroupArn>"         }     ] }

在中输入以下命令AWSCLI。此命令需要更新令牌才能添加新规则。该令牌用于确认自您上次检索策略以来该策略未发生更改。

UPDATETOKEN=(`aws network-firewall describe-firewall-policy \               --firewall-policy-name firewall-policy-anfw \               --output text --query UpdateToken`)    aws network-firewall update-firewall-policy \  --update-token $UPDATETOKEN \  --firewall-policy-name firewall-policy-anfw \  --firewall-policy file://firewall-policy-anfw.json
AWS系统管理员
确认策略更新。

(可选)如果您想确认已添加规则并查看策略格式,请在中输入以下命令AWSCLI。

❯ aws network-firewall describe-firewall-policy \   --firewall-policy-name firewall-policy-anfw \   --query FirewallPolicy

下面是一个示例输出。

{     "StatelessDefaultActions": [         "aws:forward_to_sfe"     ],     "StatelessFragmentDefaultActions": [         "aws:forward_to_sfe"     ],     "StatefulRuleGroupReferences": [         {             "ResourceArn": "arn:aws:network-firewall:us-east-2:1234567890:stateful-rulegroup/custom"         }     ] }
AWS系统管理员
任务描述所需技能
生成用于测试的警报。
  1. 登录到防火墙子网中的测试工作站。

  2. 输入应生成警报的命令。例如,您可以使用 wgetcurl

    wget -U "badstuff" http://www.amazon.com -o /dev/null
    curl -A "morebadstuff" http://www.amazon.com -o /dev/null
AWS系统管理员
验证警报是否已记录。
  1. 在以下位置打开 CloudWatch 控制台 https://console.aws.amazon.com/cloudwatch/

  2. 导航到正确的日志组和流。有关更多信息,请参阅查看发送到日志的 CloudWatch 日志数据(CloudWatch 日志文档)。

  3. 确认记录的事件类似于以下示例。这些示例仅显示警报的相关部分。

    示例 1

            "alert": {             "action": "allowed",             "signature_id": 3,             "rev": 1,             "signature": "",             "category": "Misc activity",             "severity": 3         }

    示例 2

            "alert": {             "action": "allowed",             "signature_id": 4,             "rev": 1,             "signature": "",             "category": "Potentially Bad Traffic",             "severity": 2         }
AWS系统管理员
任务描述所需技能
更新防火墙规则。
  1. 在文本编辑器中,打开 custom.rules文件。

  2. 将第一条规则更改为与以下内容类似。此规则必须在文件中的一行中输入。

    alert http any any -> any any (msg:"Watch out - Bad Stuff!!"; content:"badstuff"; classtype:misc-activity; priority:2; sid:3; rev:2; metadata:custom-field-2 Danger!, custom-field More Info;)

    这会对规则进行以下更改:

    • 添加 msg(Suricata 网站)字符串,该字符串提供有关签名或警报的文本信息。在生成的警报中,这会映射到签名。 

    • misc-activity的默认优先级(Suricata 网站)从 3 调整为 2。有关各种 classtypes的默认值,请参阅其他信息部分。

    • 将自定义元数据(Suricata 网站)添加到警报。这是添加到签名中的附加信息。建议使用键值对。

    • rev(Suricata 网站)从 1 更改为 2。这代表签名的版本。

AWS系统管理员
更新规则组。

在中 AWSCLI,运行以下命令。使用您的防火墙策略。ARN这些命令获取更新令牌,并使用规则更改更新规则组。

❯ UPDATETOKEN=(`aws network-firewall \                 describe-rule-group \ --rule-group-arn arn:aws:network-firewall:us-east-2:123457890:stateful-rulegroup/custom \ --output text --query UpdateToken`)
 ❯ aws network-firewall update-rule-group \   --rule-group-arn arn:aws:network-firewall:us-east-2:1234567890:stateful-rulegroup/custom \ --rules file://custom.rules \ --update-token $UPDATETOKEN

下面是一个示例输出。

{     "UpdateToken": "7536939f-6a1d-414c-96d1-bb28110996ed",     "RuleGroupResponse": {         "RuleGroupArn": "arn:aws:network-firewall:us-east-2:1234567890:stateful-rulegroup/custom",         "RuleGroupName": "custom",         "RuleGroupId": "238a8259-9eaf-48bb-90af-5e690cf8c48b",         "Type": "STATEFUL",         "Capacity": 10,         "RuleGroupStatus": "ACTIVE",         "Tags": [             {                 "Key": "environment",                 "Value": "development"             }         ]     } }
AWS系统管理员
任务描述所需技能
生成用于测试的警报。
  1. 登录到防火墙子网中的测试工作站。

  2. 输入应生成警报的命令。例如,您可以使用 curl

    curl -A "badstuff" http://www.amazon.com -o /dev/null
AWS系统管理员
验证警报是否已更改。
  1. 在以下位置打开 CloudWatch 控制台 https://console.aws.amazon.com/cloudwatch/

  2. 导航到正确的日志组和流。

  3. 确认记录的事件类似于以下示例。该示例仅显示警报的相关部分。

    "alert": {     "action": "allowed",     "signature_id": 3,     "rev": 2,     "signature": "Watch out - Bad Stuff!!",     "category": "Misc activity",     "severity": 2,     "metadata": {         "custom-field": [             "More Info"         ],         "custom-field-2": [             "Danger!"         ]     } }
AWS系统管理员

相关资源

参考

教程和视频

其他信息

以下是 Suricata 5.0.2 中的分类配置文件。创建防火墙规则时将使用这些分类。

# config classification:shortname,short description,priority   config classification: not-suspicious,Not Suspicious Traffic,3 config classification: unknown,Unknown Traffic,3 config classification: bad-unknown,Potentially Bad Traffic, 2 config classification: attempted-recon,Attempted Information Leak,2 config classification: successful-recon-limited,Information Leak,2 config classification: successful-recon-largescale,Large Scale Information Leak,2 config classification: attempted-dos,Attempted Denial of Service,2 config classification: successful-dos,Denial of Service,2 config classification: attempted-user,Attempted User Privilege Gain,1 config classification: unsuccessful-user,Unsuccessful User Privilege Gain,1 config classification: successful-user,Successful User Privilege Gain,1 config classification: attempted-admin,Attempted Administrator Privilege Gain,1 config classification: successful-admin,Successful Administrator Privilege Gain,1   # NEW CLASSIFICATIONS config classification: rpc-portmap-decode,Decode of an RPC Query,2 config classification: shellcode-detect,Executable code was detected,1 config classification: string-detect,A suspicious string was detected,3 config classification: suspicious-filename-detect,A suspicious filename was detected,2 config classification: suspicious-login,An attempted login using a suspicious username was detected,2 config classification: system-call-detect,A system call was detected,2 config classification: tcp-connection,A TCP connection was detected,4 config classification: trojan-activity,A Network Trojan was detected, 1 config classification: unusual-client-port-connection,A client was using an unusual port,2 config classification: network-scan,Detection of a Network Scan,3 config classification: denial-of-service,Detection of a Denial of Service Attack,2 config classification: non-standard-protocol,Detection of a non-standard protocol or event,2 config classification: protocol-command-decode,Generic Protocol Command Decode,3 config classification: web-application-activity,access to a potentially vulnerable web application,2 config classification: web-application-attack,Web Application Attack,1 config classification: misc-activity,Misc activity,3 config classification: misc-attack,Misc Attack,2 config classification: icmp-event,Generic ICMP event,3 config classification: inappropriate-content,Inappropriate Content was Detected,1 config classification: policy-violation,Potential Corporate Privacy Violation,1 config classification: default-login-attempt,Attempt to login by a default username and password,2   # Update config classification: targeted-activity,Targeted Malicious Activity was Detected,1 config classification: exploit-kit,Exploit Kit Activity Detected,1 config classification: external-ip-check,Device Retrieving External IP Address Detected,2 config classification: domain-c2,Domain Observed Used for C2 Detected,1 config classification: pup-activity,Possibly Unwanted Program Detected,2 config classification: credential-theft,Successful Credential Theft Detected,1 config classification: social-engineering,Possible Social Engineering Attempted,2 config classification: coin-mining,Crypto Currency Mining Activity Detected,2 config classification: command-and-control,Malware Command and Control Activity Detected,1