SECURITY ENGINEERING · PART 2 · NETWORKING FOR SECURITY · ATTACKS · 25 OF 229

TCP/IP Attacks: SYN Floods, Spoofing, Hijacking

The weaknesses built into TCP and IP, and what defends against each: IP address spoofing and why UDP makes it worse, the SYN flood that fills a server with half-open connections, SYN cookies, reset and session hijacking attacks, ICMP abuse, and amplification, with the kernel settings, filtering and encryption that blunt them.

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 9
  9. 10
  10. 11
  11. 12
  12. 13
  13. 14
  14. 15
  15. 16
  16. 17
  17. 18
  18. 19
  19. 20
  20. 21
  21. 22
  22. 23
  23. 24
  24. 25
  25. 26
  26. 27
  27. 28
  28. 29
  29. 30
  30. 31
  31. 32
  32. 33
  33. 34
  34. 35
  35. 36
  36. 37
  37. 38
  38. 39
  39. 40
  40. 41
  41. 42
  42. 43
  43. 44
  44. 45
  45. 46
  46. 47
  47. 48
  48. 49
  49. 50
  50. 51
  51. 52
  52. 53
  53. 54
  54. 55
  55. 56
  56. 57
  57. 58
  58. 59
  59. 60
  60. 61
  61. 62
  62. 63
  63. 64
  64. 106
  65. 107
  66. 108
  67. 109
  68. 110
  69. 111
  70. 112
  71. 113
  72. 114
  73. 115
  74. 116
  75. 117
  76. 118
  77. 119
  78. 120
  79. 121
  80. 122
  81. 123
  82. 124
  83. 125
  84. 126
  85. 127
  86. 128
  87. 129
  88. 130
  89. 131
  90. 132
  91. 133
  92. 134
  93. 135
  94. 136
  95. 137
  96. 138
  97. 139
  98. 140
  99. 141
  100. 142
  101. 143
  102. 144
1 / 13

Press play to hear the narration, or step through at your own pace.

Key takeaways

  • Source addresses can be forged
  • SYN floods and SYN cookies
  • resets and hijacking
  • amplification
  • filter, harden, encrypt

Notes

IP spoofing

Start with the root weakness. The source address on an IP packet is just a field the sender fills in, and nothing checks it. An attacker can write any address there. The catch is that replies go to the forged address, not to the attacker, so spoofing is useless for holding a conversation but ideal for flooding and for blaming someone else. It is especially easy with UDP, which has no handshake to complete.

Forged source addresses
  • an IP packet carries a source address, unverified
  • an attacker can write any address there
  • the reply goes to the forged address, not to them
  • so: fine for floods, useless for a normal conversation
  • UDP has no handshake: easy

The handshake

To see the next attack you need the TCP handshake. The client sends a SYN. The server answers with a SYN-ACK and, importantly, reserves a little memory for this half-open connection while it waits. The client replies with an ACK and data can flow. Notice the imbalance: the server commits resources after receiving a single cheap packet. That imbalance is the whole attack.

SYN, SYN-ACK, ACK
  • client: SYN (let us talk)
  • server: SYN-ACK (agreed) and it reserves memory for this half-open connection
  • client: ACK (confirmed)
  • now data can flow
  • the server commits resources after only one packet

SYN flood

A SYN flood exploits it. The attacker sends a storm of SYN packets, often with spoofed source addresses, and never completes the handshake. The server reserves a slot for each one and waits for an acknowledgement that never arrives. The queue of half-open connections fills, and real clients are turned away. The server is not broken into. It is simply too busy holding the door for nobody to let anyone in.

SYN flood
  • the attacker sends a storm of SYNs, often spoofed
  • the server reserves a slot for each and waits for ACKs that never come
  • the queue fills up real clients are turned away
  • a classic denial of service

SYN cookies

The classic defense is SYN cookies. Instead of reserving memory, the server encodes the connection details into the sequence number of its SYN-ACK and stores nothing at all. Only a client that returns a valid acknowledgement, which proves it really received the reply, gets a connection. Spoofed SYNs cost the server nothing. Linux enables this by default. For large floods you also need help upstream, which the DDoS episode covers.

The defense
# Linux: on by default
sysctl net.ipv4.tcp_syncookies
net.ipv4.tcp_syncookies = 1

the server encodes the state in
the SYN-ACK sequence number and
stores nothing; only a valid ACK
creates the connection
plus: a bigger backlog, shorter
timeouts, upstream scrubbing

Resets and hijacking

A live connection can be attacked too. TCP identifies a connection only by addresses, ports and sequence numbers. An attacker who can observe or guess them can inject a packet that appears to belong to it. A forged reset tears the connection down. Forged data is session hijacking. Modern systems randomise sequence numbers, which makes blind guessing very hard, and TLS finishes the job: injected data fails its integrity check and is thrown away.

Attacking a live connection
  • a connection is identified by addresses, ports and sequence numbers
  • guess or observe them and you can inject a packet
  • a forged RST kills the connection
  • forged data = session hijack
  • far harder with random sequence numbers; TLS rejects injected data

Amplification

Spoofing and UDP combine into amplification. The attacker sends a small request to an open server, with the victim's address forged as the source. The server sends its much larger reply to the victim. Open DNS resolvers, time servers and exposed cache servers have all been used this way, multiplying an attacker's traffic many times over. Your duty as an engineer is not to be the amplifier: no open resolvers, rate limits, and no UDP services exposed without need.

