Skip to content

Ddos_protection


DDoS (Distributed Denial of Service) attacks overwhelm your infrastructure with malicious traffic.

DDoS Attack Impact
=================
Normal Traffic: DDoS Attack:
================ ==============
1,000 users/day 100,000 malicious requests/sec
Server handles fine Server becomes unreachable
All users served No users can access
─────────────────────────────────────────────────────────
Real Example:
GitHub (2018) - 1.35 Tbps attack
Largest recorded DDoS ever
Mitigated by Akamai in 10 minutes
LayerAttack TypeTargetExample
L3/L4VolumetricNetwork bandwidthUDP flood
L3/L4ProtocolServer resourcesSYN flood
L7ApplicationSpecific appHTTP flood
1. Volumetric Attacks (L3/L4)
============================
Goal: Consume all bandwidth
Techniques:
β€’ UDP Flood - Send thousands of UDP packets
β€’ ICMP Flood - Ping flood
β€’ Amplification - DNS/NTP reflection
Scale: Up to 100+ Gbps
─────────────────────────────────────────
2. Protocol Attacks (L3/L4)
=========================
Goal: Exhaust server resources
Techniques:
β€’ SYN Flood - Half-open connections
β€’ SYN-ACK Flood
β€’ TCP Connection exhaustion
Scale: Millions of packets/sec
─────────────────────────────────────────
3. Application Layer Attacks (L7)
==============================
Goal: Crash specific application
Techniques:
β€’ HTTP Flood - GET/POST flood
β€’ Slowloris - Slow headers
β€’ ReDoS - Regex exhaustion
Scale: Harder to detect, looks like real traffic

Multi-Layer DDoS Protection
==========================
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Layer 1: Edge/Network Protection β”‚
β”‚ ────────────────────────────────────────────────────────│
β”‚ β”‚
β”‚ β€’ CDN (Cloudflare, Fastly, CloudFront) β”‚
β”‚ β€’ Anycast network β”‚
β”‚ β€’ Massive bandwidth capacity β”‚
β”‚ β€’ Scrubbing centers β”‚
β”‚ β”‚
β”‚ Blocks: Volumetric attacks (100+ Gbps) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β–Ό Traffic filtered β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Layer 2: DDoS Protection Service β”‚
β”‚ ────────────────────────────────────────────────────────│
β”‚ β”‚
β”‚ β€’ AWS Shield (Standard/Advanced) β”‚
β”‚ β€’ Cloudflare DDoS Protection β”‚
β”‚ β€’ Akamai Prolexic β”‚
β”‚ β€’ Google Cloud Armor β”‚
β”‚ β”‚
β”‚ Blocks: Protocol + some L7 attacks β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β–Ό Further filtered β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Layer 3: WAF (Web Application Firewall) β”‚
β”‚ ────────────────────────────────────────────────────────│
β”‚ β”‚
β”‚ β€’ AWS WAF β”‚
β”‚ β€’ Cloudflare WAF β”‚
β”‚ β€’ ModSecurity β”‚
β”‚ β”‚
β”‚ Blocks: Application attacks, SQLi, XSS β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β–Ό Clean traffic β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Layer 4: Application Protection β”‚
β”‚ ────────────────────────────────────────────────────────│
β”‚ β”‚
β”‚ β€’ Rate limiting β”‚
β”‚ β€’ API gateways β”‚
β”‚ β€’ Authentication β”‚
β”‚ β”‚
β”‚ Blocks: Specific abuse patterns β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

AWS Shield Options
=================
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ AWS Shield Standard (FREE) β”‚
β”‚ ─────────────────────────────────────────────────────────│
β”‚ β”‚
β”‚ β€’ Always-on DDoS mitigation β”‚
β”‚ β€’ Protection against common L3/L4 attacks β”‚
β”‚ β€’ SYN floods, UDP floods, reflection attacks β”‚
β”‚ β€’ Integrates with CloudFront, Route 53, API Gateway β”‚
β”‚ β”‚
β”‚ Automatic with AWS services! β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ AWS Shield Advanced ($3,000/month) β”‚
β”‚ ─────────────────────────────────────────────────────────│
β”‚ β”‚
β”‚ β€’ DDoS response team (24/7) β”‚
β”‚ β€’ Financial protection (up to $300K) β”‚
β”‚ β€’ Real-time visibility via CloudWatch β”‚
β”‚ β€’ Advanced attack mitigation β”‚
β”‚ β€’ Protection for EIP, ALB, CloudFront, Route 53 β”‚
β”‚ β”‚
β”‚ Recommended for production apps β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

