1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
# -*- coding: binary -*-
require 'spec_helper'
require 'packetfu/protos/eth'
require 'packetfu/protos/ip'
require 'packetfu/protos/ipv6'
require 'packetfu/protos/tcp'
require 'packetfu/protos/udp'
require 'packetfu/protos/icmp'
require 'packetfu/config'
require 'packetfu/inject'
require 'packetfu/pcap'
require 'packetfu/utils'
require 'tempfile'
include PacketFu
describe Inject do
context "when creating an object from scratch" do
before :each do
@inject = PacketFu::Inject.new
end
xit "should have sane defaults" do
expect(@inject.array).to be_kind_of(Array)
expect(@inject.stream).to be_kind_of(Array)
expect(@inject.iface).to be_kind_of(String)
expect(@inject.snaplen).to eql(65535)
expect(@inject.promisc).to eql(false)
expect(@inject.timeout).to eql(1)
end
xit "should allow creating an inject object with non-std attributes" do
# Can only run this if we're root
if Process.uid == 0
options = {
:iface => PacketFu::Utils::default_int,
:snaplen => 0xfffe,
:promisc => true,
:timeout => 5,
}
@inject = PacketFu::Capture.new(options)
expect(@inject.array).to be_kind_of(Array)
expect(@inject.stream).to be_kind_of(Array)
expect(@inject.iface).to eql(options[:iface])
expect(@inject.snaplen).to eql(options[:snaplen])
expect(@inject.promisc).to eql(options[:promisc])
expect(@inject.timeout).to eql(options[:timeout])
end
end
end
context "when injecting on the wire" do
before :each do
@inject = PacketFu::Inject.new
end
xit "should have sane defaults" do
expect(@inject.array).to be_kind_of(Array)
expect(@inject.stream).to be_kind_of(Array)
expect(@inject.iface).to be_kind_of(String)
expect(@inject.snaplen).to eql(65535)
expect(@inject.promisc).to eql(false)
expect(@inject.timeout).to eql(1)
end
# Can only run these if we're root
if Process.uid == 0
xit "should allow creating an inject object with non-std attributes" do
udp_packet = PacketFu::UDPPacket.new(:iface => PacketFu::Utils::default_int)
udp_packet.ip_dst = PacketFu::Utils.rand_routable_daddr.to_s
udp_packet.udp_dport = 12345
udp_packet.udp_sport = 12345
udp_packet.payload = "PacketFu test packet"
udp_packet.recalc
expect(udp_packet.to_w).to eql([1, 1, 62])
end
xit "should allow creating an inject object with non-std attributes" do
packet_array = []
udp_packet = PacketFu::UDPPacket.new(:iface => PacketFu::Utils::default_int)
udp_packet.ip_dst = PacketFu::Utils.rand_routable_daddr.to_s
udp_packet.udp_dport = 12345
udp_packet.udp_sport = 12345
udp_packet.payload = "PacketFu test packet"
udp_packet.recalc
3.times { packet_array << udp_packet.to_s}
inject = PacketFu::Inject.new(:iface => PacketFu::Utils::default_int)
expect(inject.array_to_wire(:array => packet_array)).to eql([3, 3, 186])
end
end
end
end
|