본문 바로가기

Security

[실습] Amazon GuardDuty 실습하기 (EventBridge, SNS, CloudWatch 구성)

반응형

안녕하세요 서후아빠입니다. ^_^

이번 세션은 GuardDuty에 EventBridge와 SNS, CloudWatch를 연결하여 관리자에게 알림을 보내고 Logging하는 실습을 해보겠습니다.


구성도

Cloud Shell에서 EC2 or S3에 대해서 Sample 공격을 시도하면 GuardDuty가 탐지합니다. 
EventBridge(ebRule)는 GuardDuty의 탐지 결과를 SNS로 호출합니다.
SNS(mytopic)는 구독(user01@gtek.com)과 Publish에 연결된 Lambda(mytopicfunction)를 호출합니다.
Lambda는 event 내용을 CloudWatch Log group(/aws/lambda/mytopicfuntion)로 호출합니다.

1단계 : SNS 설정

SNS 설정에 대한 설명은 생략합니다. (아래 링크에서 2~4단계만 진행하시기 바랍니다.)

2022.08.17 - [Management] - [실습] Amazon SNS(Simple Notification Service) 실습하기

 

[실습] Amazon SNS(Simple Notification Service) 실습하기

안녕하세요 서후아빠입니다. ^_^ 이번 세션은 Amazon SNS에 대해서 실습 해보겠습니다. 구성도 1단계 : Topic (주제) 생성 Amazon SNS > Topics > Creat topic Details Encryption(옵션) Access policy(옵션) Del..

sh-t.tistory.com

2단계 : EventBridge Rule 설정

Amazon EventBridge > Rules > Create rule

Define rule detail Build event pattern Selct target(s)
Name : ebRule
Event bus : default
Enable the rule on the selected event bus : Enable
Rule type : Rule with an event pattern (or Schedule)
Event source : AWS events or EventBridge partner events (or Other or All events)
Sample event(옵션) 
- Select : AWS events (or EventBridge prtner events or Enter my own)
- Sample events : GuardDuty Finding (여러 서비스 중 선택)
Event pattern
- Event source : AWS services (or EventBridge partners)
- AWS service : GuardDuty (여러 서비스 중 선택)
- Event type : GuardDuty Finding (or All Events or API Call vid CloudTrail)
Target types : AWS service (or EventBridge event bus or EventBridge API destination)
Select a target : SNS topic (여러 서비스 중 선택)
Topic : mytopic
Additional settings(추가 옵션) : -
pattern과 일치하는 event 발생 시 select target(SNS)을 호출합니다.

3단계 : GuardDuty 활성화 (Region별)

GuardDuty > Get Started > Enable GuardDuty (최초 활성화 시 30일 무료)

4단계 Cloud Shell로 Sample 테스트 하는 경우 GaurdDuty도 Cloud Shell과 동일한 Tokyo 리전을 활성화해야 합니다. Region이 다를경우 아래와 같은 Error가 발생합니다. 
  - aws: error: argument --detector-id: expected one argument
  - The request is rejected because the input detectorId is not owned by the current account

Cloud Shell를 사용하지 않고 IAM User로 aws cli를 로그인하여 진행하는 경우는 Region과 관계없이 테스트 가능할 것으로 보입니다. 

4단계 : 테스트

Cloud Shell > Supported Regions (Asia Pacific(Tokyo)) > 아래 명령어 진행 : 2022년 8월 기준 서울리전 미지원

 

# 중요도 높음 Sample
aws guardduty create-sample-findings \
--detector-id $(aws guardduty list-detectors --query 'DetectorIds' --output text) \
--finding-types Backdoor:EC2/DenialOfService.UnusualProtocol

# 중요도 중간 Sample
aws guardduty create-sample-findings \
--detector-id $(aws guardduty list-detectors --query 'DetectorIds' --output text) \
--finding-types Behavior:EC2/NetworkPortUnusual

# 중요도 낮음 Sample
aws guardduty create-sample-findings \
--detector-id $(aws guardduty list-detectors --query 'DetectorIds' --output text) \
--finding-types Policy:S3/AccountBlockPublicAccessDisabled

GuardDuty > Findings : 3개 확인

Findings으로 탐지된 목록은 지속적으로 알람 발생(노이즈)되므로 Archive 조치 필요
 - 오탐지된 Findings 체크 > Actions > Archive
 - Trusted list(신뢰 목록)에 추가하여 WhiteList 동작 : Suppression Rule(제외규칙)에 필터링 설정하여 Archive 자동 처리
   ※ 필터링 조건 : Finding Type, Resource ID, Resource Type 등

수신 메일(aws에서 user01@gtek.com로 발송된 메일) 확인

CloudWatch > Log groups > /aws/lambda/mytopicfunction : 로깅 확인

의도적으로 EC2의 SSH 기본포트(TCP 22)를 ANY 허용한 경우도 탐지된다고 하니 확인해 보시기 바랍니다.

별첨 : 탐지 결과 S3로 내보내기

GuardDuty 탐지 결과는 90일만 보관하기 때문에 필요한 경우 S3로 내보내기하여 관리합니다.

GuardDuty > Settings > Findings export options 

Frequency for updated findings S3 bucket > configure now 비고
6시간 마다 (or 1시간 or 15분) Select : Existing bucket (or New bucket)
Choose a bucket : mybucket
Log file prefix(옵션) : -
KMS encryption : CustomMyKey
KMS Key 필수이므로
사전 생성 필요
Log file prefix 미설정 경우 "mybucket/AWSLogs/GuardDuty/{ACCOUNT_ID}/{REGION}/YYYY/MM/DD/" 계층 구조로 생성

KMS 키 정책에 액세스 권한이 없는 경우 "Failed to configure export options because GuardDuty does not have permission to the KMS key, the S3 bucket , or the specified location in the bucket." 같은 Error message 출력

별첨 : Etc

GuardDuty ID 확인 : GuardDuty > Settings > Detector ID

Sample findings 생성 : GuardDuty > Settings > Sample findings > Generate sample findings

GuardDuty ID는 Region별로 모두 다릅니다.
Sample findings을 생성하여 GuardDuty가 탐지하는 Log 내용(형식과 정보)가 담겨 있는지 알아보시기 바랍니다.
반응형