⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frame.pm

📁 SinFP是一种新的识别对方计算机操作系统类型的工具
💻 PM
📖 第 1 页 / 共 2 页
字号:
         $self->cgDebugPrint(3,            "send: l2: type:". sprintf("0x%x", $self->l2->type). ", ".            "@{[$self->l2->src]} => @{[$self->l2->dst]}"         );      }      if ($self->isIp) {         $self->cgDebugPrint(3,            "send: l3: protocol:@{[$self->l3->protocol]}, ".            "size:@{[$self->getLength]}, ".            "@{[$self->l3->src]} => @{[$self->l3->dst]}"         );      }      elsif ($self->isArp) {         $self->cgDebugPrint(3,            "send: l3: @{[$self->l3->src]} => @{[$self->l3->dst]}"         );      }      if ($self->isTcp || $self->isUdp) {         $self->cgDebugPrint(3,            "send: l4: @{[$self->l4->is]}, ".            "@{[$self->l4->src]} => @{[$self->l4->dst]}"         );      }   }   $self->[$__timestamp] = _gettimeofday();   $env->desc->send($self->[$__raw]);}sub reSend { my $self = shift; $self->send unless $self->[$__reply] }sub getFilter {   my $self = shift;   my $filter;   # L4 filtering   if ($self->[$__l4]) {      if ($self->isTcp) {         $filter .= "(tcp and".                    " src port @{[$self->[$__l4]->dst]}".                    " and dst port @{[$self->[$__l4]->src]})";      }      elsif ($self->isUdp) {         $filter .= "(udp and".                    " src port @{[$self->[$__l4]->dst]}".                    " and dst port @{[$self->[$__l4]->src]})";      }      elsif ($self->isIcmpv4) {         $filter .= "(icmp)";      }      $filter .= " or icmp";   }   # L3 filtering   if ($self->[$__l3]) {      $filter .= " and " if $filter;      if ($self->isIpv4) {         $filter .= "(src host @{[$self->[$__l3]->dst]}".                    " and dst host @{[$self->[$__l3]->src]}) ".                    " or ".                    "(icmp and dst host @{[$self->[$__l3]->src]})";      }      elsif ($self->isIpv6) {         $filter .= "(ip6 and src host @{[$self->[$__l3]->dst]}".                    " and dst host @{[$self->[$__l3]->src]})";      }      elsif ($self->isArp) {         $filter .= "(arp and src host @{[$self->[$__l3]->dstIp]}".                    " and dst host @{[$self->[$__l3]->srcIp]})";      }   }       $filter;}sub recv {   my $self = shift;   $self->[$__env]->dump->nextAll if $self->[$__env]->dump->isRunning;   #燱e already have the reply   return undef if $self->[$__reply];   croak("@{[(caller(0))[3]]}: \$self->env->dump variable not set\n")      unless $self->[$__env]->dump;   if ($self->[$__l4] && $self->[$__l4]->can('recv')) {      $self->[$__reply] = $self->[$__l4]->recv($self);   }   elsif ($self->[$__l3] && $self->[$__l3]->can('recv')) {      $self->[$__reply] = $self->[$__l3]->recv($self);   }   else {      carp("@{[(caller(0))[3]]}: not implemented for this Layer\n");      return undef;   }   $self->[$__reply]      ? do { $self->cgDebugPrint(1, "Reply received"); return $self->[$__reply]}      : return undef;}## Helpers#sub _isL2 { my $self = shift; $self->[$__l2] && $self->[$__l2]->is eq shift() }sub _isL3 { my $self = shift; $self->[$__l3] && $self->[$__l3]->is eq shift() }sub _isL4 { my $self = shift; $self->[$__l4] && $self->[$__l4]->is eq shift() }sub _isL7 { my $self = shift; $self->[$__l7] && $self->[$__l7]->is eq shift() }sub isEth    { shift->_isL2(NP_LAYER_ETH)    }sub isRaw    { shift->_isL2(NP_LAYER_RAW)    }sub isNull   { shift->_isL2(NP_LAYER_NULL)   }sub isSll    { shift->_isL2(NP_LAYER_SLL)    }sub isArp    { shift->_isL3(NP_LAYER_ARP)    }sub isIpv4   { shift->_isL3(NP_LAYER_IPv4)   }sub isIpv6   { shift->_isL3(NP_LAYER_IPv6)   }sub isVlan   { shift->_isL3(NP_LAYER_VLAN)   }sub isTcp    { shift->_isL4(NP_LAYER_TCP)    }sub isUdp    { shift->_isL4(NP_LAYER_UDP)    }sub isIcmpv4 { shift->_isL4(NP_LAYER_ICMPv4) }sub is7      { shift->_isL7(NP_LAYER_7)      }sub isIp     { my $self = shift; $self->isIpv4 || $self->isIpv6 }sub isIcmp   { my $self = shift; $self->isIcmpv4 } #燲XX: ||爒61;__END__=head1 NAMENet::Packet::Frame - the core of Net::Packet framework=head1 SYNOPSIS   require Net::Packet::Frame;   # Since we passed a layer 3 object, a Net::Packet::DescL3 object    # will be created automatically, by default. See Net::Packet::Env    # regarding changing this behaviour. Same for Net::Packet::Dump.   my $frame = Net::Packet::Frame->new(      l3 => $ipv4,  #燦et::Packet::IPv4 object      l4 => $tcp,   #燦et::Packet::TCP object                    # (here, a SYN request, for example)   );   # Without retries   $frame->send;   sleep(3);   if ($frame->recv) {      print $frame->reply->l3, "\n";      print $frame->reply->l4, "\n";   }   # Or with retries   for (1..3) {      $frame->reSend;      until ($Env->dump->timeout) {         if ($frame->recv) {            print $frame->reply->l3, "\n";            print $frame->reply->l4, "\n";            last;         }      }   }=head1 DESCRIPTIONIn B<Net::Packet>, each sent and/or received frame is parsed and converted into a B<Net::Packet::Frame> object. Basically, it encapsulates various layers (2, 3, 4 and 7) into an object, making it easy to get or set information about it.When you create a frame object, a B<Net::Packet::Desc> object is created if none is found in the default B<$Env> object (from B<Net::Packet> module), and a B<Net::Packet::Dump> object is also created if none is found in this same B<$Env> object. You can change this beheaviour, see B<Net::Packet::Env>.Two B<new> invocation method exist, one with attributes passing, another with B<raw> attribute. This second method is usually used internally, in order to unpack received frame into all corresponding layers.=head1 ATTRIBUTES=over 4=item B<env>Stores the B<Net::Packet::Env> object. The default is to use B<$Env> from B<Net::Packet>. So, you can send/recv frames to/from different environements.=item B<raw>Pass this attribute when you want to decode a raw string captured from network. Usually used internally.=item B<padding>In Ethernet world, a frame should be at least 60 bytes in length. So when you send frames at layer 2, a padding is added in order to achieve this length, avoiding a local memory leak to network. Also, when you receive a frame from network, this attribute is filled with what have been used to pad it. This padding feature currently works for IPv4 and ARP frames.=item B<l2>Stores a layer 2 object. See B<Net::Packet> for layer 2 classes hierarchy.=item B<l3>Stores a layer 3 object. See B<Net::Packet> for layer 3 classes hierarchy.=item B<l4>Stores a layer 4 object. See B<Net::Packet> for layer 4 classes hierarchy.=item B<l7>Stores a layer 7 object. See B<Net::Packet::Layer7>.=item B<reply>When B<recv> method has been called on a frame object, and a corresponding reply has been catched, a pointer is stored in this attribute.=item B<timestamp>When a frame is packed/unpacked, the happening time is stored here.=item B<noPadding>Frames are normally automatically padded to achieve the minimum required length. Set it to 1 to avoid padding. Default is to pad the frame.=back=head1 METHODS=over 4=item B<new>Object constructor. If a B<$Env->desc> object does not exists, one is created by analyzing attributes (so, either one of B<Net::Packet::DescL2>, B<Net::Packet::DescL3>. B<Net::Packet::DescL4> cannot be created automatically for now). The same behaviour is true for B<$Env->dump> object. You can change this default creation behaviour, see B<Net::Packet::Env>. Default values:timestamp: gettimeofday(),env:       $Env=item B<getLengthFromL7>=item B<getLengthFromL4>=item B<getLengthFromL3>=item B<getLengthFromL2>Returns the raw length in bytes from specified layer.=item B<getLength>Alias for B<getLengthFromL3>.=item B<unpack>Unpacks the raw string from network into various layers. Returns 1 on success, undef on failure.=item B<pack>Packs various layers into the raw string to send to network. Returns 1 on success, undef on failure.=item B<send>On the first send invocation in your program, the previously created B<Net::Packet::Dump> object is started (if available). That is, packet capturing is run. The B<timestamp> attribute is set to the sending time. The B<env> attribute is used to know where to send this frame.=item B<reSend>Will call B<send> method if no frame has been B<recv>'d, that is the B<reply> attribute is undef.=item B<getFilter>Will return a string which is a pcap filter, and corresponding to what you should receive compared with the frame request.=item B<recv>Searches B<framesSorted> or B<frames> from B<Net::Packet::Dump> for a matching response. If a reply has already been received (that is B<reply> attribute is already set), undef is returned. It no reply is received, return undef, else the B<Net::Packet::Frame> response.=item B<isEth>=item B<isRaw>=item B<isNull>=item B<isSll>=item B<isArp>=item B<isIpv4>=item B<isIpv6>=item B<isIp> - either IPv4 or IPv6=item B<isVlan>=item B<isTcp>=item B<isUdp>=item B<isIcmpv4>=item B<isIcmp> - currently only ICMPv4=item B<is7>Returns 1 if the B<Net::Packet::Frame> is of specified layer, 0 otherwise.=back=head1 AUTHORPatrice E<lt>GomoRE<gt> Auffret=head1 COPYRIGHT AND LICENSECopyright (c) 2004-2006, Patrice E<lt>GomoRE<gt> AuffretYou may distribute this module under the terms of the Artistic license.See LICENSE.Artistic file in the source distribution archive.=head1 RELATED MODULESL<NetPacket>, L<Net::RawIP>, L<Net::RawSock>=cut

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -