Skip to content
About Me
----

Perimeter Threat Defense: AWS WAF, Shield & Security Hub

Architect Key Takeaways

Master AWS perimeter defense: Layer 7 Web Application Firewall (WAF), Layer 3/4 DDoS mitigation (AWS Shield Standard vs Advanced), and centralized compliance via AWS Security Hub.

Perimeter Threat Defense: AWS WAF, Shield & Security Hub

Section titled β€œPerimeter Threat Defense: AWS WAF, Shield & Security Hub”

Securing cloud applications requires a Defense-in-Depth model where malicious traffic, volumetric floods, and application exploits are blocked at the cloud perimeter before consuming backend compute, exhausting connection pools, or touching sensitive databases. In AWS, perimeter defense is anchored by AWS WAF (Layer 7), AWS Shield (Layer 3/4 DDoS), and AWS Security Hub (Centralized CSPM and automated incident response).


Distributed Denial of Service (DDoS) attacks attempt to exhaust network bandwidth and crash infrastructure by flooding systems with traffic.

Feature AWS Shield Standard AWS Shield Advanced ($3,000 / month + data transfer)
Availability Enabled automatically for all AWS customers at zero cost Subscription-based enterprise tier per Organization
Protected Layers Layer 3 (Network) & Layer 4 (Transport) Layer 3, Layer 4, and Layer 7 (Application)
Targeted Attacks Dropped SYN Floods, UDP Reflection, NTP Amplification HTTP Floods, DNS Floods, low-and-slow application exhaustion
Protected Resources Route 53, CloudFront, ALB, Elastic IPs CloudFront, Route 53, ALB, NLB, AWS Global Accelerator
Financial Safeguard None DDoS Cost Spike Protection (AWS credits back auto-scaling costs caused by an attack)
Specialized Support Standard AWS Support tickets 24/7 direct engagement with the AWS Shield Response Team (SRT)
Bundled Perks WAF rules billed separately AWS WAF and AWS Firewall Manager fees are 100% waived
AWS Perimeter Defense: Shield, WAF & ALB Inspection Flow

AWS WAF inspects HTTP/HTTPS requests at the perimeter and attaches directly to:

  • Amazon CloudFront (Global edge PoPs)
  • Application Load Balancer (ALB) (Regional)
  • Amazon API Gateway (REST / HTTP APIs)
  • AWS AppSync (GraphQL)
  • Amazon Cognito User Pools (Authentication endpoints)
  1. AWS Managed Rules (AMR):
    • AWSManagedRulesCommonRuleSet (Core Rule Set): Protects against OWASP Top 10 vulnerabilities (LFI, RFI, command injection).
    • AWSManagedRulesSQLiRuleSet: Advanced heuristics detecting SQL syntax injection in headers, parameters, and payloads.
    • AWSManagedRulesKnownBadInputsRuleSet: Blocks known exploitation paths and vulnerability scanning bots.
  2. Rate-Based Rules: Enforces sliding-window request limits (e.g., maximum 500 requests per 5-minute window per IP) to neutralize brute-force login attempts and denial-of-wallet scraping.
  3. IP Reputation Sets: Amazon IP reputation list drops requests originating from compromised hosts, VPN exit nodes, and Tor exit nodes.
  4. Custom Geo-Blocking / Allow-Listing: Rejects traffic originating outside sanctioned operating jurisdictions.

Production Terraform: Hardened AWS WAFv2 Web ACL with Rate Limiting & Managed Rules

