自訂 AWS Network Firewall 的 Amazon CloudWatch 提醒 - AWS 方案指引

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

自訂 AWS Network Firewall 的 Amazon CloudWatch 提醒

由 Jason Owens 建立 (AWS)

Summary

此模式可協助您自訂 Amazon Web Services (AWS) 網路防火牆產生的 Amazon CloudWatch 警示。您可以使用預先定義的規則,或建立自訂規則來判斷警示的訊息、中繼資料和嚴重性。然後,您可以對這些提醒採取行動,或自動回應其他 Amazon 服務,例如 Amazon EventBridge。

在此模式中,您會產生 Suricata 相容防火牆規則。Suricata 是開放原始碼威脅偵測引擎。您首先建立簡單的規則,然後測試它們以確認 CloudWatch 警示已產生和記錄。成功測試規則後,您可以修改規則以定義自訂訊息、中繼資料和嚴重性,然後再次測試以確認更新。

先決條件和限制

先決條件

  • 作用中的 AWS 帳戶。

  • AWS 命令列界面 (AWSCLI) 已安裝並設定於您的 Linux、macOS 或 Windows 工作站。如需詳細資訊,請參閱安裝或更新最新版本的 AWS CLI

  • AWS 已安裝並設定為使用 CloudWatch Logs 的網路防火牆。如需詳細資訊,請參閱從網路防火牆記錄AWS網路流量

  • 受 Network Firewall 保護之虛擬私有雲端 (EC2) 私有子網路中的 Amazon Elastic Compute Cloud (Amazon VPC) 執行個體。

產品版本

  • 對於 第 1 AWS 版CLI,請使用 1.18.180 或更新版本。對於 第 2 AWS 版CLI,請使用 2.1.2 或更新版本。

  • 來自 Suricata 5.0.2 版的 classification.config 檔案。如需此組態檔案的副本,請參閱其他資訊一節。

架構

目標技術堆疊

  • Network Firewall

  • Amazon CloudWatch Logs

目標架構

EC2 執行個體請求會在 Network Firewall 中產生警示,將警示轉送至 CloudWatch

架構圖顯示下列工作流程:

  1. 私有子網路中的EC2執行個體使用 curlWget 提出請求。

  2. Network Firewall 會處理流量並產生提醒。

  3. Network Firewall 會將記錄的提醒傳送至 CloudWatch Logs。

工具

AWS 服務

  • Amazon CloudWatch 可協助您AWS即時監控 AWS 資源的指標,以及您在 上執行的應用程式。

  • Amazon CloudWatch Logs 可協助您集中所有系統、應用程式AWS和服務中的日誌,以便您可以監控日誌並將其安全地封存。

  • AWS Command Line Interface (AWS CLI) 是一種開放原始碼工具,可協助您透過命令列 shell 中的命令與 AWS服務互動。

  • AWS Network Firewall 是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 系統管理員、網路管理員
建立規則群組。

在 AWS 中CLI,輸入下列命令。這會建立規則群組。

❯ 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的 。

在 AWS 中CLI,輸入下列命令。這會傳回防火牆政策的 Amazon Resource Name (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>"         }     ] }

在 AWS 中輸入下列命令CLI。此命令需要更新字符才能新增新規則。字符用於確認自您上次擷取以來,政策尚未變更。

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 系統管理員
確認政策更新。

(選用) 如果您想要確認已新增規則並檢視政策格式,請在 AWS 中輸入下列命令CLI。

❯ 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;)

    這會對規則進行下列變更:

    • 新增訊息 (Suricata 網站) 字串,提供簽章或提醒的相關文字資訊。在產生的提醒中,這會映射到簽章。 

    • 將預設優先順序 (Suricata 網站) misc-activity 從 3 調整為 2。如需各種 的預設值classtypes,請參閱其他資訊一節。

    • 將自訂中繼資料 (Suricata 網站) 新增至提醒。這是新增到簽章的其他資訊。建議您使用鍵/值對。

    • rev (Suricata 網站) 從 1 變更為 2。這表示簽章的版本。

AWS 系統管理員
更新規則群組。

在 AWS 中CLI,執行下列命令。使用防火牆政策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