Reflection and amplification
  • send a small UDP request with the *victim's* address as the source
  • an open server sends its large reply to the victim
  • DNS, NTP, memcached have amplified traffic many times
  • fix: no open resolvers, rate limit, disable unused UDP

ICMP abuse

ICMP, the protocol behind ping and network error messages, gets abused as well. Ping sweeps map which hosts are alive. Forged redirect messages try to change a host's routing. And data can be hidden inside ping payloads as a covert channel. The temptation is to block ICMP completely, but that breaks useful things like path size discovery. The sensible setting is to ignore redirects, rate limit, and allow the message types the network actually needs.

ICMP
  • ping sweeps: map which hosts are alive
  • ICMP redirects: tell a host to use a different route
  • ICMP tunnels: hide data in ping payloads
  • do not block it all: path MTU discovery needs it
  • ignore redirects; rate limit

Filtering

Spoofing can be stopped where traffic enters a network. A router knows which addresses can legitimately arrive on each link, and can drop packets that claim an impossible source. On Linux that is reverse path filtering. For internet providers it is a practice known as BCP thirty eight. Cloud providers block spoofed packets from their virtual machines. The more networks filter, the less spoofing works anywhere. Hardening benchmarks include these kernel settings.

Anti-spoofing
# drop packets whose source
# could not arrive on this path
net.ipv4.conf.all.rp_filter = 1
# ignore redirects, source routes
net.ipv4.conf.all.accept_redirects=0
net.ipv4.conf.all.accept_source_route=0

ISPs: BCP 38 ingress filtering
cloud: providers block spoofing

What protects you

In practice three layers do most of the work. Sane kernel network settings: SYN cookies, reverse path filtering and ignoring redirects, all of which the hardening benchmarks from Part one check. TLS everywhere, which makes injected or altered data worthless. And firewalls plus upstream DDoS protection for sheer volume. You will rarely fight these attacks by hand. Your job is to make sure the defaults are on and nothing you run can be used against others.

In practice
  • hardened kernel defaults: SYN cookies, rp_filter, no redirects (CIS checks these)
  • TLS everywhere: injected or altered data is rejected
  • firewalls and upstream DDoS protection for volume
  • do not run exposed UDP services you do not need

Common mistakes

Mistakes. Turning off SYN cookies because an old tuning guide said so. Running an open DNS resolver or time server that anyone can use as an amplifier. Exposing cache servers or other UDP services to the internet. Blocking all ICMP and breaking the network in subtle ways. Treating a source IP address as proof of identity, in firewall rules or in application logic. And still running plain-text protocols, where hijacking is easy.

Avoid these
  • SYN cookies disabled by an old tuning guide
  • open DNS resolver or NTP server on the internet
  • memcached or other UDP services exposed
  • blocking all ICMP
  • trusting source IP as identity
  • plain-text protocols

Say it like this

In the interview: in a SYN flood the attacker sends many SYN packets, often with spoofed sources, and never completes the handshake, so the server's queue of half-open connections fills and real clients are refused. SYN cookies mitigate it by encoding state in the SYN-ACK and storing nothing until a valid acknowledgement returns. I also tune the backlog and timeouts, and for large floods rely on upstream DDoS protection.

In the interview
  • "The attacker sends many SYNs, often spoofed, and never
  • completes the handshake, so the half-open queue fills and real
  • clients are refused. SYN
  • cookies avoid storing state
  • until a valid ACK returns; for large floods I add upstream
  • DDoS protection."

Interview questions

Q1What is IP spoofing?

Sending packets with a forged source IP address. Because replies go to the forged address, it is used for floods, reflection attacks and evading attribution rather than for normal two-way sessions, and it is easiest with UDP, which has no handshake.

Q2What is a SYN flood?

A denial-of-service attack that sends many TCP SYN packets, usually spoofed, without completing the handshake. The server keeps a half-open connection entry for each, the backlog fills, and legitimate connections are refused.

Q3How do SYN cookies work?

The server does not store state for a new SYN. It encodes the connection parameters into the initial sequence number of the SYN-ACK and only creates the connection when a valid ACK with the matching number returns, so spoofed SYNs consume no memory.

Q4What is TCP session hijacking?

Injecting packets into an existing TCP connection by knowing or guessing its addresses, ports and sequence numbers, either to insert data or to reset it. Randomised initial sequence numbers make blind attacks hard, and TLS rejects injected data.

Q5What is a reflection or amplification attack?

The attacker sends small requests to open UDP services with the victim’s address spoofed as the source, so the services send their larger replies to the victim. DNS, NTP and memcached have been abused; closing open services and rate limiting prevent it.

Q6What is BCP 38?

A best practice for network operators to filter traffic at the edge so packets with source addresses that could not legitimately originate from that network are dropped, reducing IP spoofing across the internet. Reverse path filtering is the host-level equivalent.

Q7Should you block all ICMP at the firewall?

No. Some ICMP types are needed, for example for path MTU discovery and error reporting. The better practice is to allow the necessary types, rate limit, and ignore ICMP redirects, while blocking or monitoring the rest.

Q8Why is a source IP address a weak form of authentication?

It can be spoofed for connectionless traffic, shared behind NAT, or reached through a compromised host. Allowlists by IP can reduce exposure, but identity should be established with cryptographic authentication such as TLS client certificates or tokens.