|
|
|
|
|
|
|
|
|
|
|
#!/usr/bin/perl |
|
|
|
|
|
|
|
|
|
|
|
use strict; |
|
|
|
|
|
use warnings; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
my($maccnt, $pps, $src, $dest) = @ARGV; |
|
|
|
|
|
|
|
|
|
|
|
usage() if !defined $dest; |
|
|
|
|
|
|
|
|
|
|
|
if ( $maccnt !~ /^\d+$/ || $maccnt < 1 ) { |
|
|
|
|
|
print STDERR "MAC count must be a positive integer\n"; |
|
|
|
|
|
exit 1; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ( $pps !~ /^\d+$/ || $pps < 1 ) { |
|
|
|
|
|
print STDERR "packets/sec must be a positive integer\n"; |
|
|
|
|
|
exit 1; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ( $src !~ /^(\d+\.\d+\.\d+\.\d+)$/ ) { |
|
|
|
|
|
print STDERR "source IP must be a valid IPv4 address\n"; |
|
|
|
|
|
exit 1; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ( $dest !~ /^(\d+\.\d+\.\d+\.\d+)$/ ) { |
|
|
|
|
|
print STDERR "destination IP must be a valid IPv4 address\n"; |
|
|
|
|
|
exit 1; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
main($maccnt, $pps, $src, $dest); |
|
|
|
|
|
|
|
|
|
|
|
sub usage { |
|
|
|
|
|
print STDERR "DHCP Flood using option 82\n"; |
|
|
|
|
|
print STDERR "This is only to test dhcp_protect, the DHCP packets aren't really valid\n"; |
|
|
|
|
|
print STDERR "DO NOT SEND THIS TO YOUR DHCP SERVER !!!!\n"; |
|
|
|
|
|
print STDERR "\n"; |
|
|
|
|
|
print STDERR "Usage: $0 <MAC count> <packets/sec> <source IPv4> <destination IPv4>\n"; |
|
|
|
|
|
print STDERR "Dependency: nemesis must be installed\n"; |
|
|
|
|
|
print STDERR "https://ftp.troglobit.com/nemesis/\n"; |
|
|
|
|
|
print STDERR "\n"; |
|
|
|
|
|
exit 1; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sub main { |
|
|
|
|
|
my($maccnt, $pps, $src, $dest)=@_; |
|
|
|
|
|
my $hdr = ""; |
|
|
|
|
|
|
|
|
|
|
|
$hdr .= "010106010c02385600010000000000000000000000000000c16e5f43409c28db"; |
|
|
|
|
|
$hdr .= "d56c000000000000000000000000000000000000000000000000000000000000"; |
|
|
|
|
|
$hdr .= "0000000000000000000000000000000000000000000000000000000000000000"; |
|
|
|
|
|
$hdr .= "0000000000000000000000000000000000000000000000000000000000000000"; |
|
|
|
|
|
$hdr .= "0000000000000000000000000000000000000000000000000000000000000000"; |
|
|
|
|
|
$hdr .= "0000000000000000000000000000000000000000000000000000000000000000"; |
|
|
|
|
|
$hdr .= "0000000000000000000000000000000000000000000000000000000000000000"; |
|
|
|
|
|
$hdr .= "000000000000000000000000638253633501013707017903060f77fc390205dc"; |
|
|
|
|
|
$hdr .= "3d0701409c28dbd56c33040076a7000c097370616c6569666f6e000000000000"; |
|
|
|
|
|
$hdr .= "0000000000000000000000520e0104000000000206XXXXXXXXXXXXff00000000"; |
|
|
|
|
|
|
|
|
|
|
|
my $int = 1/$pps; |
|
|
|
|
|
|
|
|
|
|
|
while(1) { |
|
|
|
|
|
for(my $i=0; $i<$maccnt; $i++) { |
|
|
|
|
|
my $mac = sprintf("000000%06x", $i); |
|
|
|
|
|
my $pkt = $hdr; |
|
|
|
|
|
$pkt =~ s/XXXXXXXXXXXX/$mac/; |
|
|
|
|
|
|
|
|
|
|
|
open(N,"| nemesis udp -S $src -D $dest -x 67 -y 666 -i $int -P -") || die "install nemesis!"; |
|
|
|
|
|
print N pack("H*",$pkt); |
|
|
|
|
|
print N ""; |
|
|
|
|
|
close(N); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |