hping3 in a lab: crafting TCP packets to see SYN floods and firewall behavior
hping3 builds custom TCP, UDP, and ICMP packets, which makes it a teaching tool for how SYN floods fill connection tables and how firewalls answer. Lab-only examples, what the target sees, and SYN cookies as the defense.
What is hping3?
hping3 is a program that can build custom packets and can also generate load. Older network write-ups treat it as a teaching tool. This page does not include packet-crafting commands, flood options, or install steps. It describes the outage that kind of load creates and the controls that limit it.
Who is affected when crafted packets or a flood exhaust a service?
Anyone who needed the host to answer: users of the service, and the operator who has to explain the outage. People on a shared network are affected too if a test is not kept on an isolated lab.
What do you change to defend against hping3-style load?
Use a default-deny firewall so unexpected packets never reach the service. Limit connections and request rates at the firewall or the reverse proxy. Do not publish services you do not need. Keep any packet experiment on a host-only lab you own, and never against a network you do not administer.
Diagram
A SYN flood seen from the target
Step 1 of 4
Probe
In a lab, a few SYNs to an open and a closed port show the normal answers.
$ sudo hping3 -S -p 80 -c 3 10.10.0.20 len=46 ip=10.10.0.20 ttl=64 DF id=0 sport=80 flags=SA seq=0 win=64240 rtt=0.6 ms $ sudo hping3 -S -p 81 -c 1 10.10.0.20 len=46 ip=10.10.0.20 ttl=64 DF id=0 sport=81 flags=RA seq=0 win=0 rtt=0.5 ms
The example on the open step is one illustration, or the fix you can paste into an application you own.
What this page is made of
3 pieces. Each one says what fails, who is affected, what you would notice, and what you change.
Firewall answers
- What fails
- hping3 shows whether a port answers SYN-ACK, RST, or nothing.
- Who is affected
- Teams verifying their own firewall rules.
- What you would notice
- Unexpected SYN-ACKs from ports that should be closed.
- What you change
- Test rules from outside in a maintenance window you own.
Spoofed sources
- What fails
- Floods often use random source addresses, so replies go elsewhere.
- Who is affected
- Third parties receiving backscatter.
- What you would notice
- SYN-ACKs to addresses you never contacted.
- What you change
- Ask upstream providers to filter spoofed traffic (BCP 38).
Lab setup
Use two VMs on a host-only network. Never point hping3 at an address you do not own; even a small flood against someone else’s server is an attack. Keep -c counts small for probes, and watch the target with ss and tcpdump while you test.
# on the target VM $ sudo tcpdump -nn -i eth1 'tcp port 80 and tcp[tcpflags] & tcp-syn != 0' $ watch -n1 "ss -n state syn-recv sport = :80 | wc -l"
Other things hping3 teaches
Traceroute with TCP (hping3 -S -p 443 --traceroute) shows paths that drop ICMP, and the TTL and window values in replies hint at the operating system. Both are useful for checking your own perimeter.
Check yourself
Recognition and the fix. Nothing here is a procedure.
hping3 -S to a closed port returns flags=RA. What does that mean?
Go deeper
Specific techniques, exercises, and glossary cards for this topic.
- 01LOIC: what the Low Orbit Ion Cannon does and how defenders spot itLOIC is an old, simple flooding tool that sends TCP, UDP, or HTTP traffic from the user’s own IP. Includes the diagram and a defensive fix.
- 02Denial of service and DDoS: volumetric, protocol, and application floodsThe three families of denial-of-service attack, what each exhausts (bandwidth, connection state, or application work), how botnets and reflection amplify them, and the layered defenses from upstream scrubbing to rate limits. Includes the diagram and a defensive fix.
- 03Snort and intrusion detectionSnort watches traffic and raises an alert when a rule matches. Includes the diagram and a defensive fix.