packetgen 3.3.2 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +37 -21
- data/lib/packetgen/capture.rb +2 -2
- data/lib/packetgen/config.rb +0 -1
- data/lib/packetgen/deprecation.rb +7 -7
- data/lib/packetgen/header/arp.rb +13 -13
- data/lib/packetgen/header/asn1_base.rb +1 -1
- data/lib/packetgen/header/base.rb +17 -18
- data/lib/packetgen/header/bootp.rb +32 -34
- data/lib/packetgen/header/dhcp/option.rb +19 -19
- data/lib/packetgen/header/dhcp/options.rb +1 -1
- data/lib/packetgen/header/dhcp.rb +3 -3
- data/lib/packetgen/header/dhcpv6/duid.rb +16 -16
- data/lib/packetgen/header/dhcpv6/option.rb +53 -53
- data/lib/packetgen/header/dhcpv6/options.rb +1 -1
- data/lib/packetgen/header/dhcpv6/relay.rb +5 -5
- data/lib/packetgen/header/dhcpv6.rb +6 -6
- data/lib/packetgen/header/dns/name.rb +14 -10
- data/lib/packetgen/header/dns/opt.rb +2 -2
- data/lib/packetgen/header/dns/option.rb +11 -11
- data/lib/packetgen/header/dns/qdsection.rb +1 -1
- data/lib/packetgen/header/dns/question.rb +6 -8
- data/lib/packetgen/header/dns/rr.rb +56 -43
- data/lib/packetgen/header/dns/rrsection.rb +4 -4
- data/lib/packetgen/header/dns.rb +27 -30
- data/lib/packetgen/header/dot11/control.rb +11 -11
- data/lib/packetgen/header/dot11/data.rb +20 -20
- data/lib/packetgen/header/dot11/element.rb +4 -4
- data/lib/packetgen/header/dot11/management.rb +8 -8
- data/lib/packetgen/header/dot11/sub_mngt.rb +39 -53
- data/lib/packetgen/header/dot11.rb +88 -93
- data/lib/packetgen/header/dot1q.rb +10 -12
- data/lib/packetgen/header/dot1x.rb +9 -9
- data/lib/packetgen/header/eap/fast.rb +4 -4
- data/lib/packetgen/header/eap/md5.rb +6 -6
- data/lib/packetgen/header/eap/tls.rb +13 -15
- data/lib/packetgen/header/eap/ttls.rb +13 -15
- data/lib/packetgen/header/eap.rb +22 -22
- data/lib/packetgen/header/eth.rb +18 -18
- data/lib/packetgen/header/gre.rb +8 -10
- data/lib/packetgen/header/http/headers.rb +2 -2
- data/lib/packetgen/header/http/request.rb +17 -16
- data/lib/packetgen/header/http/response.rb +18 -17
- data/lib/packetgen/header/http/verbs.rb +1 -3
- data/lib/packetgen/header/icmp.rb +8 -8
- data/lib/packetgen/header/icmpv6.rb +3 -3
- data/lib/packetgen/header/igmp.rb +8 -8
- data/lib/packetgen/header/igmpv3/group_record.rb +12 -12
- data/lib/packetgen/header/igmpv3/mq.rb +16 -18
- data/lib/packetgen/header/igmpv3/mr.rb +4 -4
- data/lib/packetgen/header/igmpv3.rb +7 -7
- data/lib/packetgen/header/ip/addr.rb +13 -13
- data/lib/packetgen/header/ip/option.rb +31 -33
- data/lib/packetgen/header/ip/options.rb +1 -1
- data/lib/packetgen/header/ip.rb +37 -72
- data/lib/packetgen/header/ipv6/addr.rb +14 -14
- data/lib/packetgen/header/ipv6/extension.rb +8 -8
- data/lib/packetgen/header/ipv6/hop_by_hop.rb +9 -9
- data/lib/packetgen/header/ipv6.rb +20 -22
- data/lib/packetgen/header/llc.rb +17 -17
- data/lib/packetgen/header/mdns.rb +1 -1
- data/lib/packetgen/header/mld.rb +6 -6
- data/lib/packetgen/header/mldv2/mcast_address_record.rb +11 -11
- data/lib/packetgen/header/mldv2/mlq.rb +21 -23
- data/lib/packetgen/header/mldv2/mlr.rb +8 -8
- data/lib/packetgen/header/ospfv2/db_description.rb +11 -12
- data/lib/packetgen/header/ospfv2/hello.rb +11 -11
- data/lib/packetgen/header/ospfv2/ls_ack.rb +1 -1
- data/lib/packetgen/header/ospfv2/ls_request.rb +9 -9
- data/lib/packetgen/header/ospfv2/ls_update.rb +3 -3
- data/lib/packetgen/header/ospfv2/lsa.rb +54 -58
- data/lib/packetgen/header/ospfv2/lsa_header.rb +9 -9
- data/lib/packetgen/header/ospfv2.rb +27 -29
- data/lib/packetgen/header/ospfv3/db_description.rb +13 -14
- data/lib/packetgen/header/ospfv3/hello.rb +12 -12
- data/lib/packetgen/header/ospfv3/ipv6_prefix.rb +17 -19
- data/lib/packetgen/header/ospfv3/ls_ack.rb +2 -2
- data/lib/packetgen/header/ospfv3/ls_request.rb +9 -9
- data/lib/packetgen/header/ospfv3/ls_update.rb +4 -4
- data/lib/packetgen/header/ospfv3/lsa.rb +48 -51
- data/lib/packetgen/header/ospfv3/lsa_header.rb +9 -9
- data/lib/packetgen/header/ospfv3.rb +25 -27
- data/lib/packetgen/header/sctp/chunk.rb +44 -41
- data/lib/packetgen/header/sctp/error.rb +52 -52
- data/lib/packetgen/header/sctp/parameter.rb +38 -38
- data/lib/packetgen/header/sctp.rb +5 -5
- data/lib/packetgen/header/snmp.rb +2 -2
- data/lib/packetgen/header/tcp/option.rb +45 -39
- data/lib/packetgen/header/tcp/options.rb +2 -2
- data/lib/packetgen/header/tcp.rb +55 -44
- data/lib/packetgen/header/tftp.rb +16 -16
- data/lib/packetgen/header/udp.rb +8 -8
- data/lib/packetgen/header.rb +9 -10
- data/lib/packetgen/headerable.rb +13 -3
- data/lib/packetgen/inspect.rb +2 -2
- data/lib/packetgen/packet.rb +54 -37
- data/lib/packetgen/pcap.rb +15 -4
- data/lib/packetgen/pcapng/block.rb +18 -17
- data/lib/packetgen/pcapng/epb.rb +13 -15
- data/lib/packetgen/pcapng/file.rb +3 -97
- data/lib/packetgen/pcapng/idb.rb +9 -11
- data/lib/packetgen/pcapng/shb.rb +13 -15
- data/lib/packetgen/pcapng/spb.rb +8 -10
- data/lib/packetgen/pcapng/unknown_block.rb +6 -17
- data/lib/packetgen/pcapng.rb +4 -4
- data/lib/packetgen/pcaprub_wrapper.rb +17 -1
- data/lib/packetgen/proto.rb +1 -1
- data/lib/packetgen/unknown_packet.rb +2 -2
- data/lib/packetgen/utils/arp_spoofer.rb +18 -19
- data/lib/packetgen/utils.rb +2 -2
- data/lib/packetgen/version.rb +1 -1
- data/lib/packetgen.rb +4 -3
- metadata +34 -29
- data/lib/packetgen/types/abstract_tlv.rb +0 -278
- data/lib/packetgen/types/array.rb +0 -287
- data/lib/packetgen/types/cstring.rb +0 -109
- data/lib/packetgen/types/enum.rb +0 -171
- data/lib/packetgen/types/fieldable.rb +0 -66
- data/lib/packetgen/types/fields.rb +0 -622
- data/lib/packetgen/types/int.rb +0 -473
- data/lib/packetgen/types/int_string.rb +0 -102
- data/lib/packetgen/types/length_from.rb +0 -54
- data/lib/packetgen/types/oui.rb +0 -52
- data/lib/packetgen/types/string.rb +0 -97
- data/lib/packetgen/types/tlv.rb +0 -161
- data/lib/packetgen/types.rb +0 -26
@@ -11,19 +11,55 @@ module PacketGen
|
|
11
11
|
class DNS
|
12
12
|
# DNS Ressource Record
|
13
13
|
# @author Sylvain Daubert
|
14
|
+
# @author LemonTree55
|
14
15
|
class RR < Question
|
15
16
|
# @!attribute ttl
|
16
17
|
# 32-bit time to live
|
17
18
|
# @return [Integer]
|
18
|
-
|
19
|
+
define_attr :ttl, BinStruct::Int32
|
19
20
|
# @!attribute rdlength
|
20
21
|
# 16-bit {#rdata} length
|
21
22
|
# @return [Integer]
|
22
|
-
|
23
|
+
define_attr :rdlength, BinStruct::Int16
|
23
24
|
# @!attribute rdata
|
24
|
-
# @return [
|
25
|
-
|
26
|
-
|
25
|
+
# @return [BinStruct::String]
|
26
|
+
define_attr :rdata, BinStruct::String,
|
27
|
+
builder: ->(rr, t) { t.new(length_from: rr[:rdlength]) }
|
28
|
+
|
29
|
+
# @private RData struct
|
30
|
+
class RData < BinStruct::Struct
|
31
|
+
attr_accessor :dns
|
32
|
+
|
33
|
+
def initialize(options={})
|
34
|
+
@dns = options.delete(:dns)
|
35
|
+
super
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# @private MX struct
|
40
|
+
class MX < RData
|
41
|
+
define_attr :pref, BinStruct::Int16
|
42
|
+
define_attr :exchange, Name, builder: ->(h, t) { t.new(dns: h.dns) }
|
43
|
+
end
|
44
|
+
|
45
|
+
# @private SOA struct
|
46
|
+
class SOA < RData
|
47
|
+
define_attr :mname, Name, builder: ->(h, t) { t.new(dns: h.dns) }
|
48
|
+
define_attr :rname, Name, builder: ->(h, t) { t.new(dns: h.dns) }
|
49
|
+
define_attr :serial, BinStruct::Int32
|
50
|
+
define_attr :refresh, BinStruct::Int32
|
51
|
+
define_attr :retryi, BinStruct::Int32
|
52
|
+
define_attr :expire, BinStruct::Int32
|
53
|
+
define_attr :minimum, BinStruct::Int32
|
54
|
+
end
|
55
|
+
|
56
|
+
# @private SRV struct
|
57
|
+
class SRV < RData
|
58
|
+
define_attr :priority, BinStruct::Int16
|
59
|
+
define_attr :weight, BinStruct::Int16
|
60
|
+
define_attr :port, BinStruct::Int16
|
61
|
+
define_attr :target, Name, builder: ->(h, t) { t.new(dns: h.dns) }
|
62
|
+
end
|
27
63
|
|
28
64
|
# @param [DNS] dns
|
29
65
|
# @param [Hash] options
|
@@ -47,8 +83,8 @@ module PacketGen
|
|
47
83
|
# @param [String] data
|
48
84
|
# @return [void]
|
49
85
|
def rdata=(data)
|
50
|
-
self[:rdlength].
|
51
|
-
self[:rdata].read
|
86
|
+
self[:rdlength].from_human(data.size)
|
87
|
+
self[:rdata].read(data)
|
52
88
|
end
|
53
89
|
|
54
90
|
# rubocop:disable Metrics/AbcSize
|
@@ -60,8 +96,7 @@ module PacketGen
|
|
60
96
|
|
61
97
|
case type
|
62
98
|
when TYPES['NS'], TYPES['PTR'], TYPES['CNAME']
|
63
|
-
name = Name.new
|
64
|
-
name.dns = self[:name].dns
|
99
|
+
name = Name.new(dns: self[:name].dns)
|
65
100
|
str = name.read(self[:rdata]).to_human
|
66
101
|
when TYPES['SOA']
|
67
102
|
str = human_soa_rdata
|
@@ -78,9 +113,9 @@ module PacketGen
|
|
78
113
|
# Get human readable class
|
79
114
|
# @return [String]
|
80
115
|
def human_rrclass
|
81
|
-
if self[:name].dns.is_a?
|
116
|
+
if self[:name].dns.is_a?(MDNS)
|
82
117
|
str = self.class::CLASSES.key(self.rrclass & 0x7fff) || '0x%04x' % (self.rrclass & 0x7fff)
|
83
|
-
str += ' CACHE-FLUSH' if
|
118
|
+
str += ' CACHE-FLUSH' if self.rrclass.anybits?(0x8000)
|
84
119
|
str
|
85
120
|
else
|
86
121
|
self.class::CLASSES.key(self.rrclass) || '0x%04x' % self.rrclass
|
@@ -100,49 +135,27 @@ module PacketGen
|
|
100
135
|
|
101
136
|
case type
|
102
137
|
when TYPES['A'], TYPES['AAAA']
|
103
|
-
IPAddr.new_ntoh(self[:rdata]).to_s
|
138
|
+
IPAddr.new_ntoh(self[:rdata].string).to_s
|
104
139
|
end
|
105
140
|
end
|
106
141
|
|
107
142
|
def human_mx_data
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
pref = Types::Int16.new.read(self[:rdata][0, 2])
|
112
|
-
exchange = name.read(self[:rdata][2..]).to_human
|
113
|
-
|
114
|
-
'%u %s' % [pref.to_i, exchange]
|
143
|
+
mx = MX.new(dns: self[:name].dns).read(self[:rdata])
|
144
|
+
"#{mx.pref} #{mx.exchange}"
|
115
145
|
end
|
116
146
|
|
117
|
-
# rubocop:disable Metrics/AbcSize
|
147
|
+
# /rubocop:disable Metrics/AbcSize
|
118
148
|
def human_soa_rdata
|
119
|
-
|
120
|
-
|
121
|
-
mname
|
122
|
-
|
123
|
-
|
124
|
-
serial = Types::Int32.new.read(self[:rdata][mname.sz + rname.sz, 4])
|
125
|
-
refresh = Types::Int32.new.read(self[:rdata][mname.sz + rname.sz + 4, 4])
|
126
|
-
retryi = Types::Int32.new.read(self[:rdata][mname.sz + rname.sz + 8, 4])
|
127
|
-
expire = Types::Int32.new.read(self[:rdata][mname.sz + rname.sz + 12, 4])
|
128
|
-
minimum = Types::Int32.new.read(self[:rdata][mname.sz + rname.sz + 16, 4])
|
129
|
-
|
130
|
-
"#{mname.to_human} #{rname.to_human} #{serial.to_i} #{refresh.to_i} " \
|
131
|
-
"#{retryi.to_i} #{expire.to_i} #{minimum.to_i}"
|
149
|
+
soa = SOA.new(dns: self[:name].dns).read(self[:rdata])
|
150
|
+
|
151
|
+
"#{soa.mname} #{soa.rname} #{soa.serial} #{soa.refresh} " \
|
152
|
+
"#{soa.retryi} #{soa.expire} #{soa.minimum}"
|
132
153
|
end
|
133
154
|
|
134
155
|
def human_srv_data
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
priority = Types::Int16.new.read(self[:rdata][0, 2])
|
139
|
-
weight = Types::Int16.new.read(self[:rdata][2, 2])
|
140
|
-
port = Types::Int16.new.read(self[:rdata][4, 2])
|
141
|
-
target = name.read(self[:rdata][6, self[:rdata].size]).to_human
|
142
|
-
|
143
|
-
"#{priority.to_i} #{weight.to_i} #{port.to_i} #{target}"
|
156
|
+
srv = SRV.new(dns: self[:name].dns).read(self[:rdata])
|
157
|
+
"#{srv.priority} #{srv.weight} #{srv.port} #{srv.target}"
|
144
158
|
end
|
145
|
-
# rubocop:enable Metrics/AbcSize
|
146
159
|
end
|
147
160
|
end
|
148
161
|
end
|
@@ -11,10 +11,10 @@ module PacketGen
|
|
11
11
|
class DNS
|
12
12
|
# Define a DNS Ressource Record Section
|
13
13
|
# @author Sylvain Daubert
|
14
|
-
class RRSection <
|
14
|
+
class RRSection < BinStruct::Array
|
15
15
|
# @api private
|
16
16
|
# @param [DNS] dns
|
17
|
-
# @param [
|
17
|
+
# @param [BinStruct::Int] counter
|
18
18
|
def initialize(dns, counter)
|
19
19
|
super(counter: counter)
|
20
20
|
@dns = dns
|
@@ -32,7 +32,7 @@ module PacketGen
|
|
32
32
|
rr = RR.new(@dns).read(str)
|
33
33
|
rr = OPT.new(@dns).read(str) if rr.type?('OPT')
|
34
34
|
str.slice!(0, rr.sz)
|
35
|
-
push
|
35
|
+
push(rr)
|
36
36
|
end
|
37
37
|
self
|
38
38
|
end
|
@@ -40,7 +40,7 @@ module PacketGen
|
|
40
40
|
private
|
41
41
|
|
42
42
|
def record_from_hash(hsh)
|
43
|
-
if hsh.key?
|
43
|
+
if hsh.key?(:rtype)
|
44
44
|
case hsh.delete(:rtype)
|
45
45
|
when 'Question'
|
46
46
|
Question.new(@dns, hsh)
|
data/lib/packetgen/header/dns.rb
CHANGED
@@ -141,35 +141,9 @@ module PacketGen
|
|
141
141
|
|
142
142
|
# @!attribute id
|
143
143
|
# @return [Integer]
|
144
|
-
|
144
|
+
define_attr :id, BinStruct::Int16
|
145
145
|
# @!attribute u16
|
146
146
|
# @return [Integer]
|
147
|
-
define_field :u16, Types::Int16
|
148
|
-
# @!attribute qdcount
|
149
|
-
# @return [Integer]
|
150
|
-
define_field :qdcount, Types::Int16
|
151
|
-
# @!attribute ancount
|
152
|
-
# @return [Integer]
|
153
|
-
define_field :ancount, Types::Int16
|
154
|
-
# @!attribute nscount
|
155
|
-
# @return [Integer]
|
156
|
-
define_field :nscount, Types::Int16
|
157
|
-
# @!attribute arcount
|
158
|
-
# @return [Integer]
|
159
|
-
define_field :arcount, Types::Int16
|
160
|
-
# @!attribute qd
|
161
|
-
# @return [QDSection]
|
162
|
-
define_field :qd, QDSection, builder: ->(h, t) { t.new(h, h[:qdcount]) }
|
163
|
-
# @!attribute an
|
164
|
-
# @return [RRSection]
|
165
|
-
define_field :an, RRSection, builder: ->(h, t) { t.new(h, h[:ancount]) }
|
166
|
-
# @!attribute ns
|
167
|
-
# @return [RRSection]
|
168
|
-
define_field :ns, RRSection, builder: ->(h, t) { t.new(h, h[:nscount]) }
|
169
|
-
# @!attribute ar
|
170
|
-
# @return [RRSection]
|
171
|
-
define_field :ar, RRSection, builder: ->(h, t) { t.new(h, h[:arcount]) }
|
172
|
-
|
173
147
|
# @!attribute qr
|
174
148
|
# @return [Boolean] query (+false+) or response (+true+)
|
175
149
|
# @!attribute opcode
|
@@ -188,11 +162,34 @@ module PacketGen
|
|
188
162
|
# @return [Boolean] Checking Disabled
|
189
163
|
# @!attribute rcode
|
190
164
|
# @return [Integer] Response code. See {RCODES}.
|
191
|
-
|
192
|
-
:ad, :cd, :rcode, 4
|
193
|
-
|
165
|
+
define_bit_attr :u16, qr: 1, opcode: 4, aa: 1, tc: 1, rd: 1, ra: 1, z: 1, ad: 1, cd: 1, rcode: 4
|
194
166
|
undef opcode=, rcode=
|
195
167
|
|
168
|
+
# @!attribute qdcount
|
169
|
+
# @return [Integer]
|
170
|
+
define_attr :qdcount, BinStruct::Int16
|
171
|
+
# @!attribute ancount
|
172
|
+
# @return [Integer]
|
173
|
+
define_attr :ancount, BinStruct::Int16
|
174
|
+
# @!attribute nscount
|
175
|
+
# @return [Integer]
|
176
|
+
define_attr :nscount, BinStruct::Int16
|
177
|
+
# @!attribute arcount
|
178
|
+
# @return [Integer]
|
179
|
+
define_attr :arcount, BinStruct::Int16
|
180
|
+
# @!attribute qd
|
181
|
+
# @return [QDSection]
|
182
|
+
define_attr :qd, QDSection, builder: ->(h, t) { t.new(h, h[:qdcount]) }
|
183
|
+
# @!attribute an
|
184
|
+
# @return [RRSection]
|
185
|
+
define_attr :an, RRSection, builder: ->(h, t) { t.new(h, h[:ancount]) }
|
186
|
+
# @!attribute ns
|
187
|
+
# @return [RRSection]
|
188
|
+
define_attr :ns, RRSection, builder: ->(h, t) { t.new(h, h[:nscount]) }
|
189
|
+
# @!attribute ar
|
190
|
+
# @return [RRSection]
|
191
|
+
define_attr :ar, RRSection, builder: ->(h, t) { t.new(h, h[:arcount]) }
|
192
|
+
|
196
193
|
# Set opcode
|
197
194
|
# @param [Integer,String] value
|
198
195
|
# @return [Integer]
|
@@ -16,12 +16,12 @@ module PacketGen
|
|
16
16
|
# (control frame).
|
17
17
|
#
|
18
18
|
# A IEEE 802.11 control header consists of:
|
19
|
-
# * a {#frame_ctrl} ({
|
20
|
-
# * a {#id}/duration ({
|
19
|
+
# * a {#frame_ctrl} ({BinStruct::Int16}),
|
20
|
+
# * a {#id}/duration ({BinStruct::Int16le}),
|
21
21
|
# * a {#mac1} ({Eth::MacAddr}).
|
22
22
|
# * sometimes a {#mac2} ({Eth::MacAddr}),
|
23
|
-
# * a {#body} (a {
|
24
|
-
# * and a Frame check sequence ({#fcs}, of type {
|
23
|
+
# * a {#body} (a {BinStruct::String} or another {Base} class),
|
24
|
+
# * and a Frame check sequence ({#fcs}, of type {BinStruct::Int32le}).
|
25
25
|
# @author Sylvain Daubert
|
26
26
|
class Control < Dot11
|
27
27
|
# Control subtypes
|
@@ -44,8 +44,8 @@ module PacketGen
|
|
44
44
|
# @see Base#initialize
|
45
45
|
def initialize(options={})
|
46
46
|
super({ type: 1 }.merge!(options))
|
47
|
-
@
|
48
|
-
|
47
|
+
@applicable_attributes -= %i[mac3 sequence_ctrl mac4 qos_ctrl ht_ctrl]
|
48
|
+
define_applicable_attributes
|
49
49
|
end
|
50
50
|
|
51
51
|
# Get human readable subtype
|
@@ -56,12 +56,12 @@ module PacketGen
|
|
56
56
|
|
57
57
|
private
|
58
58
|
|
59
|
-
def
|
59
|
+
def define_applicable_attributes
|
60
60
|
super
|
61
|
-
if @
|
62
|
-
@
|
63
|
-
elsif SUBTYPES_WITH_MAC2.include?
|
64
|
-
@
|
61
|
+
if @applicable_attributes.include?(:mac2)
|
62
|
+
@applicable_attributes -= %i[mac2] unless SUBTYPES_WITH_MAC2.include?(self.subtype)
|
63
|
+
elsif SUBTYPES_WITH_MAC2.include?(self.subtype)
|
64
|
+
@applicable_attributes[3, 0] = :mac2
|
65
65
|
end
|
66
66
|
end
|
67
67
|
end
|
@@ -16,23 +16,23 @@ module PacketGen
|
|
16
16
|
# (data frame).
|
17
17
|
#
|
18
18
|
# A IEEE 802.11 data header consists of:
|
19
|
-
# * a {#frame_ctrl} ({
|
20
|
-
# * a {#id}/duration ({
|
19
|
+
# * a {#frame_ctrl} ({BinStruct::Int16}),
|
20
|
+
# * a {#id}/duration ({BinStruct::Int16le}),
|
21
21
|
# * a {#mac2} ({Eth::MacAddr}),
|
22
22
|
# * a {#mac3} ({Eth::MacAddr}),
|
23
|
-
# * a {#sequence_ctrl} ({
|
23
|
+
# * a {#sequence_ctrl} ({BinStruct::Int16}),
|
24
24
|
# * sometimes a {#mac4} ({Eth::MacAddr}),
|
25
|
-
# * sometimes a {#qos_ctrl} ({
|
26
|
-
# * a {#body} (a {
|
27
|
-
# * and a Frame check sequence ({#fcs}, of type {
|
25
|
+
# * sometimes a {#qos_ctrl} ({BinStruct::Int16}),
|
26
|
+
# * a {#body} (a {BinStruct::String} or another {Base} class),
|
27
|
+
# * and a Frame check sequence ({#fcs}, of type {BinStruct::Int32le}).
|
28
28
|
# @author Sylvain Daubert
|
29
29
|
class Data < Dot11
|
30
30
|
# @param [Hash] options
|
31
31
|
# @see Base#initialize
|
32
32
|
def initialize(options={})
|
33
33
|
super({ type: 2 }.merge!(options))
|
34
|
-
@
|
35
|
-
|
34
|
+
@applicable_attributes -= %i[mac4 qos_ctrl ht_ctrl]
|
35
|
+
define_applicable_attributes
|
36
36
|
end
|
37
37
|
|
38
38
|
# Invert source and destination addresses (see Table 8-19 from
|
@@ -45,22 +45,22 @@ module PacketGen
|
|
45
45
|
case ds
|
46
46
|
when 0
|
47
47
|
# MAC1: RA/DA, MAC2: TA/SA
|
48
|
-
invert_mac
|
48
|
+
invert_mac(:mac1, :mac2)
|
49
49
|
when 1
|
50
50
|
# MAC1: RA/BSSID, MAC2: TA/SA, MAC3: DA
|
51
|
-
invert_mac
|
51
|
+
invert_mac(:mac1, :mac2)
|
52
52
|
self.to_ds = false
|
53
53
|
self.from_ds = true
|
54
54
|
when 2
|
55
55
|
# MAC1: RA/DA, MAC2: BSSID, MAC3: SA or BSSID
|
56
|
-
invert_mac
|
56
|
+
invert_mac(:mac1, :mac2)
|
57
57
|
self.to_ds = true
|
58
58
|
self.from_ds = false
|
59
59
|
when 3
|
60
60
|
# MAC1: RA, MAC2: TA
|
61
|
-
invert_mac
|
61
|
+
invert_mac(:mac1, :mac2)
|
62
62
|
# MAC3: DA, MAC4: SA
|
63
|
-
invert_mac
|
63
|
+
invert_mac(:mac3, :mac4)
|
64
64
|
end
|
65
65
|
self
|
66
66
|
end
|
@@ -111,19 +111,19 @@ module PacketGen
|
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
114
|
-
def
|
114
|
+
def define_applicable_attributes
|
115
115
|
super
|
116
|
-
if (subtype >= 8) && !@
|
116
|
+
if (subtype >= 8) && !@applicable_attributes.include?(:qos_ctrl)
|
117
117
|
# Insert after mac4, if present
|
118
118
|
# else insert after sequence_ctrl
|
119
|
-
if @
|
120
|
-
idx = @
|
121
|
-
@
|
119
|
+
if @applicable_attributes.include? :mac4
|
120
|
+
idx = @applicable_attributes.index(:mac4)
|
121
|
+
@applicable_attributes[idx, 0] = :qos_ctrl
|
122
122
|
else
|
123
|
-
@
|
123
|
+
@applicable_attributes[6, 0] = :qos_ctrl
|
124
124
|
end
|
125
125
|
elsif subtype < 8
|
126
|
-
@
|
126
|
+
@applicable_attributes -= %i[qos_ctrl]
|
127
127
|
end
|
128
128
|
end
|
129
129
|
|
@@ -15,10 +15,10 @@ module PacketGen
|
|
15
15
|
# #
|
16
16
|
# # An {Element} is a piece of data contained in a Dot11 management frame.
|
17
17
|
# # @since 1.4.0
|
18
|
-
# # @since 3.1.0 subclass of {
|
19
|
-
# class Element <
|
18
|
+
# # @since 3.1.0 subclass of {BinStruct::AbstractTLV}
|
19
|
+
# class Element < BinStruct::AbstractTLV; end
|
20
20
|
# @private
|
21
|
-
Element =
|
21
|
+
Element = BinStruct::AbstractTLV.create
|
22
22
|
|
23
23
|
class Element
|
24
24
|
# Known element types
|
@@ -44,7 +44,7 @@ module PacketGen
|
|
44
44
|
|
45
45
|
# Array of {Element}.
|
46
46
|
# @since 3.1.1
|
47
|
-
class ArrayOfElements <
|
47
|
+
class ArrayOfElements < BinStruct::Array
|
48
48
|
set_of Element
|
49
49
|
end
|
50
50
|
end
|
@@ -16,14 +16,14 @@ module PacketGen
|
|
16
16
|
# (management frame).
|
17
17
|
#
|
18
18
|
# A IEEE 802.11 management header consists of:
|
19
|
-
# * a {#frame_ctrl} ({
|
20
|
-
# * a {#id}/duration ({
|
19
|
+
# * a {#frame_ctrl} ({BinStruct::Int16}),
|
20
|
+
# * a {#id}/duration ({BinStruct::Int16le}),
|
21
21
|
# * a {#mac1} ({Eth::MacAddr}).
|
22
22
|
# * a {#mac2} ({Eth::MacAddr}),
|
23
23
|
# * a {#mac3} ({Eth::MacAddr}),
|
24
|
-
# * a {#sequence_ctrl} ({
|
25
|
-
# * a {#body} (a {
|
26
|
-
# * and a Frame check sequence ({#fcs}, of type {
|
24
|
+
# * a {#sequence_ctrl} ({BinStruct::Int16}),
|
25
|
+
# * a {#body} (a {BinStruct::String} or another {Base} class),
|
26
|
+
# * and a Frame check sequence ({#fcs}, of type {BinStruct::Int32le}).
|
27
27
|
#
|
28
28
|
# Management frames should be constructed with more headers from
|
29
29
|
# {SubMngt} subclasses.
|
@@ -44,8 +44,8 @@ module PacketGen
|
|
44
44
|
# @see Base#initialize
|
45
45
|
def initialize(options={})
|
46
46
|
super({ type: 0 }.merge!(options))
|
47
|
-
@
|
48
|
-
|
47
|
+
@applicable_attributes -= %i[mac4 qos_ctrl ht_ctrl]
|
48
|
+
define_applicable_attributes
|
49
49
|
end
|
50
50
|
|
51
51
|
# Add an {Element}
|
@@ -54,7 +54,7 @@ module PacketGen
|
|
54
54
|
# @return [self]
|
55
55
|
# @since 2.1.3
|
56
56
|
def add_element(type:, value:)
|
57
|
-
raise FormatError, 'Before adding an Element, you have to add a Dot11::SubMngt subclass instance' unless self[:body].is_a?
|
57
|
+
raise FormatError, 'Before adding an Element, you have to add a Dot11::SubMngt subclass instance' unless self[:body].is_a?(SubMngt)
|
58
58
|
|
59
59
|
self[:body].elements << { type: type, value: value }
|
60
60
|
self
|
@@ -20,21 +20,7 @@ module PacketGen
|
|
20
20
|
# @author Sylvain Daubert
|
21
21
|
class SubMngt < Base
|
22
22
|
# @return [Array<Element>]
|
23
|
-
|
24
|
-
|
25
|
-
# Add an {Element} to header
|
26
|
-
# @param [Integer,String] type element type
|
27
|
-
# @param [Object] value element value
|
28
|
-
# @return [self]
|
29
|
-
# @since 2.1.3
|
30
|
-
# @since 3.1.1 #elements in no more an Array but an {ArrayOfElements}
|
31
|
-
# @deprecated Prefer use of +submngt.element << {type: type, value: value}+
|
32
|
-
def add_element(type:, value:)
|
33
|
-
Deprecation.deprecated(self.class, __method__, 'elements')
|
34
|
-
element = Element.new(type: type, value: value)
|
35
|
-
self.elements << element
|
36
|
-
self
|
37
|
-
end
|
23
|
+
define_attr :elements, ArrayOfElements
|
38
24
|
end
|
39
25
|
|
40
26
|
# IEEE 802.11 Association Request frame
|
@@ -42,16 +28,16 @@ module PacketGen
|
|
42
28
|
# Specialize {Dot11::Management} with +subtype+ set to 0.
|
43
29
|
#
|
44
30
|
# Add fields:
|
45
|
-
# * {#cap} ({
|
46
|
-
# * {#listen_interval} ({
|
31
|
+
# * {#cap} ({BinStruct::Int16le}),
|
32
|
+
# * {#listen_interval} ({BinStruct::Int16le}).
|
47
33
|
# @author Sylvain Daubert
|
48
34
|
class AssoReq < SubMngt
|
49
35
|
# @!attribute cap
|
50
36
|
# @return [Integer] 16-bit capabillities word
|
51
|
-
|
37
|
+
define_attr_before :elements, :cap, BinStruct::Int16le
|
52
38
|
# @!attribute listen_interval
|
53
39
|
# @return [Integer] 16-bit listen interval value
|
54
|
-
|
40
|
+
define_attr_before :elements, :listen_interval, BinStruct::Int16le, default: 0x00c8
|
55
41
|
end
|
56
42
|
Header.add_class AssoReq
|
57
43
|
Management.bind AssoReq, type: 0, subtype: 0
|
@@ -61,20 +47,20 @@ module PacketGen
|
|
61
47
|
# Specialize {Dot11::Management} with +subtype+ set to 1.
|
62
48
|
#
|
63
49
|
# Add fields:
|
64
|
-
# * {#cap} ({
|
65
|
-
# * {#status} ({
|
66
|
-
# * {#aid} ({
|
50
|
+
# * {#cap} ({BinStruct::Int16le}),
|
51
|
+
# * {#status} ({BinStruct::Int16le}),
|
52
|
+
# * {#aid} ({BinStruct::Int16le}).
|
67
53
|
# @author Sylvain Daubert
|
68
54
|
class AssoResp < SubMngt
|
69
55
|
# @!attribute cap
|
70
56
|
# @return [Integer] 16-bit capabillities word
|
71
|
-
|
57
|
+
define_attr_before :elements, :cap, BinStruct::Int16le
|
72
58
|
# @!attribute status
|
73
59
|
# @return [Integer] 16-bit status word
|
74
|
-
|
60
|
+
define_attr_before :elements, :status, BinStruct::Int16le
|
75
61
|
# @!attribute aid
|
76
62
|
# @return [Integer] 16-bit AID word
|
77
|
-
|
63
|
+
define_attr_before :elements, :aid, BinStruct::Int16le
|
78
64
|
end
|
79
65
|
Header.add_class AssoResp
|
80
66
|
Management.bind AssoResp, type: 0, subtype: 1
|
@@ -84,14 +70,14 @@ module PacketGen
|
|
84
70
|
# Specialize {Dot11::Management} with +subtype+ set to 2.
|
85
71
|
#
|
86
72
|
# Add fields:
|
87
|
-
# * {#cap} ({
|
88
|
-
# * {#listen_interval} ({
|
73
|
+
# * {#cap} ({BinStruct::Int16le}),
|
74
|
+
# * {#listen_interval} ({BinStruct::Int16le}),
|
89
75
|
# * {#current_ap} ({Eth::MacAddr}).
|
90
76
|
# @author Sylvain Daubert
|
91
77
|
class ReAssoReq < AssoReq
|
92
78
|
# @!attribute current_ap
|
93
79
|
# @return [Eth::MAcAddr]
|
94
|
-
|
80
|
+
define_attr_before :elements, :current_ap, Eth::MacAddr
|
95
81
|
end
|
96
82
|
Header.add_class ReAssoReq
|
97
83
|
Management.bind ReAssoReq, type: 0, subtype: 2
|
@@ -101,9 +87,9 @@ module PacketGen
|
|
101
87
|
# Specialize {Dot11::Management} with +subtype+ set to 3.
|
102
88
|
#
|
103
89
|
# Add fields:
|
104
|
-
# * {#cap} ({
|
105
|
-
# * {#status} ({
|
106
|
-
# * {#aid} ({
|
90
|
+
# * {#cap} ({BinStruct::Int16le}),
|
91
|
+
# * {#status} ({BinStruct::Int16le}),
|
92
|
+
# * {#aid} ({BinStruct::Int16le}).
|
107
93
|
# @author Sylvain Daubert
|
108
94
|
class ReAssoResp < AssoResp
|
109
95
|
end
|
@@ -126,20 +112,20 @@ module PacketGen
|
|
126
112
|
# Specialize {Dot11::Management} with +subtype+ set to 5.
|
127
113
|
#
|
128
114
|
# Add fields:
|
129
|
-
# * {#timestamp} ({
|
130
|
-
# * {#beacon_interval} ({
|
131
|
-
# * {#cap} ({
|
115
|
+
# * {#timestamp} ({BinStruct::Int64le}),
|
116
|
+
# * {#beacon_interval} ({BinStruct::Int16le}),
|
117
|
+
# * {#cap} ({BinStruct::Int16le}).
|
132
118
|
# @author Sylvain Daubert
|
133
119
|
class ProbeResp < SubMngt
|
134
120
|
# @!attribute timestamp
|
135
121
|
# @return [Integer] 64-bit timestamp
|
136
|
-
|
122
|
+
define_attr_before :elements, :timestamp, BinStruct::Int64le
|
137
123
|
# @!attribute beacon_interval
|
138
124
|
# @return [Integer] 16-bit beacon interval value
|
139
|
-
|
125
|
+
define_attr_before :elements, :beacon_interval, BinStruct::Int16le, default: 0x0064
|
140
126
|
# @!attribute cap
|
141
127
|
# @return [Integer] 16-bit capabillities word
|
142
|
-
|
128
|
+
define_attr_before :elements, :cap, BinStruct::Int16le
|
143
129
|
end
|
144
130
|
Header.add_class ProbeResp
|
145
131
|
Management.bind ProbeResp, type: 0, subtype: 5
|
@@ -149,20 +135,20 @@ module PacketGen
|
|
149
135
|
# Specialize {Dot11::Management} with +subtype+ set to 8.
|
150
136
|
#
|
151
137
|
# Add fields:
|
152
|
-
# * {#timestamp} ({
|
153
|
-
# * {#interval} ({
|
154
|
-
# * {#cap} ({
|
138
|
+
# * {#timestamp} ({BinStruct::Int64le}),
|
139
|
+
# * {#interval} ({BinStruct::Int16le}),
|
140
|
+
# * {#cap} ({BinStruct::Int16le}).
|
155
141
|
# @author Sylvain Daubert
|
156
142
|
class Beacon < SubMngt
|
157
143
|
# @!attribute timestamp
|
158
144
|
# @return [Integer] 64-bit timestamp
|
159
|
-
|
145
|
+
define_attr_before :elements, :timestamp, BinStruct::Int64le
|
160
146
|
# @!attribute interval
|
161
147
|
# @return [Integer] 16-bit interval value
|
162
|
-
|
148
|
+
define_attr_before :elements, :interval, BinStruct::Int16le, default: 0x64
|
163
149
|
# @!attribute cap
|
164
150
|
# @return [Integer] 16-bit capabillities word
|
165
|
-
|
151
|
+
define_attr_before :elements, :cap, BinStruct::Int16le
|
166
152
|
end
|
167
153
|
Header.add_class Beacon
|
168
154
|
Management.bind Beacon, type: 0, subtype: 8
|
@@ -182,12 +168,12 @@ module PacketGen
|
|
182
168
|
# Specialize {Dot11::Management} with +subtype+ set to 10.
|
183
169
|
#
|
184
170
|
# Add fields:
|
185
|
-
# * {#reason} ({
|
171
|
+
# * {#reason} ({BinStruct::Int16le}).
|
186
172
|
# @author Sylvain Daubert
|
187
173
|
class Disas < SubMngt
|
188
174
|
# @!attribute reason
|
189
175
|
# @return [Integer] 16-bit reason value
|
190
|
-
|
176
|
+
define_attr_before :elements, :reason, BinStruct::Int16le
|
191
177
|
end
|
192
178
|
Header.add_class Disas
|
193
179
|
Management.bind Disas, type: 0, subtype: 10
|
@@ -197,20 +183,20 @@ module PacketGen
|
|
197
183
|
# Specialize {Dot11::Management} with +subtype+ set to 11.
|
198
184
|
#
|
199
185
|
# Add fields:
|
200
|
-
# * {#algo} ({
|
201
|
-
# * {#seqnum} ({
|
202
|
-
# * {#status} ({
|
186
|
+
# * {#algo} ({BinStruct::Int16le}),
|
187
|
+
# * {#seqnum} ({BinStruct::Int16le}),
|
188
|
+
# * {#status} ({BinStruct::Int16le}).
|
203
189
|
# @author Sylvain Daubert
|
204
190
|
class Auth < SubMngt
|
205
191
|
# @!attribute algo
|
206
192
|
# @return [Integer] 16-bit algo value
|
207
|
-
|
193
|
+
define_attr_before :elements, :algo, BinStruct::Int16le
|
208
194
|
# @!attribute seqnum
|
209
195
|
# @return [Integer] 16-bit seqnum value
|
210
|
-
|
196
|
+
define_attr_before :elements, :seqnum, BinStruct::Int16le
|
211
197
|
# @!attribute status
|
212
198
|
# @return [Integer] 16-bit status word
|
213
|
-
|
199
|
+
define_attr_before :elements, :status, BinStruct::Int16le
|
214
200
|
end
|
215
201
|
Header.add_class Auth
|
216
202
|
Management.bind Auth, type: 0, subtype: 11
|
@@ -220,12 +206,12 @@ module PacketGen
|
|
220
206
|
# Specialize {Dot11::Management} with +subtype+ set to 12.
|
221
207
|
#
|
222
208
|
# Add fields:
|
223
|
-
# * {#reason} ({
|
209
|
+
# * {#reason} ({BinStruct::Int16le}).
|
224
210
|
# @author Sylvain Daubert
|
225
211
|
class DeAuth < SubMngt
|
226
212
|
# @!attribute reason
|
227
213
|
# @return [Integer] 16-bit reason value
|
228
|
-
|
214
|
+
define_attr_before :elements, :reason, BinStruct::Int16le
|
229
215
|
end
|
230
216
|
Header.add_class DeAuth
|
231
217
|
Management.bind DeAuth, type: 0, subtype: 12
|