Creando paquetes UDP

Iniciado por mr.blood, Mayo 13, 2013, 07:39:40 PM

Tema anterior - Siguiente tema

0 Miembros y 1 Visitante están viendo este tema.

De mr.blood para You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login

Como no queremos liarnos mas de lo necesario dejamos los checksum a 0.

Codigo cliente.

Código: perl
#!/usr/bin/perl
use Socket;
use strict;

#~ Datos
my $data        =       "Hi!\n";
#~ UDP Header
my %udp         =       (sport=>(rand(3000)+5001), dport=>5000, len=>8+length($data), checksum=>0);
#~ IP Header
my %ip          =       (version=>4, IHL=>"45", ToS=>0, TL=>0, ID=>rand(20000), flags=>"010", FO=>"0"x13, TTL=>64,
                                Proto=>17, checksum=>0, saddr=>(gethostbyname("111.111.111.111"))[4],
                                daddr=>(gethostbyname("127.0.0.1"))[4]);

#~ Esto es cosa del protocolo IP, los flags y FO van "juntos"
my $ip_flags_FO=$ip{flags}.$ip{FO};

#~ Preparamos el paquete
my $paquete=pack("H2H2nnB16C2na4a4", $ip{IHL}, $ip{ToS}, $ip{TL}, $ip{ID},
                        $ip_flags_FO, $ip{TTL}, $ip{Proto},
                        $ip{checksum}, $ip{saddr},      $ip{daddr}).pack("nnnn",$udp{sport},
                        $udp{dport}, $udp{len}, $udp{checksum}).pack("a*", $data);

#~ Creamos el descriptor en SOCK del tipo SOCK_RAW
socket(SOCK, AF_INET, SOCK_RAW, 255);
#~ Para que la funcion send sepa donde enviarlo
my $destino = pack('Sna4x8', AF_INET, $udp{dport}, $ip{daddr});
send(SOCK,$paquete,0,$destino);


Fuentes:
You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login (Me apoye para los pack)
You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login (Me apoye para los pack tambien)
Propia (Horas mirando con Wireshark)
You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login

Sa1uDoS

P.D.: Como vereis por las fuentes los pack no son lo mio xD.