packetfu 1.1.9 → 1.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bench/octets.rb +9 -9
- data/examples/100kpackets.rb +12 -12
- data/examples/ackscan.rb +16 -16
- data/examples/arp.rb +35 -35
- data/examples/arphood.rb +36 -36
- data/examples/dissect_thinger.rb +6 -6
- data/examples/new-simple-stats.rb +23 -23
- data/examples/packetfu-shell.rb +25 -25
- data/examples/simple-sniffer.rb +9 -9
- data/examples/simple-stats.rb +23 -23
- data/examples/slammer.rb +3 -3
- data/lib/packetfu.rb +127 -127
- data/lib/packetfu/capture.rb +169 -169
- data/lib/packetfu/config.rb +52 -52
- data/lib/packetfu/inject.rb +56 -56
- data/lib/packetfu/packet.rb +528 -528
- data/lib/packetfu/pcap.rb +579 -579
- data/lib/packetfu/protos/arp.rb +90 -90
- data/lib/packetfu/protos/arp/header.rb +158 -158
- data/lib/packetfu/protos/arp/mixin.rb +36 -36
- data/lib/packetfu/protos/eth.rb +44 -44
- data/lib/packetfu/protos/eth/header.rb +243 -243
- data/lib/packetfu/protos/eth/mixin.rb +3 -3
- data/lib/packetfu/protos/hsrp.rb +69 -69
- data/lib/packetfu/protos/hsrp/header.rb +107 -107
- data/lib/packetfu/protos/hsrp/mixin.rb +29 -29
- data/lib/packetfu/protos/icmp.rb +71 -71
- data/lib/packetfu/protos/icmp/header.rb +82 -82
- data/lib/packetfu/protos/icmp/mixin.rb +14 -14
- data/lib/packetfu/protos/invalid.rb +49 -49
- data/lib/packetfu/protos/ip.rb +69 -69
- data/lib/packetfu/protos/ip/header.rb +291 -291
- data/lib/packetfu/protos/ip/mixin.rb +40 -40
- data/lib/packetfu/protos/ipv6.rb +50 -50
- data/lib/packetfu/protos/ipv6/header.rb +188 -188
- data/lib/packetfu/protos/ipv6/mixin.rb +29 -29
- data/lib/packetfu/protos/tcp.rb +176 -176
- data/lib/packetfu/protos/tcp/ecn.rb +35 -35
- data/lib/packetfu/protos/tcp/flags.rb +74 -74
- data/lib/packetfu/protos/tcp/header.rb +268 -268
- data/lib/packetfu/protos/tcp/hlen.rb +32 -32
- data/lib/packetfu/protos/tcp/mixin.rb +46 -46
- data/lib/packetfu/protos/tcp/option.rb +321 -321
- data/lib/packetfu/protos/tcp/options.rb +95 -95
- data/lib/packetfu/protos/tcp/reserved.rb +35 -35
- data/lib/packetfu/protos/udp.rb +116 -116
- data/lib/packetfu/protos/udp/header.rb +91 -91
- data/lib/packetfu/protos/udp/mixin.rb +3 -3
- data/lib/packetfu/structfu.rb +280 -280
- data/lib/packetfu/utils.rb +226 -217
- data/lib/packetfu/version.rb +41 -41
- data/packetfu.gemspec +2 -1
- data/spec/ethpacket_spec.rb +48 -48
- data/spec/packet_spec.rb +57 -57
- data/spec/packet_subclasses_spec.rb +8 -8
- data/spec/packetfu_spec.rb +59 -59
- data/spec/structfu_spec.rb +268 -268
- data/spec/tcp_spec.rb +75 -75
- data/test/all_tests.rb +13 -13
- data/test/func_lldp.rb +3 -3
- data/test/ptest.rb +2 -2
- data/test/test_arp.rb +116 -116
- data/test/test_capture.rb +45 -45
- data/test/test_eth.rb +68 -68
- data/test/test_hsrp.rb +9 -9
- data/test/test_icmp.rb +52 -52
- data/test/test_inject.rb +18 -18
- data/test/test_invalid.rb +16 -16
- data/test/test_ip.rb +36 -36
- data/test/test_ip6.rb +48 -48
- data/test/test_octets.rb +21 -21
- data/test/test_packet.rb +154 -154
- data/test/test_pcap.rb +170 -170
- data/test/test_structfu.rb +97 -97
- data/test/test_tcp.rb +320 -320
- data/test/test_udp.rb +76 -76
- metadata +4 -3
data/test/test_tcp.rb
CHANGED
@@ -4,349 +4,349 @@ $:.unshift File.join(File.expand_path(File.dirname(__FILE__)), "..", "lib")
|
|
4
4
|
require 'packetfu'
|
5
5
|
|
6
6
|
class String
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
def bin
|
8
|
+
self.scan(/../).map {|x| x.to_i(16).chr}.join
|
9
|
+
end
|
10
10
|
end
|
11
11
|
|
12
12
|
class TcpEcnTest < Test::Unit::TestCase
|
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
|
-
|
13
|
+
include PacketFu
|
14
|
+
|
15
|
+
def test_ecn_set
|
16
|
+
t = TcpEcn.new
|
17
|
+
assert_kind_of TcpEcn, t
|
18
|
+
assert_equal(0, t.to_i)
|
19
|
+
t.n = 1
|
20
|
+
assert_equal(4, t.to_i)
|
21
|
+
t.c = 1
|
22
|
+
assert_equal(6, t.to_i)
|
23
|
+
t.e = 1
|
24
|
+
assert_equal(7, t.to_i)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_ecn_read
|
28
|
+
t = TcpEcn.new
|
29
|
+
assert_kind_of TcpEcn, t
|
30
|
+
t.read("\x30\xc0")
|
31
|
+
assert_equal(0, t.n)
|
32
|
+
assert_equal(1, t.c)
|
33
|
+
assert_equal(1, t.e)
|
34
|
+
t.read("\xa3\x38")
|
35
|
+
assert_equal(1, t.n)
|
36
|
+
assert_equal(0, t.c)
|
37
|
+
assert_equal(0, t.e)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_hlen_set
|
41
|
+
t = TcpHlen.new
|
42
|
+
assert_kind_of TcpHlen, t
|
43
|
+
assert_equal(0, t.to_i)
|
44
|
+
t.hlen = 10
|
45
|
+
assert_equal(10, t.to_i)
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_hlen_read
|
49
|
+
t = TcpHlen.new
|
50
|
+
t.read("\xa0")
|
51
|
+
assert_equal(10, t.to_i)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_reserved_set
|
55
|
+
t = TcpReserved.new
|
56
|
+
assert_kind_of TcpReserved, t
|
57
|
+
assert_equal(0, t.to_i)
|
58
|
+
t.r1 = 1
|
59
|
+
assert_equal(4, t.to_i)
|
60
|
+
t.r2 = 1
|
61
|
+
assert_equal(6, t.to_i)
|
62
|
+
t.r3 = 1
|
63
|
+
assert_equal(7, t.to_i)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_reserved_read
|
67
|
+
t = TcpReserved.new
|
68
|
+
t.read("\xa0")
|
69
|
+
assert_equal(0, t.to_i)
|
70
|
+
end
|
71
71
|
|
72
72
|
end
|
73
73
|
|
74
74
|
class TcpFlagsTest < Test::Unit::TestCase
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
75
|
+
include PacketFu
|
76
|
+
|
77
|
+
def test_tcp_flags_set
|
78
|
+
t = TcpFlags.new
|
79
|
+
assert_kind_of TcpFlags, t
|
80
|
+
t.fin = 1
|
81
|
+
t.ack = 1
|
82
|
+
assert_equal(0x11, t.to_i)
|
83
|
+
t.fin = 0
|
84
|
+
t.syn = 1
|
85
|
+
assert_equal(0x12, t.to_i)
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_tcp_flags_unset
|
89
|
+
t = TcpFlags.new
|
90
|
+
assert_kind_of TcpFlags, t
|
91
|
+
t.syn = 1
|
92
|
+
assert_equal(0x02, t.to_i)
|
93
|
+
t.syn = 0
|
94
|
+
assert_equal(0x00, t.to_i)
|
95
|
+
t.syn = 1
|
96
|
+
t.syn = false
|
97
|
+
assert_equal(0x00, t.to_i)
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_tcp_flags_read
|
101
|
+
t = TcpFlags.new
|
102
|
+
t.read("\x11")
|
103
|
+
assert_equal(1, t.fin)
|
104
|
+
assert_equal(1, t.ack)
|
105
|
+
t.read("\xa6")
|
106
|
+
assert_equal(1, t.urg)
|
107
|
+
assert_equal(1, t.rst)
|
108
|
+
assert_equal(1, t.syn)
|
109
|
+
assert_equal(0, t.psh)
|
110
|
+
assert_equal(0, t.ack)
|
111
|
+
assert_equal(0, t.fin)
|
112
|
+
end
|
113
113
|
|
114
114
|
end
|
115
115
|
|
116
116
|
class TcpOptionsTest < Test::Unit::TestCase
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
117
|
+
include PacketFu
|
118
|
+
|
119
|
+
def test_tcp_option
|
120
|
+
t = TcpOption.new
|
121
|
+
assert_equal("\x00", t.to_s)
|
122
|
+
t = TcpOption.new(:kind => 2, :optlen => 4, :value => 1024)
|
123
|
+
assert_equal("\x02\x04\x04\x00", t.to_s)
|
124
|
+
t = TcpOption.new(:kind => 0xf0, :optlen => 6, :value => 1024)
|
125
|
+
assert_equal("\xf0\x06\x00\x00\x04\x00", t.to_s)
|
126
|
+
t = TcpOption.new(:kind => 0xf0, :optlen => 6, :value => "1024")
|
127
|
+
assert_equal("\xf0\x061024", t.to_s)
|
128
|
+
t = TcpOption.new(:kind => 0xf0, :optlen => 6, :value => nil)
|
129
|
+
assert_equal("\xf0\x06", t.to_s)
|
130
|
+
t = TcpOption.new(:kind => 0xf1, :optlen => 10, :value => "a1b2c3d4e5")
|
131
|
+
assert_equal("\xf1\x0aa1b2c3d4e5", t.to_s)
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_eol
|
135
|
+
t = TcpOption::EOL.new
|
136
|
+
assert_equal("\x00", t.to_s)
|
137
|
+
assert_equal(0, t.kind.to_i)
|
138
|
+
assert_equal(0, t.kind.value)
|
139
|
+
assert_equal(nil, t.optlen.value)
|
140
|
+
assert_equal("", t.value)
|
141
|
+
assert_equal("EOL",t.decode)
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_nop
|
145
|
+
t = TcpOption::NOP.new
|
146
|
+
assert_equal("\x01", t.to_s)
|
147
|
+
assert_equal("NOP",t.decode)
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_mss
|
151
|
+
t = TcpOption::MSS.new
|
152
|
+
t.read("\x02\x04\x05\xb4")
|
153
|
+
assert_equal("MSS:1460",t.decode)
|
154
|
+
t = TcpOption::MSS.new(:value => 1460)
|
155
|
+
assert_equal("\x02\x04\x05\xb4", t.to_s)
|
156
|
+
assert_equal("MSS:1460",t.decode)
|
157
|
+
end
|
158
|
+
|
159
|
+
def test_sack
|
160
|
+
t = TcpOption::SACKOK.new
|
161
|
+
assert_equal("\x04\x02", t.to_s)
|
162
|
+
assert_equal("SACKOK",t.decode)
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_sackok
|
166
|
+
t = TcpOption::SACK.new
|
167
|
+
assert_equal("\x05\x02", t.to_s)
|
168
|
+
assert_equal("SACK:",t.decode)
|
169
|
+
t = TcpOption::SACK.new(:value => "ABCD")
|
170
|
+
assert_equal("\x05\x06\x41\x42\x43\x44", t.to_s)
|
171
|
+
assert_equal("SACK:ABCD",t.decode)
|
172
|
+
t = TcpOptions.new
|
173
|
+
t.encode("SACK:ABCD,NOP,NOP") # Testing the variable optlen
|
174
|
+
assert_equal("SACK:ABCD,NOP,NOP",t.decode)
|
175
|
+
end
|
176
|
+
|
177
|
+
def test_echo
|
178
|
+
t = TcpOption::ECHO.new(:value => "ABCD")
|
179
|
+
assert_equal("\x06\x06\x41\x42\x43\x44", t.to_s)
|
180
|
+
assert_equal("ECHO:ABCD",t.decode)
|
181
|
+
t = TcpOption::ECHO.new
|
182
|
+
t.read("\x06\x06\x41\x42\x43\x44")
|
183
|
+
assert_equal("ECHO:ABCD",t.decode)
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_echoreply
|
187
|
+
t = TcpOption::ECHOREPLY.new(:value => "ABCD")
|
188
|
+
assert_equal("\x07\x06\x41\x42\x43\x44", t.to_s)
|
189
|
+
assert_equal("ECHOREPLY:ABCD",t.decode)
|
190
|
+
t = TcpOption::ECHOREPLY.new
|
191
|
+
t.read("\x07\x06\x41\x42\x43\x44")
|
192
|
+
assert_equal("ECHOREPLY:ABCD",t.decode)
|
193
|
+
end
|
194
|
+
|
195
|
+
def test_tsopt
|
196
|
+
t = TcpOption::TS.new
|
197
|
+
assert_equal("\x08\x0a\x00\x00\x00\x00\x00\x00\x00\x00", t.to_s)
|
198
|
+
assert_equal("TS:0;0",t.decode)
|
199
|
+
end
|
200
|
+
|
201
|
+
def test_tcpoptions
|
202
|
+
opt_string = "0101080a002af12c12ef0d57".bin
|
203
|
+
t = TcpOptions.new
|
204
|
+
t.read opt_string
|
205
|
+
assert_equal("NOP,NOP,TS:2814252;317656407", t.decode)
|
206
|
+
assert_equal(opt_string, t.to_s)
|
207
|
+
opt_string = "020405b40402080a002af1120000000001030306".bin
|
208
|
+
t = TcpOptions.new
|
209
|
+
t.read opt_string
|
210
|
+
assert_equal("MSS:1460,SACKOK,TS:2814226;0,NOP,WS:6", t.decode)
|
211
|
+
end
|
212
|
+
|
213
|
+
def test_tcpoptions_encode
|
214
|
+
opt_string = "mss:1460,sackok,ts:2814226;0,nop,ws:6"
|
215
|
+
t = TcpOptions.new
|
216
|
+
t.encode opt_string
|
217
|
+
assert_equal(opt_string.upcase, t.decode)
|
218
|
+
assert_kind_of(StructFu::Int8,t[0].kind)
|
219
|
+
assert_kind_of(StructFu::Int8,t[0].optlen)
|
220
|
+
assert_kind_of(StructFu::Int16,t[0].value)
|
221
|
+
assert_equal("\x02\x04\x05\xb4", t[0].to_s)
|
222
|
+
assert_equal("\x08\x0a\x00\x2a\xf1\x12\x00\x00\x00\x00", t[2].to_s)
|
223
|
+
end
|
224
224
|
|
225
225
|
end
|
226
226
|
|
227
227
|
class TcpHeaderTest < Test::Unit::TestCase
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
228
|
+
include PacketFu
|
229
|
+
|
230
|
+
def test_header_new
|
231
|
+
t = TCPHeader.new
|
232
|
+
assert_kind_of TCPHeader, t
|
233
|
+
assert_equal 20, t.sz
|
234
|
+
assert_equal 13, t.size
|
235
|
+
end
|
236
|
+
|
237
|
+
def test_header_read
|
238
|
+
t = TCPHeader.new
|
239
|
+
str = "da920050c9fd6d2b2f54cc2f8018005c74de00000101080a002af11e12ef0d4a".bin
|
240
|
+
str << "474554202f20485454502f312e310d0a557365722d4167656e743a206375726c2f372e31382e322028693438362d70632d6c696e75782d676e7529206c69626375726c2f372e31382e32204f70656e53534c2f302e392e3867207a6c69622f312e322e332e33206c696269646e2f312e31300d0a486f73743a207777772e706c616e622d73656375726974792e6e65740d0a4163636570743a202a2f2a0d0a0d0a".bin
|
241
|
+
t.read str
|
242
|
+
assert_equal 55954, t.tcp_sport
|
243
|
+
assert_equal 80, t.tcp_dport
|
244
|
+
assert_equal 3388828971, t.tcp_seq
|
245
|
+
assert_equal 794086447, t.tcp_ack
|
246
|
+
assert_equal 8, t.tcp_hlen
|
247
|
+
assert_equal 0, t.tcp_reserved
|
248
|
+
assert_equal 0, t.tcp_ecn
|
249
|
+
assert_equal 1, t.tcp_flags.psh
|
250
|
+
assert_equal 1, t.tcp_flags.ack
|
251
|
+
assert_equal 0, t.tcp_flags.syn
|
252
|
+
assert_equal 92, t.tcp_win
|
253
|
+
assert_equal 0x74de, t.tcp_sum
|
254
|
+
assert_equal "NOP,NOP,TS:2814238;317656394", t.tcp_options
|
255
|
+
assert_equal "GET /", t.body[0,5]
|
256
|
+
assert_equal "*\x0d\x0a\x0d\x0a", t.body[-5,5]
|
257
|
+
end
|
258
258
|
|
259
259
|
end
|
260
260
|
|
261
261
|
class TCPPacketTest < Test::Unit::TestCase
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
262
|
+
include PacketFu
|
263
|
+
|
264
|
+
def test_tcp_peek
|
265
|
+
t = TCPPacket.new
|
266
|
+
t.ip_saddr = "10.20.30.40"
|
267
|
+
t.ip_daddr = "50.60.70.80"
|
268
|
+
t.tcp_src = 55954
|
269
|
+
t.tcp_dport = 80
|
270
|
+
t.tcp_flags.syn = 1
|
271
|
+
t.tcp_flags.ack = true
|
272
|
+
t.payload = "GET / HTTP/1.1\x0d\x0aHost: 50.60.70.80\x0d\x0a\x0d\x0a"
|
273
|
+
t.recalc
|
274
|
+
puts "\n"
|
275
|
+
puts "TCP Peek format: "
|
276
|
+
puts t.peek
|
277
|
+
assert (t.peek.size <= 80)
|
278
|
+
end
|
279
|
+
|
280
|
+
def test_tcp_pcap
|
281
|
+
t = TCPPacket.new
|
282
|
+
assert_kind_of TCPPacket, t
|
283
|
+
t.recalc
|
284
|
+
t.to_f('tcp_test.pcap','a')
|
285
|
+
t.recalc
|
286
|
+
#t.to_f('tcp_test.pcap','a')
|
287
|
+
t.ip_saddr = "10.20.30.40"
|
288
|
+
t.ip_daddr = "50.60.70.80"
|
289
|
+
t.payload = "+some fakey-fake tcp packet"
|
290
|
+
t.tcp_sport = 1206
|
291
|
+
t.tcp_dst = 13013
|
292
|
+
t.tcp_flags.syn = 1
|
293
|
+
t.tcp_flags.ack = true
|
294
|
+
t.tcp_flags.psh = false
|
295
|
+
t.recalc
|
296
|
+
#t.to_f('tcp_test.pcap','a')
|
297
|
+
end
|
298
|
+
|
299
|
+
def test_tcp_read
|
300
|
+
sample_packet = PcapFile.new.file_to_array(:f => 'sample.pcap')[7]
|
301
|
+
pkt = Packet.parse(sample_packet)
|
302
|
+
assert_kind_of TCPPacket, pkt
|
303
|
+
assert_equal(0x5a73, pkt.tcp_sum)
|
304
|
+
pkt.to_f('tcp_test.pcap','a')
|
305
|
+
end
|
306
|
+
|
307
|
+
def test_tcp_alter
|
308
|
+
sample_packet = PcapFile.new.file_to_array(:f => 'sample2.pcap')[3]
|
309
|
+
pkt = Packet.parse(sample_packet)
|
310
|
+
assert_kind_of TCPPacket, pkt
|
311
|
+
pkt.tcp_sport = 13013
|
312
|
+
pkt.payload = pkt.payload.gsub(/planb/,"brandx")
|
313
|
+
pkt.recalc
|
314
|
+
pkt.to_f('tcp_test.pcap','a')
|
315
|
+
end
|
316
|
+
|
317
|
+
def test_tcp_read_strip
|
318
|
+
str = "e0f8472161a600254ba0760608004500004403554000400651d0c0a83207c0a832370224c1d22d94847f0b07c4ba8018ffff30ba00000101080a8731821433564b8c01027165000000000000200000000000".bin
|
319
|
+
str << "0102".bin # Tacking on a couple extra bites tht we'll strip off.
|
320
|
+
not_stripped = TCPPacket.new
|
321
|
+
not_stripped.read(str)
|
322
|
+
assert_equal 18, not_stripped.tcp_header.body.length
|
323
|
+
stripped = TCPPacket.new
|
324
|
+
stripped.read(str, :strip => true)
|
325
|
+
assert_equal 16, stripped.tcp_header.body.length
|
326
|
+
end
|
327
|
+
|
328
|
+
def test_tcp_reread
|
329
|
+
sample_packet = PacketFu::TCPPacket.new
|
330
|
+
pkt = Packet.parse(sample_packet.to_s)
|
331
|
+
assert sample_packet.is_tcp?
|
332
|
+
assert pkt.is_tcp?
|
333
|
+
end
|
334
334
|
|
335
335
|
end
|
336
336
|
|
337
337
|
class TCPPacketTest < Test::Unit::TestCase
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
338
|
+
include PacketFu
|
339
|
+
|
340
|
+
def test_tcp_edit_opts
|
341
|
+
t = TCPPacket.new
|
342
|
+
assert_equal(0, t.tcp_options.size)
|
343
|
+
assert_equal(0, t.tcp_opts_len)
|
344
|
+
assert_equal(5, t.tcp_hlen)
|
345
|
+
t.tcp_options = "NOP,NOP,NOP,NOP"
|
346
|
+
assert_equal(4, t.tcp_opts_len)
|
347
|
+
t.recalc
|
348
|
+
assert_equal(6, t.tcp_hlen)
|
349
|
+
end
|
350
350
|
|
351
351
|
end
|
352
352
|
|