Section titled β€œProduction Terraform: Hardened AWS WAFv2 Web ACL with Rate Limiting & Managed Rules”
resource "aws_wafv2_web_acl" "production_perimeter" {
name = "production-alb-perimeter-waf"
description = "Enterprise perimeter defense with AWS Managed Rules and Rate Limiting"
scope = "REGIONAL" # Set to CLOUDFRONT for edge deployments
default_action {
allow {}
}
# 1. AWS Managed Common Rule Set (OWASP Top 10)
rule {
name = "AWS-AWSManagedRulesCommonRuleSet"
priority = 10
override_action {
none {}
}
statement {
managed_rule_group_statement {
name = "AWSManagedRulesCommonRuleSet"
vendor_name = "AWS"
}
}
visibility_config {
cloudwatch_metrics_enabled = true
metric_name = "WAFCommonRulesMetric"
sampled_requests_enabled = true
}
}
# 2. Rate-Limiting Rule: Block IPs exceeding 500 requests per 5 minutes
rule {
name = "EnforceRateLimitingPerIP"
priority = 20
action {
block {
custom_response {
response_code = 429
custom_response_body_key = "rate_limit_exceeded"
}
}
}
statement {
rate_based_statement {
limit = 500
aggregate_key_type = "IP"
}
}
visibility_config {
cloudwatch_metrics_enabled = true
metric_name = "WAFRateLimitMetric"
sampled_requests_enabled = true
}
}
custom_response_body {
key = "rate_limit_exceeded"
content = jsonencode({ error = "Too Many Requests", message = "Perimeter rate limit exceeded. Try again later." })
content_type = "APPLICATION_JSON"
}
visibility_config {
cloudwatch_metrics_enabled = true
metric_name = "ProductionPerimeterWAFMetrics"
sampled_requests_enabled = true
}
}
# Associate WAF ACL with Application Load Balancer
resource "aws_wafv2_web_acl_association" "alb_association" {
resource_arn = var.application_load_balancer_arn
web_acl_arn = aws_wafv2_web_acl.production_perimeter.arn
}

3. Centralized Posture & Auto-Remediation: AWS Security Hub

Section titled β€œ3. Centralized Posture & Auto-Remediation: AWS Security Hub”

Managing security findings across hundreds of microservices and multi-account landing zones requires automated normalization and automated remediation pipelines. AWS Security Hub acts as the central CSPM (Cloud Security Posture Management) engine.

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Amazon GuardDuty (Threat Intel) β”‚ ──┐
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚
β”‚ Amazon Inspector (CVE Scans) β”‚ ──┼──> [ AWS Security Hub ] ──> [ Amazon EventBridge ]
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ β”‚ β”‚
β”‚ AWS Config (Compliance Drift) β”‚ β”€β”€β”˜ β–Ό β–Ό
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ [ Normalized ASFF ] [ Auto-Remediate Lambda ]
(CIS AWS Benchmark) - Revoke Security Group 0.0.0.0/0
- Quarentine Compromised EC2
  1. Compliance Standard Benchmarking: Runs continuous, automated audits against:
    • CIS AWS Foundations Benchmark v3.0.0
    • PCI-DSS v3.2.1
    • AWS Foundational Security Best Practices (FSBP)
  2. AWS Security Finding Format (ASFF): Ingests raw alerts from GuardDuty, Macie, Inspector, IAM Access Analyzer, and third-party tools (Snyk, Prisma Cloud, Aqua), standardizing them into a single JSON schema containing Severity, ResourceId, and ComplianceStatus.
  3. Automated Event-Driven Remediation: Emits finding state changes to Amazon EventBridge, which invokes serverless AWS Lambda runbooks to eliminate misconfigurations without waiting for human intervention.

EventBridge Pattern: Auto-Remediating Unrestricted SSH (Port 22 Open to 0.0.0.0/0)

Section titled β€œEventBridge Pattern: Auto-Remediating Unrestricted SSH (Port 22 Open to 0.0.0.0/0)”
{
"source": ["aws.securityhub"],
"detail-type": ["Security Hub Findings - Imported"],
"detail": {
"findings": {
"Compliance": {
"Status": ["FAILED"]
},
"GeneratorId": ["aws-foundational-security-best-practices/v/1.0.0/EC2.19"],
"Severity": {
"Label": ["CRITICAL", "HIGH"]
}
}
}
}

