packetfu 1.1.12.pre → 1.1.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 27fdb60e2d8cf9c2abe63361c024c6b6b4077c45
4
- data.tar.gz: ddb6a367565f97de59c730d6e5141e85165407f4
3
+ metadata.gz: 712224a72548bc850cf753d398d54c91560b5ca4
4
+ data.tar.gz: 79a17434b2b794b94ad8f17339e9eed70f8110ad
5
5
  SHA512:
6
- metadata.gz: d063030465de3423c0b59295bd5ebd02d568d1832f7770965cb6825d29d645cfd6bc6ab43e40cb5871fb7b187507d3ba2a1415bc3d63b7b017287b39adfd5481
7
- data.tar.gz: 445f37e0c272b179382396bd2307fa24e6214fd0ae8cdb34d65cbcdef3fd05562a927239bea0f4aeaf6d79d34386827d4c2489604b9261b35422eb376ba6937b
6
+ metadata.gz: 0552cd39507b9d8fa6613a2e0c6fed7a9950336d0ed5a315ae721d829d8b5db66acde56e756e7977d332fb0d69136f621e04c4d4d791f5edc61631d1624aea48
7
+ data.tar.gz: 6ec922087b78eeddb1dcfd827a6d4348bf7e132d1d349afaf9ab88aab56e9f58c1703e500ef9864bf1553a5ae43858a426784dd009e619a2ba6a911e904351f6
Binary file
@@ -0,0 +1,5 @@
1
+ @�Rr˟� ��?t�Zy�ҫ��_K>؉� {n��V�U3�|TEц7{���g�I5;� ����Bt��"2t���G�ĉ�Q:71l�}&~:��$����0˿7��w� �DCkV�|"5�wp
2
+ T�����ZT�cO�
3
+ q��󑉈����jf��O��b�w����ߏ� ˡ����džM�
4
+
5
+ s<ݮʆ��A �۴;oj��ܹ"s8k�%�O�ߨ/����,[�@����E������
data/.gitignore CHANGED
@@ -1,4 +1,6 @@
1
1
  *.gem
2
+ *.swp
3
+ *~
2
4
  doc/
3
5
  .yardoc/
4
6
  pkg/
@@ -2,6 +2,7 @@ language: ruby
2
2
  before_install:
3
3
  - sudo apt-get install libpcap-dev -qq
4
4
  rvm:
5
- - 2.1.6
6
- - 2.2.3
7
- - 2.3.0
5
+ - 2.1
6
+ - 2.2
7
+ - 2.3.3
8
+ - 2.4.0
data/README.md CHANGED
@@ -64,33 +64,33 @@ Here's an example of creating a TCPPacket and sending it out on the wire:
64
64
  ```
65
65
  2.3.0 :002 > packet = TCPPacket.new(:config => Utils.whoami?)
66
66
  => --EthHeader-------------------------------------------
67
- eth_dst ec:08:6b:62:bc:d2 PacketFu::EthMac
68
- eth_src ac:bc:32:85:47:3f PacketFu::EthMac
69
- eth_proto 0x0800 StructFu::Int16
67
+ eth_dst ec:08:6b:62:bc:d2 PacketFu::EthMac
68
+ eth_src ac:bc:32:85:47:3f PacketFu::EthMac
69
+ eth_proto 0x0800 StructFu::Int16
70
70
  --IPHeader--------------------------------------------
71
- ip_v 4 Fixnum
72
- ip_hl 5 Fixnum
73
- ip_tos 0 StructFu::Int8
74
- ip_len 20 StructFu::Int16
75
- ip_id 0x77e4 StructFu::Int16
76
- ip_frag 0 StructFu::Int16
77
- ip_ttl 32 StructFu::Int8
78
- ip_proto 6 StructFu::Int8
79
- ip_sum 0xffff StructFu::Int16
80
- ip_src 192.168.0.100 PacketFu::Octets
81
- ip_dst 0.0.0.0 PacketFu::Octets
71
+ ip_v 4 Integer
72
+ ip_hl 5 Integer
73
+ ip_tos 0 StructFu::Int8
74
+ ip_len 20 StructFu::Int16
75
+ ip_id 0x77e4 StructFu::Int16
76
+ ip_frag 0 StructFu::Int16
77
+ ip_ttl 32 StructFu::Int8
78
+ ip_proto 6 StructFu::Int8
79
+ ip_sum 0xffff StructFu::Int16
80
+ ip_src 192.168.0.100 PacketFu::Octets
81
+ ip_dst 0.0.0.0 PacketFu::Octets
82
82
  --TCPHeader-------------------------------------------
83
- tcp_src 42653 StructFu::Int16
84
- tcp_dst 0 StructFu::Int16
85
- tcp_seq 0x8d65fbbf StructFu::Int32
86
- tcp_ack 0x00000000 StructFu::Int32
87
- tcp_hlen 5 PacketFu::TcpHlen
83
+ tcp_src 42653 StructFu::Int16
84
+ tcp_dst 0 StructFu::Int16
85
+ tcp_seq 0x8d65fbbf StructFu::Int32
86
+ tcp_ack 0x00000000 StructFu::Int32
87
+ tcp_hlen 5 PacketFu::TcpHlen
88
88
  tcp_reserved 0 PacketFu::TcpReserved
89
- tcp_ecn 0 PacketFu::TcpEcn
90
- tcp_flags ...... PacketFu::TcpFlags
91
- tcp_win 16384 StructFu::Int16
92
- tcp_sum 0x7f29 StructFu::Int16
93
- tcp_urg 0 StructFu::Int16
89
+ tcp_ecn 0 PacketFu::TcpEcn
90
+ tcp_flags ...... PacketFu::TcpFlags
91
+ tcp_win 16384 StructFu::Int16
92
+ tcp_sum 0x7f29 StructFu::Int16
93
+ tcp_urg 0 StructFu::Int16
94
94
  tcp_opts PacketFu::TcpOptions
95
95
 
96
96
  2.3.0 :003 > packet.ip_dst = "8.8.8.8"
@@ -0,0 +1,40 @@
1
+ # Usage:
2
+ # rvmsudo ruby examples/ping.rb 8.8.8.8
3
+
4
+ # Path setting slight of hand:
5
+ $: << File.expand_path("../../lib", __FILE__)
6
+
7
+ require 'packetfu'
8
+
9
+ ip = ARGV[0].chomp
10
+
11
+ config = PacketFu::Utils.whoami?()
12
+
13
+ icmp_packet = PacketFu::ICMPPacket.new(:config => config)
14
+ icmp_packet.ip_daddr = ip
15
+ icmp_packet.payload = "I'm sending ICMP packets using PacketFu!!!"
16
+ icmp_packet.icmp_type = 8
17
+ icmp_packet.recalc
18
+
19
+ capture_thread = Thread.new do
20
+ begin
21
+ Timeout::timeout(3) {
22
+ cap = PacketFu::Capture.new(:iface => config[:iface], :start => true)
23
+ cap.stream.each do |p|
24
+ pkt = PacketFu::Packet.parse p
25
+ next unless pkt.is_icmp?
26
+ if pkt.ip_saddr == ip and pkt.icmp_type == 0
27
+ puts "Got ICMP echo reply from #{ip}"
28
+ break
29
+ end
30
+ end
31
+ }
32
+ rescue Timeout::Error
33
+ puts "ICMP echo request timed out"
34
+ end
35
+ end
36
+
37
+ puts "Sending ICMP echo request to #{ip}"
38
+ icmp_packet.to_w
39
+
40
+ capture_thread.join
@@ -0,0 +1,61 @@
1
+ # Usage:
2
+ # rvmsudo ruby examples/tcp_handshake.rb 192.30.252.130
3
+
4
+ # Notes:
5
+ # because we're bypassing the kernel for this raw TCP handshake it will normally
6
+ # RST SYN/ACK operations because the kernel is not tracking the TCP session.
7
+ # You can prevent the RST from being sent by your client using the following iptables hack.
8
+ #
9
+ # iptables -A OUTPUT -p tcp --tcp-flags RST RST -j DROP
10
+
11
+ # Path setting slight of hand:
12
+ $: << File.expand_path("../../lib", __FILE__)
13
+
14
+ require 'packetfu'
15
+
16
+ ip = ARGV[0].chomp
17
+
18
+ config = PacketFu::Utils.whoami?()
19
+
20
+ syn_packet = PacketFu::TCPPacket.new(:config => config)
21
+ syn_packet.ip_daddr = ip
22
+ syn_packet.tcp_dst = 80
23
+ syn_packet.tcp_flags.syn = 1
24
+ syn_packet.recalc
25
+
26
+ capture_thread = Thread.new do
27
+ begin
28
+ Timeout::timeout(3) {
29
+ cap = PacketFu::Capture.new(:iface => config[:iface], :start => true)
30
+ cap.stream.each do |p|
31
+ pkt = PacketFu::Packet.parse p
32
+ next unless pkt.is_tcp?
33
+
34
+ if pkt.ip_saddr == ip &&
35
+ pkt.tcp_flags.syn == 1 &&
36
+ pkt.tcp_flags.ack == 1
37
+
38
+ puts "Got SYN/ACK reply from #{ip}"
39
+
40
+ syn_ack_packet = pkt
41
+ ack_packet = syn_packet.dup
42
+ ack_packet.tcp_flags.syn = 0
43
+ ack_packet.tcp_flags.ack = 1
44
+ ack_packet.tcp_ack = syn_ack_packet.tcp_seq + 1
45
+ ack_packet.tcp_seq = syn_ack_packet.tcp_ack
46
+
47
+ puts "Sending ACK reply to #{ip}"
48
+ ack_packet.to_w
49
+ break
50
+ end
51
+ end
52
+ }
53
+ rescue Timeout::Error
54
+ puts "SYN request timed out"
55
+ end
56
+ end
57
+
58
+ puts "Sending SYN request to #{ip}"
59
+ syn_packet.to_w
60
+
61
+ capture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imu6381SmLU
18
+ LZVT1SzAMqjK5HKaFwBwmb9i+vPycblrL8ngjSg4TWqMt4PLXOTvyiCy2IQRXb+o
19
+ aNODmav4FDa8Yham3QhPACahVVxZczCpbDHFvojjk127uca93t3gc2IGx1jYO0mv
20
+ bGMb9KcX7MTVhg4J4u5k6A==
21
21
  -----END CERTIFICATE-----
@@ -44,7 +44,7 @@ module PacketFu
44
44
  end
45
45
 
46
46
  new_args = {}
47
- new_args[:on_ipv6] = true if IPv6Packet.can_parse?(packet)
47
+ new_args[:on_ipv6] = true if PacketFu::IPv6Packet.can_parse?(packet)
48
48
  p = classes.detect { |pclass| pclass.can_parse?(packet) }.new(new_args)
49
49
  parsed_packet = p.read(packet,args)
50
50
  end
@@ -6,24 +6,24 @@ module PacketFu
6
6
  #
7
7
  # ==== Header Definition
8
8
  #
9
- # Fixnum :b0
10
- # Fixnum :b1
11
- # Fixnum :b2
12
- # Fixnum :b3
13
- # Fixnum :b4
14
- # Fixnum :b5
15
- # Fixnum :local
16
- # Fixnum :multicast
9
+ # Integer :b0
10
+ # Integer :b1
11
+ # Integer :b2
12
+ # Integer :b3
13
+ # Integer :b4
14
+ # Integer :b5
15
+ # Integer :local
16
+ # Integer :multicast
17
17
  # Int16 :oui, Default: 0x1ac5 :)
18
18
  class EthOui < Struct.new(:b5, :b4, :b3, :b2, :b1, :b0, :local, :multicast, :oui)
19
19
 
20
20
  # EthOui is unusual in that the bit values do not enjoy StructFu typing.
21
21
  def initialize(args={})
22
- args[:local] ||= 0
22
+ args[:local] ||= 0
23
23
  args[:oui] ||= 0x1ac # :)
24
- args.each_pair {|k,v| args[k] = 0 unless v}
25
- super(args[:b5], args[:b4], args[:b3], args[:b2],
26
- args[:b1], args[:b0], args[:local], args[:multicast],
24
+ args.each_pair {|k,v| args[k] = 0 unless v}
25
+ super(args[:b5], args[:b4], args[:b3], args[:b2],
26
+ args[:b1], args[:b0], args[:local], args[:multicast],
27
27
  args[:oui])
28
28
  end
29
29
 
@@ -68,15 +68,15 @@ module PacketFu
68
68
  #
69
69
  # ==== Header Definition
70
70
  #
71
- # Fixnum :n1
72
- # Fixnum :n2
73
- # Fixnum :n3
71
+ # Integer:n1
72
+ # Integer:n2
73
+ # Integer:n3
74
74
  #
75
75
  class EthNic < Struct.new(:n0, :n1, :n2)
76
76
 
77
77
  # EthNic does not enjoy StructFu typing.
78
78
  def initialize(args={})
79
- args.each_pair {|k,v| args[k] = 0 unless v}
79
+ args.each_pair {|k,v| args[k] = 0 unless v}
80
80
  super(args[:n0], args[:n1], args[:n2])
81
81
  end
82
82
 
@@ -84,7 +84,7 @@ module PacketFu
84
84
  def to_s
85
85
  [n0,n1,n2].map {|x| x.to_i}.pack("C3")
86
86
  end
87
-
87
+
88
88
  # Reads a string to populate the object.
89
89
  def read(str)
90
90
  force_binary(str)
@@ -125,11 +125,11 @@ module PacketFu
125
125
 
126
126
  end
127
127
 
128
- # EthHeader is a complete Ethernet struct, used in EthPacket.
129
- # It's the base header for all other protocols, such as IPHeader,
130
- # TCPHeader, etc.
128
+ # EthHeader is a complete Ethernet struct, used in EthPacket.
129
+ # It's the base header for all other protocols, such as IPHeader,
130
+ # TCPHeader, etc.
131
131
  #
132
- # For more on the construction on MAC addresses, see
132
+ # For more on the construction on MAC addresses, see
133
133
  # http://en.wikipedia.org/wiki/MAC_address
134
134
  #
135
135
  # TODO: Need to come up with a good way of dealing with vlan
@@ -185,7 +185,7 @@ module PacketFu
185
185
  self
186
186
  end
187
187
 
188
- # Converts a readable MAC (11:22:33:44:55:66) to a binary string.
188
+ # Converts a readable MAC (11:22:33:44:55:66) to a binary string.
189
189
  # Readable MAC's may be split on colons, dots, spaces, or underscores.
190
190
  #
191
191
  # irb> PacketFu::EthHeader.mac2str("11:22:33:44:55:66")
@@ -200,7 +200,7 @@ module PacketFu
200
200
  return ret
201
201
  end
202
202
 
203
- # Converts a binary string to a readable MAC (11:22:33:44:55:66).
203
+ # Converts a binary string to a readable MAC (11:22:33:44:55:66).
204
204
  #
205
205
  # irb> PacketFu::EthHeader.str2mac("\x11\x22\x33\x44\x55\x66")
206
206
  #
@@ -218,7 +218,7 @@ module PacketFu
218
218
  self[:eth_src]
219
219
  end
220
220
 
221
- # Gets the source MAC address in a more readable way.
221
+ # Gets the source MAC address in a more readable way.
222
222
  def eth_saddr
223
223
  EthHeader.str2mac(self[:eth_src].to_s)
224
224
  end
@@ -230,7 +230,7 @@ module PacketFu
230
230
  self[:eth_dst]
231
231
  end
232
232
 
233
- # Gets the destination MAC address in a more readable way.
233
+ # Gets the destination MAC address in a more readable way.
234
234
  def eth_daddr
235
235
  EthHeader.str2mac(self[:eth_dst].to_s)
236
236
  end
@@ -10,7 +10,7 @@ module PacketFu
10
10
  class Octets < Struct.new(:ip_addr)
11
11
  include StructFu
12
12
 
13
- IPV4_RE = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/
13
+ IPV4_RE = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/
14
14
  def initialize(args={})
15
15
  super(
16
16
  Int32.new(args[:ip_addr]))
@@ -46,7 +46,7 @@ module PacketFu
46
46
  match = IPV4_RE.match(str)
47
47
  if match.nil?
48
48
  raise ArgumentError.new("str is not a valid IPV4 address")
49
- end
49
+ end
50
50
  a = match[1].to_i
51
51
  b = match[2].to_i
52
52
  c = match[3].to_i
@@ -57,7 +57,7 @@ module PacketFu
57
57
  d >= 0 && d <= 255)
58
58
  raise ArgumentError.new("str is not a valid IPV4 address")
59
59
  end
60
-
60
+
61
61
  self[:ip_addr].value = (a<<24) + (b<<16) + (c<<8) + d
62
62
  self
63
63
  end
@@ -65,7 +65,7 @@ module PacketFu
65
65
  # Returns the IP address as 4 octets
66
66
  def octets
67
67
  addr = self.to_i
68
- [
68
+ [
69
69
  ((addr >> 24) & 0xff),
70
70
  ((addr >> 16) & 0xff),
71
71
  ((addr >> 8) & 0xff),
@@ -101,21 +101,21 @@ module PacketFu
101
101
  #
102
102
  # ==== Header Definition
103
103
  #
104
- # Fixnum (4 bits) :ip_v, Default: 4
105
- # Fixnum (4 bits) :ip_hl, Default: 5
104
+ # Integer (4 bits) :ip_v, Default: 4
105
+ # Integer (4 bits) :ip_hl, Default: 5
106
106
  # Int8 :ip_tos, Default: 0 # TODO: Break out the bits
107
- # Int16 :ip_len, Default: calculated
108
- # Int16 :ip_id, Default: calculated # IRL, hardly random.
107
+ # Int16 :ip_len, Default: calculated
108
+ # Int16 :ip_id, Default: calculated # IRL, hardly random.
109
109
  # Int16 :ip_frag, Default: 0 # TODO: Break out the bits
110
110
  # Int8 :ip_ttl, Default: 0xff # Changes per flavor
111
111
  # Int8 :ip_proto, Default: 0x01 # TCP: 0x06, UDP 0x11, ICMP 0x01
112
- # Int16 :ip_sum, Default: calculated
113
- # Octets :ip_src
114
- # Octets :ip_dst
112
+ # Int16 :ip_sum, Default: calculated
113
+ # Octets :ip_src
114
+ # Octets :ip_dst
115
115
  # String :body
116
116
  #
117
- # Note that IPPackets will always be somewhat incorrect upon initalization,
118
- # and want an IPHeader#recalc() to become correct before a
117
+ # Note that IPPackets will always be somewhat incorrect upon initalization,
118
+ # and want an IPHeader#recalc() to become correct before a
119
119
  # Packet#to_f or Packet#to_w.
120
120
  class IPHeader < Struct.new(:ip_v, :ip_hl, :ip_tos, :ip_len,
121
121
  :ip_id, :ip_frag, :ip_ttl, :ip_proto,
@@ -233,7 +233,7 @@ module PacketFu
233
233
  (ip_hl * 4) + body.to_s.length
234
234
  end
235
235
 
236
- # Return the claimed header length
236
+ # Return the claimed header length
237
237
  def ip_hlen
238
238
  (ip_hl * 4)
239
239
  end
@@ -250,7 +250,7 @@ module PacketFu
250
250
  checksum += (self.ip_src & 0xffff)
251
251
  checksum += (self.ip_dst >> 16)
252
252
  checksum += (self.ip_dst & 0xffff)
253
- checksum = checksum % 0xffff
253
+ checksum = checksum % 0xffff
254
254
  checksum = 0xffff - checksum
255
255
  checksum == 0 ? 0xffff : checksum
256
256
  end
@@ -260,14 +260,14 @@ module PacketFu
260
260
  @random_id
261
261
  end
262
262
 
263
- # Sets a more readable IP address. If you wants to manipulate individual octets,
264
- # (eg, for host scanning in one network), it would be better use ip_src.o1 through
265
- # ip_src.o4 instead.
263
+ # Sets a more readable IP address. If you wants to manipulate individual octets,
264
+ # (eg, for host scanning in one network), it would be better use ip_src.o1 through
265
+ # ip_src.o4 instead.
266
266
  def ip_saddr=(addr)
267
267
  self[:ip_src].read_quad(addr)
268
268
  end
269
269
 
270
- # Returns a more readable IP source address.
270
+ # Returns a more readable IP source address.
271
271
  def ip_saddr
272
272
  self[:ip_src].to_x
273
273
  end
@@ -286,11 +286,9 @@ module PacketFu
286
286
  def self.octet_array(addr)
287
287
  if addr.class == String
288
288
  oa = addr.split('.').collect {|x| x.to_i}
289
- elsif addr.class == Fixnum
290
- oa = IPAddr.new(addr, Socket::AF_INET).to_s.split('.')
291
- elsif addr.class == Bignum
289
+ elsif addr.kind_of? Integer
292
290
  oa = IPAddr.new(addr, Socket::AF_INET).to_s.split('.')
293
- elsif addr.class == Array
291
+ elsif addr.kind_of? Array
294
292
  oa = addr
295
293
  else
296
294
  raise ArgumentError, "IP Address should be a dotted quad string, an array of ints, or a bignum"
@@ -298,9 +296,9 @@ module PacketFu
298
296
  end
299
297
 
300
298
  # Recalculate the calculated IP fields. Valid arguments are:
301
- # :all
302
- # :ip_len
303
- # :ip_sum
299
+ # :all
300
+ # :ip_len
301
+ # :ip_sum
304
302
  # :ip_id
305
303
  def ip_recalc(arg=:all)
306
304
  case arg
@@ -32,7 +32,7 @@ module PacketFu
32
32
  (a1.to_i << 96) + (a2.to_i << 64) + (a3.to_i << 32) + a4.to_i
33
33
  end
34
34
 
35
- # Returns the address as a colon-delimited hex string.
35
+ # Returns the address as a colon-delimited hex string.
36
36
  def to_x
37
37
  IPAddr.new(self.to_i, Socket::AF_INET6).to_s
38
38
  end
@@ -60,13 +60,13 @@ module PacketFu
60
60
 
61
61
  end
62
62
 
63
- # IPv6Header is complete IPv6 struct, used in IPv6Packet.
63
+ # IPv6Header is complete IPv6 struct, used in IPv6Packet.
64
64
  #
65
65
  # ==== Header Definition
66
66
  #
67
- # Fixnum (4 bits) :ipv6_v Default: 6 # Versiom
68
- # Fixnum (8 bits) :ipv6_class Defualt: 0 # Class
69
- # Fixnum (20 bits) :ipv6_label Defualt: 0 # Label
67
+ # Integer(4 bits) :ipv6_v Default: 6 # Versiom
68
+ # Integer(8 bits) :ipv6_class Defualt: 0 # Class
69
+ # Integer(20 bits) :ipv6_label Defualt: 0 # Label
70
70
  # Int16 :ipv6_len Default: calc # Payload length
71
71
  # Int8 :ipv6_next # Next Header
72
72
  # Int8 :ipv6_hop Default: 0xff # Hop limit
@@ -116,9 +116,9 @@ module PacketFu
116
116
  self
117
117
  end
118
118
 
119
- # Setter for the version (usually, 6).
119
+ # Setter for the version (usually, 6).
120
120
  def ipv6_v=(i); self[:ip_v] = i.to_i; end
121
- # Getter for the version (usually, 6).
121
+ # Getter for the version (usually, 6).
122
122
  def ipv6_v; self[:ipv6_v].to_i; end
123
123
  # Setter for the traffic class.
124
124
  def ipv6_class=(i); self[:ip_class] = i.to_i; end
@@ -164,22 +164,22 @@ module PacketFu
164
164
  end
165
165
  end
166
166
 
167
- # Get the source address in a more readable form.
167
+ # Get the source address in a more readable form.
168
168
  def ipv6_saddr
169
169
  self[:ipv6_src].to_x
170
170
  end
171
171
 
172
- # Set the source address in a more readable form.
172
+ # Set the source address in a more readable form.
173
173
  def ipv6_saddr=(str)
174
174
  self[:ipv6_src].read_x(str)
175
175
  end
176
176
 
177
- # Get the destination address in a more readable form.
177
+ # Get the destination address in a more readable form.
178
178
  def ipv6_daddr
179
179
  self[:ipv6_dst].to_x
180
180
  end
181
181
 
182
- # Set the destination address in a more readable form.
182
+ # Set the destination address in a more readable form.
183
183
  def ipv6_daddr=(str)
184
184
  self[:ipv6_dst].read_x(str)
185
185
  end
@@ -5,9 +5,9 @@ module PacketFu
5
5
  # ==== Header Definition
6
6
  #
7
7
  #
8
- # Fixnum (1 bit) :n
9
- # Fixnum (1 bit) :c
10
- # Fixnum (1 bit) :e
8
+ # Integer(1 bit) :n
9
+ # Integer(1 bit) :c
10
+ # Integer(1 bit) :e
11
11
  class TcpEcn < Struct.new(:n, :c, :e)
12
12
 
13
13
  include StructFu
@@ -4,12 +4,12 @@ module PacketFu
4
4
  #
5
5
  # ==== Header Definition
6
6
  #
7
- # Fixnum (1 bit) :urg
8
- # Fixnum (1 bit) :ack
9
- # Fixnum (1 bit) :psh
10
- # Fixnum (1 bit) :rst
11
- # Fixnum (1 bit) :syn
12
- # Fixnum (1 bit) :fin
7
+ # Integer(1 bit) :urg
8
+ # Integer(1 bit) :ack
9
+ # Integer(1 bit) :psh
10
+ # Integer(1 bit) :rst
11
+ # Integer(1 bit) :syn
12
+ # Integer(1 bit) :fin
13
13
  #
14
14
  # Flags can typically be set by setting them either to 1 or 0, or to true or false.
15
15
  class TcpFlags < Struct.new(:urg, :ack, :psh, :rst, :syn, :fin)
@@ -23,11 +23,11 @@ module PacketFu
23
23
  super( 0, 0, 0, 0, 0, 0)
24
24
  else
25
25
  super(
26
- (args[:urg] ? 1 : 0),
27
- (args[:ack] ? 1 : 0),
28
- (args[:psh] ? 1 : 0),
29
- (args[:rst] ? 1 : 0),
30
- (args[:syn] ? 1 : 0),
26
+ (args[:urg] ? 1 : 0),
27
+ (args[:ack] ? 1 : 0),
28
+ (args[:psh] ? 1 : 0),
29
+ (args[:rst] ? 1 : 0),
30
+ (args[:syn] ? 1 : 0),
31
31
  (args[:fin] ? 1 : 0)
32
32
  )
33
33
  end
@@ -36,7 +36,7 @@ module PacketFu
36
36
  # Returns the TcpFlags as an integer.
37
37
  # Also not a great candidate for to_s due to the short bitspace.
38
38
  def to_i
39
- (urg.to_i << 5) + (ack.to_i << 4) + (psh.to_i << 3) +
39
+ (urg.to_i << 5) + (ack.to_i << 4) + (psh.to_i << 3) +
40
40
  (rst.to_i << 2) + (syn.to_i << 1) + fin.to_i
41
41
  end
42
42
 
@@ -4,7 +4,7 @@ module PacketFu
4
4
  #
5
5
  # ==== Header Definition
6
6
  #
7
- # Fixnum (4 bits) :hlen
7
+ # Integer(4 bits) :hlen
8
8
  class TcpHlen < Struct.new(:hlen)
9
9
 
10
10
  include StructFu
@@ -5,9 +5,9 @@ module PacketFu
5
5
  # ==== Header Definition
6
6
  #
7
7
  #
8
- # Fixnum (1 bit) :r1
9
- # Fixnum (1 bit) :r2
10
- # Fixnum (1 bit) :r3
8
+ # Integer(1 bit) :r1
9
+ # Integer(1 bit) :r2
10
+ # Integer(1 bit) :r3
11
11
  class TcpReserved < Struct.new(:r1, :r2, :r3)
12
12
 
13
13
  include StructFu
@@ -1,9 +1,9 @@
1
1
  # -*- coding: binary -*-
2
2
  # StructFu, a nifty way to leverage Ruby's built in Struct class
3
- # to create meaningful binary data.
3
+ # to create meaningful binary data.
4
4
 
5
5
  module StructFu
6
-
6
+
7
7
  # Normally, self.size and self.length will refer to the Struct
8
8
  # size as an array. It's a hassle to redefine, so this introduces some
9
9
  # shorthand to get at the size of the resultant string.
@@ -15,7 +15,7 @@ module StructFu
15
15
 
16
16
  # Typecast is used mostly by packet header classes, such as IPHeader,
17
17
  # TCPHeader, and the like. It takes an argument, and casts it to the
18
- # expected type for that element.
18
+ # expected type for that element.
19
19
  def typecast(i)
20
20
  c = caller[0].match(/.*`([^']+)='/)[1]
21
21
  self[c.intern].read i
@@ -45,17 +45,17 @@ module StructFu
45
45
 
46
46
  # Ints all have a value, an endianness, and a default value.
47
47
  # Note that the signedness of Int values are implicit as
48
- # far as the subclasses are concerned; to_i and to_f will
48
+ # far as the subclasses are concerned; to_i and to_f will
49
49
  # return Integer/Float versions of the input value, instead
50
50
  # of attempting to unpack the pack value. (This can be a useful
51
51
  # hint to other functions).
52
52
  #
53
53
  # ==== Header Definition
54
54
  #
55
- # Fixnum :value
55
+ # Integer :value
56
56
  # Symbol :endian
57
- # Fixnum :width
58
- # Fixnum :default
57
+ # Integer :width
58
+ # Integer :default
59
59
  class Int < Struct.new(:value, :endian, :width, :default)
60
60
  alias :v= :value=
61
61
  alias :v :value
@@ -80,7 +80,7 @@ module StructFu
80
80
  def to_f
81
81
  (self.v || self.d).to_f
82
82
  end
83
-
83
+
84
84
  def initialize(value=nil, endian=nil, width=nil, default=nil)
85
85
  super(value,endian,width,default=0)
86
86
  end
@@ -122,7 +122,7 @@ module StructFu
122
122
  end
123
123
 
124
124
  end
125
-
125
+
126
126
  # Int16be is a two byte value in big-endian format. The endianness cannot be altered.
127
127
  class Int16be < Int16
128
128
  undef :endian=
@@ -204,7 +204,7 @@ module StructFu
204
204
 
205
205
  # Provides a primitive for creating strings, preceeded by
206
206
  # an Int type of length. By default, a string of length zero with
207
- # a one-byte length is presumed.
207
+ # a one-byte length is presumed.
208
208
  #
209
209
  # Note that IntStrings aren't used for much, but it seemed like a good idea at the time.
210
210
  class IntString < Struct.new(:int, :string, :mode)
@@ -240,7 +240,7 @@ module StructFu
240
240
  # is calculated upon assignment. If you'd prefer to have
241
241
  # an incorrect value, use the syntax, obj[:string]="value"
242
242
  # instead. Note, by using the alternate form, you must
243
- # #calc before you can trust the int's value. Think of the =
243
+ # #calc before you can trust the int's value. Think of the =
244
244
  # assignment as "set to equal," while the []= assignment
245
245
  # as "boxing in" the value. Maybe.
246
246
  def string=(s)
@@ -277,10 +277,10 @@ module StructFu
277
277
  # based on the declared length, or the actual length. Which strategy
278
278
  # is used is dependant on which :mode is set (with self.mode).
279
279
  #
280
- # :parse : Read the length, and then read in that many bytes of the string.
280
+ # :parse : Read the length, and then read in that many bytes of the string.
281
281
  # The string may be truncated or padded out with nulls, as dictated by the value.
282
282
  #
283
- # :fix : Skip the length, read the rest of the string, then set the length
283
+ # :fix : Skip the length, read the rest of the string, then set the length
284
284
  # to what it ought to be.
285
285
  #
286
286
  # else : If neither of these modes are set, just perfom a normal read().
@@ -289,7 +289,7 @@ module StructFu
289
289
  unless s[0,int.width].size == int.width
290
290
  raise StandardError, "String is too short for type #{int.class}"
291
291
  else
292
- case mode
292
+ case mode
293
293
  when :parse
294
294
  int.read(s[0,int.width])
295
295
  self[:string] = s[int.width,int.value]
@@ -2,7 +2,7 @@
2
2
  module PacketFu
3
3
 
4
4
  # Check the repo's for version release histories
5
- VERSION = "1.1.12.pre"
5
+ VERSION = "1.1.12"
6
6
 
7
7
  # Returns PacketFu::VERSION
8
8
  def self.version
@@ -16,11 +16,11 @@ Gem::Specification.new do |s|
16
16
  s.files = `git ls-files`.split($/)
17
17
  s.license = 'BSD'
18
18
  s.required_ruby_version = '>= 2.1.0'
19
- s.add_dependency('pcaprub', '~> 0.12')
20
- s.add_development_dependency('rake', '~> 10.3')
21
- s.add_development_dependency('rspec', '~> 3.0')
22
- s.add_development_dependency('rspec-its', '~> 1.2')
23
- s.add_development_dependency('sdoc', '~> 0.4.1')
19
+ s.add_dependency('pcaprub')
20
+ s.add_development_dependency('rake')
21
+ s.add_development_dependency('rspec')
22
+ s.add_development_dependency('rspec-its')
23
+ s.add_development_dependency('sdoc')
24
24
  s.add_development_dependency('pry')
25
25
  s.add_development_dependency('coveralls')
26
26
 
@@ -17,7 +17,7 @@ describe ARPHeader do
17
17
  it "should have the correct classes for initialization values" do
18
18
  expect(@arp_header).to be_kind_of(ARPHeader)
19
19
  expect(@arp_header[:arp_hw]).to be_kind_of(StructFu::Int16)
20
- expect(@arp_header.arp_hw).to be_kind_of(Fixnum)
20
+ expect(@arp_header.arp_hw).to be_kind_of(Integer)
21
21
  expect(@arp_header[:arp_src_ip]).to be_kind_of(Octets)
22
22
  expect(@arp_header.arp_src_ip).to be_kind_of(String)
23
23
  expect(@arp_header[:arp_dst_mac]).to be_kind_of(EthMac)
@@ -17,7 +17,7 @@ describe IPHeader do
17
17
  expect(@ip_header.ip_hl).to eql(5)
18
18
  expect(@ip_header.ip_tos).to eql(0)
19
19
  expect(@ip_header.ip_len).to eql(20)
20
- expect(@ip_header.ip_id).to be_kind_of(Fixnum)
20
+ expect(@ip_header.ip_id).to be_kind_of(Integer)
21
21
  expect(@ip_header.ip_frag).to eql(0)
22
22
  expect(@ip_header.ip_proto).to eql(0)
23
23
  expect(@ip_header.ip_sum).to eql(65535)
@@ -39,7 +39,7 @@ describe IPPacket do
39
39
  expect(@ip_packet.ip_hl).to eql(5)
40
40
  expect(@ip_packet.ip_tos).to eql(0)
41
41
  expect(@ip_packet.ip_len).to eql(20)
42
- expect(@ip_packet.ip_id).to be_kind_of(Fixnum)
42
+ expect(@ip_packet.ip_id).to be_kind_of(Integer)
43
43
  expect(@ip_packet.ip_frag).to eql(0)
44
44
  expect(@ip_packet.ip_proto).to eql(0)
45
45
  expect(@ip_packet.ip_sum).to eql(65535)
@@ -7,7 +7,7 @@ require 'fake_packets'
7
7
 
8
8
  describe PacketFu, "version information" do
9
9
  it "reports a version number" do
10
- PacketFu::VERSION.should match /^1\.[0-9]+\.[0-9]+$/
10
+ PacketFu::VERSION.should match /^1\.[0-9]+\.[0-9]+(.pre)?$/
11
11
  end
12
12
  its(:version) {should eq PacketFu::VERSION}
13
13
 
metadata CHANGED
@@ -1,86 +1,108 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: packetfu
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.12.pre
4
+ version: 1.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tod Beardsley
8
8
  - Jonathan Claudius
9
9
  autorequire:
10
10
  bindir: bin
11
- cert_chain: []
12
- date: 2016-05-10 00:00:00.000000000 Z
11
+ cert_chain:
12
+ - |
13
+ -----BEGIN CERTIFICATE-----
14
+ MIIDbDCCAlSgAwIBAgIBATANBgkqhkiG9w0BAQUFADA+MQ0wCwYDVQQDDAR0b2Ri
15
+ MRgwFgYKCZImiZPyLGQBGRYIcGFja2V0ZnUxEzARBgoJkiaJk/IsZAEZFgNjb20w
16
+ HhcNMTcwMjAzMTc1MjAyWhcNMTgwMjAzMTc1MjAyWjA+MQ0wCwYDVQQDDAR0b2Ri
17
+ MRgwFgYKCZImiZPyLGQBGRYIcG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000000000 Z
13
35
  dependencies:
14
36
  - !ruby/object:Gem::Dependency
15
37
  name: pcaprub
16
38
  requirement: !ruby/object:Gem::Requirement
17
39
  requirements:
18
- - - "~>"
40
+ - - ">="
19
41
  - !ruby/object:Gem::Version
20
- version: '0.12'
42
+ version: '0'
21
43
  type: :runtime
22
44
  prerelease: false
23
45
  version_requirements: !ruby/object:Gem::Requirement
24
46
  requirements:
25
- - - "~>"
47
+ - - ">="
26
48
  - !ruby/object:Gem::Version
27
- version: '0.12'
49
+ version: '0'
28
50
  - !ruby/object:Gem::Dependency
29
51
  name: rake
30
52
  requirement: !ruby/object:Gem::Requirement
31
53
  requirements:
32
- - - "~>"
54
+ - - ">="
33
55
  - !ruby/object:Gem::Version
34
- version: '10.3'
56
+ version: '0'
35
57
  type: :development
36
58
  prerelease: false
37
59
  version_requirements: !ruby/object:Gem::Requirement
38
60
  requirements:
39
- - - "~>"
61
+ - - ">="
40
62
  - !ruby/object:Gem::Version
41
- version: '10.3'
63
+ version: '0'
42
64
  - !ruby/object:Gem::Dependency
43
65
  name: rspec
44
66
  requirement: !ruby/object:Gem::Requirement
45
67
  requirements:
46
- - - "~>"
68
+ - - ">="
47
69
  - !ruby/object:Gem::Version
48
- version: '3.0'
70
+ version: '0'
49
71
  type: :development
50
72
  prerelease: false
51
73
  version_requirements: !ruby/object:Gem::Requirement
52
74
  requirements:
53
- - - "~>"
75
+ - - ">="
54
76
  - !ruby/object:Gem::Version
55
- version: '3.0'
77
+ version: '0'
56
78
  - !ruby/object:Gem::Dependency
57
79
  name: rspec-its
58
80
  requirement: !ruby/object:Gem::Requirement
59
81
  requirements:
60
- - - "~>"
82
+ - - ">="
61
83
  - !ruby/object:Gem::Version
62
- version: '1.2'
84
+ version: '0'
63
85
  type: :development
64
86
  prerelease: false
65
87
  version_requirements: !ruby/object:Gem::Requirement
66
88
  requirements:
67
- - - "~>"
89
+ - - ">="
68
90
  - !ruby/object:Gem::Version
69
- version: '1.2'
91
+ version: '0'
70
92
  - !ruby/object:Gem::Dependency
71
93
  name: sdoc
72
94
  requirement: !ruby/object:Gem::Requirement
73
95
  requirements:
74
- - - "~>"
96
+ - - ">="
75
97
  - !ruby/object:Gem::Version
76
- version: 0.4.1
98
+ version: '0'
77
99
  type: :development
78
100
  prerelease: false
79
101
  version_requirements: !ruby/object:Gem::Requirement
80
102
  requirements:
81
- - - "~>"
103
+ - - ">="
82
104
  - !ruby/object:Gem::Version
83
- version: 0.4.1
105
+ version: '0'
84
106
  - !ruby/object:Gem::Dependency
85
107
  name: pry
86
108
  requirement: !ruby/object:Gem::Requirement
@@ -152,9 +174,11 @@ files:
152
174
  - examples/oui.txt
153
175
  - examples/packetfu-shell.rb
154
176
  - examples/pcap2pcapng.rb
177
+ - examples/ping.rb
155
178
  - examples/simple-sniffer.rb
156
179
  - examples/simple-stats.rb
157
180
  - examples/slammer.rb
181
+ - examples/tcp_handshake.rb
158
182
  - examples/uniqpcap.rb
159
183
  - gem-public_cert.pem
160
184
  - lib/packetfu.rb
@@ -376,12 +400,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
376
400
  version: 2.1.0
377
401
  required_rubygems_version: !ruby/object:Gem::Requirement
378
402
  requirements:
379
- - - ">"
403
+ - - ">="
380
404
  - !ruby/object:Gem::Version
381
- version: 1.3.1
405
+ version: '0'
382
406
  requirements: []
383
407
  rubyforge_project: packetfu
384
- rubygems_version: 2.6.2
408
+ rubygems_version: 2.6.8
385
409
  signing_key:
386
410
  specification_version: 4
387
411
  summary: PacketFu is a mid-level packet manipulation library.
Binary file