The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Net::Frame::Simple - frame crafting made easy

SYNOPSIS

   # We build a TCP SYN
   my $src    = '192.168.0.10';
   my $target = '192.168.0.1';
   my $port   = 22;

   use Net::Frame::Simple qw($NoUnableToUnpackWarnings $NoModuleNotFoundWarnings);
   use Net::Frame::Layer::IPv4;
   use Net::Frame::Layer::TCP;

   $NoUnableToUnpackWarnings = 1;
   $NoModuleNotFoundWarnings = 1;

   my $ip4 = Net::Frame::Layer::IPv4->new(
      src => $src,
      dst => $target,
   );
   my $tcp = Net::Frame::Layer::TCP->new(
      dst     => $port,
      options => "\x02\x04\x54\x0b",
      payload => 'test',
   );

   my $oSimple = Net::Frame::Simple->new(
      layers => [ $ip4, $tcp ],
   );

   # Now, the frame is ready to be send to the network
   # We open a sender object, and a retriever object
   use Net::Write::Layer3;
   use Net::Frame::Dump::Online;

   my $oWrite = Net::Write::Layer3->new(dst => $target);
   my $oDump  = Net::Frame::Dump::Online->new(dev => $oDevice->dev);
   $oDump->start;
   $oWrite->open;

   # We send the frame
   $oSimple->send($oWrite);

   # And finally, waiting for the response
   until ($oDump->timeout) {
      if (my $recv = $oSimple->recv($oDump)) {
         print "RECV:\n".$recv->print."\n";
         last;
      }
   }

   $oWrite->close;
   $oDump->stop;

DESCRIPTION

This module is part of Net::Frame frame crafting framework. It is totally optional, but can make playing with the network far easier.

Basically, it hides the complexity of frame forging, sending, and receiving, by providing helper methods, which will analyze internally how to assemble frames and find responses to probes.

For example, it will take care of computing lengths and checksums, and matching a response frame to the requesting frame.

ATTRIBUTES

raw

Where the packed frame will be stored, or used to unpack a raw string taken from the network (or elsewhere).

timestamp

The frame timestamp.

firstLayer

We cannot know by which layer a frame begins, so this tells how to start unpacking a raw data.

padding

Sometimes, frames are padded to achieve 60 bytes in length. The padding will be stored here, or if you craft a frame, you can manually add your own padding.

truncated

A binary flag stating when a raw frame has been truncated (or not).

reply

When the recv method is called, and a corresponding reply has been found, it is stored here.

layers

This one is an arrayref. It will store all layers to use within the Net::Frame::Simple object.

ref

This is a hashref that stores all layers. The key is the layer type (example: TCP: $oSimple->ref->{TCP}). If the frame contains multiple layers of the same type, only the one found at upper level will be kept (in fact, the latest analyzed one, aka LIFO).

METHODS

new (hash)

Object constructor. You can pass attributes in a hash as a parameter. Also note that when you call it with layers attribute set, it will automatically call computeLengths, computeChecksums and pack for you. And when you pass raw attribute, it will call unpack for you too, building layers and storing them in layers attribute.

newFromDump (hashref)

When Net::Frame::Dump next method is called, and there is a frame waiting, it returns a hashref with specific values. You can directly use it as a parameter for this method, which will create a new Net::Frame::Simple object.

computeLengths

This one hides the manual hassle of calling computeLengths method for each layers. It takes no parameter, it will know internally what to do. You may set the global variable $NoComputeLengths to 1 to avoid computing lengths.

computeChecksums

Same as above, but for checksums. you MUST call the previous one before this one. You may set the global variable $NoComputeChecksums to 1 to avoid computing checksums.

pack

Will pack all layers to to raw attribute, ready to be sent to the network.

unpack

Will unpack a raw string from the raw attribute into respective layers. By default, a warning will be displayed if unable to unpack the next layer. You may disable this message by setting the global variable $NoUnableToUnpackWarnings to 1. Furthermore, unpack() will try to load a module and print a warnings in case it is not able to load it. You may disable this message by setting the global variable $NoModuleNotFoundWarnings to 1.

getKey
getKeyReverse

These two methods are basically used to increase the speed when using recv method.

recv (Net::Frame::Dump object)

When you want to search for the response of your probe, you call it by specifying from which Net::Frame::Dump object to search. It then returns a Net::Frame::Simple object if a match is found, or undef if not.

send (Net::Write object)

Will send to the Net::Write object the raw string describing the Net::Frame::Simple object.

reSend (Net::Write object)

You can also reSend the frame, it will only rewrite it to the network if no reply has already been found.

print

Prints all layers in human readable format.

dump

Dumps the raw string in hexadecimal format.

SEE ALSO

Net::Write, Net::Frame::Dump

AUTHOR

Patrice <GomoR> Auffret

COPYRIGHT AND LICENSE

Copyright (c) 2006-2017, Patrice <GomoR> Auffret

You may distribute this module under the terms of the Artistic license. See LICENSE.Artistic file in the source distribution archive.