packetfu 1.0.0 → 1.0.2.pre

Sign up to get free protection for your applications and to get access to all the features.
Binary file
data/test/test_arp.rb CHANGED
File without changes
data/test/test_eth.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'test/unit'
3
- $: << File.expand_path(File.dirname(__FILE__) + "/../lib/")
3
+ $:.unshift File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
4
4
  require 'packetfu'
5
+ puts "Testing #{PacketFu.version}: #{$0}"
5
6
 
6
7
  class EthTest < Test::Unit::TestCase
7
8
 
data/test/test_hsrp.rb ADDED
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env ruby
2
+ require 'test/unit'
3
+ $: << File.expand_path(File.dirname(__FILE__) + "/../lib/")
4
+ require 'packetfu'
5
+
6
+ class HSRPTest < Test::Unit::TestCase
7
+ include PacketFu
8
+
9
+ def test_hsrp_read
10
+ sample_packet = PcapFile.new.file_to_array(:f => 'sample_hsrp_pcapr.cap')[0]
11
+ pkt = Packet.parse(sample_packet)
12
+ assert pkt.is_hsrp?
13
+ assert pkt.is_udp?
14
+ assert_equal(0x2d8d, pkt.udp_sum.to_i)
15
+ # pkt.to_f('udp_test.pcap','a')
16
+ end
17
+
18
+ =begin
19
+ # The rest of these tests are snarfed from UDP. TODO: need to update
20
+ # these for hsrp, shouldn't be long.
21
+ def test_hsrp_pcap
22
+ u = UDPPacket.new
23
+ assert_kind_of UDPPacket, u
24
+ u.recalc
25
+ u.to_f('udp_test.pcap','a')
26
+ u.ip_saddr = "10.20.30.40"
27
+ u.ip_daddr = "50.60.70.80"
28
+ u.payload = "+some fakey-fake udp packet"
29
+ u.udp_src = 1205
30
+ u.udp_dst = 13013
31
+ u.recalc
32
+ u.to_f('udp_test.pcap','a')
33
+ end
34
+
35
+ def test_udp_peek
36
+ u = UDPPacket.new
37
+ u.ip_saddr = "10.20.30.40"
38
+ u.ip_daddr = "50.60.70.80"
39
+ u.udp_src = 53
40
+ u.udp_dport = 1305
41
+ u.payload = "abcdefghijklmnopqrstuvwxyz"
42
+ u.recalc
43
+ puts "\n"
44
+ puts "UDP Peek format: "
45
+ puts u.peek
46
+ assert_equal 78,u.peek.size
47
+ end
48
+
49
+ def test_udp_checksum
50
+ sample_packet = PcapFile.new.file_to_array(:f => 'sample.pcap')[0]
51
+ pkt = Packet.parse(sample_packet)
52
+ assert_kind_of UDPPacket, pkt
53
+ pkt.recalc
54
+ assert_equal(0x8bf8, pkt.udp_sum.to_i)
55
+ pkt.to_f('udp_test.pcap','a')
56
+ end
57
+
58
+ def test_udp_alter
59
+ sample_packet = PcapFile.new.file_to_array(:f => 'sample.pcap')[0]
60
+ pkt = Packet.parse(sample_packet)
61
+ assert_kind_of UDPPacket, pkt
62
+ pkt.payload = pkt.payload.gsub(/metasploit/,"MeatPistol")
63
+ pkt.recalc
64
+ assert_equal(0x8341, pkt.udp_sum)
65
+ pkt.to_f('udp_test.pcap','a')
66
+ end
67
+ =end
68
+
69
+ end
70
+
71
+ # vim: nowrap sw=2 sts=0 ts=2 ff=unix ft=ruby
data/test/test_icmp.rb CHANGED
File without changes
data/test/test_ip6.rb CHANGED
File without changes
data/test/test_octets.rb CHANGED
File without changes
data/test/test_packet.rb CHANGED
@@ -1,25 +1,78 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'test/unit'
3
- $: << File.expand_path(File.dirname(__FILE__) + "/../lib/")
3
+ $:.unshift File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
4
4
  require 'packetfu'
5
+ puts "Testing #{PacketFu.version}: #{$0}"
5
6
 
