AWS WAF 웹방화벽 -2-
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월 업데이트
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(아래 주소) 을 바로 입력 가능
(옵션) 템플릿 파일을 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에서 작성