Net-Frame-Simple-1.06000755001750001750 012460365600 14100 5ustar00gomorgomor000000000000Net-Frame-Simple-1.06/MANIFEST000444001750001750 31712460365600 15347 0ustar00gomorgomor000000000000Build.PL Changes examples/build-tcp-syn.pl lib/Net/Frame/Simple.pm LICENSE LICENSE.Artistic Makefile.PL MANIFEST This list of files README t/01-use.t t/02-pod-coverage.t t/03-test-pod.t META.yml META.json Net-Frame-Simple-1.06/README000444001750001750 116012460365600 15113 0ustar00gomorgomor000000000000Net::Frame::Simple ================== INSTALLATION To install this module type the following: perl Makefile.PL make make test make install DEPENDENCIES This module requires these other modules and libraries: Perl v5.6.1 Class::Gomor Net::Frame GETTING HELP A mailing list is available for all questions concerning Net::Frame::*: https://www.secure-side.com/lists/mailman/listinfo/netframe COPYRIGHT AND LICENSE You may distribute this module under the terms of the Artistic license. See LICENSE.Artistic file in the source distribution archive. Copyright (c) 2006-2015, Patrice Auffret Net-Frame-Simple-1.06/Makefile.PL000444001750001750 65012460365600 16170 0ustar00gomorgomor000000000000# # $Id: Makefile.PL 349 2015-01-23 06:36:05Z gomor $ # use ExtUtils::MakeMaker; require v5.6.1; WriteMakefile( NAME => 'Net::Frame::Simple', VERSION_FROM => 'lib/Net/Frame/Simple.pm', LICENSE => 'artistic', ABSTRACT_FROM => 'lib/Net/Frame/Simple.pm', AUTHOR => 'GomoR ', MIN_PERL_VERSION => '5.6.1', PREREQ_PM => { 'Class::Gomor' => '1.00', 'Net::Frame' => 0, }, ); Net-Frame-Simple-1.06/Build.PL000444001750001750 76512460365600 15521 0ustar00gomorgomor000000000000# # $Id: Build.PL 349 2015-01-23 06:36:05Z gomor $ # use strict; use warnings; use Module::Build; my $builder = Module::Build->new( module_name => 'Net::Frame::Simple', license => 'artistic', dist_author => 'GomoR ', dist_version_from => 'lib/Net/Frame/Simple.pm', requires => { 'perl' => '5.6.1', 'Class::Gomor' => '1.00', 'Net::Frame' => '0', }, configure_requires => { 'Module::Build' => 0, }, ); $builder->create_build_script; Net-Frame-Simple-1.06/LICENSE000444001750001750 26512460365600 15225 0ustar00gomorgomor000000000000LICENSE This program is free software. You can redistribute it and/or modify it under the following terms: - the Perl Artistic License (in the file LICENSE.Artistic), Net-Frame-Simple-1.06/Changes000444001750001750 236012460365600 15531 0ustar00gomorgomor000000000000Revision history for Perl extension Net::Frame::Simple. 1.06 Fri Jan 23 07:32:52 CET 2015 - new: truncated attribute - update: copyright notice - update: Kwalitee 1.05 Wed Jan 25 22:48:18 CET 2012 - UPDATE: %Next variable population removed. Must be done from developer's own layer 7 modules. - bugfix: check when capture length is smaller than content length - update: copyright notice 1.04 Sun May 31 15:29:26 CEST 2009 - UPDATE: removed old computation scheme (see 1.03 changes) - update: copyright notice 1.03 Sun Nov 9 22:59:08 CET 2008 - new: made computeLengths() and computeChecksums() generic for all protocols - new: $NoComputeLengths and $NoComputeChecksums global variables to disable respective computations - WARNING: this new computation scheme does not apply to: IPv{4|6}, ICMPv{4|6}, TCP, UDP => Because the old computation scheme stills apply. 1.02 Thu Dec 21 23:48:44 CET 2006 - NEW: support for ICMPv6 - bugfix: get padding for IPv6 1.01 Sun Dec 17 17:30:19 CET 2006 - UPDATE: all layers moved to Net::Frame::Layer::* namespace - new: support for IPv6 layer (computeLengths(), computeChecksums()) 1.00 Sat Dec 9 19:38:13 CET 2006 - first public release Net-Frame-Simple-1.06/META.yml000444001750001750 115112460365600 15504 0ustar00gomorgomor000000000000--- abstract: 'frame crafting made easy' author: - 'GomoR ' build_requires: {} configure_requires: Module::Build: '0' dynamic_config: 1 generated_by: 'Module::Build version 0.421, CPAN::Meta::Converter version 2.143240' license: artistic meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Net-Frame-Simple provides: Net::Frame::Simple: file: lib/Net/Frame/Simple.pm version: '1.06' requires: Class::Gomor: '1.00' Net::Frame: '0' perl: v5.6.1 resources: license: http://opensource.org/licenses/artistic-license.php version: '1.06' Net-Frame-Simple-1.06/META.json000444001750001750 167512460365600 15667 0ustar00gomorgomor000000000000{ "abstract" : "frame crafting made easy", "author" : [ "GomoR " ], "dynamic_config" : 1, "generated_by" : "Module::Build version 0.421", "license" : [ "artistic_1" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Net-Frame-Simple", "prereqs" : { "configure" : { "requires" : { "Module::Build" : "0" } }, "runtime" : { "requires" : { "Class::Gomor" : "1.00", "Net::Frame" : "0", "perl" : "v5.6.1" } } }, "provides" : { "Net::Frame::Simple" : { "file" : "lib/Net/Frame/Simple.pm", "version" : "1.06" } }, "release_status" : "stable", "resources" : { "license" : [ "http://opensource.org/licenses/artistic-license.php" ] }, "version" : "1.06" } Net-Frame-Simple-1.06/LICENSE.Artistic000444001750001750 1373412460365600 17053 0ustar00gomorgomor000000000000 The "Artistic License" Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder as specified below. "Copyright Holder" is whoever is named in the copyright or copyrights for the package. "You" is you, if you're thinking about copying or distributing this Package. "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as uunet.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) give non-standard executables non-standard names, and clearly document the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. You may embed this Package's interpreter within an executable of yours (by linking); this shall be construed as a mere form of aggregation, provided that the complete Standard Version of the interpreter is so embedded. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whoever generated them, and may be sold commercially, and may be aggregated with this Package. If such scripts or library files are aggregated with this Package via the so-called "undump" or "unexec" methods of producing a binary executable image, then distribution of such an image shall neither be construed as a distribution of this Package nor shall it fall under the restrictions of Paragraphs 3 and 4, provided that you do not represent such an executable image as a Standard Version of this Package. 7. C subroutines (or comparably compiled subroutines in other languages) supplied by you and linked into this Package in order to emulate subroutines and variables of the language defined by this Package shall not be considered part of this Package, but are the equivalent of input as in Paragraph 6, provided these subroutines do not change the language in any way that would cause it to fail the regression tests for the language. 8. Aggregation of this Package with a commercial distribution is always permitted provided that the use of this Package is embedded; that is, when no overt attempt is made to make this Package's interfaces visible to the end user of the commercial distribution. Such use shall not be construed as a distribution of this Package. 9. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 10. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End Net-Frame-Simple-1.06/lib000755001750001750 012460365600 14646 5ustar00gomorgomor000000000000Net-Frame-Simple-1.06/lib/Net000755001750001750 012460365600 15374 5ustar00gomorgomor000000000000Net-Frame-Simple-1.06/lib/Net/Frame000755001750001750 012460365600 16426 5ustar00gomorgomor000000000000Net-Frame-Simple-1.06/lib/Net/Frame/Simple.pm000444001750001750 3216312460365600 20377 0ustar00gomorgomor000000000000# # $Id: Simple.pm 349 2015-01-23 06:36:05Z gomor $ # package Net::Frame::Simple; use warnings; use strict; our $VERSION = '1.06'; use Class::Gomor::Array; use Exporter; our @ISA = qw(Class::Gomor::Array Exporter); our @EXPORT_OK = qw( $NoComputeLengths $NoComputeChecksums ); our @AS = qw( raw reply timestamp firstLayer padding ref truncated _canMatchLayer _getKey _getKeyReverse ); our @AA = qw( layers ); __PACKAGE__->cgBuildIndices; __PACKAGE__->cgBuildAccessorsScalar(\@AS); __PACKAGE__->cgBuildAccessorsArray (\@AA); no strict 'vars'; use Carp; use Time::HiRes qw(gettimeofday); use Net::Frame::Layer qw(:consts); use Net::Frame::Layer::UDP; use Net::Frame::Layer::TCP; our $NoComputeLengths = 0; our $NoComputeChecksums = 0; sub _gettimeofday { my ($sec, $usec) = gettimeofday(); sprintf("%d.%06d", $sec, $usec); } sub new { my $self = shift->SUPER::new( timestamp => _gettimeofday(), firstLayer => NF_LAYER_UNKNOWN, truncated => 0, layers => [], @_, ); $self->[$__raw] ? $self->unpack : $self->pack; $self; } sub newFromDump { my $self = shift; my ($h) = @_; $self->new( timestamp => $h->{timestamp}, firstLayer => $h->{firstLayer}, raw => $h->{raw}, ); } # If there are multiple layers of the same type, the upper will be kept sub _setRef { my $self = shift; my ($l) = @_; $self->[$__ref]->{$l->layer} = $l; } sub unpack { my $self = shift; my $encapsulate = $self->[$__firstLayer]; if ($encapsulate eq NF_LAYER_UNKNOWN) { print("Unable to unpack frame from this layer type.\n"); return undef; } my @layers; my $n = 0; my $raw = $self->[$__raw]; my $rawLength = length($raw); my $oRaw = $raw; my $prevLayer; # No more than a thousand nested layers, maybe should be a parameter for (1..1000) { last unless $raw; $encapsulate =~ s/[^-:\w]//g; # Fix potential code injection my $layer = 'Net::Frame::Layer::'.$encapsulate; eval "require $layer"; if ($@) { print("*** $layer module not found.\n". "*** Either install it (if avail), or implement it.\n". "*** You can also send the pcap file to perl\@gomor.org.\n"); if ($prevLayer) { $prevLayer->nextLayer(NF_LAYER_NOT_AVAILABLE); } last; } my $l = $layer->new(raw => $raw)->unpack or last; $encapsulate = $l->encapsulate; $raw = $l->payload; push @layers, $l; # If there are multiple layers of the same type, the upper will be kept $self->_setRef($l); last unless $encapsulate; if ($encapsulate eq NF_LAYER_UNKNOWN) { print("Unable to unpack next layer, not yet implemented in layer: ". "$n:@{[$l->layer]}\n"); last; } $prevLayer = $l; $oRaw = $raw; } if (@layers > 0) { $self->[$__layers] = \@layers; $self->_getPadding($rawLength); $self->_searchCanGetKeyLayer; $self->_searchCanGetKeyReverseLayer; $self->_searchCanMatchLayer; return $self; } undef; } sub computeLengths { my $self = shift; my $layers = $self->[$__layers]; for my $l (reverse @$layers) { $l->computeLengths($layers); } return 1; } sub computeChecksums { my $self = shift; my $layers = $self->[$__layers]; for my $l (reverse @$layers) { $l->computeChecksums($layers); } return 1; } sub pack { my $self = shift; # If there are multiple layers of the same type, # the upper will be kept for the reference $self->_setRef($_) for @{$self->[$__layers]}; $self->computeLengths unless $NoComputeLengths; $self->computeChecksums unless $NoComputeChecksums; my $raw = ''; my $last; for (@{$self->[$__layers]}) { $raw .= $_->pack; $last = $_; } if ($last && defined($last->payload)) { $raw .= $last->payload; } $raw .= $self->[$__padding] if $self->[$__padding]; $self->_searchCanGetKeyLayer; $self->_searchCanGetKeyReverseLayer; $self->_searchCanMatchLayer; $self->[$__raw] = $raw; } sub _getPadding { my $self = shift; my ($rawLength) = @_; my $last = ${$self->[$__layers]}[-1]; # Last layer has no payload, so no padding return if (! defined($last->payload) || ! length($last->payload)); # FIX: be it available or not, we need to parse payload/padding difference # So, I comment these lines for now #if ($last->nextLayer eq NF_LAYER_NOT_AVAILABLE) { #return; #} my $tLen = 0; for my $l (@{$self->[$__layers]}) { if ($l->layer eq 'IPv4') { $tLen += $l->length; last; } elsif ($l->layer eq 'IPv6') { $tLen += $l->getLength; $tLen += $l->getPayloadLength; last; } $tLen += $l->getLength; } # No padding return if $rawLength == $tLen; my $pLen = 0; my $padding; if ($rawLength > $tLen) { $pLen = $rawLength - $tLen; $padding = substr($self->[$__raw], $tLen, $pLen); $self->[$__padding] = $padding; } else { $self->[$__truncated] = 1; } # Now, split padding between true padding and true payload my $payloadLength = length($last->payload); if ($payloadLength > $pLen) { my $payload = substr($last->payload, 0, ($payloadLength - $pLen)); $last->payload($payload); } else { $last->payload(undef); } } sub send { my $self = shift; my ($oWrite) = @_; $oWrite->send($self->[$__raw]); } sub reSend { my $self = shift; $self->send(shift()) unless $self->[$__reply] } sub _searchCanMatchLayer { my $self = shift; for my $l (reverse @{$self->[$__layers]}) { if ($l->can('match')) { $self->[$___canMatchLayer] = $l; last; } } undef; } sub _searchCanGetKeyLayer { my $self = shift; for my $l (reverse @{$self->[$__layers]}) { if ($l->can('getKey')) { $self->[$___getKey] = $l->getKey; last; } } } sub _searchCanGetKeyReverseLayer { my $self = shift; for my $l (reverse @{$self->[$__layers]}) { if ($l->can('getKeyReverse')) { $self->[$___getKeyReverse] = $l->getKeyReverse; last; } } } sub _recv { my $self = shift; my ($oDump) = @_; my $layer = $self->[$___canMatchLayer]; for my $this ($oDump->getFramesFor($self)) { next unless $this->[$__timestamp] gt $self->[$__timestamp]; # We must put ICMPv4 before, because the other will # always match for UDP. if (exists $this->[$__ref]->{ICMPv4} && (exists $this->[$__ref]->{UDP} || exists $this->[$__ref]->{TCP})) { if (exists $this->[$__ref]->{$layer->layer}) { return $this if $this->[$__ref]->{$layer->layer}->getKey eq $layer->getKey; } } elsif (exists $this->[$__ref]->{$layer->layer}) { return $this if $layer->match($this->[$__ref]->{$layer->layer}); } } undef; } sub recv { my $self = shift; my ($oDump) = @_; # We already have the reply $self->[$__reply] and return $self->[$__reply]; # Is there anything waiting ? my $h = $oDump->next or return undef; my $oSimple = Net::Frame::Simple->newFromDump($h); $oDump->store($oSimple); if (my $reply = $self->_recv($oDump)) { $self->cgDebugPrint(1, "Reply received"); return $self->[$__reply] = $reply; } undef; } # Needed by Net::Frame::Dump sub getKey { shift->[$___getKey] || 'all' } sub getKeyReverse { shift->[$___getKeyReverse] || 'all' } sub print { my $self = shift; my $str = ''; my $last; for my $l (@{$self->[$__layers]}) { $str .= $l->print."\n"; $last = $l; } $str =~ s/\n$//s; # Print remaining to be decoded, if any if ($last && $last->payload) { $str .= "\n".$last->layer.': payload:'.CORE::unpack('H*', $last->payload); } # Print the padding, if any if ($self->[$__padding]) { $str .= "\n".'Padding: '.CORE::unpack('H*', $self->[$__padding]); } $str; } sub dump { my $self = shift; my $raw = ''; $raw .= $_->raw for @{$self->[$__layers]}; $raw .= $self->[$__padding] if $self->[$__padding]; CORE::unpack('H*', $raw); } 1; __END__ =head1 NAME Net::Frame::Simple - frame crafting made easy =head1 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; use Net::Frame::Layer::IPv4; use Net::Frame::Layer::TCP; 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; =head1 DESCRIPTION This module is part of B 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. =head1 ATTRIBUTES =over 4 =item B Where the packed frame will be stored, or used to unpack a raw string taken from the network (or elsewhere). =item B The frame timestamp. =item B We cannot know by which layer a frame begins, so this tells how to start unpacking a raw data. =item B 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. =item B A binary flag stating when a raw frame has been truncated (or not). =item B When the B method is called, and a corresponding reply has been found, it is stored here. =item B This one is an arrayref. It will store all layers to use within the B object. =item B 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). =back =head1 METHODS =over 4 =item B (hash) Object constructor. You can pass attributes in a hash as a parameter. Also note that when you call it with B attribute set, it will automatically call B, B and B for you. And when you pass B attribute, it will call B for you too, building layers and storing them in B attribute. =item B (hashref) When B B 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 B object. =item B This one hides the manual hassle of calling B method for each layers. It takes no parameter, it will know internally what to do. =item B Same as above, but for checksums. you MUST call the previous one before this one. =item B Will pack all layers to to B attribute, ready to be sent to the network. =item B Will unpack a raw string from the B attribute into respective layers. =item B =item B These two methods are basically used to increase the speed when using B method. =item B (Net::Frame::Dump object) When you want to search for the response of your probe, you call it by specifying from which B object to search. It then returns a B object if a match is found, or undef if not. =item B (Net::Write object) Will send to the B object the raw string describing the B object. =item B (Net::Write object) You can also B the frame, it will only rewrite it to the network if no B has already been found. =item B Prints all layers in human readable format. =item B Dumps the B string in hexadecimal format. =back =head1 SEE ALSO L, L =head1 AUTHOR Patrice EGomoRE Auffret =head1 COPYRIGHT AND LICENSE Copyright (c) 2006-2015, Patrice EGomoRE Auffret You may distribute this module under the terms of the Artistic license. See LICENSE.Artistic file in the source distribution archive. =cut Net-Frame-Simple-1.06/t000755001750001750 012460365600 14343 5ustar00gomorgomor000000000000Net-Frame-Simple-1.06/t/01-use.t000444001750001750 10612460365600 15654 0ustar00gomorgomor000000000000use Test; BEGIN { plan(tests => 1) } use Net::Frame::Simple; ok(1); Net-Frame-Simple-1.06/t/02-pod-coverage.t000444001750001750 30112460365600 17431 0ustar00gomorgomor000000000000eval "use Test::Pod::Coverage tests => 1"; if ($@) { use Test; plan(tests => 1); skip("Test::Pod::Coverage required for testing"); } else { pod_coverage_ok("Net::Frame::Simple"); } Net-Frame-Simple-1.06/t/03-test-pod.t000444001750001750 23112460365600 16620 0ustar00gomorgomor000000000000eval "use Test::Pod 1.00"; if ($@) { use Test; plan(tests => 1); skip("Test::Pod 1.00 required for testing"); } else { all_pod_files_ok(); } Net-Frame-Simple-1.06/examples000755001750001750 012460365600 15716 5ustar00gomorgomor000000000000Net-Frame-Simple-1.06/examples/build-tcp-syn.pl000444001750001750 101512460365600 21077 0ustar00gomorgomor000000000000#!/usr/bin/perl use strict; use warnings; my $src = '192.168.0.10'; my $target = '192.168.0.1'; my $port = 22; use Net::Frame::Simple; use Net::Frame::Layer::IPv4; use Net::Frame::Layer::TCP; 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 ], ); print $oSimple->print."\n"; print $oSimple->dump."\n";