6
- class EthPacketTest < Test::Unit::TestCase
7
+ class NewPacketTest < Test::Unit::TestCase
8
+ include PacketFu
9
+
10
+ def test_method_missing_and_respond_to
11
+ p = TCPPacket.new
12
+ assert p.respond_to?(:ip_len)
13
+ assert p.ip_len = 20
14
+ assert !(p.respond_to? :ip_bogus_header)
15
+ assert_raise NoMethodError do
16
+ p.bogus_header = 20
17
+ end
18
+ end
19
+
20
+ def test_more_method_missing_magic
21
+ p = UDPPacket.new
22
+ assert_kind_of(UDPPacket,p)
23
+ assert p.is_udp?
24
+ assert p.is_ip?
25
+ assert p.is_eth?
26
+ assert_equal(p.ip_hl,5)
27
+ assert p.layer
28
+ assert_raise NoMethodError do
29
+ p.is_blue?
30
+ end
31
+ assert_raise NoMethodError do
32
+ p.tcp_blue
33
+ end
34
+ assert_raise NoMethodError do
35
+ p.udp_blue
36
+ end
37
+ assert_raise NoMethodError do
38
+ p.blue
39
+ end
40
+ end
41
+ end
42
+
43
+ class PacketStrippingTest < Test::Unit::TestCase
44
+
45
+ include PacketFu
46
+
47
+ def test_arp_strip
48
+ pcaps = PcapFile.new.file_to_array(:f => 'sample.pcap')
49
+ p = Packet.parse(pcaps[5], :fix => true) # Really ARP request.
50
+ assert_kind_of(Packet,p)
51
+ assert_kind_of(ARPPacket,p)
52
+ end
53
+
54
+ end
55
+
56
+ class PacketParsersTest < Test::Unit::TestCase
7
57
  include PacketFu
8
58
 
9
59
  def test_parse_eth_packet
60
+ assert_equal(EthPacket.layer, 1)
61
+ assert_equal(EthPacket.layer_symbol, :link)
10
62
  pcaps = PcapFile.new.file_to_array(:f => 'sample.pcap')
11
63
  p = Packet.parse(pcaps[5]) # Really ARP.
12
64
  assert_kind_of(Packet,p)
13
65
  assert_kind_of(EthHeader, p.headers[0])
14
66
  assert p.is_eth?
15
- assert p.is_ethernet?
16
67
  assert_equal(pcaps[5],p.to_s)
17
68
  end
18
69
 
19
70
  def test_parse_arp_request
71
+ assert_equal(ARPPacket.layer, 2)
20
72
  pcaps = PcapFile.new.file_to_array(:f => 'sample.pcap')
21
73
  p = Packet.parse(pcaps[5]) # Really ARP request.
22
74
  assert p.is_eth?
75
+ assert_kind_of(EthPacket,p)
23
76
  assert_kind_of(ARPPacket,p)
24
77
  assert p.is_arp?
25
78
  assert_equal(p.to_s, pcaps[5])
@@ -28,6 +81,7 @@ class EthPacketTest < Test::Unit::TestCase
28
81
  end
29
82
 
30
83
  def test_parse_arp_reply
84
+ assert_equal(ARPPacket.layer, 2)
31
85
  pcaps = PcapFile.new.file_to_array(:f => 'sample.pcap')
32
86
  p = Packet.parse(pcaps[6]) # Really ARP reply.
33
87
  assert_equal(p.to_s, pcaps[6])
@@ -35,6 +89,86 @@ class EthPacketTest < Test::Unit::TestCase
35
89
  assert_equal("\x00\x02", p.headers.last[:arp_opcode].to_s)
36
90
  end
37
91
 
