Class: PacketFu::ICMPPacket
- Includes:
- EthHeaderMixin, ICMPHeaderMixin, IPHeaderMixin
- Defined in:
- lib/packetfu/protos/icmp.rb
Overview
ICMPPacket is used to construct ICMP Packets. They contain an EthHeader, an IPHeader, and a ICMPHeader.
Example
icmp_pkt.new
icmp_pkt.icmp_type = 8
icmp_pkt.icmp_code = 0
icmp_pkt.payload = "ABC, easy as 123. As simple as do-re-mi. ABC, 123, baby, you and me!"
icmp_pkt.ip_saddr="1.2.3.4"
icmp_pkt.ip_daddr="5.6.7.8"
icmp_pkt.recalc
icmp_pkt.to_f('/tmp/icmp.pcap')
Parameters
:eth
A pre-generated EthHeader object.
:ip
A pre-generated IPHeader object.
:flavor
TODO: Sets the "flavor" of the ICMP packet. Pings, in particular, often betray their true
OS.
:config
A hash of return address details, often the output of Utils.whoami?
Instance Attribute Summary collapse
-
#eth_header ⇒ Object
Returns the value of attribute eth_header.
-
#icmp_header ⇒ Object
Returns the value of attribute icmp_header.
-
#ip_header ⇒ Object
Returns the value of attribute ip_header.
Attributes inherited from Packet
#flavor, #headers, #iface, #inspect_style
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ ICMPPacket
constructor
A new instance of ICMPPacket.
-
#peek_format ⇒ Object
Peek provides summary data on packet contents.
Methods included from ICMPHeaderMixin
#icmp_calc_sum, #icmp_code, #icmp_code=, #icmp_recalc, #icmp_sum, #icmp_sum=, #icmp_sum_readable, #icmp_type, #icmp_type=
Methods included from IPHeaderMixin
#ip_calc_id, #ip_calc_len, #ip_calc_sum, #ip_calc_sum_on_addr, #ip_daddr, #ip_daddr=, #ip_dst, #ip_dst=, #ip_dst_readable, #ip_frag, #ip_frag=, #ip_hl, #ip_hl=, #ip_hlen, #ip_id, #ip_id=, #ip_id_readable, #ip_len, #ip_len=, #ip_proto, #ip_proto=, #ip_recalc, #ip_saddr, #ip_saddr=, #ip_src, #ip_src=, #ip_src_readable, #ip_sum, #ip_sum=, #ip_sum_readable, #ip_tos, #ip_tos=, #ip_ttl, #ip_ttl=, #ip_v, #ip_v=
Methods included from EthHeaderMixin
#eth_daddr, #eth_daddr=, #eth_dst, #eth_dst=, #eth_dst_readable, #eth_proto, #eth_proto=, #eth_proto_readable, #eth_saddr, #eth_saddr=, #eth_src, #eth_src=, #eth_src_readable
Methods inherited from Packet
#==, #clone, #dissect, #dissection_table, force_binary, #handle_is_identity, #hexify, inherited, #inspect, #inspect_hex, #kind_of?, #layer, layer, #layer_symbol, layer_symbol, #method_missing, #orig_kind_of?, parse, #payload, #payload=, #peek, #proto, #read, #recalc, #respond_to?, #size, #to_f, #to_pcap, #to_s, #to_w, #write
Constructor Details
#initialize(args = {}) ⇒ ICMPPacket
Returns a new instance of ICMPPacket.
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/packetfu/protos/icmp.rb', line 53 def initialize(args={}) @eth_header = EthHeader.new(args).read(args[:eth]) @ip_header = IPHeader.new(args).read(args[:ip]) @ip_header.ip_proto = 1 @icmp_header = ICMPHeader.new(args).read(args[:icmp]) @ip_header.body = @icmp_header @eth_header.body = @ip_header @headers = [@eth_header, @ip_header, @icmp_header] super end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class PacketFu::Packet
Instance Attribute Details
#eth_header ⇒ Object
Returns the value of attribute eth_header.
43 44 45 |
# File 'lib/packetfu/protos/icmp.rb', line 43 def eth_header @eth_header end |
#icmp_header ⇒ Object
Returns the value of attribute icmp_header.
43 44 45 |
# File 'lib/packetfu/protos/icmp.rb', line 43 def icmp_header @icmp_header end |
#ip_header ⇒ Object
Returns the value of attribute ip_header.
43 44 45 |
# File 'lib/packetfu/protos/icmp.rb', line 43 def ip_header @ip_header end |
Class Method Details
.can_parse?(str) ⇒ Boolean
45 46 47 48 49 50 51 |
# File 'lib/packetfu/protos/icmp.rb', line 45 def self.can_parse?(str) return false unless str.size >= 38 return false unless EthPacket.can_parse? str return false unless IPPacket.can_parse? str return false unless str[23,1] == "\x01" return true end |
Instance Method Details
#peek_format ⇒ Object
Peek provides summary data on packet contents.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/packetfu/protos/icmp.rb', line 67 def peek_format peek_data = ["IC "] # I is taken by IP peek_data << "%-5d" % self.to_s.size type = case self.icmp_type.to_i when 8 "ping" when 0 "pong" else "%02x-%02x" % [self.icmp_type, self.icmp_code] end peek_data << "%-21s" % "#{self.ip_saddr}:#{type}" peek_data << "->" peek_data << "%21s" % "#{self.ip_daddr}" peek_data << "%23s" % "I:" peek_data << "%04x" % self.ip_id peek_data.join end |