Showing raw Markdown: the renderer could not load.
## Why this matters
An online shop makes most of its money in the week before a holiday. On Tuesday at 10:00 the site becomes slow, then stops answering. The servers are healthy, nothing was hacked, no data was stolen. The network link is simply full of traffic that nobody asked for, and real customers can't get in. The team doesn't know whether this is an attack or a successful advertising campaign, nobody knows the phone number of the hosting provider's security desk, and every hour offline costs sales and trust.
That is a **distributed denial-of-service (DDoS)** attack: the goal is not to break in but to make a service unavailable. Attacks like this are cheap to start (the services that sell them are illegal, but they exist), they are hard to block because the traffic comes from thousands of places, and no single product stops all of them. What does work is to understand which resource each attack exhausts, put the right defence at each layer, and have a written plan before the day it happens.
This lesson explains what DoS and DDoS attacks are, how botnets make them hard to block, the three classes of attack, how reflection and amplification turn other people's servers into weapons, the defences for each layer and how to respond. The lab then lets you flood your own web server in an isolated sandbox and defend it with rate limiting.
> [!IMPORTANT]
> This module is defensive. Flooding a system you don't own is a crime in most countries, even if you call it a "test". You only attack your own containers, on an isolated network. The lesson describes attacks conceptually, so you can recognise and stop them; it gives no instructions to launch one.
## Learning objectives
- Explain what denial-of-service (DoS) and distributed denial-of-service (DDoS) attacks are, and why attacks from botnets are hard to block.
- Classify DDoS attacks as volumetric, protocol or application-layer attacks, and give an example of each.
- Explain how reflection and amplification attacks work and why source address spoofing makes them possible.
- Compare DDoS defences (overprovisioning, rate limiting, SYN cookies, web application firewalls, anycast and CDNs, scrubbing services, blackholing) and choose the right one for each attack type.
- Plan a DDoS response: traffic baseline, detection, runbook and escalation to the provider.
## Key concepts
### DoS, DDoS and botnets
Picture a small restaurant with 20 seats. One rude person who sits down and never orders takes one seat. That is a nuisance. Now 500 people walk in at the same time, order nothing and refuse to leave: real customers can't get a table, and you can't throw out 500 people one by one. The first case is a DoS attack, the second a DDoS attack.
A **denial-of-service (DoS)** attack makes a service unavailable to its legitimate users by exhausting a resource: bandwidth, memory, processor time, connection slots, or the time of a human operator. It can come from a single machine, or even from one malformed request that crashes a buggy program. A **distributed denial-of-service (DDoS)** attack does the same from many machines at once. The "distributed" part is what makes it hard to stop.
Where do thousands of machines come from? Mostly from a **botnet**: a network of ordinary devices (a **bot**, or zombie, is each infected device) taken over with malware and controlled remotely from a **command-and-control (C2)** server. The owners usually notice nothing. Internet Protocol (IP) cameras, home routers, video recorders and other Internet of Things (IoT) devices are favourite targets: they are always on, always connected, rarely updated, and often still have the default password. The **Mirai** botnet of 2016 is the classic historical example. It scanned the Internet for IoT devices that accepted default credentials, enlisted them, and was used for some of the largest attacks of its time, including one on the Domain Name System (DNS) provider Dyn that made many well-known sites hard to reach for hours. Its source code was later published, and variants followed.
Attackers need no botnet of their own. **DDoS-for-hire** ("booter" or "stresser") services rent attack capacity for a small price. They are illegal, and law enforcement agencies have repeatedly taken them down, but their existence means that the skill and money needed to start an attack are low, so any public service can become a target, whether the reason is extortion, a grudge, competition, politics, or simply boredom.
<figure class="diagram" style="--dg-w: 1180px"><svg xmlns="http://www.w3.org/2000/svg" class="dg" viewBox="0 0 1180 470" width="1180" height="470" role="img" aria-labelledby="ddos-botnet-title ddos-botnet-desc" font-family="Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" xml:lang="en">
<title id="ddos-botnet-title">A botnet floods one target while a real customer is locked out</title>
<desc id="ddos-botnet-desc">On the left, a botmaster (the attacker) controls a command-and-control server. The server sends an attack order to a botnet, shown as a zone holding six compromised devices: an IP camera, a home router, a laptop, a video recorder, a phone and a hacked server. A note says that each bot sends only a little traffic, but together it is enormous and every source address is different. A thick line labelled flood from thousands of addresses leads from the botnet to the target service at 203.0.113.80 on tcp 443. Below the target, a real customer at 198.51.100.25 tries to reach it along a dashed red line marked with a cross: the customer cannot get through.</desc>
<rect class="dg-bg" x="0.5" y="0.5" width="1179" height="469" rx="16" fill="#ffffff" stroke="#e3e3dd"/>
<g class="dg-l4"><rect class="dg-tint" x="260" y="20" width="500" height="430" rx="16" fill="#fbf4f0" stroke="#e7b39e" stroke-width="1.2" stroke-dasharray="6 5"/>
<g class="dg-icon" transform="translate(276 33) scale(0.7500)" fill="none" stroke="#c2410c" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="10" height="14" x="3" y="8" rx="2"/><path d="M5 4a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2h-2.4"/><path d="M8 18h.01"/></g>
<text x="302" y="47" font-size="13" class="dg-ink" fill="#c2410c" font-weight="700">Botnet: thousands of compromised devices</text></g>
<rect class="dg-card" x="45" y="40" width="170" height="92" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-warn"><g class="dg-icon" transform="translate(115 50) scale(1.2500)" fill="none" stroke="#b91c1c" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M20 16V7a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v9m16 0H4m16 0 1.28 2.55a1 1 0 0 1-.9 1.45H3.62a1 1 0 0 1-.9-1.45L4 16"/></g></g>
<text x="130" y="100" font-size="13.5" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle">Botmaster</text>
<text x="130" y="119" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">the attacker</text>
<rect class="dg-card" x="45" y="190" width="170" height="92" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-warn"><g class="dg-icon" transform="translate(115 200) scale(1.2500)" fill="none" stroke="#b91c1c" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect width="20" height="8" x="2" y="2" rx="2"/><rect width="20" height="8" x="2" y="14" rx="2"/><path d="M6 6h.01"/><path d="M6 18h.01"/></g></g>
<text x="130" y="250" font-size="13.5" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle">C2 server</text>
<text x="130" y="269" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">command and control</text>
<g class="dg-warn"><path class="dg-stroke" d="M130 132V190" stroke="#b91c1c" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-warn"><path class="dg-stroke" d="M124 181l6 8 6-8" stroke="#b91c1c" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-warn"><path class="dg-stroke" d="M215 236H280" stroke="#b91c1c" stroke-width="3" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-dasharray="7 6"/></g>
<g class="dg-warn"><path class="dg-stroke" d="M271 230l8 6-8 6" stroke="#b91c1c" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-warn"><rect class="dg-bg-plain" x="210.52" y="202" width="54.96" height="24" rx="12" fill="#ffffff"/><text x="238" y="218.5" font-size="11" class="dg-ink" fill="#b91c1c" font-weight="600" text-anchor="middle">orders</text></g>
<rect class="dg-card" x="265" y="70" width="140" height="74" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l4"><g class="dg-icon" transform="translate(320 80) scale(1.2500)" fill="none" stroke="#c2410c" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M12 20h.01"/><path d="M2 8.82a15 15 0 0 1 20 0"/><path d="M5 12.86a10 10 0 0 1 14 0"/><path d="M8.5 16.43a5 5 0 0 1 7 0"/></g></g>
<text x="335" y="130" font-size="13.5" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle">IP camera</text>
<rect class="dg-card" x="425" y="70" width="140" height="74" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l4"><g class="dg-icon" transform="translate(480 80) scale(1.2500)" fill="none" stroke="#c2410c" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect width="20" height="8" x="2" y="14" rx="2"/><path d="M6.01 18H6"/><path d="M10.01 18H10"/><path d="M15 10v4"/><path d="M17.84 7.17a4 4 0 0 0-5.66 0"/><path d="M20.66 4.34a8 8 0 0 0-11.31 0"/></g></g>
<text x="495" y="130" font-size="13.5" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle">Home router</text>
<rect class="dg-card" x="585" y="70" width="140" height="74" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l4"><g class="dg-icon" transform="translate(640 80) scale(1.2500)" fill="none" stroke="#c2410c" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M20 16V7a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v9m16 0H4m16 0 1.28 2.55a1 1 0 0 1-.9 1.45H3.62a1 1 0 0 1-.9-1.45L4 16"/></g></g>
<text x="655" y="130" font-size="13.5" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle">Laptop</text>
<rect class="dg-card" x="265" y="180" width="140" height="74" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l4"><g class="dg-icon" transform="translate(320 190) scale(1.2500)" fill="none" stroke="#c2410c" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect width="10" height="14" x="3" y="8" rx="2"/><path d="M5 4a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2h-2.4"/><path d="M8 18h.01"/></g></g>
<text x="335" y="240" font-size="13.5" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle">Video recorder</text>
<rect class="dg-card" x="425" y="180" width="140" height="74" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l4"><g class="dg-icon" transform="translate(480 190) scale(1.2500)" fill="none" stroke="#c2410c" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect width="14" height="20" x="5" y="2" rx="2"/><path d="M12 18h.01"/></g></g>
<text x="495" y="240" font-size="13.5" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle">Phone</text>
<rect class="dg-card" x="585" y="180" width="140" height="74" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l4"><g class="dg-icon" transform="translate(640 190) scale(1.2500)" fill="none" stroke="#c2410c" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect width="20" height="8" x="2" y="2" rx="2"/><rect width="20" height="8" x="2" y="14" rx="2"/><path d="M6 6h.01"/><path d="M6 18h.01"/></g></g>
<text x="655" y="240" font-size="13.5" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle">Hacked server</text>
<text x="510" y="322" font-size="13" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle">Each bot sends only a little traffic.</text>
<text x="510" y="344" font-size="12.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="middle">Together it is enormous, and every source address is different.</text>
<g class="dg-l4"><path class="dg-stroke" d="M760 140H950" stroke="#c2410c" stroke-width="7" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-l4"><path class="dg-stroke" d="M941 134l8 6-8 6" stroke="#c2410c" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-l4"><rect class="dg-bg-plain" x="749.74" y="100" width="230.52" height="24" rx="12" fill="#ffffff"/><text x="865" y="116.5" font-size="11.5" class="dg-ink" fill="#c2410c" font-weight="600" text-anchor="middle">flood from thousands of addresses</text></g>
<rect class="dg-card" x="960" y="90" width="200" height="100" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l3"><g class="dg-icon" transform="translate(976 106) scale(1.2500)" fill="none" stroke="#b45309" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect width="20" height="8" x="2" y="2" rx="2"/><rect width="20" height="8" x="2" y="14" rx="2"/><path d="M6 6h.01"/><path d="M6 18h.01"/></g></g>
<g class="dg-l3"><text x="1018" y="127" font-size="14" class="dg-ink" fill="#b45309" font-weight="700">Target service</text></g>
<text x="978" y="158" font-size="12.5" class="dg-text" fill="#17171c" font-weight="500" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">203.0.113.80 · tcp 443</text>
<rect class="dg-card" x="975" y="330" width="170" height="92" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l2"><g class="dg-icon" transform="translate(1045 340) scale(1.2500)" fill="none" stroke="#15803d" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M20 16V7a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v9m16 0H4m16 0 1.28 2.55a1 1 0 0 1-.9 1.45H3.62a1 1 0 0 1-.9-1.45L4 16"/></g></g>
<text x="1060" y="390" font-size="13.5" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle">Real customer</text>
<text x="1060" y="409" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">198.51.100.25</text>
<g class="dg-warn"><path class="dg-stroke" d="M1060 330V210" stroke="#b91c1c" stroke-width="3" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-dasharray="7 6"/></g>
<g class="dg-warn"><path class="dg-stroke" d="M1054 201l6-8 6 8" stroke="#b91c1c" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-warn"><circle class="dg-solid" cx="1060" cy="262" r="11" fill="#b91c1c"/><text x="1060" y="266.5" font-size="13" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">✕</text></g>
<text x="1060" y="445" font-size="12.5" class="dg-ink" fill="#b91c1c" font-weight="700" text-anchor="middle">can't get through</text>
</svg></figure>
*Figure 1. Each bot sends only a little traffic, but together they bury the target, and the real customer is locked out.*
**Why blocking IP addresses doesn't scale.** The usual reflex is "block the attacker's address". Against a single source that works. Against a botnet it fails for four reasons:
- **Too many sources.** A botnet can have tens of thousands to millions of devices. A firewall list that long is slow, and by the time you finish, the botnet has changed.
- **Each source looks harmless.** If 100,000 bots send one request every few seconds, every address is below any sensible threshold. The harm is only in the sum.
- **The sources are real people's devices.** Many are home users, often in the same countries as your customers, so blocking whole networks blocks customers too.
- **The traffic may already have done its damage.** If the link is full, a rule on your firewall comes too late: the packets filled the pipe before they reached the firewall.
So you don't win a DDoS by blocking addresses at the end of the line. You win by absorbing the traffic where there is enough capacity, filtering by behaviour rather than by address, and keeping the service cheap enough to run that the attack costs more than it gains.
> [!CHECK]
> Why is blocking the attacker's IP addresses on your own firewall a poor main defence against a botnet?
>
> - [ ] Firewalls can't block IP addresses at all.
> - [x] There are too many sources, each one looks harmless alone, and a full link is already lost before the firewall sees the packets.
> - [ ] Botnets always use the same few addresses, which firewalls can't see.
> - [ ] Blocking addresses is illegal for companies that suffer an attack.
>
> A botnet spreads a large attack over thousands of ordinary-looking addresses, and the bandwidth is exhausted before your firewall can act. Blocking works well against one noisy source, not against many quiet ones.
### The three classes of DDoS attack
Every attack exhausts something. The useful question is *what*, because the answer tells you where to defend. The usual classification has three classes, each measured in a different unit.
**Volumetric attacks** fill the **bandwidth**: the pipe between you and the Internet. Traffic you never asked for, such as a flood of User Datagram Protocol (UDP) packets or reflected responses, arrives faster than the link can carry, so legitimate packets are dropped with the rest. The unit is **bits per second (bps)**, usually Gbps or Tbps. If the pipe is full, nothing you configure behind it can help, because the damage is done before the traffic reaches you.
**Protocol attacks**, also called **state-exhaustion attacks**, exhaust the **tables and counters** of devices that keep state: servers, firewalls and load balancers. The classic example is the **SYN flood**, described in [How it works](#how-it-works). Each packet is tiny and the bandwidth looks normal, but the device runs out of memory or connection slots. The unit is **packets per second (pps)**, because the work a device does is mostly per packet, not per byte.
**Application-layer attacks** target the **application**, at layer 7: CPU, database, threads, application connections. An **HTTP flood** sends valid-looking Hypertext Transfer Protocol (HTTP) requests, preferably for expensive pages such as search or report generation, so the server works hard for each one. **Slowloris** and other **slow attacks** open many connections and send them very slowly (a few header bytes every few seconds) so the server keeps each connection reserved until it has none left for real users. The unit is **requests per second (rps)**. These attacks need very little bandwidth and look like real users, so they are the hardest to tell apart from a busy day.
| Class | Layer | Example | What runs out | Measured in | Where you defend |
|---|---|---|---|---|---|
| Volumetric | 3–4 | UDP flood, reflection | Bandwidth | bps | Upstream: provider, content delivery network (CDN), scrubbing |
| Protocol | 4 | SYN flood | State tables | pps | SYN cookies, limits, load balancers |
| Application | 7 | HTTP flood, Slowloris | CPU, database, connections | rps | Rate limits, web application firewall (WAF), caching |
Real attacks often mix classes: a large volumetric flood to distract, with a quieter application attack underneath. Plan for combinations.
<figure class="diagram" style="--dg-w: 1180px"><svg xmlns="http://www.w3.org/2000/svg" class="dg" viewBox="0 0 1180 460" width="1180" height="460" role="img" aria-labelledby="ddos-attack-classes-title ddos-attack-classes-desc" font-family="Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" xml:lang="en">
<title id="ddos-attack-classes-title">Three classes of DDoS attack compared</title>
<desc id="ddos-attack-classes-desc">Three columns. Volumetric attacks work at layers 3 and 4, for example UDP floods and reflection, fill the bandwidth of the link, are measured in bits per second, and are absorbed upstream by the provider, a CDN or a scrubbing service. Protocol or state-exhaustion attacks work at layer 4, for example a SYN flood, fill state tables with half-open connections, are measured in packets per second, and are handled with SYN cookies, connection limits and load balancers. Application-layer attacks work at layer 7, for example HTTP floods and Slowloris, use up CPU, database and threads because requests are expensive, are measured in requests per second, and are handled with rate limits, a web application firewall, bot challenges and caching.</desc>
<rect class="dg-bg" x="0.5" y="0.5" width="1179" height="459" rx="16" fill="#ffffff" stroke="#e3e3dd"/>
<rect class="dg-card" x="20" y="20" width="360" height="420" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l1"><g class="dg-icon" transform="translate(38 36) scale(1.3333)" fill="none" stroke="#0369a1" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M17 21v-2a1 1 0 0 1-1-1v-1a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2v1a1 1 0 0 1-1 1"/><path d="M19 15V6.5a1 1 0 0 0-7 0v11a1 1 0 0 1-7 0V9"/><path d="M21 21v-2h-4"/><path d="M3 5h4V3"/><path d="M7 5a1 1 0 0 1 1 1v1a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V6a1 1 0 0 1 1-1V3"/></g></g>
<g class="dg-l1"><text x="82" y="60" font-size="15.5" class="dg-ink" fill="#0369a1" font-weight="700">Volumetric</text></g>
<g class="dg-l1"><rect class="dg-solid" x="38" y="74" width="76" height="26" rx="13" fill="#0369a1"/><text x="76" y="91.5" font-size="12" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">L3 · L4</text></g>
<text x="38" y="130" font-size="11" class="dg-muted" fill="#5c5c68" font-weight="700">EXAMPLE</text>
<text x="38" y="152" font-size="14" class="dg-text" fill="#17171c" font-weight="600">UDP flood, reflection</text>
<text x="38" y="192" font-size="11" class="dg-muted" fill="#5c5c68" font-weight="700">WHAT RUNS OUT</text>
<text x="38" y="214" font-size="13" class="dg-text" fill="#17171c" font-weight="500">Bandwidth: the link to</text>
<text x="38" y="233" font-size="13" class="dg-text" fill="#17171c" font-weight="500">the Internet is full</text>
<text x="38" y="274" font-size="11" class="dg-muted" fill="#5c5c68" font-weight="700">MEASURED IN</text>
<g class="dg-l1"><rect class="dg-tint" x="38" y="284" width="182" height="26" rx="13" fill="#e6f0f6" stroke="#8ebcd5" stroke-width="1.2"/><text x="129" y="301.5" font-size="12.5" class="dg-ink" fill="#0369a1" font-weight="700" text-anchor="middle">bits per second · bps</text></g>
<path class="dg-line" d="M38 326H362" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<text x="38" y="348" font-size="11" class="dg-muted" fill="#5c5c68" font-weight="700">TYPICAL DEFENCE</text>
<text x="38" y="370" font-size="13" class="dg-text" fill="#17171c" font-weight="500">Absorb it upstream:</text>
<text x="38" y="389" font-size="13" class="dg-text" fill="#17171c" font-weight="500">provider, CDN, scrubbing</text>
<rect class="dg-card" x="410" y="20" width="360" height="420" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l4"><g class="dg-icon" transform="translate(428 36) scale(1.3333)" fill="none" stroke="#c2410c" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M8 6h13"/><path d="M8 12h13"/><path d="M8 18h13"/><path d="M3 6h.01"/><path d="M3 12h.01"/><path d="M3 18h.01"/></g></g>
<g class="dg-l4"><text x="472" y="60" font-size="15.5" class="dg-ink" fill="#c2410c" font-weight="700">Protocol (state exhaustion)</text></g>
<g class="dg-l4"><rect class="dg-solid" x="428" y="74" width="76" height="26" rx="13" fill="#c2410c"/><text x="466" y="91.5" font-size="12" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">L4</text></g>
<text x="428" y="130" font-size="11" class="dg-muted" fill="#5c5c68" font-weight="700">EXAMPLE</text>
<text x="428" y="152" font-size="14" class="dg-text" fill="#17171c" font-weight="600">SYN flood</text>
<text x="428" y="192" font-size="11" class="dg-muted" fill="#5c5c68" font-weight="700">WHAT RUNS OUT</text>
<text x="428" y="214" font-size="13" class="dg-text" fill="#17171c" font-weight="500">State tables: half-open</text>
<text x="428" y="233" font-size="13" class="dg-text" fill="#17171c" font-weight="500">connections fill the memory</text>
<text x="428" y="274" font-size="11" class="dg-muted" fill="#5c5c68" font-weight="700">MEASURED IN</text>
<g class="dg-l4"><rect class="dg-tint" x="428" y="284" width="204" height="26" rx="13" fill="#f9ece7" stroke="#e4aa92" stroke-width="1.2"/><text x="530" y="301.5" font-size="12.5" class="dg-ink" fill="#c2410c" font-weight="700" text-anchor="middle">packets per second · pps</text></g>
<path class="dg-line" d="M428 326H752" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<text x="428" y="348" font-size="11" class="dg-muted" fill="#5c5c68" font-weight="700">TYPICAL DEFENCE</text>
<text x="428" y="370" font-size="13" class="dg-text" fill="#17171c" font-weight="500">SYN cookies, connection</text>
<text x="428" y="389" font-size="13" class="dg-text" fill="#17171c" font-weight="500">limits, load balancers</text>
<rect class="dg-card" x="800" y="20" width="360" height="420" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l7"><g class="dg-icon" transform="translate(818 36) scale(1.3333)" fill="none" stroke="#6d28d9" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20"/><path d="M2 12h20"/></g></g>
<g class="dg-l7"><text x="862" y="60" font-size="15.5" class="dg-ink" fill="#6d28d9" font-weight="700">Application layer</text></g>
<g class="dg-l7"><rect class="dg-solid" x="818" y="74" width="76" height="26" rx="13" fill="#6d28d9"/><text x="856" y="91.5" font-size="12" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">L7</text></g>
<text x="818" y="130" font-size="11" class="dg-muted" fill="#5c5c68" font-weight="700">EXAMPLE</text>
<text x="818" y="152" font-size="14" class="dg-text" fill="#17171c" font-weight="600">HTTP flood, Slowloris</text>
<text x="818" y="192" font-size="11" class="dg-muted" fill="#5c5c68" font-weight="700">WHAT RUNS OUT</text>
<text x="818" y="214" font-size="13" class="dg-text" fill="#17171c" font-weight="500">CPU, database, threads:</text>
<text x="818" y="233" font-size="13" class="dg-text" fill="#17171c" font-weight="500">requests are expensive</text>
<text x="818" y="274" font-size="11" class="dg-muted" fill="#5c5c68" font-weight="700">MEASURED IN</text>
<g class="dg-l7"><rect class="dg-tint" x="818" y="284" width="212" height="26" rx="13" fill="#f0eafb" stroke="#bd9eee" stroke-width="1.2"/><text x="924" y="301.5" font-size="12.5" class="dg-ink" fill="#6d28d9" font-weight="700" text-anchor="middle">requests per second · rps</text></g>
<path class="dg-line" d="M818 326H1142" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<text x="818" y="348" font-size="11" class="dg-muted" fill="#5c5c68" font-weight="700">TYPICAL DEFENCE</text>
<text x="818" y="370" font-size="13" class="dg-text" fill="#17171c" font-weight="500">Rate limits, WAF,</text>
<text x="818" y="389" font-size="13" class="dg-text" fill="#17171c" font-weight="500">bot challenges, caching</text>
</svg></figure>
*Figure 2. Same goal, three different resources: the unit of measure tells you which class you are facing.*
> [!NOTE]
> Records for the largest attacks keep being broken, and the exact numbers depend on who measures them and how. This lesson gives no figures for them. For the current picture, read the yearly threat reports that large providers publish. What matters here: attacks above one terabit per second exist, so no single site can absorb them alone.
> [!CHECK]
> A web site has plenty of bandwidth, but its search page is slow and the database CPU is at 100%. Access logs show thousands of normal-looking `GET /search?q=...` requests per second. Which class is this?
>
> - [ ] Volumetric, because there are thousands of requests.
> - [ ] Protocol, because it uses TCP.
> - [x] Application-layer: each request is cheap to send and expensive to answer.
> - [ ] Reflection, because the requests look normal.
>
> Bandwidth is fine, the exhausted resource is the application's CPU and database, and the unit is requests per second. That is an HTTP flood.
### Reflection and amplification
Some attacks use other people's servers as weapons. Think of ordering catalogues: you write to a hundred companies "please send your big catalogue to this address", and you put your victim's address on the return line. You spend 100 stamps and the victim receives 100 heavy parcels. The companies did nothing wrong. They answered a request that looked ordinary.
In a **reflection attack**, the attacker sends a request to a third-party server (the **reflector**) with a **spoofed source address**: the packet claims to come from the victim. The reflector replies to the source address it sees, so the reply goes to the victim, and the attacker's real address never appears. This works for UDP-based services because UDP has no handshake: nothing checks that the sender really owns the source address. (The handshake of the Transmission Control Protocol (TCP) makes this hard, because the attacker would have to see the reply to continue.)
It becomes **amplification** when the reply is much bigger than the request. The **amplification factor** is response size divided by request size: with a factor of 50, an attacker who can send 100 Mbit/s of spoofed requests causes 5 Gbit/s to arrive at the victim. The attacker multiplies a small amount of own bandwidth into a large attack, and hides behind the reflectors.
Services that have been abused as reflectors are those that answer small UDP queries with large answers and, in the past, to anyone:
| Reflector | Port | Why it amplifies |
|---|---|---|
| **Open DNS resolver** | udp 53 | A short query for a record with a large answer (many records, or DNS Security Extensions (DNSSEC) data) returns a big response |
| **NTP `monlist`** | udp 123 | An old command on older Network Time Protocol (NTP) servers returned a list of up to hundreds of recent clients |
| **Memcached** | udp 11211 | A cache server with UDP enabled and exposed to the Internet can return very large stored values for a tiny request |
| **CLDAP** | udp 389 | Connectionless Lightweight Directory Access Protocol (LDAP) answers to a small query with a large directory entry |
> [!NOTE]
> Amplification factors depend on the server's configuration and the query used, so published values differ. As an order of magnitude, from the public advisories: DNS tens of times, NTP `monlist` hundreds of times, memcached tens of thousands of times. Don't treat these as exact figures. The memcached attacks of early 2018 were, at the time, the largest ever recorded, which is why they are cited so often.
<figure class="diagram" style="--dg-w: 1180px"><svg xmlns="http://www.w3.org/2000/svg" class="dg" viewBox="0 0 1180 470" width="1180" height="470" role="img" aria-labelledby="ddos-reflection-title ddos-reflection-desc" font-family="Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" xml:lang="en">
<title id="ddos-reflection-title">Reflection and amplification with a spoofed source address</title>
<desc id="ddos-reflection-desc">Left to right. The attacker at 192.0.2.66 sends a small request with a spoofed source address, 203.0.113.80, which is the victim's address. The request passes the attacker's ISP, which has no ingress filter; a note says BCP 38 would drop this packet here. It reaches open reflectors, a zone holding a DNS resolver at 198.51.100.53 on udp 53 and NTP, memcached and CLDAP servers on udp 123, 11211 and 389. Each reflector sends a much larger response to the victim at 203.0.113.80, shown with a thick red line. A note explains that the reflector believes the victim asked, so it answers the victim, and the attacker's own address never reaches the victim.</desc>
<rect class="dg-bg" x="0.5" y="0.5" width="1179" height="469" rx="16" fill="#ffffff" stroke="#e3e3dd"/>
<g class="dg-l7"><rect class="dg-tint" x="560" y="20" width="290" height="330" rx="16" fill="#f6f2fd" stroke="#c5a9f0" stroke-width="1.2" stroke-dasharray="6 5"/>
<g class="dg-icon" transform="translate(576 33) scale(0.7500)" fill="none" stroke="#6d28d9" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 6h16"/><path d="M4 12h10"/><path d="M4 18h6"/><circle cx="18" cy="16" r="3"/><path d="m22 20-1.8-1.8"/></g>
<text x="602" y="47" font-size="13" class="dg-ink" fill="#6d28d9" font-weight="700">Open reflectors · they answer anyone</text></g>
<g class="dg-l1"><path class="dg-stroke" d="M240 160H300" stroke="#0369a1" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-l1"><path class="dg-stroke" d="M450 160H560" stroke="#0369a1" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-l1"><path class="dg-stroke" d="M571 154l8 6-8 6" stroke="#0369a1" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-warn"><path class="dg-stroke" d="M830 106H865V250H890" stroke="#b91c1c" stroke-width="7" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-warn"><path class="dg-stroke" d="M830 240H865" stroke="#b91c1c" stroke-width="7" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-warn"><path class="dg-stroke" d="M891 244l8 6-8 6" stroke="#b91c1c" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<rect class="dg-card" x="25" y="114" width="210" height="92" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-warn"><g class="dg-icon" transform="translate(115 124) scale(1.2500)" fill="none" stroke="#b91c1c" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M20 16V7a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v9m16 0H4m16 0 1.28 2.55a1 1 0 0 1-.9 1.45H3.62a1 1 0 0 1-.9-1.45L4 16"/></g></g>
<text x="130" y="174" font-size="13.5" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle">Attacker</text>
<text x="130" y="193" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">192.0.2.66</text>
<rect class="dg-card" x="285" y="114" width="180" height="92" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l3"><g class="dg-icon" transform="translate(360 124) scale(1.2500)" fill="none" stroke="#b45309" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect width="20" height="8" x="2" y="14" rx="2"/><path d="M6.01 18H6"/><path d="M10.01 18H10"/><path d="M15 10v4"/><path d="M17.84 7.17a4 4 0 0 0-5.66 0"/><path d="M20.66 4.34a8 8 0 0 0-11.31 0"/></g></g>
<text x="375" y="174" font-size="13.5" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle">Attacker's ISP</text>
<text x="375" y="193" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">no ingress filter</text>
<g class="dg-warn"><circle class="dg-solid" cx="375" cy="214" r="11" fill="#b91c1c"/><text x="375" y="218.5" font-size="13" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">✕</text></g>
<text x="375" y="252" font-size="12" class="dg-ink" fill="#b91c1c" font-weight="700" text-anchor="middle">BCP 38 would drop this packet here</text>
<rect class="dg-card" x="580" y="56" width="250" height="100" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l7"><g class="dg-icon" transform="translate(596 72) scale(1.2500)" fill="none" stroke="#6d28d9" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M4 6h16"/><path d="M4 12h10"/><path d="M4 18h6"/><circle cx="18" cy="16" r="3"/><path d="m22 20-1.8-1.8"/></g></g>
<g class="dg-l7"><text x="638" y="93" font-size="14" class="dg-ink" fill="#6d28d9" font-weight="700">DNS resolver</text></g>
<text x="598" y="124" font-size="12.5" class="dg-text" fill="#17171c" font-weight="500" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">198.51.100.53 · udp 53</text>
<rect class="dg-card" x="580" y="190" width="250" height="100" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l7"><g class="dg-icon" transform="translate(596 206) scale(1.2500)" fill="none" stroke="#6d28d9" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect width="20" height="8" x="2" y="2" rx="2"/><rect width="20" height="8" x="2" y="14" rx="2"/><path d="M6 6h.01"/><path d="M6 18h.01"/></g></g>
<g class="dg-l7"><text x="638" y="227" font-size="14" class="dg-ink" fill="#6d28d9" font-weight="700">NTP, memcached, CLDAP</text></g>
<text x="598" y="258" font-size="12.5" class="dg-text" fill="#17171c" font-weight="500" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">udp 123 · 11211 · 389</text>
<rect class="dg-card" x="900" y="200" width="260" height="100" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l3"><g class="dg-icon" transform="translate(916 216) scale(1.2500)" fill="none" stroke="#b45309" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect width="20" height="8" x="2" y="2" rx="2"/><rect width="20" height="8" x="2" y="14" rx="2"/><path d="M6 6h.01"/><path d="M6 18h.01"/></g></g>
<g class="dg-l3"><text x="958" y="237" font-size="14" class="dg-ink" fill="#b45309" font-weight="700">Victim</text></g>
<text x="918" y="268" font-size="12.5" class="dg-text" fill="#17171c" font-weight="500" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">203.0.113.80</text>
<text x="130" y="232" font-size="13" class="dg-ink" fill="#0369a1" font-weight="700" text-anchor="middle">1 small request</text>
<text x="130" y="252" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="middle">source address spoofed:</text>
<text x="130" y="270" font-size="12" class="dg-ink" fill="#b91c1c" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">203.0.113.80</text>
<g class="dg-warn"><rect class="dg-bg-plain" x="961.5" y="138" width="137" height="24" rx="12" fill="#ffffff"/><text x="1030" y="154.5" font-size="12.5" class="dg-ink" fill="#b91c1c" font-weight="600" text-anchor="middle">2 large response</text></g>
<text x="1030" y="180" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="middle">sent to the victim</text>
<path class="dg-line" d="M20 392H1160" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<g class="dg-l3"><g class="dg-icon" transform="translate(20 410) scale(1.0000)" fill="none" stroke="#b45309" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3"/><path d="M12 9v4"/><path d="M12 17h.01"/></g></g>
<text x="54" y="428" font-size="13" class="dg-text" fill="#17171c" font-weight="600">The reflector believes the victim asked, so it answers the victim. The attacker's own address never reaches the victim.</text>
</svg></figure>
*Figure 3. A small spoofed request becomes a large response aimed at the victim. The root fix is at the attacker's network, where the spoofed packet should never have left.*
**The root fix: BCP 38.** Spoofing is possible because the attacker's network lets packets leave with a source address that doesn't belong to it. **Ingress filtering**, described in [RFC 2827](https://www.rfc-editor.org/rfc/rfc2827) (also known as **BCP 38**, a Best Current Practice), means that a network edge drops any packet whose source address isn't in the range assigned to that customer. If every network did it, spoofed reflection attacks would not work. Unfortunately it protects other people's networks more than your own, so adoption is incomplete. [RFC 3704](https://www.rfc-editor.org/rfc/rfc3704) (BCP 84) extends it to networks with several providers. What you can do: filter on your own network edge so you never become the source of spoofed traffic, and choose providers that do.
> [!CHECK]
> Why can an attacker aim a reflection attack at a victim without the victim ever seeing the attacker's real address?
>
> - [ ] The attacker encrypts the packets, so the victim can't read the source.
> - [x] The attacker spoofs the victim's address as the source, so the reflectors answer the victim, and the attacker's network doesn't filter spoofed sources.
> - [ ] The reflectors hide the sender's address on purpose, to protect their users.
> - [ ] The victim's firewall removes the attacker's address from the logs.
>
> UDP services answer the source address they see, and without BCP 38 ingress filtering nothing stops a network from sending packets with a false source address.
### Defences by layer
No single tool stops every attack, because each attack class exhausts something different. A good defence is layered, so each layer removes what the next one could not afford to see. The closer to the attacker the layer is, the bigger the attack it can absorb.
<figure class="diagram" style="--dg-w: 1180px"><svg xmlns="http://www.w3.org/2000/svg" class="dg" viewBox="0 0 1180 360" width="1180" height="360" role="img" aria-labelledby="ddos-layered-defence-title ddos-layered-defence-desc" font-family="Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" xml:lang="en">
<title id="ddos-layered-defence-title">Layered DDoS defence from the provider to the application</title>
<desc id="ddos-layered-defence-desc">Five numbered layers in a row, from the Internet to the service. 1 Provider or ISP: scrubbing centre, with blackholing as a last resort; it handles volumetric and reflection attacks. 2 CDN and anycast: spread the load over many sites and cache; it handles volumetric attacks and HTTP floods. 3 Network edge: firewall and load balancer with SYN cookies and limits; it handles SYN floods. 4 Web server or WAF: rate limit, bot challenge and rules; it handles HTTP floods and Slowloris. 5 Application: cheap pages, caching, timeouts and queues; it handles expensive requests. A note says each layer stops what the next one could not afford to see: the closer to the attacker, the bigger the attack it can absorb.</desc>
<rect class="dg-bg" x="0.5" y="0.5" width="1179" height="359" rx="16" fill="#ffffff" stroke="#e3e3dd"/>
<text x="20" y="30" font-size="13.5" class="dg-ink" fill="#b91c1c" font-weight="700">Attack traffic from the Internet</text>
<text x="1160" y="30" font-size="13.5" class="dg-ink" fill="#15803d" font-weight="700" text-anchor="end">Clean traffic to your service</text>
<rect class="dg-card" x="20" y="50" width="200.8" height="118" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l1"><circle class="dg-solid" cx="42" cy="74" r="12" fill="#0369a1"/><text x="42" y="78.5" font-size="12.5" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">1</text></g>
<g class="dg-l1"><g class="dg-icon" transform="translate(180.8 62) scale(1.0833)" fill="none" stroke="#0369a1" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z"/></g></g>
<text x="34" y="112" font-size="14" class="dg-text" fill="#17171c" font-weight="700">Provider or ISP</text>
<text x="34" y="132" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="500">Scrubbing centre,</text>
<text x="34" y="149" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="500">blackhole as last resort</text>
<path class="dg-line" d="M226.8 109H248.8" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<path class="dg-line" d="M240.8 103l8 6-8 6" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<rect class="dg-card" x="254.8" y="50" width="200.8" height="118" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l1"><circle class="dg-solid" cx="276.8" cy="74" r="12" fill="#0369a1"/><text x="276.8" y="78.5" font-size="12.5" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">2</text></g>
<g class="dg-l1"><g class="dg-icon" transform="translate(415.6 62) scale(1.0833)" fill="none" stroke="#0369a1" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20"/><path d="M2 12h20"/></g></g>
<text x="268.8" y="112" font-size="14" class="dg-text" fill="#17171c" font-weight="700">CDN and anycast</text>
<text x="268.8" y="132" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="500">Spread the load over</text>
<text x="268.8" y="149" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="500">many sites, cache</text>
<path class="dg-line" d="M461.6 109H483.6" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<path class="dg-line" d="M475.6 103l8 6-8 6" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<rect class="dg-card" x="489.6" y="50" width="200.8" height="118" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l1"><circle class="dg-solid" cx="511.6" cy="74" r="12" fill="#0369a1"/><text x="511.6" y="78.5" font-size="12.5" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">3</text></g>
<g class="dg-l1"><g class="dg-icon" transform="translate(650.4 62) scale(1.0833)" fill="none" stroke="#0369a1" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z"/></g></g>
<text x="503.6" y="112" font-size="14" class="dg-text" fill="#17171c" font-weight="700">Network edge</text>
<text x="503.6" y="132" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="500">Firewall, load balancer:</text>
<text x="503.6" y="149" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="500">SYN cookies, limits</text>
<path class="dg-line" d="M696.4 109H718.4" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<path class="dg-line" d="M710.4 103l8 6-8 6" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<rect class="dg-card" x="724.4" y="50" width="200.8" height="118" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l1"><circle class="dg-solid" cx="746.4" cy="74" r="12" fill="#0369a1"/><text x="746.4" y="78.5" font-size="12.5" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">4</text></g>
<g class="dg-l1"><g class="dg-icon" transform="translate(885.2 62) scale(1.0833)" fill="none" stroke="#0369a1" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M8 6h13"/><path d="M8 12h13"/><path d="M8 18h13"/><path d="M3 6h.01"/><path d="M3 12h.01"/><path d="M3 18h.01"/></g></g>
<text x="738.4" y="112" font-size="14" class="dg-text" fill="#17171c" font-weight="700">Web server or WAF</text>
<text x="738.4" y="132" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="500">Rate limit, bot</text>
<text x="738.4" y="149" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="500">challenge, rules</text>
<path class="dg-line" d="M931.2 109H953.2" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<path class="dg-line" d="M945.2 103l8 6-8 6" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<rect class="dg-card" x="959.2" y="50" width="200.8" height="118" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l1"><circle class="dg-solid" cx="981.2" cy="74" r="12" fill="#0369a1"/><text x="981.2" y="78.5" font-size="12.5" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">5</text></g>
<g class="dg-l1"><g class="dg-icon" transform="translate(1120 62) scale(1.0833)" fill="none" stroke="#0369a1" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><ellipse cx="12" cy="5" rx="9" ry="3"/><path d="M3 5V19A9 3 0 0 0 21 19V5"/><path d="M3 12A9 3 0 0 0 21 12"/></g></g>
<text x="973.2" y="112" font-size="14" class="dg-text" fill="#17171c" font-weight="700">Application</text>
<text x="973.2" y="132" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="500">Cheap pages, caching,</text>
<text x="973.2" y="149" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="500">timeouts, queues</text>
<g class="dg-l1"><rect class="dg-solid" x="24" y="186" width="96" height="26" rx="13" fill="#0369a1"/><text x="72" y="203.5" font-size="12" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">Volumetric</text></g>
<g class="dg-l1"><rect class="dg-solid" x="24" y="218" width="96" height="26" rx="13" fill="#0369a1"/><text x="72" y="235.5" font-size="12" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">Reflection</text></g>
<g class="dg-l1"><rect class="dg-solid" x="258.8" y="186" width="96" height="26" rx="13" fill="#0369a1"/><text x="306.8" y="203.5" font-size="12" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">Volumetric</text></g>
<g class="dg-l7"><rect class="dg-solid" x="258.8" y="218" width="96" height="26" rx="13" fill="#6d28d9"/><text x="306.8" y="235.5" font-size="12" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">HTTP flood</text></g>
<g class="dg-l4"><rect class="dg-solid" x="493.6" y="186" width="89" height="26" rx="13" fill="#c2410c"/><text x="538.1" y="203.5" font-size="12" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">SYN flood</text></g>
<g class="dg-l7"><rect class="dg-solid" x="728.4" y="186" width="96" height="26" rx="13" fill="#6d28d9"/><text x="776.4" y="203.5" font-size="12" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">HTTP flood</text></g>
<g class="dg-l7"><rect class="dg-solid" x="830.4" y="186" width="89" height="26" rx="13" fill="#6d28d9"/><text x="874.9" y="203.5" font-size="12" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">Slowloris</text></g>
<g class="dg-l7"><rect class="dg-solid" x="963.2" y="186" width="154" height="26" rx="13" fill="#6d28d9"/><text x="1040.2" y="203.5" font-size="12" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">Expensive requests</text></g>
<path class="dg-line" d="M20 262H1160" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<g class="dg-l3"><g class="dg-icon" transform="translate(20 278) scale(1.0000)" fill="none" stroke="#b45309" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3"/><path d="M12 9v4"/><path d="M12 17h.01"/></g></g>
<text x="54" y="296" font-size="13" class="dg-text" fill="#17171c" font-weight="600">Each layer stops what the next one could not afford to see: the closer to the attacker, the bigger the attack it can absorb.</text>
</svg></figure>
*Figure 4. Five layers, from the provider to the application. Each is matched to the attack classes it stops.*
**Overprovisioning.** Buy more bandwidth and capacity than you need. It is simple and also helps with the legitimate surge of a marketing campaign. But its limits are clear: attackers can send more than you can afford, you pay for capacity that sits idle most of the year, and it does nothing against a small application-layer attack that exhausts a database. Treat it as the base layer, not the plan.
**Rate limiting and connection limits.** Cap how many requests (or new connections) a single client can make per time unit, and how many connections it can hold open at once. Everything above the cap gets a quick refusal, such as HTTP status `429 Too Many Requests`, which is much cheaper for the server than doing the real work. This is the main defence against application-layer floods and slow attacks, and it is what you build in the lab. Limits have weaknesses: a botnet where each bot stays below the limit passes through (you need global limits, per-page limits, and behaviour rules too), and many real users can share one address behind a carrier-grade network address translation (NAT) or a company proxy, so a strict per-address limit can punish them.
**SYN cookies.** A way to survive a SYN flood without keeping a table entry for every half-open connection. They are explained in [How it works](#how-it-works) and described in [RFC 4987](https://www.rfc-editor.org/rfc/rfc4987). Operating systems and load balancers include them.
**Web application firewall (WAF) and bot challenges.** A WAF inspects HTTP requests and blocks those matching rules or known bad patterns. Bot management goes further: it separates humans from scripts using a JavaScript or proof-of-work **challenge**, a CAPTCHA, or browser and behaviour signals, and rate-limits or blocks the scripts. These work at layer 7 and are your best tool against HTTP floods that look like real users.
**Anycast and content delivery networks (CDNs).** In **anycast**, the same IP address is announced from many locations, and the Internet's routing sends each client to the nearest one ([RFC 4786](https://www.rfc-editor.org/rfc/rfc4786) describes the practice). Attack traffic from a botnet is therefore split among many sites, each absorbing the part that is near its sources, instead of reaching one place. A **CDN** puts a worldwide network of caching servers in front of your origin: static content is served from the edge, and only the requests that need the origin reach it. A CDN also hides your origin address, which must then stay private and accept traffic only from the CDN.
**Scrubbing centres and provider or ISP protection.** A **scrubbing centre** is a facility with a very large capacity that receives your traffic, removes the attack traffic and sends back the clean traffic. Providers offer this as a service, either **always-on** (all traffic goes through it) or **on-demand** (traffic is redirected, usually by changing the routing announcements, when an attack starts). Large clouds and ISPs include basic protection, and many sell stronger tiers. Examples exist from several vendors, and the choice depends on your provider and size.
**Remotely triggered blackholing (RTBH).** The last resort. You ask your provider to drop all traffic to the attacked IP address, by tagging that address's route with the well-known **BLACKHOLE community**, 65535:666, defined in [RFC 7999](https://www.rfc-editor.org/rfc/rfc7999). The attack stops hurting the link and everything else on it. The trade-off is hard: **the attacker gets what they wanted for that address**, because the target is now unreachable for everybody, customers included. Blackholing saves the rest of your network, and it works best if the attacked address is not the only one your service uses. Think of it as sacrificing a room to save the house.
**Close the reflectors you operate.** Your servers can be somebody else's weapon. Don't run open DNS resolvers (restrict recursion to your own clients), disable the NTP `monlist` feature and restrict NTP queries, bind memcached to a local interface or disable its UDP port, and block unneeded UDP services such as CLDAP from the Internet at the edge. Combine with ingress and egress filtering (BCP 38) so your network can't send spoofed packets.
| Attack | First layer to use | Also |
|---|---|---|
| Volumetric flood or reflection | Provider or scrubbing service, anycast CDN | Blackholing as a last resort |
| SYN flood | SYN cookies, load balancer in front | Connection limits, scrubbing |
| HTTP flood | WAF, bot challenge, rate limits, CDN caching | Scrubbing with layer 7 filtering |
| Slow attack (Slowloris) | Short timeouts, per-address connection limit, reverse proxy | WAF |
| Reflection from your servers | Close open reflectors, filter spoofed sources | Monitoring |
> [!CHECK]
> You ask your provider to blackhole the one IP address under attack. What is the main trade-off?
>
> - [ ] The attack grows, because blackholing amplifies the traffic.
> - [ ] Only the attacker's traffic is dropped, so there is no trade-off.
> - [x] The rest of the network is protected, but the attacked address is unreachable for everyone, so the attack achieved its goal for that address.
> - [ ] The provider has to change your DNS records and it takes days.
>
> A blackhole drops all traffic to the address, good and bad. It is a last resort that saves the other services sharing the link.
### Respond: before, during and after
When the attack comes, you have no time to think about who to call. A DDoS response plan is mostly work done in advance.
<figure class="diagram" style="--dg-w: 1180px"><svg xmlns="http://www.w3.org/2000/svg" class="dg" viewBox="0 0 1180 310" width="1180" height="310" role="img" aria-labelledby="ddos-response-plan-title ddos-response-plan-desc" font-family="Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" xml:lang="en">
<title id="ddos-response-plan-title">A DDoS response plan in six steps</title>
<desc id="ddos-response-plan-desc">Six numbered steps in a row. 1 Baseline, before the attack: know normal traffic and capacity. 2 Detect, during: alerts on traffic, errors and latency. 3 Triage, during: is it an attack or a popular day? 4 Mitigate, during: follow the runbook steps and call the provider. 5 Communicate, during: status page, customers and managers. 6 Review, after: what worked, and update the runbook. A note says the two steps that decide the outcome happen before the attack: a baseline and a written runbook with contacts.</desc>
<rect class="dg-bg" x="0.5" y="0.5" width="1179" height="309" rx="16" fill="#ffffff" stroke="#e3e3dd"/>
<rect class="dg-card" x="20" y="30" width="161.667" height="118" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l1"><circle class="dg-solid" cx="42" cy="54" r="12" fill="#0369a1"/><text x="42" y="58.5" font-size="12.5" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">1</text></g>
<g class="dg-l1"><g class="dg-icon" transform="translate(141.667 42) scale(1.0833)" fill="none" stroke="#0369a1" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M3 3v16a2 2 0 0 0 2 2h16"/><path d="m19 9-5 5-4-4-3 3"/></g></g>
<text x="34" y="92" font-size="14" class="dg-text" fill="#17171c" font-weight="700">Baseline</text>
<text x="34" y="112" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="500">Know normal traffic</text>
<text x="34" y="129" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="500">and capacity</text>
<path class="dg-line" d="M187.667 89H209.667" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<path class="dg-line" d="M201.667 83l8 6-8 6" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<rect class="dg-card" x="215.667" y="30" width="161.667" height="118" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l1"><circle class="dg-solid" cx="237.667" cy="54" r="12" fill="#0369a1"/><text x="237.667" y="58.5" font-size="12.5" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">2</text></g>
<g class="dg-l1"><g class="dg-icon" transform="translate(337.333 42) scale(1.0833)" fill="none" stroke="#0369a1" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3"/><path d="M12 9v4"/><path d="M12 17h.01"/></g></g>
<text x="229.667" y="92" font-size="14" class="dg-text" fill="#17171c" font-weight="700">Detect</text>
<text x="229.667" y="112" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="500">Alerts on traffic,</text>
<text x="229.667" y="129" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="500">errors, latency</text>
<path class="dg-line" d="M383.333 89H405.333" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<path class="dg-line" d="M397.333 83l8 6-8 6" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<rect class="dg-card" x="411.333" y="30" width="161.667" height="118" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l1"><circle class="dg-solid" cx="433.333" cy="54" r="12" fill="#0369a1"/><text x="433.333" y="58.5" font-size="12.5" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">3</text></g>
<g class="dg-l1"><g class="dg-icon" transform="translate(533 42) scale(1.0833)" fill="none" stroke="#0369a1" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M8 6h13"/><path d="M8 12h13"/><path d="M8 18h13"/><path d="M3 6h.01"/><path d="M3 12h.01"/><path d="M3 18h.01"/></g></g>
<text x="425.333" y="92" font-size="14" class="dg-text" fill="#17171c" font-weight="700">Triage</text>
<text x="425.333" y="112" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="500">Attack or a</text>
<text x="425.333" y="129" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="500">popular day?</text>
<path class="dg-line" d="M579 89H601" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<path class="dg-line" d="M593 83l8 6-8 6" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<rect class="dg-card" x="607" y="30" width="161.667" height="118" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l1"><circle class="dg-solid" cx="629" cy="54" r="12" fill="#0369a1"/><text x="629" y="58.5" font-size="12.5" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">4</text></g>
<g class="dg-l1"><g class="dg-icon" transform="translate(728.667 42) scale(1.0833)" fill="none" stroke="#0369a1" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z"/></g></g>
<text x="621" y="92" font-size="14" class="dg-text" fill="#17171c" font-weight="700">Mitigate</text>
<text x="621" y="112" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="500">Runbook steps,</text>
<text x="621" y="129" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="500">call the provider</text>
<path class="dg-line" d="M774.667 89H796.667" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<path class="dg-line" d="M788.667 83l8 6-8 6" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<rect class="dg-card" x="802.667" y="30" width="161.667" height="118" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l1"><circle class="dg-solid" cx="824.667" cy="54" r="12" fill="#0369a1"/><text x="824.667" y="58.5" font-size="12.5" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">5</text></g>
<g class="dg-l1"><g class="dg-icon" transform="translate(924.333 42) scale(1.0833)" fill="none" stroke="#0369a1" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect width="14" height="20" x="5" y="2" rx="2"/><path d="M12 18h.01"/></g></g>
<text x="816.667" y="92" font-size="14" class="dg-text" fill="#17171c" font-weight="700">Communicate</text>
<text x="816.667" y="112" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="500">Status page,</text>
<text x="816.667" y="129" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="500">customers, managers</text>
<path class="dg-line" d="M970.333 89H992.333" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<path class="dg-line" d="M984.333 83l8 6-8 6" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<rect class="dg-card" x="998.333" y="30" width="161.667" height="118" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l1"><circle class="dg-solid" cx="1020.33" cy="54" r="12" fill="#0369a1"/><text x="1020.33" y="58.5" font-size="12.5" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">6</text></g>
<g class="dg-l1"><g class="dg-icon" transform="translate(1120 42) scale(1.0833)" fill="none" stroke="#0369a1" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"/><path d="M14 2v4a2 2 0 0 0 2 2h4"/><path d="M10 9H8"/><path d="M16 13H8"/><path d="M16 17H8"/></g></g>
<text x="1012.33" y="92" font-size="14" class="dg-text" fill="#17171c" font-weight="700">Review</text>
<text x="1012.33" y="112" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="500">What worked? Update</text>
<text x="1012.33" y="129" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="500">the runbook</text>
<g class="dg-l1"><rect class="dg-solid" x="40.3333" y="164" width="121" height="26" rx="13" fill="#0369a1"/><text x="100.833" y="181.5" font-size="12" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">Before</text></g>
<g class="dg-l4"><rect class="dg-solid" x="236" y="164" width="121" height="26" rx="13" fill="#c2410c"/><text x="296.5" y="181.5" font-size="12" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">During</text></g>
<g class="dg-l4"><rect class="dg-solid" x="431.667" y="164" width="121" height="26" rx="13" fill="#c2410c"/><text x="492.167" y="181.5" font-size="12" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">During</text></g>
<g class="dg-l4"><rect class="dg-solid" x="627.333" y="164" width="121" height="26" rx="13" fill="#c2410c"/><text x="687.833" y="181.5" font-size="12" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">During</text></g>
<g class="dg-l4"><rect class="dg-solid" x="823" y="164" width="121" height="26" rx="13" fill="#c2410c"/><text x="883.5" y="181.5" font-size="12" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">During</text></g>
<g class="dg-l2"><rect class="dg-solid" x="1018.67" y="164" width="121" height="26" rx="13" fill="#15803d"/><text x="1079.17" y="181.5" font-size="12" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">After</text></g>
<path class="dg-line" d="M20 226H1160" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<g class="dg-l3"><g class="dg-icon" transform="translate(20 242) scale(1.0000)" fill="none" stroke="#b45309" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3"/><path d="M12 9v4"/><path d="M12 17h.01"/></g></g>
<text x="54" y="260" font-size="13" class="dg-text" fill="#17171c" font-weight="600">The two steps that decide the outcome happen before the attack: a baseline and a written runbook with contacts.</text>
</svg></figure>
*Figure 5. The first step and the last decide most of the result: know what normal looks like before, and learn from the attack after.*
1. **Baseline (before).** Measure normal traffic: requests per second, bandwidth, new connections per second, error rate and latency, by hour and day of the week. Know your capacity: the number of requests your servers handle before they slow down, found by load-testing your own systems in a test environment. You can't see "abnormal" without "normal".
2. **Detect (during).** Alert on the symptoms: traffic or requests far above the baseline, a rise in 5xx errors, rising latency, a spike of connections in half-open state, a flood from few autonomous systems or countries you don't usually serve. Alert the right people at any hour.
3. **Triage (during).** Is it an attack or a legitimate surge (a campaign, a news mention, a product launch)? Look at the user agents, the pages requested, the geographic spread and whether the requests look like real sessions. Check which resource is exhausted (bandwidth, connection table, application CPU) to know the class and pick the defence.
4. **Mitigate and escalate (during).** Follow a **runbook**: a short written procedure of who does what in which order. Typical steps: enable stricter rate limits or a "under attack" challenge mode, move traffic to the scrubbing service, call the provider's security or support line (with the number and your account details already written in the runbook), and consider blackholing only for the single address if everything else fails.
5. **Communicate (during).** Tell customers and your own management early and honestly: a status page, a short note, an estimated next update. A clear message prevents panic and support overload. Keep a log of timestamps and actions.
6. **Review (after).** In a post-incident review (without blame), ask what you saw first, how long detection and mitigation took, what worked, what failed and what to change: thresholds, contacts, capacity, architecture. Update the runbook and test it.
> [!CHECK]
> Which preparation matters most for noticing a DDoS attack quickly and correctly?
>
> - [ ] Buying a second firewall of the same brand.
> - [ ] Publishing your server's real IP address in the DNS records.
> - [x] A traffic baseline with alerts, so abnormal traffic is visible and a busy day can be told from an attack.
> - [ ] Waiting for customers to report problems.
>
> Without a baseline you can't tell "abnormal" from "normal". Alerts on traffic, errors and latency turn the baseline into early detection.
## How it works
The SYN flood is the best example of a protocol attack, because it abuses how a normal TCP connection starts. If you need to refresh the three-way handshake, read [Networking 08 — Transport Layer: TCP, UDP and Ports](../../networking/08-tcp-udp/README.md).
**The half-open connection table.** A server that listens on a port does the following when a client sends a **SYN** (synchronize, the first message of the handshake): it records the new connection in a table, in the state `SYN_RECV` (also called half-open, because the handshake is not finished), and answers with a **SYN-ACK**. It then waits for the client's final **ACK** (acknowledgement). That wait is the weakness. The table has a limited size (the **listen backlog**), and an entry stays there until the ACK arrives or a timeout expires, which can take many seconds.
In a **SYN flood**, the attacker sends a very large number of SYN packets, often with random spoofed source addresses. The server answers each one with a SYN-ACK to an address that never asked for it, so the final ACK never arrives, and each half-open entry waits until its timeout. The table fills. When it is full, new SYNs, including those from real customers, are dropped. The bandwidth looks small and the server is not "busy", but it can't accept any new connection. Real bots do not even need to spoof: a botnet sending real SYNs does the same.
<figure class="diagram" style="--dg-w: 1180px"><svg xmlns="http://www.w3.org/2000/svg" class="dg" viewBox="0 0 1180 420" width="1180" height="420" role="img" aria-labelledby="ddos-syn-flood-title ddos-syn-flood-desc" font-family="Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" xml:lang="en">
<title id="ddos-syn-flood-title">A SYN flood fills the half-open connection table</title>
<desc id="ddos-syn-flood-desc">On the left, an attacker with spoofed sources sends many SYN packets from random source addresses to a server at 203.0.113.80 on tcp 443. The server keeps a half-open connection table, the listen backlog, which has a fixed number of slots. The table lists four entries in state SYN_RECV, for the sources 203.0.113.7:51034, 198.51.100.9:40211, 192.0.2.200:33102 and 203.0.113.141:60977, and is marked full. Each entry waits for an ACK that never comes. Below, a real customer at 198.51.100.25 sends a SYN that is dropped on a red line marked with a cross, because no slot is free.</desc>
<rect class="dg-bg" x="0.5" y="0.5" width="1179" height="419" rx="16" fill="#ffffff" stroke="#e3e3dd"/>
<rect class="dg-card" x="35" y="70" width="190" height="92" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-warn"><g class="dg-icon" transform="translate(115 80) scale(1.2500)" fill="none" stroke="#b91c1c" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M20 16V7a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v9m16 0H4m16 0 1.28 2.55a1 1 0 0 1-.9 1.45H3.62a1 1 0 0 1-.9-1.45L4 16"/></g></g>
<text x="130" y="130" font-size="13.5" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle">Attacker</text>
<text x="130" y="149" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">spoofed sources</text>
<g class="dg-warn"><path class="dg-stroke" d="M225 116H380" stroke="#b91c1c" stroke-width="5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-warn"><path class="dg-stroke" d="M371 110l8 6-8 6" stroke="#b91c1c" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-warn"><rect class="dg-bg-plain" x="243.895" y="78" width="116.21" height="24" rx="12" fill="#ffffff"/><text x="302" y="94.5" font-size="11.5" class="dg-ink" fill="#b91c1c" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">SYN, SYN, SYN…</text></g>
<text x="302" y="148" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="middle">random source addresses</text>
<g class="dg-l4"><rect class="dg-tint" x="390" y="20" width="520" height="330" rx="16" fill="#fbf4f0" stroke="#e7b39e" stroke-width="1.2" stroke-dasharray="6 5"/>
<g class="dg-icon" transform="translate(406 33) scale(0.7500)" fill="none" stroke="#c2410c" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="20" height="8" x="2" y="2" rx="2"/><rect width="20" height="8" x="2" y="14" rx="2"/><path d="M6 6h.01"/><path d="M6 18h.01"/></g>
<text x="432" y="47" font-size="13" class="dg-ink" fill="#c2410c" font-weight="700">Server · 203.0.113.80 · tcp 443</text></g>
<text x="414" y="70" font-size="14" class="dg-text" fill="#17171c" font-weight="700">Half-open connection table</text>
<text x="414" y="90" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="500">listen backlog, a fixed number of slots</text>
<rect class="dg-tint" x="410" y="106" width="480" height="36" rx="8" fill="#faf0ec" stroke="#e7b39e"/>
<text x="426" y="129" font-size="12.5" class="dg-text" fill="#17171c" font-weight="600" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">203.0.113.7:51034</text>
<text x="640" y="129" font-size="12.5" class="dg-ink" fill="#c2410c" font-weight="700" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">SYN_RECV</text>
<rect class="dg-tint" x="410" y="150" width="480" height="36" rx="8" fill="#faf0ec" stroke="#e7b39e"/>
<text x="426" y="173" font-size="12.5" class="dg-text" fill="#17171c" font-weight="600" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">198.51.100.9:40211</text>
<text x="640" y="173" font-size="12.5" class="dg-ink" fill="#c2410c" font-weight="700" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">SYN_RECV</text>
<rect class="dg-tint" x="410" y="194" width="480" height="36" rx="8" fill="#faf0ec" stroke="#e7b39e"/>
<text x="426" y="217" font-size="12.5" class="dg-text" fill="#17171c" font-weight="600" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">192.0.2.200:33102</text>
<text x="640" y="217" font-size="12.5" class="dg-ink" fill="#c2410c" font-weight="700" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">SYN_RECV</text>
<rect class="dg-tint" x="410" y="238" width="480" height="36" rx="8" fill="#faf0ec" stroke="#e7b39e"/>
<text x="426" y="261" font-size="12.5" class="dg-text" fill="#17171c" font-weight="600" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">203.0.113.141:60977</text>
<text x="640" y="261" font-size="12.5" class="dg-ink" fill="#c2410c" font-weight="700" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">SYN_RECV</text>
<g class="dg-warn"><rect class="dg-solid" x="602" y="292" width="96" height="26" rx="13" fill="#b91c1c"/><text x="650" y="309.5" font-size="12" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">table full</text></g>
<text x="410" y="332" font-size="12.5" class="dg-muted" fill="#5c5c68" font-weight="500">each entry waits for an ACK that never comes</text>
<rect class="dg-card" x="35" y="280" width="190" height="92" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l2"><g class="dg-icon" transform="translate(115 290) scale(1.2500)" fill="none" stroke="#15803d" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M20 16V7a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v9m16 0H4m16 0 1.28 2.55a1 1 0 0 1-.9 1.45H3.62a1 1 0 0 1-.9-1.45L4 16"/></g></g>
<text x="130" y="340" font-size="13.5" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle">Real customer</text>
<text x="130" y="359" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">198.51.100.25</text>
<g class="dg-warn"><path class="dg-stroke" d="M225 326H390" stroke="#b91c1c" stroke-width="3" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-dasharray="7 6"/></g>
<g class="dg-warn"><circle class="dg-solid" cx="318" cy="326" r="11" fill="#b91c1c"/><text x="318" y="330.5" font-size="13" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">✕</text></g>
<text x="310" y="392" font-size="12.5" class="dg-ink" fill="#b91c1c" font-weight="700" text-anchor="middle">SYN dropped: no free slot</text>
</svg></figure>
*Figure 6. The attack costs the attacker almost nothing per packet, but each packet reserves a slot until its timeout.*
**SYN cookies.** [RFC 4987](https://www.rfc-editor.org/rfc/rfc4987) describes several mitigations (bigger backlog, shorter timeouts, filtering, and others) and, among them, **SYN cookies**. The idea: if the table is full, stop using it. The server answers the SYN with a SYN-ACK whose **sequence number is a cookie**: a value computed from the client's address and port, the server's address and port, a coarse timestamp and a secret that only the server knows. It stores **nothing**. A real client answers with an ACK that acknowledges "cookie + 1". The server recomputes the cookie from the packet and, if it matches, creates the connection at that moment. A spoofed sender never answers, so the attack no longer uses any table slot.
<figure class="diagram" style="--dg-w: 940px"><svg xmlns="http://www.w3.org/2000/svg" class="dg" viewBox="0 0 940 556" width="940" height="556" role="img" aria-labelledby="ddos-syn-cookies-title ddos-syn-cookies-desc" font-family="Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" xml:lang="en">
<title id="ddos-syn-cookies-title">How SYN cookies avoid keeping state during the handshake</title>
<desc id="ddos-syn-cookies-desc">A sequence between a client at 198.51.100.25 and a server at 203.0.113.80. Step 1: the client sends a SYN with sequence number x. A note says the server stores nothing and computes a cookie from the addresses, ports, a timestamp and a secret. Step 2: the server answers with a SYN-ACK whose sequence number is the cookie and whose acknowledgement is x plus one. Step 3: the client sends an ACK that acknowledges the cookie plus one. A note says the cookie checks out, and only now is the connection created. A final note says a spoofed sender never answers, so no table slot is ever used.</desc>
<rect class="dg-bg" x="0.5" y="0.5" width="939" height="555" rx="16" fill="#ffffff" stroke="#e3e3dd"/>
<path class="dg-line" d="M190 98V540" stroke="#cfcfc8" stroke-width="1.5" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-dasharray="7 6"/>
<path class="dg-line" d="M750 98V540" stroke="#cfcfc8" stroke-width="1.5" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-dasharray="7 6"/>
<rect class="dg-card" x="85" y="24" width="210" height="74" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l2"><g class="dg-icon" transform="translate(99 38) scale(1.1667)" fill="none" stroke="#15803d" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M20 16V7a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v9m16 0H4m16 0 1.28 2.55a1 1 0 0 1-.9 1.45H3.62a1 1 0 0 1-.9-1.45L4 16"/></g></g>
<text x="137" y="56" font-size="14" class="dg-text" fill="#17171c" font-weight="700">Client</text>
<text x="137" y="76" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="500" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">198.51.100.25</text>
<rect class="dg-card" x="645" y="24" width="210" height="74" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l4"><g class="dg-icon" transform="translate(659 38) scale(1.1667)" fill="none" stroke="#c2410c" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect width="20" height="8" x="2" y="2" rx="2"/><rect width="20" height="8" x="2" y="14" rx="2"/><path d="M6 6h.01"/><path d="M6 18h.01"/></g></g>
<text x="697" y="56" font-size="14" class="dg-text" fill="#17171c" font-weight="700">Server</text>
<text x="697" y="76" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="500" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">203.0.113.80</text>
<rect class="dg-bg-plain" x="452.562" y="115" width="34.875" height="17" fill="#ffffff"/>
<text x="470" y="128" font-size="12.5" class="dg-text" fill="#17171c" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">SYN</text>
<rect class="dg-bg-plain" x="437.312" y="132" width="65.375" height="17" fill="#ffffff"/>
<text x="470" y="145" font-size="12.5" class="dg-text" fill="#17171c" font-weight="500" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">seq = x</text>
<g class="dg-l1"><circle class="dg-solid" cx="440.562" cy="124" r="11" fill="#0369a1"/><text x="440.562" y="128.5" font-size="12" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">1</text></g>
<g class="dg-l1"><path class="dg-stroke" d="M194 159H744" stroke="#0369a1" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-l1"><path class="dg-stroke" d="M736 153l8 6-8 6" stroke="#0369a1" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-l4"><rect class="dg-tint" x="608" y="181" width="284" height="65" rx="8" fill="#f9ece7" stroke="#e4aa92" stroke-width="1.2"/>
<text x="750" y="198" font-size="12.5" class="dg-ink" fill="#c2410c" font-weight="600" text-anchor="middle">The server stores nothing.</text>
<text x="750" y="215" font-size="12.5" class="dg-ink" fill="#c2410c" font-weight="600" text-anchor="middle">It computes a cookie from addresses,</text>
<text x="750" y="232" font-size="12.5" class="dg-ink" fill="#c2410c" font-weight="600" text-anchor="middle">ports, a timestamp and a secret.</text>
</g>
<rect class="dg-bg-plain" x="437.312" y="267" width="65.375" height="17" fill="#ffffff"/>
<text x="470" y="280" font-size="12.5" class="dg-text" fill="#17171c" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">SYN-ACK</text>
<rect class="dg-bg-plain" x="372.5" y="284" width="195" height="17" fill="#ffffff"/>
<text x="470" y="297" font-size="12.5" class="dg-text" fill="#17171c" font-weight="500" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">seq = cookie · ack = x+1</text>
<g class="dg-l4"><circle class="dg-solid" cx="425.312" cy="276" r="11" fill="#c2410c"/><text x="425.312" y="280.5" font-size="12" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">2</text></g>
<g class="dg-l4"><path class="dg-stroke" d="M746 311H196" stroke="#c2410c" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-l4"><path class="dg-stroke" d="M204 305l-8 6 8 6" stroke="#c2410c" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<rect class="dg-bg-plain" x="452.562" y="336" width="34.875" height="17" fill="#ffffff"/>
<text x="470" y="349" font-size="12.5" class="dg-text" fill="#17171c" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">ACK</text>
<rect class="dg-bg-plain" x="410.625" y="353" width="118.75" height="17" fill="#ffffff"/>
<text x="470" y="366" font-size="12.5" class="dg-text" fill="#17171c" font-weight="500" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">ack = cookie+1</text>
<g class="dg-l1"><circle class="dg-solid" cx="440.562" cy="345" r="11" fill="#0369a1"/><text x="440.562" y="349.5" font-size="12" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">3</text></g>
<g class="dg-l1"><path class="dg-stroke" d="M194 380H744" stroke="#0369a1" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-l1"><path class="dg-stroke" d="M736 374l8 6-8 6" stroke="#0369a1" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-ok"><rect class="dg-tint" x="611.5" y="402" width="277" height="48" rx="8" fill="#e8f2ec" stroke="#96c6a8" stroke-width="1.2"/>
<text x="750" y="419" font-size="12.5" class="dg-ink" fill="#15803d" font-weight="600" text-anchor="middle">The cookie checks out:</text>
<text x="750" y="436" font-size="12.5" class="dg-ink" fill="#15803d" font-weight="600" text-anchor="middle">only now is the connection created.</text>
</g>
<g class="dg-l2"><rect class="dg-tint" x="150" y="468" width="640" height="48" rx="8" fill="#e8f2ec" stroke="#96c6a8" stroke-width="1.2"/>
<text x="470" y="485" font-size="12.5" class="dg-ink" fill="#15803d" font-weight="600" text-anchor="middle">A spoofed sender never answers,</text>
<text x="470" y="502" font-size="12.5" class="dg-ink" fill="#15803d" font-weight="600" text-anchor="middle">so no table slot is ever used.</text>
</g>
</svg></figure>
*Figure 7. With SYN cookies the server keeps no state until the client proves it received the SYN-ACK.*
There is a cost: because the server remembers nothing, some TCP options negotiated in the SYN (such as the maximum segment size, window scaling and selective acknowledgements) must be squeezed into the cookie or may be lost, so the connection can be slightly less efficient. That is why many systems use cookies **only when the table is full**. Linux does this by default: the setting `net.ipv4.tcp_syncookies` has the value `1`, which means "use cookies only when the backlog overflows". You read it in the lab. A SYN flood that is big enough in packets per second can still saturate the CPU or the link, so SYN cookies are one layer, not the whole answer.
> [!CHECK]
> What does a server using SYN cookies do when a SYN arrives and its half-open table is full?
>
> - [ ] It drops the SYN so that the table can drain.
> - [ ] It blocks the source address for an hour.
> - [x] It answers with a SYN-ACK that carries a cookie, keeps no state, and creates the connection only if the returning ACK matches the cookie.
> - [ ] It asks the client to send the SYN again over UDP.
>
> The cookie encodes what the server would have stored, so the proof comes back with the client's ACK. Spoofed senders never reply, so they never take a slot.
## Worked example
You run a web site on `203.0.113.80`. Its normal traffic is about 40 requests per second at the busiest hour, and it stays healthy until about 300 requests per second, because every page needs a database query. This is your baseline and your capacity.
**1. Detection.** A monitoring alert fires at 10:02: "requests per second above 3 times the daily peak". The access log shows this:
```text
203.0.113.7 - - [07/Nov/2026:10:02:11 +0000] "GET /search?q=a HTTP/1.1" 200 5120 "-" "Mozilla/5.0"
198.51.100.9 - - [07/Nov/2026:10:02:11 +0000] "GET /search?q=b HTTP/1.1" 200 5120 "-" "Mozilla/5.0"
192.0.2.200 - - [07/Nov/2026:10:02:11 +0000] "GET /search?q=c HTTP/1.1" 200 5120 "-" "Mozilla/5.0"
```
**2. Triage.** Bandwidth is only 5% of the link, the SYN backlog is normal, and 90% of the requests are `/search`: the class is application-layer. Many addresses send a modest rate each, so a per-address ban won't solve it.
**3. Choose defences by class.** Because the resource at risk is the database, you (a) put a rate limit on `/search` in the web server or CDN, (b) turn on the CDN's challenge mode for that path, (c) cache popular search results for 30 seconds, and (d) open a ticket with the provider's DDoS team to tell them what you see, with the runbook's contact.
**4. Do the arithmetic for a rate limit.** In nginx (the web server used in the lab), the rule `rate=5r/s` with `burst=10` and `nodelay` lets one client address through with 10 immediate requests, then 5 more per second:
```nginx
limit_req_zone $binary_remote_addr zone=perip:10m rate=5r/s;
server {
location /search {
limit_req zone=perip burst=10 nodelay;
limit_req_status 429;
}
}
```
In `T` seconds, one address can make about `10 + 5 × T` successful requests. In 15 seconds that is `10 + 5 × 15 = 85`, no matter how many requests it sends. You check this number in the lab: the two simulated bots each got about 85 answers out of thousands of attempts. A person who clicks around gets 429 only if they exceed 5 requests per second.
**5. See the limit of the rule.** Suppose the attack comes from 10,000 addresses. Each is allowed `10 + 5 × 15 = 85` requests in 15 seconds, so together they still make 10,000 × 85 / 15 ≈ 56,700 requests per second on average over those 15 seconds, and 10,000 × 5 = 50,000 per second once the bursts are used up. Your capacity is 300. Per-address limits are necessary, but against a real botnet you also need a global limit, a challenge, caching and upstream capacity (CDN or scrubbing).
**6. Close the loop.** After the attack, the review finds that the alert fired after 2 minutes but the provider's phone number in the runbook was out of date. You fix it, lower the alert threshold and schedule a test of the procedure.
**A quick bandwidth calculation** shows why the units matter. A 1 Gbit/s link carrying the smallest Ethernet frames (64 bytes, plus 20 bytes of preamble and gap on the wire, 84 bytes in total) has room for `1,000,000,000 / (84 × 8) ≈ 1.49` million packets per second. A device that can only process 500,000 packets per second would be overwhelmed by small packets at about a third of the link speed: a *pps* problem, not a *bps* problem.
## Common pitfalls
- **Having the plan only in somebody's head** — the person who knows the provider's number is on holiday. Write the runbook, with contacts, and test it.
- **Trusting only one layer** — a firewall in front of a full link does nothing, and a CDN does nothing for an origin whose address is public and attackable directly. Cover each class.
- **Confusing a flash crowd with an attack** — blocking a successful campaign is also an outage. Check user agents, pages requested and referrers before blocking.
- **Setting limits without measuring normal traffic** — a limit too low blocks real users (especially those sharing one address), and one too high stops nothing. Base it on the baseline.
- **Blackholing too early** — it completes the attack for that address. Try scrubbing, filtering and rate limits first, unless the rest of your network is in danger.
- **Leaving the origin exposed behind a CDN** — if attackers find the origin's real address, they bypass the CDN. Restrict the origin to the CDN's address ranges and keep the address private.
- **Running an open reflector yourself** — an open DNS resolver or memcached with UDP exposed makes your server part of other people's attacks, and may get your network blocked.
## Security considerations
- **Legal and ethical limits.** Launching or renting a DDoS attack is a criminal offence in most countries, whatever the motive and whatever you call it ("test", "stress test", "joke"). Even a short flood against a shared host harms other customers of that host. Stress-test only systems you own, or with written authorization, and read your cloud provider's policy on load testing before you do it.
- **Don't be part of the problem.** Patch and password-protect IoT and other devices: default credentials are how botnets grow. Filter spoofed source addresses on your network edge (BCP 38). Close the reflectors you operate.
- **DDoS as a smokescreen.** Attackers sometimes use a flood to distract the security team while they do something else, such as intrusion or data theft. Keep watching the rest of your logs while you handle the attack.
- **Extortion.** Some attackers demand money to stop. Paying is discouraged by authorities because it funds more attacks and doesn't guarantee they stop. Follow your incident procedure and involve law enforcement and the provider.
- **Mitigation has costs.** Challenges can block assistive technologies and legitimate automation (for example an API client), rate limits can hurt shared addresses, and traffic redirected to a third-party scrubbing or CDN service passes through that provider, so check what it can see (it terminates Transport Layer Security (TLS), so it sees the content) and what your data protection obligations are.
- **Don't announce your capacity.** The numbers you set (limits, thresholds) belong in internal documents, not in public pages.
## Summary
- A DoS attack exhausts a resource; a DDoS attack does it from many machines at once, usually a botnet of compromised devices, so blocking addresses one by one doesn't scale.
- The three classes exhaust different things: volumetric attacks fill bandwidth (bps), protocol attacks fill state tables (pps), application attacks use CPU, database and connections (rps).
- Reflection and amplification turn open UDP services into weapons, thanks to spoofed source addresses. The root fix is BCP 38 ingress filtering (RFC 2827) and closing the reflectors you operate.
- Defend in layers: provider and scrubbing, CDN and anycast, SYN cookies and limits at the edge, rate limiting and a WAF at the web server, a cheap and cached application. Blackholing (RFC 7999) is a last resort that completes the attack for that address.
- Prepare before: a traffic baseline, alerts, a runbook with provider contacts. After the attack, review and improve.
## Glossary
| Term | Definition |
|---|---|
| Denial-of-service (DoS) | An attack that makes a service unavailable to its users by exhausting a resource |
| Distributed denial-of-service (DDoS) | A DoS attack launched from many machines at once |
| Botnet | A network of compromised devices (bots) controlled remotely by an attacker |
| Bot | One compromised device that follows the attacker's orders |
| Command-and-control (C2) server | The server through which an attacker sends orders to the bots in a botnet |
| Internet of Things (IoT) | Connected everyday devices such as cameras, routers and sensors, often weakly secured |
| Mirai | A botnet of 2016 made of IoT devices with default passwords, a historical example |
| DDoS-for-hire | Illegal services that rent out attack capacity, also called booters or stressers |
| Volumetric attack | An attack that fills the bandwidth of a link, measured in bits per second |
| Protocol attack (state exhaustion) | An attack that fills the state tables of servers, firewalls or load balancers, measured in packets per second |
| Application-layer attack | An attack on layer 7 that exhausts CPU, database or connections, measured in requests per second |
| SYN flood | A protocol attack that sends many TCP SYN packets to fill the half-open connection table |
| Half-open connection | A TCP connection where the server has answered the SYN but has not yet received the final ACK |
| Listen backlog | The limited queue where a server keeps half-open connections |
| HTTP flood | An application attack that sends a large number of valid-looking HTTP requests |
| Slowloris | A slow attack that holds many connections open by sending requests very slowly |
| Reflection attack | An attack that makes third-party servers send their replies to the victim by spoofing the victim's address |
| Reflector | A server (for example an open DNS resolver) that answers requests sent with a spoofed source |
| Amplification factor | The size of the response divided by the size of the request in a reflection attack |
| Source address spoofing | Sending packets with a false source IP address |
| Ingress filtering (BCP 38) | Dropping packets whose source address does not belong to the network they come from (RFC 2827) |
| Overprovisioning | Buying more capacity than normal traffic needs, to absorb surges |
| Rate limiting | Capping how many requests or connections one client can make per time unit |
| SYN cookies | A technique that encodes the connection state in the SYN-ACK sequence number so the server stores nothing until the ACK returns (RFC 4987) |
| Web application firewall (WAF) | A filter that inspects HTTP requests and blocks those that match its rules |
| Challenge (bot challenge) | A test, such as a CAPTCHA or a script, that tells humans from automated clients |
| Anycast | Announcing the same IP address from many locations so each client reaches the nearest one |
| Content delivery network (CDN) | A worldwide network of caching servers placed in front of an origin server |
| Scrubbing centre | A high-capacity facility that removes attack traffic and returns clean traffic |
| Remotely triggered blackhole (RTBH) | Asking the provider to drop all traffic to one IP address, using the BLACKHOLE community (RFC 7999) |
| Runbook | A short written procedure that says who does what, in what order, during an incident |
| Baseline | The measured normal level of traffic, errors and latency |
## Check your understanding
1. Why is a botnet attack from 50,000 addresses harder to stop than the same volume from one address, even if your firewall can block addresses?
2. A customer says your site is down. Bandwidth is at 3%, but the connection table of your load balancer is full. Which class of attack is this and which defence fits first?
3. An open resolver you forgot about is used in a reflection attack. Who receives the traffic, who suffers a cost, and what should be configured to prevent it?
4. What are the advantages and the limits of per-address rate limiting? When does it fail?
5. Write the five lines that must be in a DDoS runbook's first page.
## References
- [RFC 4987](https://www.rfc-editor.org/rfc/rfc4987) — TCP SYN Flooding Attacks and Common Mitigations
- [RFC 2827 (BCP 38)](https://www.rfc-editor.org/rfc/rfc2827) — Network Ingress Filtering: Defeating Denial of Service Attacks which employ IP Source Address Spoofing
- [RFC 3704 (BCP 84)](https://www.rfc-editor.org/rfc/rfc3704) — Ingress Filtering for Multihomed Networks
- [RFC 4786 (BCP 126)](https://www.rfc-editor.org/rfc/rfc4786) — Operation of Anycast Services
- [RFC 7999](https://www.rfc-editor.org/rfc/rfc7999) — BLACKHOLE Community
- [RFC 9293](https://www.rfc-editor.org/rfc/rfc9293) — Transmission Control Protocol (TCP)
- [CISA: Understanding and Responding to DDoS Attacks](https://www.cisa.gov/resources-tools/resources/understanding-and-responding-distributed-denial-service-attacks)
- [nginx documentation: ngx_http_limit_req_module](https://nginx.org/en/docs/http/ngx_http_limit_req_module.html)