92
+ def test_parse_ip_packet
93
+ assert_equal(IPPacket.layer, 2)
94
+ pcaps = PcapFile.new.file_to_array(:f => 'sample.pcap')
95
+ p = Packet.parse(pcaps[0]) # Really DNS request
96
+ assert_equal(p.to_s[0,20], pcaps[0][0,20])
97
+ assert_equal(p.to_s, pcaps[0])
98
+ assert_kind_of(EthPacket,p)
99
+ assert_kind_of(IPPacket,p)
100
+ end
101
+
102
+ def test_parse_tcp_packet
103
+ assert_equal(TCPPacket.layer, 3)
104
+ pcaps = PcapFile.new.file_to_array(:f => 'sample.pcap')
105
+ p = Packet.parse(pcaps[7]) # Really FIN/ACK
106
+ assert_equal(p.to_s, pcaps[7])
107
+ assert_kind_of(EthPacket,p)
108
+ assert_kind_of(IPPacket,p)
109
+ assert_kind_of(TCPPacket,p)
110
+ end
111
+
112
+ def test_parse_udp_packet
113
+ assert_equal(UDPPacket.layer, 3)
114
+ pcaps = PcapFile.new.file_to_array(:f => 'sample.pcap')
115
+ p = Packet.parse(pcaps[0]) # Really DNS request
116
+ assert_equal(p.to_s, pcaps[0])
117
+ assert_kind_of(EthPacket,p)
118
+ assert_kind_of(IPPacket,p)
119
+ assert_kind_of(UDPPacket,p)
120
+ end
121
+
122
+ def test_parse_icmp_packet
123
+ assert_equal(ICMPPacket.layer, 3)
124
+ assert_equal(ICMPPacket.layer_symbol, :transport)
125
+ pcaps = PcapFile.new.file_to_array(:f => 'sample.pcap')
126
+ p = Packet.parse(pcaps[3]) # Really ICMP reply
127
+ assert_equal(p.to_s, pcaps[3])
128
+ assert_kind_of(EthPacket,p)
129
+ assert_kind_of(IPPacket,p)
130
+ assert_kind_of(ICMPPacket,p)
131
+ end
132
+
133
+ def test_parse_invalid_packet
134
+ assert_equal(InvalidPacket.layer, 0)
135
+ assert_equal(InvalidPacket.layer_symbol, :invalid)
136
+ p = Packet.parse("\xff\xfe\x00\x01")
137
+ assert_equal(p.to_s, "\xff\xfe\x00\x01")
138
+ assert_kind_of(InvalidPacket,p)
139
+ end
140
+
141
+ def test_parse_ipv6_packet
142
+ assert_equal(IPv6Packet.layer, 2)
143
+ assert_equal(IPv6Packet.layer_symbol, :internet)
144
+ pcaps = PcapFile.new.file_to_array(:f => 'sample-ipv6.pcap')
145
+ p = Packet.parse(pcaps[0]) # Really an IPv6 packet
146
+ assert_equal(p.to_s, pcaps[0])
147
+ assert_kind_of(EthPacket,p)
148
+ assert(!p.kind_of?(IPPacket), "Misidentified as an IP Packet!")
149
+ assert_kind_of(IPv6Packet,p)
150
+ end
151
+
152
+ def test_parse_hsrp_packet
153
+ assert_equal(HSRPPacket.layer, 4)
154
+ assert_equal(HSRPPacket.layer_symbol, :application)
155
+ pcaps = PcapFile.new.file_to_array(:f => 'sample_hsrp_pcapr.cap')
156
+ p = Packet.parse(pcaps[0]) # Really an HSRP Hello packet
157
+ assert_equal(p.to_s, pcaps[0])
158
+ assert_kind_of(EthPacket,p)
159
+ assert_kind_of(IPPacket,p)
160
+ assert_kind_of(UDPPacket,p)
161
+ assert_kind_of(HSRPPacket,p)
162
+ end
163
+
164
+ def test_parse_hsrp_as_udp
165
+ assert_equal(:application, HSRPPacket.layer_symbol)
166
+ pcaps = PcapFile.new.file_to_array(:f => 'sample_hsrp_pcapr.cap')
167
+ p = Packet.parse(pcaps[0], :parse_app => false) # Really an HSRP Hello packet
168
+ assert_kind_of(UDPPacket,p)
169
+ assert(!p.kind_of?(HSRPPacket), "Misidentified HSRP packet when we didn't want it!" )
170
+ end
171
+
38
172
  end
39
173
 
40
174
 
File without changes
data/test/test_tcp.rb CHANGED
File without changes
data/test/test_udp.rb CHANGED
File without changes
Binary file
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: packetfu
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
5
- prerelease: false
4
+ hash: 1344461223
5
+ prerelease: 6
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 0
10
- version: 1.0.0
9
+ - 2
10
+ - pre
11
+ version: 1.0.2.pre
11
12
  platform: ruby
12
13
  authors:
13
14
  - Tod Beardsley
@@ -15,13 +16,29 @@ autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2010-07-31 00:00:00 -05:00
19
+ date: 2011-05-22 00:00:00 -05:00
19
20
  default_executable:
20
21
  dependencies:
21
22
  - !ruby/object:Gem::Dependency
22
23
  name: pcaprub
23
24
  prerelease: false
24
25
  requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 63
31
+ segments:
32
+ - 0
33
+ - 9
34
+ - 2
35
+ version: 0.9.2
36
+ type: :development
37
+ version_requirements: *id001
38
+ - !ruby/object:Gem::Dependency
39
+ name: rspec
40
+ prerelease: false
41
+ requirement: &id002 !ruby/object:Gem::Requirement
25
42
  none: false
26
43
  requirements:
27
44
  - - ">="
@@ -31,7 +48,7 @@ dependencies:
31
48
  - 0
32
49
  version: "0"
33
50
  type: :development
34
- version_requirements: *id001
51
+ version_requirements: *id002
35
52
  description: PacketFu is a mid-level packet manipulation library for Ruby. With it, users can read, parse, and write network packets with the level of ease and fun they expect from Ruby. Note that this gem does not automatically require pcaprub, since users may install pcaprub through non-gem means.
36
53
  email: todb@planb-security.net
37
54
  executables: []
@@ -44,44 +61,56 @@ extra_rdoc_files:
44
61
  - .document
45
62
  files:
