AWS

AWS WAF 웹방화벽 -2-

가시다 2020. 3. 4. 22:44

AWS WAF 웹방화벽 -2-

2019년 3월 26일 화요일

오후 9:31

# AWS 에서 제공하는 WAF Security Automations 대해서 알아보고 실습을 해본다

 

1. AWS WAF Security Automations 소개

애플리케이션 보안 규칙 정책을 CloudFormation Template 통하여 쉽게 구성하게함.

다양한 보안 기능 동작을 위하여 Lambda, API GW 등을 활용함.

 

제공 보안 정책

Honeypot (A) : 봇/스크래퍼 유인 후 소스IP수집 후 차단

SQL injection (B) & cross-site scripting (C) protection : SQL injection/XSS 공격 차단

Log parsing 혹은 Scanner & Probe Protection (D): 악의적으로 40X 에러코드를 유발(?) 시 해당 소스IP를 식별하여 차단

Manual IP lists (E): IP기반 허용/차단 List

IP-list parsing (F): malicious IP 를 third-party IP reputation lists 에서 매 시간 차단 IP List에 적용

HTTP flood protection (G): DoS와 같은 임계값 초과 시 차단

 

2. AWS WAF Security Automations 이해를 위한 링크 정리

WAF Security Automations 소개/설명서 : 기본적인 소개 설명서 Source code 링크, 2018 12 업데이트

https://aws.amazon.com/es/solutions/aws-waf-security-automations/?nc1=h_ls

https://docs.aws.amazon.com/solutions/latest/aws-waf-security-automations/welcome.html

 

WAF Security Automations Implementation Guide(추천) : 설명서의 부족한 부분을 포함된 실제 배포를 위한 상세 설명, 2018 12 업데이트

https://s3.amazonaws.com/solutions-reference/aws-waf-security-automations/latest/aws-waf-security-automations.pdf

 

3. AWS WAF Security Automations Demo

3.1 기본 환경 구성도 (Seoul Region)

웹서버 : Amazon Linux DVWA 설치함, 취약한 웹서버 환경 제공,  http://www.dvwa.co.uk/

Cloudfront : Origin(EC2 Public DNS 입력), Access Log(S3 저장)

Route53 : 도메인 접속을 위한 설정, Type(A) Alias Target(Cloudfront)

 

3.2 Cloudfront Access log 저장 S3 생성 Cloudfront log 설정

S3 bucket Name : solaweb-cloudfront-accesslog "편한대로 설정"

Cloudfront 설정(Distibution Settings) : 아래 처럼 Logging(On) 선택 Buckets for Logs( S3 선택)

 

3.3 WAF Security Automations 배포(with Cloudformation)

Cloudformation 템플릿 지정 : Amazon S3 URL(아래 주소) 바로 입력 가능

https://s3.amazonaws.com/solutions-reference/aws-waf-security-automations/latest/aws-waf-security-automations.template

 

(옵션) 템플릿 파일을 Designer 에서 보기

 

Stack Name : SOLA-WAF "편한대로 설정"

파라미터(Protection List) : 각각 WAF 보안 정책( 1 제공 보안 정책 참고) 사용 여부에 따라 yes/no 선택

Settings : Endpoint Type - Cloudfront / ALB WAF 적용 선택 , Access Log Bucket Name - Endpoint Access Log S3 지정

Advanced Settings

 Request Settings(HTTP Flood Rule 적용) : 5분동안 1개의 IP에서 '지정된 갯수 만큼' 요청 발생 차단

 Error Threshold(Scanner & Probe Protection Rule 적용) : 1분당 1개의 IP에서 '지정된 갯수 만큼' 400,402,404' 발생 유도 차단

 WAF Block Period(Scanner & Probe Protection Rule 적용) : 조건 만족하여 차단 발생 '지정된 시간()' 이후에 차단 해제

생성 선택 대략 15~20 사이에 생성 완료됨

 

3.4 WAF Security Automations 배포 확인

3.4.1 CloudFormation 확인

SOLA-WAF Stack Nested Stack(=중첩스택) 정상 생성 것을 확인

 

SOLA-WAF Stack 출력(=output) 확인

BadBotHoneypotEndpoint badbot 아래 URL(=API GW) 유인하여 링크 인입 자동으로 Black IP List 업데이트 되고 차단됨

WAFWebACL CloudFormation 통하여 생성된 Web ACL ID

 

SOLA-WAF Stack 리소스 확인

4가지 역할의 Lambda:Function 생성 확인

 

Cloudwatch Monitoring Dashboard 생성 확인

 

그외 중략

 

3.4.2 Web ACL 확인

생성된 Web ACL 확인, 8 Rules Rule Action 확인, 8 Rule 전부 매칭되지 않을 Default action(allow) 확인

 

