Class: PacketFu::Inject
- Inherits:
-
Object
- Object
- PacketFu::Inject
- Defined in:
- lib/packetfu/inject.rb
Overview
The Inject class handles injecting arrays of binary data on the wire.
To inject single packets, use PacketFu::Packet.to_w() instead.
Instance Attribute Summary collapse
-
#array ⇒ Object
Leave these public and open.
-
#iface ⇒ Object
readonly
Cant change after the init.
-
#promisc ⇒ Object
readonly
Cant change after the init.
-
#show_live ⇒ Object
Leave these public and open.
-
#snaplen ⇒ Object
readonly
Cant change after the init.
-
#stream ⇒ Object
Leave these public and open.
-
#timeout ⇒ Object
readonly
Cant change after the init.
Instance Method Summary collapse
-
#a2w(args = {}) ⇒ Object
Equivalent to array_to_wire.
-
#array_to_wire(args = {}) ⇒ Object
Takes an array, and injects them onto an interface.
-
#initialize(args = {}) ⇒ Inject
constructor
A new instance of Inject.
-
#inject(args = {}) ⇒ Object
Equivalent to array_to_wire.
Constructor Details
#initialize(args = {}) ⇒ Inject
Returns a new instance of Inject.
10 11 12 13 14 15 16 17 18 |
# File 'lib/packetfu/inject.rb', line 10 def initialize(args={}) @array = [] # Where the packet array goes. @stream = [] # Where the stream goes. @iface = args[:iface] || ENV['IFACE'] || Pcap.lookupdev || "lo" @snaplen = args[:snaplen] || 0xffff @promisc = args[:promisc] || false # Sensible for some Intel wifi cards @timeout = args[:timeout] || 1 @show_live = nil end |
Instance Attribute Details
#array ⇒ Object
Leave these public and open.
7 8 9 |
# File 'lib/packetfu/inject.rb', line 7 def array @array end |
#iface ⇒ Object (readonly)
Cant change after the init.
8 9 10 |
# File 'lib/packetfu/inject.rb', line 8 def iface @iface end |
#promisc ⇒ Object (readonly)
Cant change after the init.
8 9 10 |
# File 'lib/packetfu/inject.rb', line 8 def promisc @promisc end |
#show_live ⇒ Object
Leave these public and open.
7 8 9 |
# File 'lib/packetfu/inject.rb', line 7 def show_live @show_live end |
#snaplen ⇒ Object (readonly)
Cant change after the init.
8 9 10 |
# File 'lib/packetfu/inject.rb', line 8 def snaplen @snaplen end |
#stream ⇒ Object
Leave these public and open.
7 8 9 |
# File 'lib/packetfu/inject.rb', line 7 def stream @stream end |
#timeout ⇒ Object (readonly)
Cant change after the init.
8 9 10 |
# File 'lib/packetfu/inject.rb', line 8 def timeout @timeout end |
Instance Method Details
#a2w(args = {}) ⇒ Object
Equivalent to array_to_wire
55 56 57 |
# File 'lib/packetfu/inject.rb', line 55 def a2w(args={}) array_to_wire(args) end |
#array_to_wire(args = {}) ⇒ Object
Takes an array, and injects them onto an interface. Note that complete packets (Ethernet headers on down) are expected.
Parameters
:array || arr
An array of binary data (usually packet.to_s style).
:int || sleep
Number of seconds to sleep between injections (in float format)
:show_live || :live
If true, puts data about what was injected to stdout.
Example
inj = PacketFu::Inject.new
inj.array_to_wire(:array => [pkt1, pkt2, pkt3], :sleep => 0.1)
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/packetfu/inject.rb', line 37 def array_to_wire(args={}) pkt_array = args[:array] || args[:arr] || @array interval = args[:int] || args[:sleep] show_live = args[:show_live] || args[:live] || @show_live @stream = Pcap.open_live(@iface,@snaplen,@promisc,@timeout) pkt_count = 0 pkt_array.each do |pkt| @stream.inject(pkt) sleep interval if interval pkt_count +=1 puts "Sent Packet \##{pkt_count} (#{pkt.size})" if show_live end # Return # of packets sent, array size, and array total size [pkt_count, pkt_array.size, pkt_array.join.size] end |
#inject(args = {}) ⇒ Object
Equivalent to array_to_wire
60 61 62 |
# File 'lib/packetfu/inject.rb', line 60 def inject(args={}) array_to_wire(args) end |