packetgen 4.0.0 → 4.1.1
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.
- checksums.yaml +4 -4
- data/README.md +7 -9
- data/lib/packetgen/capture.rb +3 -6
- data/lib/packetgen/config.rb +1 -1
- data/lib/packetgen/deprecation.rb +7 -1
- data/lib/packetgen/header/arp.rb +7 -8
- data/lib/packetgen/header/asn1_base.rb +3 -2
- data/lib/packetgen/header/base.rb +39 -27
- data/lib/packetgen/header/bootp.rb +15 -15
- data/lib/packetgen/header/dhcp/option.rb +9 -9
- data/lib/packetgen/header/dhcp/options.rb +3 -3
- data/lib/packetgen/header/dhcp.rb +7 -8
- data/lib/packetgen/header/dhcpv6/duid.rb +3 -5
- data/lib/packetgen/header/dhcpv6/option.rb +38 -16
- data/lib/packetgen/header/dhcpv6/options.rb +4 -4
- data/lib/packetgen/header/dhcpv6/relay.rb +2 -1
- data/lib/packetgen/header/dhcpv6.rb +14 -15
- data/lib/packetgen/header/dns/name.rb +10 -9
- data/lib/packetgen/header/dns/opt.rb +4 -1
- data/lib/packetgen/header/dns/option.rb +8 -8
- data/lib/packetgen/header/dns/qdsection.rb +3 -3
- data/lib/packetgen/header/dns/question.rb +2 -1
- data/lib/packetgen/header/dns/rr.rb +2 -4
- data/lib/packetgen/header/dns/rrsection.rb +3 -3
- data/lib/packetgen/header/dns.rb +77 -61
- data/lib/packetgen/header/dot11/control.rb +6 -6
- data/lib/packetgen/header/dot11/data.rb +12 -11
- data/lib/packetgen/header/dot11/element.rb +2 -2
- data/lib/packetgen/header/dot11/management.rb +19 -16
- data/lib/packetgen/header/dot11/sub_mngt.rb +23 -22
- data/lib/packetgen/header/dot11.rb +39 -39
- data/lib/packetgen/header/dot1q.rb +6 -5
- data/lib/packetgen/header/dot1x.rb +9 -9
- data/lib/packetgen/header/eap/fast.rb +4 -4
- data/lib/packetgen/header/eap/md5.rb +12 -4
- data/lib/packetgen/header/eap/tls.rb +10 -9
- data/lib/packetgen/header/eap/ttls.rb +14 -11
- data/lib/packetgen/header/eap.rb +59 -34
- data/lib/packetgen/header/eth.rb +27 -13
- data/lib/packetgen/header/gre.rb +27 -3
- data/lib/packetgen/header/http/headers.rb +7 -6
- data/lib/packetgen/header/http/request.rb +25 -17
- data/lib/packetgen/header/http/response.rb +23 -16
- data/lib/packetgen/header/http/verbs.rb +1 -1
- data/lib/packetgen/header/http.rb +1 -1
- data/lib/packetgen/header/icmp.rb +11 -11
- data/lib/packetgen/header/icmpv6.rb +11 -10
- data/lib/packetgen/header/igmp.rb +22 -11
- data/lib/packetgen/header/igmpv3/group_record.rb +8 -3
- data/lib/packetgen/header/igmpv3/mq.rb +2 -2
- data/lib/packetgen/header/igmpv3/mr.rb +2 -2
- data/lib/packetgen/header/igmpv3.rb +12 -11
- data/lib/packetgen/header/ip/addr.rb +7 -3
- data/lib/packetgen/header/ip/option.rb +19 -6
- data/lib/packetgen/header/ip/options.rb +1 -1
- data/lib/packetgen/header/ip.rb +53 -36
- data/lib/packetgen/header/ipv6/addr.rb +15 -14
- data/lib/packetgen/header/ipv6/extension.rb +10 -8
- data/lib/packetgen/header/ipv6/hop_by_hop.rb +27 -8
- data/lib/packetgen/header/ipv6.rb +32 -23
- data/lib/packetgen/header/llc.rb +21 -14
- data/lib/packetgen/header/mdns.rb +10 -3
- data/lib/packetgen/header/mld.rb +12 -10
- data/lib/packetgen/header/mldv2/mcast_address_record.rb +7 -2
- data/lib/packetgen/header/mldv2/mlq.rb +9 -9
- data/lib/packetgen/header/mldv2/mlr.rb +5 -5
- data/lib/packetgen/header/mldv2.rb +2 -2
- data/lib/packetgen/header/ospfv2/db_description.rb +11 -11
- data/lib/packetgen/header/ospfv2/hello.rb +12 -11
- data/lib/packetgen/header/ospfv2/ls_ack.rb +6 -7
- data/lib/packetgen/header/ospfv2/ls_request.rb +8 -7
- data/lib/packetgen/header/ospfv2/ls_update.rb +8 -8
- data/lib/packetgen/header/ospfv2/lsa.rb +34 -11
- data/lib/packetgen/header/ospfv2/lsa_header.rb +4 -3
- data/lib/packetgen/header/ospfv2.rb +32 -27
- data/lib/packetgen/header/ospfv3/db_description.rb +13 -14
- data/lib/packetgen/header/ospfv3/hello.rb +11 -10
- data/lib/packetgen/header/ospfv3/ipv6_prefix.rb +7 -3
- data/lib/packetgen/header/ospfv3/ls_ack.rb +6 -7
- data/lib/packetgen/header/ospfv3/ls_request.rb +11 -11
- data/lib/packetgen/header/ospfv3/ls_update.rb +8 -8
- data/lib/packetgen/header/ospfv3/lsa.rb +24 -10
- data/lib/packetgen/header/ospfv3/lsa_header.rb +4 -3
- data/lib/packetgen/header/ospfv3.rb +39 -35
- data/lib/packetgen/header/sctp/chunk.rb +39 -18
- data/lib/packetgen/header/sctp/error.rb +170 -198
- data/lib/packetgen/header/sctp/padded32.rb +4 -4
- data/lib/packetgen/header/sctp/parameter.rb +86 -133
- data/lib/packetgen/header/sctp.rb +15 -4
- data/lib/packetgen/header/snmp.rb +111 -10
- data/lib/packetgen/header/tcp/option.rb +8 -1
- data/lib/packetgen/header/tcp/options.rb +12 -4
- data/lib/packetgen/header/tcp.rb +34 -27
- data/lib/packetgen/header/tftp.rb +17 -11
- data/lib/packetgen/header/udp.rb +16 -14
- data/lib/packetgen/header.rb +20 -14
- data/lib/packetgen/headerable.rb +10 -4
- data/lib/packetgen/inject.rb +1 -1
- data/lib/packetgen/inspect.rb +3 -8
- data/lib/packetgen/packet.rb +95 -37
- data/lib/packetgen/pcap.rb +1 -1
- data/lib/packetgen/pcapng/block.rb +3 -2
- data/lib/packetgen/pcapng/epb.rb +1 -1
- data/lib/packetgen/pcapng/file.rb +42 -15
- data/lib/packetgen/pcapng/idb.rb +3 -2
- data/lib/packetgen/pcapng/shb.rb +3 -2
- data/lib/packetgen/pcapng/spb.rb +2 -2
- data/lib/packetgen/pcapng/unknown_block.rb +1 -1
- data/lib/packetgen/pcapng.rb +3 -1
- data/lib/packetgen/pcaprub_wrapper.rb +1 -1
- data/lib/packetgen/proto.rb +5 -1
- data/lib/packetgen/unknown_packet.rb +4 -4
- data/lib/packetgen/utils/arp_spoofer.rb +1 -1
- data/lib/packetgen/utils.rb +4 -5
- data/lib/packetgen/version.rb +2 -2
- data/lib/packetgen.rb +9 -3
- metadata +8 -9
data/lib/packetgen/header/eap.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# This file is part of PacketGen
|
4
|
-
# See https://
|
4
|
+
# See https://codeberg.org/lemontree55/packetgen for more informations
|
5
5
|
# Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
|
6
6
|
# Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
|
7
7
|
# This program is published under MIT license.
|
@@ -12,34 +12,22 @@ module PacketGen
|
|
12
12
|
# {https://tools.ietf.org/html/rfc3748 RFC 3748}
|
13
13
|
#
|
14
14
|
# A EAP header has:
|
15
|
-
# * a {#code} field (
|
16
|
-
# * a {#id} field (
|
17
|
-
# * a {#length} field (
|
15
|
+
# * a {#code} field (+BinStruct::Int8Enum+),
|
16
|
+
# * a {#id} field (+BinStruct::Int8+),
|
17
|
+
# * a {#length} field (+BinStruct::Int16+).
|
18
18
|
# Request (code 1) and Response (code 2) packets also have:
|
19
19
|
# * a {#type} field (+BinStruct::Int8Enum+).
|
20
20
|
# And Expanded Types (type 254) packets also have:
|
21
|
-
# * a {#vendor_id} field (
|
22
|
-
# * a {#vendor_type} field (
|
23
|
-
# Finally, all packets have a {#body} (
|
24
|
-
#
|
25
|
-
# == Create EAP headers
|
26
|
-
# An EAP header may be created this way:
|
27
|
-
# # create a request header with default type (1)
|
28
|
-
# eap = EAP.new(code: 1) # => PacketGen::Header::EAP
|
29
|
-
# # the same
|
30
|
-
# eap = EAP.new(code: 'Request') # => PacketGen::Header::EAP
|
31
|
-
# # create a Response header of type Nak
|
32
|
-
# nak = EAP.new(code: 'Response', type: 'Nak')
|
21
|
+
# * a {#vendor_id} field (+BinStruct::Int24+),
|
22
|
+
# * a {#vendor_type} field (+BinStruct::Int32+).
|
23
|
+
# Finally, all packets have a {#body} (+BinStruct::String+).
|
33
24
|
#
|
34
25
|
# === Specialized headers
|
35
26
|
# Some EAP has a specialized class:
|
36
|
-
# * EAP-MD5,
|
37
|
-
# * EAP-TLS,
|
38
|
-
# * EAP-TTLS,
|
39
|
-
# * EAP-FAST.
|
40
|
-
# Creating such a header is fairly simple:
|
41
|
-
# # Generate a EAP-TLS Response (type is forced to 13)
|
42
|
-
# eap = EAP::TLS.new(code: 2) # => PacketGen::Header::EAP::TLS
|
27
|
+
# * EAP-MD5 ({EAP::MD5}),
|
28
|
+
# * EAP-TLS ({EAP::TLS}),
|
29
|
+
# * EAP-TTLS ({EAP::TTLS}),
|
30
|
+
# * EAP-FAST ({EAP::FAST}).
|
43
31
|
#
|
44
32
|
# == Header accessors
|
45
33
|
# EAP headers may be accessed through +Packet#eap+ accessor.
|
@@ -54,7 +42,29 @@ module PacketGen
|
|
54
42
|
# So result of parsing a EAP header may be a {EAP}, {EAP::MD5}, {EAP::TLS},
|
55
43
|
# {EAP::TTLS} or {EAP::FAST} instance. But this instance is still accessible
|
56
44
|
# through +Packet#eap+.
|
45
|
+
#
|
46
|
+
# @example Create EAP headers
|
47
|
+
# # create a request header with default type (1)
|
48
|
+
# eap = PacketGen::Header::EAP.new(code: 1)
|
49
|
+
# eap.human_code #=> 'Request'
|
50
|
+
# # the same
|
51
|
+
# eap = PacketGen::Header::EAP.new(code: 'Request')
|
52
|
+
# eap.code #=> 1
|
53
|
+
# # create a Response header of type Nak
|
54
|
+
# nak = PacketGen::Header::EAP.new(code: 'Response', type: 'Nak')
|
55
|
+
# nak.code #=> 2
|
56
|
+
# nak.type #=> 3
|
57
|
+
#
|
58
|
+
# @example Create a specialized EAP header
|
59
|
+
# eap = PacketGen::Header::EAP::TLS.new(code: 2)
|
60
|
+
# eap.class #=> PacketGen::Header::EAP::TLS
|
61
|
+
#
|
62
|
+
# @example Parse a specialized class from a binary string
|
63
|
+
# pkt = PacketGen.parse("\x01\x00\x00\x0e\x04\x04\x00\x01\x02\x03name", first_header: 'EAP')
|
64
|
+
# pkt.eap.class # => PacketGen::Header::EAP::MD5
|
65
|
+
#
|
57
66
|
# @author Sylvain Daubert
|
67
|
+
# @author LemonTree55
|
58
68
|
# @since 2.1.4
|
59
69
|
class EAP < Base
|
60
70
|
# EAP known codes
|
@@ -81,41 +91,48 @@ module PacketGen
|
|
81
91
|
}.freeze
|
82
92
|
|
83
93
|
# @!attribute code
|
84
|
-
#
|
94
|
+
# 8-bit EAP code. See {CODES known EAP codes}
|
95
|
+
# @return [Integer]
|
85
96
|
define_attr :code, BinStruct::Int8Enum, enum: CODES
|
86
97
|
|
87
98
|
# @!attribute id
|
88
|
-
#
|
99
|
+
# 8-bit identifier
|
100
|
+
# @return [Integer]
|
89
101
|
define_attr :id, BinStruct::Int8
|
90
102
|
|
91
103
|
# @!attribute length
|
92
|
-
#
|
104
|
+
# 16-bit length of EAP packet
|
105
|
+
# @return [Integer]
|
93
106
|
define_attr :length, BinStruct::Int16, default: 4
|
94
107
|
|
95
108
|
# @!attribute type
|
96
|
-
#
|
97
|
-
#
|
98
|
-
#
|
109
|
+
# 8-bit request or response type.
|
110
|
+
# This field is present only for Request or Response packets.
|
111
|
+
# See {TYPES known EAP types}.
|
112
|
+
# @return [Integer]
|
99
113
|
define_attr :type, BinStruct::Int8Enum,
|
100
114
|
enum: TYPES,
|
101
115
|
optional: lambda(&:type?)
|
102
116
|
|
103
117
|
# @!attribute vendor_id
|
118
|
+
# 24-bit vendor ID.
|
104
119
|
# This field is present only for Request or Response packets,
|
105
120
|
# with type equal to +Expanded Types+ (254).
|
106
|
-
# @return [Integer]
|
121
|
+
# @return [Integer]
|
107
122
|
define_attr :vendor_id, BinStruct::Int24,
|
108
123
|
optional: ->(eap) { eap.type? && (eap.type == 254) }
|
109
124
|
|
110
125
|
# @!attribute vendor_type
|
126
|
+
# 32-bit vendor type.
|
111
127
|
# This field is present only for Request or Response packets,
|
112
128
|
# with type equal to +Expanded Types+ (254).
|
113
|
-
# @return [Integer]
|
129
|
+
# @return [Integer]
|
114
130
|
define_attr :vendor_type, BinStruct::Int32,
|
115
131
|
optional: ->(eap) { eap.type? && (eap.type == 254) }
|
116
132
|
|
117
133
|
# @!attribute body
|
118
|
-
#
|
134
|
+
# EAP packet body
|
135
|
+
# @return [BinStruct::String, Headerable]
|
119
136
|
define_attr :body, BinStruct::String
|
120
137
|
|
121
138
|
# @return [EAP]
|
@@ -129,7 +146,7 @@ module PacketGen
|
|
129
146
|
|
130
147
|
# Populate object from a binary string
|
131
148
|
# @param [String] str
|
132
|
-
# @return [
|
149
|
+
# @return [EAP] may return a subclass object if a more specific class
|
133
150
|
# may be determined
|
134
151
|
def read(str)
|
135
152
|
super
|
@@ -189,11 +206,19 @@ module PacketGen
|
|
189
206
|
code == CODES['Failure']
|
190
207
|
end
|
191
208
|
|
209
|
+
# Is packet a NAK?
|
210
|
+
# @return [Boolean]
|
211
|
+
# @since 4.1.0
|
212
|
+
# @author LemonTree55
|
213
|
+
def nak?
|
214
|
+
(code == 2) && (type == 3)
|
215
|
+
end
|
216
|
+
|
192
217
|
# Return an array of desired authentication types from a Nak packet
|
193
218
|
# @return [Array<Integer>]
|
194
219
|
# @raise [ParseError] not a Nak packet
|
195
220
|
def desired_auth_type
|
196
|
-
raise ParseError, 'not a Nak response'
|
221
|
+
raise ParseError, 'not a Nak response' unless nak?
|
197
222
|
|
198
223
|
body.to_s.unpack('C*')
|
199
224
|
end
|
data/lib/packetgen/header/eth.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# This file is part of PacketGen
|
4
|
-
# See https://
|
4
|
+
# See https://codeberg.org/lemontree55/packetgen for more informations
|
5
5
|
# Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
|
6
6
|
# Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
|
7
7
|
# This program is published under MIT license.
|
@@ -10,26 +10,32 @@ module PacketGen
|
|
10
10
|
module Header
|
11
11
|
# An Ethernet header consists of:
|
12
12
|
# * a destination MAC address ({MacAddr}),
|
13
|
-
# * a source MAC address (MacAddr),
|
14
|
-
# * a {#ethertype} (
|
15
|
-
# * and a body (a
|
13
|
+
# * a source MAC address ({MacAddr}),
|
14
|
+
# * a {#ethertype} (+BinStruct::Int16+),
|
15
|
+
# * and a body (a +BinStruct::String+ or another {Headerable} class).
|
16
16
|
#
|
17
|
-
#
|
17
|
+
# @example Create a Ethernet header
|
18
18
|
# # standalone
|
19
19
|
# eth = PacketGen::Header::Eth.new
|
20
20
|
# # in a packet
|
21
21
|
# pkt = PacketGen.gen('Eth')
|
22
22
|
# # access to Ethernet header
|
23
|
-
# pkt.eth # => PacketGen::Header::Eth
|
23
|
+
# pkt.eth.class # => PacketGen::Header::Eth
|
24
24
|
#
|
25
|
-
#
|
25
|
+
# @example Access to Ethernet attributes
|
26
|
+
# eth = PacketGen::Header::Eth.new(src: '00:01:01:01:01:01', ethertype: 0x1234)
|
27
|
+
# # Set destination MAC address
|
26
28
|
# eth.dst = "00:01:02:03:04:05"
|
27
|
-
#
|
28
|
-
# eth
|
29
|
-
#
|
29
|
+
# # Access source MAC address, human-redable
|
30
|
+
# eth.src # => "00:01:01:01:01:01"
|
31
|
+
# # Access to MacAddr object
|
32
|
+
# eth[:src].class # => PacketGen::Header::Eth::MacAddr
|
33
|
+
# eth.ethertype # => 0x1234
|
34
|
+
# # Set Ethernet body
|
30
35
|
# eth.body = "This is a body"
|
31
36
|
#
|
32
37
|
# @author Sylvain Daubert
|
38
|
+
# @author LemonTree55
|
33
39
|
class Eth < Base
|
34
40
|
# Ethernet MAC address, as a group of 6 bytes
|
35
41
|
# @author Sylvain Daubert
|
@@ -58,6 +64,10 @@ module PacketGen
|
|
58
64
|
# Read a human-readable string to populate +MacAddr+
|
59
65
|
# @param [String] str
|
60
66
|
# @return [self]
|
67
|
+
# @example
|
68
|
+
# mac = PacketGen::Header::Eth::MacAddr.new
|
69
|
+
# mac.from_human('01:02:03:04:05:06')
|
70
|
+
# mac.a5 # => 6
|
61
71
|
def from_human(str)
|
62
72
|
return self if str.nil?
|
63
73
|
|
@@ -76,6 +86,8 @@ module PacketGen
|
|
76
86
|
attributes.map { |m| '%02x' % self[m] }.join(':')
|
77
87
|
end
|
78
88
|
|
89
|
+
# Equality check. +true+ only if +other+ is a MacAddr, and each address byte is the same.
|
90
|
+
# @return [Boolean]
|
79
91
|
def ==(other)
|
80
92
|
other.is_a?(self.class) &&
|
81
93
|
attributes.all? { |attr| self[attr].value == other[attr].value }
|
@@ -83,16 +95,18 @@ module PacketGen
|
|
83
95
|
end
|
84
96
|
|
85
97
|
# @!attribute dst
|
86
|
-
#
|
98
|
+
# Destination MAC address
|
99
|
+
# @return [::String]
|
87
100
|
define_attr :dst, MacAddr, default: '00:00:00:00:00:00'
|
88
101
|
# @!attribute src
|
89
|
-
#
|
102
|
+
# Source MAC address
|
103
|
+
# @return [::String]
|
90
104
|
define_attr :src, MacAddr, default: '00:00:00:00:00:00'
|
91
105
|
# @!attribute ethertype
|
92
106
|
# @return [Integer] 16-bit integer to determine payload type
|
93
107
|
define_attr :ethertype, BinStruct::Int16, default: 0
|
94
108
|
# @!attribute body
|
95
|
-
# @return [BinStruct::String,
|
109
|
+
# @return [BinStruct::String,Headerable]
|
96
110
|
define_attr :body, BinStruct::String
|
97
111
|
|
98
112
|
# send Eth packet on wire.
|
data/lib/packetgen/header/gre.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# This file is part of PacketGen
|
4
|
-
# See https://
|
4
|
+
# See https://codeberg.org/lemontree55/packetgen for more informations
|
5
5
|
# Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
|
6
6
|
# Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
|
7
7
|
# This program is published under MIT license.
|
@@ -20,21 +20,40 @@ module PacketGen
|
|
20
20
|
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
21
21
|
# | Sequence Number (Optional) |
|
22
22
|
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
23
|
+
#
|
24
|
+
# A GRE header is composed of:
|
25
|
+
# * A first 16-bit attribute containing given flags:
|
26
|
+
# * {#c} indicates if {#checksum} and {#reserved1} attributes are present.
|
27
|
+
# * {#k} indicates if {#key} attribute is present.
|
28
|
+
# * {#s} indicatesid {#sequence_number} attribute is present.
|
29
|
+
# * {#ver} 3-bit version number.
|
30
|
+
# * {#protocol_type} (+BinStruct::Int16+).
|
31
|
+
# * optional {#checksum} and {#reserved1} attribute (both +BinStruct::Int16+).
|
32
|
+
# * optional {#key} attribute (+BinStruct::Int32+).
|
33
|
+
# * optional {#sequence_number} attribute (+BinStruct::Int32+).
|
34
|
+
# * and a {#body} (+BinStruct::String or {Headerable}).
|
35
|
+
#
|
36
|
+
# Current implementation supports tunneling {IP} and {IPv6} packets in GRE.
|
23
37
|
# @author Sylvain Daubert
|
38
|
+
# @author LemonTree55
|
24
39
|
# @since 2.1.0
|
25
40
|
class GRE < Base
|
26
41
|
# IP protocol number for GRE
|
27
42
|
IP_PROTOCOL = 47
|
28
43
|
|
29
44
|
# @!attribute c
|
45
|
+
# Say if {#checksum} and {#reserved1} attributes are present
|
30
46
|
# @return [Boolean]
|
31
47
|
# @!attribute k
|
48
|
+
# Say if {#key} attribute is present
|
32
49
|
# @return [Boolean]
|
33
50
|
# @!attribute s
|
51
|
+
# Say if {#sequence_number} attribute is present
|
34
52
|
# @return [Boolean]
|
35
53
|
# @!attribute reserved0
|
36
54
|
# @return [Integer]
|
37
55
|
# @!attribute ver
|
56
|
+
# 3-bit GRE protocol version.
|
38
57
|
# @return [Integer]
|
39
58
|
define_bit_attr :u16, c: 1, r: 1, k: 1, s: 1, reserved0: 9, ver: 3
|
40
59
|
|
@@ -42,19 +61,24 @@ module PacketGen
|
|
42
61
|
# @return [Integer]
|
43
62
|
define_attr :protocol_type, BinStruct::Int16
|
44
63
|
# @!attribute checksum
|
64
|
+
# IP checksum over all 16-bit words in GRE header and its body. Present only if {#c} is set.
|
45
65
|
# @return [Integer]
|
46
66
|
define_attr :checksum, BinStruct::Int16, default: 0, optional: lambda(&:c?)
|
47
67
|
# @!attribute reserved1
|
68
|
+
# Reserved field, present only if {#c} is set.
|
48
69
|
# @return [Integer]
|
49
70
|
define_attr :reserved1, BinStruct::Int16, default: 0, optional: lambda(&:c?)
|
50
71
|
# @!attribute key
|
72
|
+
# 32-bit integer used to identify an individual traffic flow within a tunnel.
|
73
|
+
# Present only if {#k} is set.
|
51
74
|
# @return [Integer]
|
52
75
|
define_attr :key, BinStruct::Int32, optional: lambda(&:k?)
|
53
76
|
# @!attribute sequence_number
|
77
|
+
# 32-bit integer. Present only if {#s} is set.
|
54
78
|
# @return [Integer]
|
55
79
|
define_attr :sequence_number, BinStruct::Int32, optional: lambda(&:s?)
|
56
80
|
# @!attribute body
|
57
|
-
#
|
81
|
+
# @return [BinStruct::String,Headerable]
|
58
82
|
define_attr :body, BinStruct::String
|
59
83
|
|
60
84
|
alias seqnum sequence_number
|
@@ -65,7 +89,7 @@ module PacketGen
|
|
65
89
|
super(opts)
|
66
90
|
end
|
67
91
|
|
68
|
-
# Compute checksum and set +checksum+
|
92
|
+
# Compute checksum and set +checksum+ attribute.
|
69
93
|
# @return [Integer]
|
70
94
|
def calc_checksum
|
71
95
|
sum = IP.sum16(self)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# This file is part of PacketGen
|
4
|
-
# See https://
|
4
|
+
# See https://codeberg.org/lemontree55/packetgen for more informations
|
5
5
|
# Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
|
6
6
|
# Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
|
7
7
|
# This program is published under MIT license.
|
@@ -9,14 +9,15 @@
|
|
9
9
|
module PacketGen
|
10
10
|
module Header
|
11
11
|
# @since 2.2.0
|
12
|
+
# @author Kent 'picat' Gruber
|
12
13
|
module HTTP
|
13
14
|
# @abstract Base class for HTTP headers.
|
14
15
|
# @author Kent 'picat' Gruber
|
15
16
|
class Headers
|
16
17
|
include BinStruct::Structable
|
17
18
|
|
18
|
-
# Underlying Headers data
|
19
|
-
# @return [Hash, nil]
|
19
|
+
# Underlying Headers data.
|
20
|
+
# @return [Hash{String => String}, nil]
|
20
21
|
attr_reader :data
|
21
22
|
alias to_h data
|
22
23
|
|
@@ -25,7 +26,7 @@ module PacketGen
|
|
25
26
|
end
|
26
27
|
|
27
28
|
# Populate object from a string or directly from a hash.
|
28
|
-
# @param [String, Hash] s_or_h
|
29
|
+
# @param [String, Hash{String=>String}] s_or_h
|
29
30
|
# @return [self]
|
30
31
|
def read(s_or_h)
|
31
32
|
case s_or_h
|
@@ -69,14 +70,14 @@ module PacketGen
|
|
69
70
|
d.join("\r\n") << "\r\n\r\n"
|
70
71
|
end
|
71
72
|
|
72
|
-
# Get a human readable
|
73
|
+
# Get a human readable hash.
|
73
74
|
# @return [Hash]
|
74
75
|
def to_human
|
75
76
|
@data
|
76
77
|
end
|
77
78
|
|
78
79
|
# Read human-readable data to populate header data.
|
79
|
-
# @param [Hash] data
|
80
|
+
# @param [Hash{String=>String}] data
|
80
81
|
# @return [self]
|
81
82
|
def from_human(data)
|
82
83
|
read(data)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# This file is part of PacketGen
|
4
|
-
# See https://
|
4
|
+
# See https://codeberg.org/lemontree55/packetgen for more informations
|
5
5
|
# Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
|
6
6
|
# Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
|
7
7
|
# This program is published under MIT license.
|
@@ -10,28 +10,30 @@ module PacketGen
|
|
10
10
|
module Header
|
11
11
|
module HTTP
|
12
12
|
# An HTTP/1.1 Request packet consists of:
|
13
|
-
# * the http verb (
|
14
|
-
# * the path (
|
15
|
-
# * the version (
|
13
|
+
# * the http verb (+BinStruct::String+).
|
14
|
+
# * the path (+BinStruct::String+).
|
15
|
+
# * the version (+BinStruct::String+).
|
16
16
|
# * associated http headers ({HTTP::Headers}).
|
17
|
+
# * and a {#body} (+BinStruct::String+).
|
17
18
|
#
|
18
|
-
#
|
19
|
+
# Note: When creating a HTTP Request packet, {TCP#sport} and {TCP#dport}
|
20
|
+
# attributes are not set.
|
21
|
+
#
|
22
|
+
# @example Create a HTTP Request header
|
19
23
|
# # standalone
|
20
|
-
#
|
24
|
+
# http_request = PacketGen::Header::HTTP::Request.new
|
21
25
|
# # in a packet
|
22
26
|
# pkt = PacketGen.gen("IP").add("TCP").add("HTTP::Request")
|
23
27
|
# # access to HTTP Request header
|
24
|
-
# pkt.http_request # => PacketGen::Header::HTTP::Request
|
25
|
-
#
|
26
|
-
# Note: When creating a HTTP Request packet, +sport+ and +dport+
|
27
|
-
# attributes of TCP header are not set.
|
28
|
+
# pkt.http_request.class # => PacketGen::Header::HTTP::Request
|
28
29
|
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
30
|
+
# @example HTTP Request attributes
|
31
|
+
# http_request = PacketGen::Header::HTTP::Request.new
|
32
|
+
# http_request.version #=> "HTTP/1.1"
|
33
|
+
# http_request.verb = "GET"
|
34
|
+
# http_request.path = "/meow.html"
|
35
|
+
# http_request.headers = "Host: tcpdump.org" # string or
|
36
|
+
# http_request.headers = { "Host": "tcpdump.org" } # even a hash
|
35
37
|
#
|
36
38
|
# @author Kent 'picat' Gruber
|
37
39
|
# @author Sylvain Daubert
|
@@ -39,13 +41,16 @@ module PacketGen
|
|
39
41
|
# @since 3.1.0 Rename +#method+ into {#verb} to not mask +Object#method+.
|
40
42
|
class Request < Base
|
41
43
|
# @!attribute verb
|
44
|
+
# HTTP verb (method)
|
42
45
|
# @return [BinStruct::String]
|
43
46
|
# @since 3.1.0
|
44
47
|
define_attr :verb, BinStruct::String
|
45
48
|
# @!attribute path
|
49
|
+
# Requested path
|
46
50
|
# @return [BinStruct::String]
|
47
51
|
define_attr :path, BinStruct::String
|
48
52
|
# @!attribute version
|
53
|
+
# HTTP version
|
49
54
|
# @return [BinStruct::String]
|
50
55
|
define_attr :version, BinStruct::String, default: 'HTTP/1.1'
|
51
56
|
# @!attribute headers
|
@@ -53,6 +58,7 @@ module PacketGen
|
|
53
58
|
# @return [HTTP::Headers]
|
54
59
|
define_attr :headers, HTTP::Headers
|
55
60
|
# @!attribute body
|
61
|
+
# HTTP request body, if any
|
56
62
|
# @return [BinStruct::String]
|
57
63
|
define_attr :body, BinStruct::String
|
58
64
|
|
@@ -67,7 +73,7 @@ module PacketGen
|
|
67
73
|
end
|
68
74
|
|
69
75
|
# Read in the HTTP portion of the packet, and parse it.
|
70
|
-
# @return [
|
76
|
+
# @return [self]
|
71
77
|
def read(str)
|
72
78
|
lines = lines(str)
|
73
79
|
first_line_words = lines.shift.split
|
@@ -83,6 +89,8 @@ module PacketGen
|
|
83
89
|
self
|
84
90
|
end
|
85
91
|
|
92
|
+
# May be parsed as a HTTP request if verb is known, and if version is +HTTP/1.x+.
|
93
|
+
# @return [Boolean]
|
86
94
|
def parse?
|
87
95
|
VERBS.include?(self.verb) && self.version.start_with?('HTTP/1.')
|
88
96
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# This file is part of PacketGen
|
4
|
-
# See https://
|
4
|
+
# See https://codeberg.org/lemontree55/packetgen for more informations
|
5
5
|
# Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
|
6
6
|
# Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
|
7
7
|
# This program is published under MIT license.
|
@@ -10,25 +10,26 @@ module PacketGen
|
|
10
10
|
module Header
|
11
11
|
module HTTP
|
12
12
|
# An HTTP/1.1 Response packet consists of:
|
13
|
-
# * the version (
|
14
|
-
# * the status code (
|
15
|
-
# * the status message (
|
16
|
-
# * associated
|
17
|
-
# * the actual
|
13
|
+
# * the version (+BinStruct::String+).
|
14
|
+
# * the status code (+BinStruct::String+).
|
15
|
+
# * the status message (+BinStruct::String+).
|
16
|
+
# * associated HTTP headers ({HTTP::Headers}).
|
17
|
+
# * the actual HTTP payload body (+BinStruct::String+).
|
18
18
|
#
|
19
|
-
#
|
19
|
+
# Note: When creating a HTTP Response packet, +sport+ and +dport+
|
20
|
+
# attributes of TCP header are not set.
|
21
|
+
#
|
22
|
+
# @example Create a HTTP Response header
|
20
23
|
# # standalone
|
21
24
|
# http_resp = PacketGen::Header::HTTP::Response.new
|
22
25
|
# # in a packet
|
23
26
|
# pkt = PacketGen.gen("IP").add("TCP").add("HTTP::Response")
|
24
27
|
# # access to HTTP Response header
|
25
|
-
# pkt.http_response # => PacketGen::Header::HTTP::Response
|
28
|
+
# pkt.http_response.class # => PacketGen::Header::HTTP::Response
|
26
29
|
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
# == HTTP Response attributes
|
31
|
-
# http_resp.version = "HTTP/1.1"
|
30
|
+
# @example HTTP Response attributes
|
31
|
+
# http_resp = PacketGen::Header::HTTP::Response.new
|
32
|
+
# http_resp.version #=> "HTTP/1.1"
|
32
33
|
# http_resp.status_code = "200"
|
33
34
|
# http_resp.status_mesg = "OK"
|
34
35
|
# http_resp.body = "this is a body"
|
@@ -39,20 +40,24 @@ module PacketGen
|
|
39
40
|
# @author LemonTree55
|
40
41
|
class Response < Base
|
41
42
|
# @!attribute version
|
43
|
+
# HTTP version
|
42
44
|
# @return [BinStruct::String]
|
43
45
|
define_attr :version, BinStruct::String, default: 'HTTP/1.1'
|
44
46
|
# @!attribute status_code
|
47
|
+
# Response status code
|
45
48
|
# @return [BinStruct::String]
|
46
49
|
define_attr :status_code, BinStruct::String
|
47
50
|
# @!attribute status_mesg
|
51
|
+
# Response status message
|
48
52
|
# @return [BinStruct::String]
|
49
53
|
define_attr :status_mesg, BinStruct::String
|
50
54
|
# @!attribute headers
|
51
55
|
# associated http/1.1 headers
|
52
|
-
# @return [
|
56
|
+
# @return [HTTP::Headers]
|
53
57
|
define_attr :headers, HTTP::Headers
|
54
58
|
# @!attribute body
|
55
|
-
#
|
59
|
+
# Response body
|
60
|
+
# @return [BinStruct::String]
|
56
61
|
define_attr :body, BinStruct::String
|
57
62
|
|
58
63
|
# @param [Hash] options
|
@@ -67,7 +72,7 @@ module PacketGen
|
|
67
72
|
end
|
68
73
|
|
69
74
|
# Read in the HTTP portion of the packet, and parse it.
|
70
|
-
# @return [
|
75
|
+
# @return [self]
|
71
76
|
def read(str)
|
72
77
|
headers, data = collect_headers_and_data(str)
|
73
78
|
|
@@ -80,6 +85,8 @@ module PacketGen
|
|
80
85
|
self
|
81
86
|
end
|
82
87
|
|
88
|
+
# May be parsed as a HTTP response if version is +HTTP/1.x+.
|
89
|
+
# @return [Boolean]
|
83
90
|
def parse?
|
84
91
|
version.start_with?('HTTP/1.')
|
85
92
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# This file is part of PacketGen
|
4
|
-
# See https://
|
4
|
+
# See https://codeberg.org/lemontree55/packetgen for more informations
|
5
5
|
# Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
|
6
6
|
# Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
|
7
7
|
# This program is published under MIT license.
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# This file is part of PacketGen
|
4
|
-
# See https://
|
4
|
+
# See https://codeberg.org/lemontree55/packetgen for more informations
|
5
5
|
# Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
|
6
6
|
# Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
|
7
7
|
# This program is published under MIT license.
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# This file is part of PacketGen
|
4
|
-
# See https://
|
4
|
+
# See https://codeberg.org/lemontree55/packetgen for more informations
|
5
5
|
# Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
|
6
6
|
# Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
|
7
7
|
# This program is published under MIT license.
|
@@ -15,24 +15,25 @@ module PacketGen
|
|
15
15
|
# | Type | Code | Checksum |
|
16
16
|
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
17
17
|
# A ICMP header consists of:
|
18
|
-
# * a {#type} field (
|
19
|
-
# * a {#code} field (
|
20
|
-
# * a {#checksum} field (
|
18
|
+
# * a {#type} field (+BinStruct::Int8+ type),
|
19
|
+
# * a {#code} field (+BinStruct::Int8+ type),
|
20
|
+
# * a {#checksum} field (+BinStruct::Int16+ type),
|
21
21
|
# * and a {#body}.
|
22
22
|
#
|
23
|
-
#
|
23
|
+
# @example Create a ICMP header
|
24
24
|
# # standalone
|
25
25
|
# icmp = PacketGen::Header::ICMP.new
|
26
26
|
# # in a packet
|
27
27
|
# pkt = PacketGen.gen('IP').add('ICMP')
|
28
28
|
# # access to ICMP header
|
29
|
-
# pkt.icmp
|
29
|
+
# pkt.icmp.class # => PacketGen::Header::ICMP
|
30
30
|
#
|
31
|
-
#
|
31
|
+
# @example ICMP attributes
|
32
|
+
# icmp = PacketGen::Header::ICMP.new
|
32
33
|
# icmp.code = 0
|
33
34
|
# icmp.type = 200
|
34
35
|
# icmp.checksum = 0x248a
|
35
|
-
# icmp.body
|
36
|
+
# icmp.body = 'this is a body'
|
36
37
|
# @author Sylvain Daubert
|
37
38
|
class ICMP < Base
|
38
39
|
# ICMP internet protocol number
|
@@ -51,7 +52,8 @@ module PacketGen
|
|
51
52
|
# @return [Integer]
|
52
53
|
define_attr :checksum, BinStruct::Int16
|
53
54
|
# @!attribute body
|
54
|
-
#
|
55
|
+
# ICMP body
|
56
|
+
# @return [BinStruct::String,Headerable]
|
55
57
|
define_attr :body, BinStruct::String
|
56
58
|
|
57
59
|
# Compute checksum and set +checksum+ field
|
@@ -61,9 +63,7 @@ module PacketGen
|
|
61
63
|
self.checksum = IP.reduce_checksum(sum)
|
62
64
|
end
|
63
65
|
end
|
64
|
-
|
65
66
|
self.add_class ICMP
|
66
|
-
|
67
67
|
IP.bind ICMP, protocol: ICMP::IP_PROTOCOL
|
68
68
|
end
|
69
69
|
end
|