Whitelist Rule Blacklist Rule IP 기반하여 허용/차단 하는 정책

 

SQL Injection Rule : SQL Injection 방어를 위한 11개의 filters 확인

 

XSS Rule : cross-site scripting 방어를 위한 11개의 filters 확인

 

IP Reputation Lists Rule : 1시간 마다 불량 IP List 됨을 확인, 현재 2183

아래 3.5 항목에서 상세 설명

 

Scanners & Probes Rule HTTP Flood Rule 이전 포스팅에서 다룬 내용으로 skip

https://sola99.tistory.com/461

 

Bad Bot Rule robots.txt Disallow 로봇(Bot/Crawler) 검색을 차단한 영역을 무시하고 접근 차단하는 정책

아래 3.6 항목에서 상세 설명

 

WebACL 선택 우측화면에 간단한 Rule match 통계 그래프를 확인 가능함

 

WebACL 선택 우측하단에 Rule 요청에 대한 Sampled(상세) 정보를 쉽고 빠르게 확인

단점은 WAF Full logs 아니며, 대략 3시간 이전까지 내용만 확인 가능 WAF Full Logs 기능 참고

 

(참고) WAF Full Logs 실시간(거의)으로 모니터링 하며, 상세한 정보 확인

 

3.4.3 Cloudwatch 대시보드

자동으로 Cloudwatch 대시보드에 metric 추가됨

Block(차단) / Allow(허용) / Count(카운트) 요청 갯수 확인

 

3.5 IP Reputation Lists Rule

1시간 마다(=Cloudwatch Event Rule) 3개의 사이트에서 IP List 받아서 Web IP Reputation List 동적으로 업데이트함(=Lambda)

사이트: https://www.spamhaus.org/drop/ , https://rules.emergingthreats.net/fwrules/emerging-Block-IPs.txt , https://check.torproject.org/exit-addresses

 

Cloudwatch Event Rule 확인 : 아래처럼 1시간 마다 Lambda 실행

ReputationListsParser 동작을 하는 Lambda 함수 확인

 

Lambda IP List WAF 반영하였는지를 CloudWatch Logs 에서 확인 : 아래 처럼 WAF IP Set 2182 update 것을 확인

 

WAF IP Reputation Lists 확인 : 시간마다 3 사이트를 확인 업데이트함, 아래처럼 현재 2183 IP List 반영됨

$ aws waf list-ip-sets --output text | grep Reputation

IPSETS  9b9376e1-7264-4b21-bad6-b81ff36b66b5    SOLA-WAF-CloudFrontStack-17ZXMLASUR7MW - IP Reputation Lists Set

$ aws waf get-ip-set --ip-set-id 9b9376e1-7264-4b21-bad6-b81ff36b66b5 --output text | wc -l

2183

 

3.6 Bad Bot Rule

Bad Bot Rule robots.txt Disallow 로봇(Bot/Crawler) 검색을 차단한 영역을 무시하고 접근 차단하는 정책

https://docs.aws.amazon.com/solutions/latest/aws-waf-security-automations/deployment.html#step3

Website robots.txt 파일 생성(예시)

User-agent: *

Disallow: /behavior_path

 

Honeypot Endpoint Cloudfront 에서 연결(Origin)하거나 혹은 Web Content 직접 link 하자

<a href="/behavior_path" rel="nofollow" style="display: none" aria-hidden="true">honeypot link</a>

 

bad bot 경우에는 Disallow 규약을 무시하고 접근을 것이다

 

Honeypot Endpoint API_GW 처리함, URL 확인

 

실제 Honey Endpoint 접속하게 되면 '방문 환경' 메시지와 함께 접속자의 IP Block IP List 업데이트 되어 이제부터 차단된다

 

WAF Bad Bot Rule 차단되는 IP List 자동으로 등록되어 있음을 확인

 

Tip. Collection of Anonymous Data : AWS 전송 차단 설정

전송/수집 정보

Solution ID: The AWS solution identifier

Unique ID (UUID): Randomly generated, unique identifier for each deployment of this solution

Timestamp: Data-collection timestamp

Solution configuration: Features enabled and parameters set during initial launch

Lifecycle: How long the customer used the solution (based on stack delete)

Log Parser data:

The number of IP addresses in the manual blacklist set and the automatically created set to block

The number of requests processed and blocked

IP Lists Parser data:

The number of IP addresses in the set

The number of requests blocked

Access Handler data:

The number of IP addresses in the set

The number of requests blocked

https://docs.aws.amazon.com/solutions/latest/aws-waf-security-automations/appendix-c.html

 

전송 차단 설정 : Cloudformation SendAnonymousUsageData 에 "Yes" "No" 변경

Solution:

    Data : {

       SendAnonymousUsageData :  "No"

 

Microsoft OneNote 2013에서 작성