WAF protects against application-layer attacks by filtering malicious requests.

WAF Protection
=============
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Common WAF Rules β”‚
β”‚ ─────────────────────────────────────────────────────────│
β”‚ β”‚
β”‚ 1. SQL Injection Protection β”‚
β”‚ Block: ' OR '1'='1 β”‚
β”‚ β”‚
β”‚ 2. XSS Protection β”‚
β”‚ Block: <script>alert(1)</script> β”‚
β”‚ β”‚
β”‚ 3. Path Traversal β”‚
β”‚ Block: ../../../etc/passwd β”‚
β”‚ β”‚
β”‚ 4. Rate Limiting β”‚
β”‚ Block: >100 requests/minute from single IP β”‚
β”‚ β”‚
β”‚ 5. Geo Blocking β”‚
β”‚ Block: Traffic from certain countries β”‚
β”‚ β”‚
β”‚ 6. IP Reputation β”‚
β”‚ Block: Known malicious IPs β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
# AWS WAF Web ACL
AWSTemplateFormatVersion: '2010-09-09'
Resources:
MyWebACL:
Type: AWS::WAFv2::WebACL
Properties:
Name: my-web-acl
Scope: CLOUDFRONT
DefaultAction:
Allow: {}
Rules:
- Name: SQLInjectionRule
Priority: 0
Statement:
SqliMatchStatement:
FieldToMatch:
QueryString: {}
TextTransformations:
- Type: LOWERCASE
- Type: URL_DECODE
Action:
Block: {}
VisibilityConfig:
SampledRequestsEnabled: true
CloudWatchMetricsEnabled: true
MetricName: SQLInjectionRule
- Name: RateLimitRule
Priority: 1
Statement:
RateBasedStatement:
Limit: 1000
EvaluationWindowSec: 60
AggregateKeyType: IP
Action:
Block: {}
VisibilityConfig:
SampledRequestsEnabled: true
CloudWatchMetricsEnabled: true
MetricName: RateLimitRule
- Name: XSSRule
Priority: 2
Statement:
XssMatchStatement:
FieldToMatch:
Body: {}
TextTransformations:
- Type: URL_DECODE
- Type: HTML_ENTITY_DECODE
Action:
Block: {}

DDoS Protection Checklist
=========================
βœ“ Use CDN (Cloudflare, CloudFront)
βœ“ Enable AWS Shield (Standard is free)
βœ“ Configure WAF rules
βœ“ Implement rate limiting at API gateway
βœ“ Enable auto-scaling
βœ“ Use multiple availability zones
βœ“ Set up monitoring and alerts
βœ“ Create incident response plan
βœ“ Test DDoS resilience regularly
─────────────────────────────────────────
Application Best Practices:
───────────────────────────
βœ“ Minimize exposed surfaces
βœ“ Use authentication everywhere
βœ“ Implement rate limiting
βœ“ Validate all input
βœ“ Use secure headers
βœ“ Set appropriate timeouts
Protected Architecture
=====================
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Internet β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Cloudflare (Edge) β”‚
β”‚ β€’ DDoS protection β”‚
β”‚ β€’ WAF β”‚
β”‚ β€’ CDN β”‚
β”‚ β€’ SSL/TLS termination β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ AWS Shield + WAF β”‚
β”‚ β€’ Layer 3/4 protection β”‚
β”‚ β€’ Application rules β”‚
β”‚ β€’ Rate limiting β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ ALB + Auto Scaling Group β”‚
β”‚ β€’ Distributes traffic β”‚
β”‚ β€’ Scales with load β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Application Servers (Multiple AZs) β”‚
β”‚ β€’ Protected core application β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

  1. DDoS attacks - Volumetric, Protocol, Application layer
  2. Layered defense - CDN β†’ Shield β†’ WAF β†’ Rate limiting
  3. AWS Shield - Standard (free) + Advanced (paid)
  4. WAF - Blocks SQLi, XSS, rate limit
  5. CDN - Absorbs volumetric attacks
  6. Auto-scaling - Handles traffic spikes
  7. Monitoring - Detect and respond to attacks

Next: Chapter 46: Designing Twitter