When triggered, the downstream Lambda executes aws ec2 revoke-security-group-ingress, immediately closing the rogue perimeter hole.


4. Incident Triage Runbook: Legitimate Traffic Blocked with 403 Forbidden by WAF

Section titled β€œ4. Incident Triage Runbook: Legitimate Traffic Blocked with 403 Forbidden by WAF”

A mobile app release triggers widespread customer reports of 403 Forbidden errors when uploading image attachments or submitting search forms.

[ Mobile App Client ] ──> [ AWS WAF ] ──> ❌ 403 Forbidden (Blocked by Managed Rule)

Step 1: Query Sampled Requests in AWS WAF Console / CLI

Section titled β€œStep 1: Query Sampled Requests in AWS WAF Console / CLI”

Identify the exact Web ACL rule terminating the request:

Terminal window
aws wafv2 get-sampled-requests \
--web-acl-arn arn:aws:wafv2:ap-south-1:123456789012:regional/webacl/production-alb-perimeter-waf/abc-123 \
--rule-metric-name WAFCommonRulesMetric \
--scope REGIONAL \
--time-window StartTime=$(date -u -v-1H +%s),EndTime=$(date -u +%s) \
--max-items 50 \
--output json

Step 2: Identify False Positives in CloudWatch Log Insights

Section titled β€œStep 2: Identify False Positives in CloudWatch Log Insights”

Query the WAF centralized Kinesis Firehose / CloudWatch log group:

fields @timestamp, httpRequest.clientIp, httpRequest.uri, terminatingRuleId, terminatingRuleType
| filter action = "BLOCK"
| stats count(*) as BlockCount by terminatingRuleId, httpRequest.uri
| sort BlockCount desc
| limit 20

If an AWS Managed Rule (such as SizeRestrictions_BODY or GenericRFI_BODY) is triggering on legitimate multipart form data:

  1. Do not disable the entire Managed Rule Group.
  2. In your Terraform code, configure a rule_action_override setting the offending specific rule to count (dry run / alert only):
rule {
name = "AWS-AWSManagedRulesCommonRuleSet"
priority = 10
statement {
managed_rule_group_statement {
name = "AWSManagedRulesCommonRuleSet"
vendor_name = "AWS"
rule_action_override {
name = "SizeRestrictions_BODY"
action_to_use {
count {} # Mitigates production blocking while logging requests
}
}
}
}
# ...
}

Q1: Why should an enterprise deploy AWS WAF on CloudFront rather than directly on the Application Load Balancer whenever feasible?

Deploying WAF on CloudFront enforces perimeter security at AWS Edge locations worldwide (over 450+ Points of Presence), blocking malicious requests before they traverse the AWS backbone network or consume regional ALB bandwidth. Furthermore, CloudFront shields your origin ALB IP address from public scanning, and edge caching absorbs volumetric traffic without incurring ALB compute costs.

Q2: If an attacker spoofed their HTTP request header with X-Forwarded-For: 1.2.3.4, how does AWS WAF prevent rate limit evasion?

By default, AWS WAF inspects the immediate socket source IP address connecting to the listener. When behind proxies or CDNs, you can configure the WAF rate-based rule to evaluate the X-Forwarded-For header with a fallback configuration (MATCHING_IP or FIRST_IP) while ensuring that intermediate reverse proxies are configured to overwrite, rather than append, client-supplied headers.

Q3: How does AWS Shield Advanced mitigate financial risk during a massive distributed DDoS attack against an Auto Scaling Group?

During a sustained DDoS attack, backend EC2 instances or ECS tasks behind an ALB might scale out aggressively due to CPU or request-count spikes, incurring massive unexpected cloud infrastructure costs. With AWS Shield Advanced, customers can submit a DDoS Cost Spike Protection claim to AWS Support. After verifying the attack window, AWS refunds or credits back the infrastructure scaling charges incurred directly as a result of the attack.