[AWS] WAF 설정 ( 크롤링봇제한 )

류정현·2024년 10월 2일

Web ACLs 를 생성하고, Load Balancer에 연결한다.
ACLs 에 Rule 을 추가하는데, AWS-AWSManagedRules 혹은 직접 생성한 Rule 을 지정하여 각각의 Rule에 대한 우선순위를 지정하여 운영하면 된다.

이 모든 것은 Bot 으로부터 시작되었다. 어느 순간 서버가 감당하지 못하지 못할 정도의 트래픽이 밀려들어왔고, Web Server 의 Access-log 를 확인해 보니 User-AgentBytedance , Bytespider Bots 이 사이트를 미친듯이 크롤링하고 있었다. 여기에 더해서 Meta 의 facebookexternalhit 가 크롤링, bongbot, Googlebot 까지 겹쳐 사이트를 뒤져대고 있었다.

크롤링만이 아니었다. 여러가지 방식의 해킹으로 의심되는 접속, 특히 SQL-Injection 으로 보이는 파라미터가 포함된 접속도 미친듯이 서버를 두들겨 대고 있었다. **Kali Linux** 를 이용해서 해킹시도를 해본 사람은 바로 알 수 있다.

크롤링에 대해서는 여러가지 문제가 있었다. robot.txt 의 디렉토리 설정, 헤더의 메타태그 등 설정이 잘 되어 있지 않았다. 이 상황에서 최선의 선택은 방어의 가장 바깥쪽인 Load Balancer 단에서 WAF 를 이용하여 처리하는 것이라 판단했다.

Web ACLs 을 생성하고, AWSManagedRules 을 먼저 적용하였다.

[AWS-AWSManagedRulesAmazonIpReputationList](https://us-east-1.console.aws.amazon.com/wafv2/homev2/web-acl/rule/redit-web-ACL/3a864b6d-1a73-488c-a280-9e11269f42d3/AWS-AWSManagedRulesAmazonIpReputationList?region=ap-northeast-2)
[AWS-AWSManagedRulesKnownBadInputsRuleSet](https://us-east-1.console.aws.amazon.com/wafv2/homev2/web-acl/rule/redit-web-ACL/3a864b6d-1a73-488c-a280-9e11269f42d3/AWS-AWSManagedRulesKnownBadInputsRuleSet?region=ap-northeast-2)
AWS-AWSManagedRulesLinuxRuleSet
AWS-AWSManagedRulesSQLiRuleSet
AWS-AWSManagedRulesBotControlRuleSet
AWS-AWSManagedRulesAnonymousIpList
[AWS-AWSManagedRulesSQLiRuleSet](https://us-east-1.console.aws.amazon.com/wafv2/homev2/web-acl/rule/redit-web-ACL/3a864b6d-1a73-488c-a280-9e11269f42d3/AWS-AWSManagedRulesSQLiRuleSet?region=ap-northeast-2)

AWS-AWSManagedRulesAmazonIpReputationList 에는 다음과 같은 Rule 이 포함되어 있다.



This group contains rules that are based on Amazon threat intelligence. This is useful if you would like to block sources associated with bots or other threats.

AWS-AWSManagedRulesKnownBadInputsRuleSet 에는 다음과 같은 Rule 이 포함되어 있다.


Contains rules that allow you to block request patterns that are known to be invalid and are associated with exploitation or discovery of vulnerabilities. This can help reduce the risk of a malicious actor discovering a vulnerable application.

AWS-AWSManagedRulesLinuxRuleSet 에는 다음과 같은 Rule 이 포함되어 있다.

Contains rules that block request patterns associated with exploitation of vulnerabilities specific to Linux, including LFI attacks. This can help prevent attacks that expose file contents or execute code for which the attacker should not have had access.

AWS-AWSManagedRulesSQLiRuleSet 에는 다음과 같은 Rule 이 포함되어 있다.

Contains rules that allow you to block request patterns associated with exploitation of SQL databases, like SQL injection attacks. This can help prevent remote injection of unauthorized queries.

AWS-AWSManagedRulesBotControlRuleSet 에는 다음과 같은 Rule 이 포함되어 있다.

Provides protection against automated bots that can consume excess resources, skew business metrics, cause downtime, or perform malicious activities. Bot Control provides additional visibility through Amazon CloudWatch and generates labels that you can use to control bot traffic to your applications.

AWS-AWSManagedRulesAnonymousIpList 에는 다음과 같은 Rule 이 포함되어 있다.


This group contains rules that allow you to block requests from services that allow obfuscation of viewer identity. This can include request originating from VPN, proxies, Tor nodes, and hosting providers. This is useful if you want to filter out viewers that may be trying to hide their identity from your application.

AWSManagedRules 이 아닌 내가 원하는 Rule 을 생성하려면

  1. Rule Group 을 생성하고,
  2. Rule 을 추가하고,
  3. 우선순위를 정하여 저장한 다음,
  4. Web ACLs 에 Rule 을 추가하면 된다.

예를 들어 같은 아이피로 갑자기 많은 트래픽이 발생한 경우를 차단하고 싶다면 Rate-based rule 을 생성하여 위의 단계에 맞추어 지정하면 된다.


block 을 할 수도, CAPTCHA 혹은 Challenge 로 사람인지 구분할 수도 있다.

Rate limit 과 Evaluation window 를 적절히 지정한다.

하지만 여기서 끝이 아니다.
Web ACLs 를 통과해서 우리 서버에 접속하지만 우리가 보기에 문제가 되는 것이 있다.
위에서 언급했듯이 아래와 같은 문제점이 있기에 해결해야 할 여러가지가 있었고, 시간이 필요했다.

크롤링에 대해서는 여러가지 문제가 있었다. 
robot.txt 의 디렉토리 설정, 헤더의 메타태그 등 설정이 잘 되어 있지 않았다.

트래픽의 비율을 확인해 보면 우리는 국내 사용자가 99%를 넘는 상황이고, 따라서 인덱싱 혹은 광고를 위해 접속하는 정상적인 트래픽을 새벽시간으로 제한하였다.

profile
사용자의 경험을 설계하고 시스템의 생명주기를 책임지는 개발자

0개의 댓글