46
63
  - lib/packetfu.rb
47
- - lib/packetfu/tcp.rb
48
- - lib/packetfu/eth.rb
64
+ - lib/packetfu/version.rb
49
65
  - lib/packetfu/structfu.rb
50
- - lib/packetfu/ipv6.rb
51
66
  - lib/packetfu/capture.rb
52
67
  - lib/packetfu/pcap.rb
53
- - lib/packetfu/udp.rb
54
68
  - lib/packetfu/config.rb
55
- - lib/packetfu/arp.rb
56
- - lib/packetfu/ip.rb
57
69
  - lib/packetfu/inject.rb
58
- - lib/packetfu/invalid.rb
70
+ - lib/packetfu/protos/tcp.rb
71
+ - lib/packetfu/protos/eth.rb
72
+ - lib/packetfu/protos/ipv6.rb
73
+ - lib/packetfu/protos/udp.rb
74
+ - lib/packetfu/protos/arp.rb
75
+ - lib/packetfu/protos/ip.rb
76
+ - lib/packetfu/protos/invalid.rb
77
+ - lib/packetfu/protos/icmp.rb
78
+ - lib/packetfu/protos/hsrp.rb
59
79
  - lib/packetfu/utils.rb
60
- - lib/packetfu/icmp.rb
61
80
  - lib/packetfu/packet.rb
62
81
  - CHANGES
63
82
  - INSTALL
64
83
  - LICENSE
65
84
  - README
66
85
  - .document
67
- - TODO
68
86
  - test/test_octets.rb
69
87
  - test/test_icmp.rb
88
+ - test/udp_test.pcap
70
89
  - test/sample2.pcap
71
90
  - test/sample.pcap
72
91
  - test/test_ip6.rb
73
92
  - test/all_tests.rb
74
93
  - test/test_invalid.rb
94
+ - test/packetfu_spec.rb
75
95
  - test/test_packet.rb
76
96
  - test/test_pcap.rb
97
+ - test/icmp_test.pcap
77
98
  - test/test_udp.rb
99
+ - test/sample_hsrp_pcapr.cap
78
100
  - test/test_tcp.rb
101
+ - test/tcp_test.pcap
79
102
  - test/test_arp.rb
103
+ - test/arp_test.pcap
80
104
  - test/test_inject.rb
81
105
  - test/test_eth.rb
106
+ - test/sample-ipv6.pcap
107
+ - test/test_hsrp.rb
82
108
  - test/test_structfu.rb
83
109
  - test/ptest.rb
110
+ - test/ip_test.pcap
111
+ - test/eth_test.pcap
84
112
  - test/test_ip.rb
113
+ - test/structfu_spec.rb
85
114
  - examples/oui.txt
86
115
  - examples/uniqpcap.rb
87
116
  - examples/examples.rb
@@ -115,16 +144,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
115
144
  required_rubygems_version: !ruby/object:Gem::Requirement
116
145
  none: false
117
146
  requirements:
118
- - - ">="
147
+ - - ">"
119
148
  - !ruby/object:Gem::Version
120
- hash: 3
149
+ hash: 25
121
150
  segments:
122
- - 0
123
- version: "0"
151
+ - 1
152
+ - 3
153
+ - 1
154
+ version: 1.3.1
124
155
  requirements: []
125
156
 
126
157
  rubyforge_project: packetfu
127
- rubygems_version: 1.3.7
158
+ rubygems_version: 1.4.2
128
159
  signing_key:
129
160
  specification_version: 3
130
161
  summary: PacketFu is a mid-level packet manipulation library.
@@ -140,5 +171,6 @@ test_files:
140
171
  - test/test_arp.rb
141
172
  - test/test_inject.rb
142
173
  - test/test_eth.rb
174
+ - test/test_hsrp.rb
143
175
  - test/test_structfu.rb
144
176
  - test/test_ip.rb
data/TODO DELETED
@@ -1,25 +0,0 @@
1
- TODO for PacketFu
2
-
3
- Bugs:
4
-
5
- See http://code.google.com/p/packetfu/issues/list
6
-
7
- Next major version:
8
-
9
- Rewrite TCPOpts to be safe and sane by using BinData structs
10
-
11
- Pcapfiles should take and honor usec fields.
12
-
13
- Collect Metasploit diffs to incorporate.
14
-
15
- Someday:
16
- Rewrite the whole protocol tree so a simple 'require protocol' is sufficent.
17
-
18
- Think about adding taint values to rewritten packets?
19
-
20
- --Merge in release version of BinData once readeof-patch is committed to a tagged version--
21
-
22
- Fix up setup.rb to prompt for an overwrite of existing BinData and Pcaprub installations.
23
-
24
- Create a gem distribution (?? I dunno I still kind of hate gems)
25
-