packetgen 3.3.3 → 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 +29 -38
- 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
data/lib/packetgen/pcapng/idb.rb
CHANGED
@@ -36,18 +36,18 @@ module PacketGen
|
|
36
36
|
# @!attribute link_type
|
37
37
|
# 16-bit link type
|
38
38
|
# @return [Integer]
|
39
|
-
|
39
|
+
define_attr_before :block_len2, :link_type, BinStruct::Int16, default: 1
|
40
40
|
# @!attribute reserved
|
41
41
|
# 16-bit reserved field
|
42
42
|
# @return [Integer]
|
43
|
-
|
43
|
+
define_attr_before :block_len2, :reserved, BinStruct::Int16, default: 0
|
44
44
|
# @!attribute snaplen
|
45
45
|
# 32-bit snap length
|
46
46
|
# @return [Integer]
|
47
|
-
|
47
|
+
define_attr_before :block_len2, :snaplen, BinStruct::Int32, default: 0
|
48
48
|
# @!attribute options
|
49
|
-
# @return [
|
50
|
-
|
49
|
+
# @return [BinStruct::String]
|
50
|
+
define_attr_before :block_len2, :options, BinStruct::String
|
51
51
|
|
52
52
|
# @param [Hash] options
|
53
53
|
# @option options [:little, :big] :endian set block endianness
|
@@ -61,10 +61,8 @@ module PacketGen
|
|
61
61
|
# @option options [Integer] :block_len2 block total length
|
62
62
|
def initialize(options={})
|
63
63
|
super
|
64
|
-
endianness(options[:endian] || :little)
|
65
64
|
@packets = []
|
66
65
|
@options_decoded = false
|
67
|
-
recalc_block_len
|
68
66
|
self.type = options[:type] || PcapNG::IDB_TYPE.to_i
|
69
67
|
end
|
70
68
|
|
@@ -76,9 +74,9 @@ module PacketGen
|
|
76
74
|
return self if io.eof?
|
77
75
|
|
78
76
|
%i[type block_len link_type reserved snaplen].each do |attr|
|
79
|
-
self[attr].read
|
77
|
+
self[attr].read(io.read(self[attr].sz))
|
80
78
|
end
|
81
|
-
self[:options].read
|
79
|
+
self[:options].read(io.read(self.block_len - MIN_SIZE))
|
82
80
|
read_blocklen2_and_check(io)
|
83
81
|
|
84
82
|
self
|
@@ -107,7 +105,7 @@ module PacketGen
|
|
107
105
|
# Return the object as a String
|
108
106
|
# @return [String]
|
109
107
|
def to_s
|
110
|
-
pad_field
|
108
|
+
pad_field(:options)
|
111
109
|
recalc_block_len
|
112
110
|
super << @packets.map(&:to_s).join
|
113
111
|
end
|
@@ -119,7 +117,7 @@ module PacketGen
|
|
119
117
|
@options_decoded = true
|
120
118
|
return @ts_resol = 1E-6 if tsresol.nil?
|
121
119
|
|
122
|
-
@ts_resol = if (
|
120
|
+
@ts_resol = if tsresol.nobits?(0x80)
|
123
121
|
10**-tsresol
|
124
122
|
else
|
125
123
|
2**-(tsresol & 0x7f)
|
data/lib/packetgen/pcapng/shb.rb
CHANGED
@@ -45,23 +45,23 @@ module PacketGen
|
|
45
45
|
# @!attribute magic
|
46
46
|
# 32-bit magic number
|
47
47
|
# @return [Integer]
|
48
|
-
|
48
|
+
define_attr_before :block_len2, :magic, BinStruct::Int32, default: MAGIC_INT32
|
49
49
|
# @!attribute ver_major
|
50
50
|
# 16-bit major version number
|
51
51
|
# @return [Integer]
|
52
|
-
|
52
|
+
define_attr_before :block_len2, :ver_major, BinStruct::Int16, default: 1
|
53
53
|
# @!attribute ver_major
|
54
54
|
# 16-bit minor version number
|
55
55
|
# @return [Integer]
|
56
|
-
|
56
|
+
define_attr_before :block_len2, :ver_minor, BinStruct::Int16, default: 0
|
57
57
|
# @!attribute section_len
|
58
58
|
# 64-bit section length
|
59
59
|
# @return [Integer]
|
60
|
-
|
61
|
-
|
60
|
+
define_attr_before :block_len2, :section_len, BinStruct::Int64,
|
61
|
+
default: SECTION_LEN_UNDEFINED
|
62
62
|
# @!attribute options
|
63
|
-
# @return [
|
64
|
-
|
63
|
+
# @return [BinStruct::String]
|
64
|
+
define_attr_before :block_len2, :options, BinStruct::String
|
65
65
|
|
66
66
|
# @param [Hash] options
|
67
67
|
# @option options [:little, :big] :endian set block endianness
|
@@ -81,8 +81,6 @@ module PacketGen
|
|
81
81
|
super
|
82
82
|
@interfaces = []
|
83
83
|
@unknown_blocks = []
|
84
|
-
endianness(options[:endian] || :little)
|
85
|
-
recalc_block_len
|
86
84
|
self.type = options[:type] || PcapNG::SHB_TYPE.to_i
|
87
85
|
end
|
88
86
|
|
@@ -93,9 +91,9 @@ module PacketGen
|
|
93
91
|
io = to_io(str_or_io)
|
94
92
|
return self if io.eof?
|
95
93
|
|
96
|
-
self[:type].read
|
94
|
+
self[:type].read(check_shb(io))
|
97
95
|
%i[block_len magic ver_major ver_minor section_len].each do |attr|
|
98
|
-
self[attr].read
|
96
|
+
self[attr].read(io.read(self[attr].sz))
|
99
97
|
end
|
100
98
|
handle_magic_and_check(self[:magic].to_s)
|
101
99
|
|
@@ -120,7 +118,7 @@ module PacketGen
|
|
120
118
|
body = @interfaces.map(&:to_s).join
|
121
119
|
self.section_len = body.size unless self.section_len == SECTION_LEN_UNDEFINED
|
122
120
|
|
123
|
-
pad_field
|
121
|
+
pad_field(:options)
|
124
122
|
recalc_block_len
|
125
123
|
super + body
|
126
124
|
end
|
@@ -135,12 +133,12 @@ module PacketGen
|
|
135
133
|
def force_endianness(endian)
|
136
134
|
@endian = endian
|
137
135
|
%i[type block_len magic block_len2].each do |attr|
|
138
|
-
self[attr] =
|
136
|
+
self[attr] = BinStruct::Int32.new(value: 0, endian: endian).read(self[attr].to_s)
|
139
137
|
end
|
140
138
|
%i[ver_major ver_minor].each do |attr|
|
141
|
-
self[attr] =
|
139
|
+
self[attr] = BinStruct::Int16.new(value: 0, endian: endian).read(self[attr].to_s)
|
142
140
|
end
|
143
|
-
self[:section_len] =
|
141
|
+
self[:section_len] = BinStruct::Int64.new(value: 0, endian: endian).read(self[:section_len].to_s)
|
144
142
|
end
|
145
143
|
|
146
144
|
# Check io contains a SHB
|
data/lib/packetgen/pcapng/spb.rb
CHANGED
@@ -29,10 +29,10 @@ module PacketGen
|
|
29
29
|
# @!attribute orig_len
|
30
30
|
# 32-bit original length
|
31
31
|
# @return [Integer]
|
32
|
-
|
32
|
+
define_attr_before :block_len2, :orig_len, BinStruct::Int32, default: 0
|
33
33
|
# @!attribute data
|
34
|
-
# @return [
|
35
|
-
|
34
|
+
# @return [BinStruct::String]
|
35
|
+
define_attr_before :block_len2, :data, BinStruct::String
|
36
36
|
|
37
37
|
# @param [Hash] options
|
38
38
|
# @option options [:little, :big] :endian set block endianness
|
@@ -45,8 +45,6 @@ module PacketGen
|
|
45
45
|
# @option options [Integer] :block_len2 block total length
|
46
46
|
def initialize(options={})
|
47
47
|
super
|
48
|
-
endianness(options[:endian] || :little)
|
49
|
-
recalc_block_len
|
50
48
|
self.type = options[:type] || PcapNG::SPB_TYPE.to_i
|
51
49
|
end
|
52
50
|
|
@@ -64,11 +62,11 @@ module PacketGen
|
|
64
62
|
io = to_io(str_or_io)
|
65
63
|
return self if io.eof?
|
66
64
|
|
67
|
-
self[:type].read
|
68
|
-
self[:block_len].read
|
69
|
-
self[:orig_len].read
|
65
|
+
self[:type].read(io.read(4))
|
66
|
+
self[:block_len].read(io.read(4))
|
67
|
+
self[:orig_len].read(io.read(4))
|
70
68
|
data_len = compute_data_len
|
71
|
-
self[:data].read
|
69
|
+
self[:data].read(io.read(data_len))
|
72
70
|
remove_padding(io, data_len)
|
73
71
|
read_blocklen2_and_check(io)
|
74
72
|
|
@@ -79,7 +77,7 @@ module PacketGen
|
|
79
77
|
# Return the object as a String
|
80
78
|
# @return [String]
|
81
79
|
def to_s
|
82
|
-
pad_field
|
80
|
+
pad_field(:data)
|
83
81
|
recalc_block_len
|
84
82
|
super
|
85
83
|
end
|
@@ -20,19 +20,8 @@ module PacketGen
|
|
20
20
|
attr_accessor :section
|
21
21
|
|
22
22
|
# @!attribute body
|
23
|
-
# @return [
|
24
|
-
|
25
|
-
|
26
|
-
# @option options [:little, :big] :endian set block endianness
|
27
|
-
# @option options [Integer] :type
|
28
|
-
# @option options [Integer] :block_len block total length
|
29
|
-
# @option options [::String] :body
|
30
|
-
# @option options [Integer] :block_len2 block total length
|
31
|
-
def initialize(options={})
|
32
|
-
super
|
33
|
-
endianness(options[:endian] || :little)
|
34
|
-
recalc_block_len
|
35
|
-
end
|
23
|
+
# @return [BinStruct::String]
|
24
|
+
define_attr_before :block_len2, :body, BinStruct::String
|
36
25
|
|
37
26
|
# Has this block options?
|
38
27
|
# @return [false]
|
@@ -48,9 +37,9 @@ module PacketGen
|
|
48
37
|
io = to_io(str_or_io)
|
49
38
|
return self if io.eof?
|
50
39
|
|
51
|
-
self[:type].read
|
52
|
-
self[:block_len].read
|
53
|
-
self[:body].read
|
40
|
+
self[:type].read(io.read(4))
|
41
|
+
self[:block_len].read(io.read(4))
|
42
|
+
self[:body].read(io.read(self[:block_len].to_i - MIN_SIZE))
|
54
43
|
read_blocklen2_and_check(io)
|
55
44
|
|
56
45
|
self
|
@@ -59,7 +48,7 @@ module PacketGen
|
|
59
48
|
# Return the object as a String
|
60
49
|
# @return [String]
|
61
50
|
def to_s
|
62
|
-
pad_field
|
51
|
+
pad_field(:body)
|
63
52
|
recalc_block_len
|
64
53
|
super
|
65
54
|
end
|
data/lib/packetgen/pcapng.rb
CHANGED
@@ -14,13 +14,13 @@ module PacketGen
|
|
14
14
|
# @author Sylvain Daubert
|
15
15
|
module PcapNG
|
16
16
|
# Section Header Block type number
|
17
|
-
SHB_TYPE =
|
17
|
+
SHB_TYPE = BinStruct::Int32.new(value: 0x0A0D0D0A, endian: :little).freeze
|
18
18
|
# Interface Description Block type number
|
19
|
-
IDB_TYPE =
|
19
|
+
IDB_TYPE = BinStruct::Int32.new(value: 1, endian: :little).freeze
|
20
20
|
# Simple Packet Block type number
|
21
|
-
SPB_TYPE =
|
21
|
+
SPB_TYPE = BinStruct::Int32.new(value: 3, endian: :little).freeze
|
22
22
|
# Enhanced Packet Block type number
|
23
|
-
EPB_TYPE =
|
23
|
+
EPB_TYPE = BinStruct::Int32.new(value: 6, endian: :little).freeze
|
24
24
|
|
25
25
|
# IEEE 802.3 Ethernet (10Mb, 100Mb, 1000Mb, and up)
|
26
26
|
LINKTYPE_ETHERNET = 1
|
@@ -10,6 +10,7 @@ require 'pcaprub'
|
|
10
10
|
module PacketGen
|
11
11
|
# Wrapper around PCAPRUB
|
12
12
|
# @author Sylvain Daubert
|
13
|
+
# @author LemonTree55
|
13
14
|
# @api private
|
14
15
|
# @since 3.1.4
|
15
16
|
module PCAPRUBWrapper
|
@@ -35,8 +36,9 @@ module PacketGen
|
|
35
36
|
pcap.setpromisc(promisc)
|
36
37
|
pcap.settimeout(TIMEOUT)
|
37
38
|
# Monitor MUST be set before pcap is activated
|
38
|
-
pcap.setmonitor
|
39
|
+
pcap.setmonitor(monitor) unless monitor.nil?
|
39
40
|
pcap.activate
|
41
|
+
pcap
|
40
42
|
end
|
41
43
|
|
42
44
|
# Capture packets from a network interface
|
@@ -74,5 +76,19 @@ module PacketGen
|
|
74
76
|
def self.read_pcap(filename:, &block)
|
75
77
|
PCAPRUB::Pcap.open_offline(filename).each_packet(&block)
|
76
78
|
end
|
79
|
+
|
80
|
+
# Write binary packets to a PCAP file
|
81
|
+
# @param [String] filename
|
82
|
+
# @param [Array<String>] packets
|
83
|
+
# @return [void]
|
84
|
+
# @since 4.0.0
|
85
|
+
# @author LemonTree55
|
86
|
+
def self.write_pcap(filename:, packets:)
|
87
|
+
PCAPRUB::Pcap.dump_open(filename) do |pcap|
|
88
|
+
packets.each do |packet|
|
89
|
+
pcap.dump(packet)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
77
93
|
end
|
78
94
|
end
|
data/lib/packetgen/proto.rb
CHANGED
@@ -30,7 +30,7 @@ module PacketGen
|
|
30
30
|
end
|
31
31
|
|
32
32
|
# Get packet body
|
33
|
-
# @return [
|
33
|
+
# @return [String]
|
34
34
|
def body
|
35
35
|
@binary_str
|
36
36
|
end
|
@@ -66,7 +66,7 @@ module PacketGen
|
|
66
66
|
str << Inspect.inspect_body(body)
|
67
67
|
end
|
68
68
|
|
69
|
-
# equality if {#to_s}
|
69
|
+
# equality if {#to_s} are equal
|
70
70
|
# @return [Boolean]
|
71
71
|
def ==(other)
|
72
72
|
to_s == other.to_s
|
@@ -22,15 +22,15 @@ module PacketGen
|
|
22
22
|
# @author Sylvain Daubert
|
23
23
|
# @since 2.1.3
|
24
24
|
class ARPSpoofer
|
25
|
-
# @param [
|
25
|
+
# @param [Numeric,nil] timeout spoof will happen for this amount
|
26
26
|
# of time
|
27
|
-
# @param [
|
27
|
+
# @param [Numeric] interval time between 2 ARP packets
|
28
28
|
# @param [String,nil] iface network interface on which do spoofing.
|
29
29
|
# Defaults to {PacketGen.default_iface}
|
30
30
|
def initialize(timeout: nil, interval: 1.0, iface: nil)
|
31
31
|
@timeout = timeout
|
32
32
|
@timeout = @timeout.to_f if @timeout
|
33
|
-
@interval = interval
|
33
|
+
@interval = interval.to_f
|
34
34
|
@iface = iface || PacketGen.default_iface
|
35
35
|
@targets = {}
|
36
36
|
@arp_packets = {}
|
@@ -56,19 +56,19 @@ module PacketGen
|
|
56
56
|
# @param [String] target_ip target IP address
|
57
57
|
# @return [void]
|
58
58
|
def remove(target_ip)
|
59
|
-
@targets.delete
|
60
|
-
@arp_packets.delete
|
59
|
+
@targets.delete(target_ip)
|
60
|
+
@arp_packets.delete(target_ip)
|
61
61
|
end
|
62
62
|
|
63
63
|
# Get registered targets (all targets, registered with {#add} and {#start})
|
64
|
-
# @return [Array<String>] list of
|
64
|
+
# @return [Array<String>] list of registeres IP addresses
|
65
65
|
def registered_targets
|
66
66
|
@targets.keys
|
67
67
|
end
|
68
68
|
|
69
69
|
# Get active targets (registered with {#start}, or all after using
|
70
70
|
# {#start_all})
|
71
|
-
# @return [Array<String>] list of
|
71
|
+
# @return [Array<String>] list of active IP addresses
|
72
72
|
def active_targets
|
73
73
|
@arp_packets.keys
|
74
74
|
end
|
@@ -83,23 +83,23 @@ module PacketGen
|
|
83
83
|
# an ARP request is made to get it.
|
84
84
|
# @return [void]
|
85
85
|
def start(target_ip, spoofed_ip, options={})
|
86
|
-
add
|
87
|
-
activate
|
86
|
+
add(target_ip, spoofed_ip, options)
|
87
|
+
activate(target_ip)
|
88
88
|
end
|
89
89
|
|
90
90
|
# Stop spoofing on given target
|
91
91
|
# @param [String] target_ip target IP address
|
92
92
|
# @return [void]
|
93
93
|
def stop(target_ip)
|
94
|
-
deactivate
|
95
|
-
remove
|
94
|
+
deactivate(target_ip)
|
95
|
+
remove(target_ip)
|
96
96
|
end
|
97
97
|
|
98
98
|
# Start spoofing on all targets added with {#add}.
|
99
99
|
# @return [void]
|
100
100
|
def start_all
|
101
101
|
@targets.each_key do |target_ip|
|
102
|
-
activate
|
102
|
+
activate(target_ip)
|
103
103
|
end
|
104
104
|
end
|
105
105
|
|
@@ -107,7 +107,7 @@ module PacketGen
|
|
107
107
|
# @return [void]
|
108
108
|
def stop_all
|
109
109
|
@targets.each_key do |target_ip|
|
110
|
-
deactivate
|
110
|
+
deactivate(target_ip)
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
@@ -115,9 +115,7 @@ module PacketGen
|
|
115
115
|
# @param [String] target_ip target IP address
|
116
116
|
# @return [Boolean]
|
117
117
|
def active?(target_ip)
|
118
|
-
|
119
|
-
return unless @targets.key?(target_ip)
|
120
|
-
# rubocop:enable Style/ReturnNilInPredicateMethodDefinition
|
118
|
+
return false unless @targets.key?(target_ip)
|
121
119
|
|
122
120
|
@targets[target_ip][:active]
|
123
121
|
end
|
@@ -126,6 +124,7 @@ module PacketGen
|
|
126
124
|
# was set on {#initialize}.
|
127
125
|
def wait
|
128
126
|
@spoof_thread.join
|
127
|
+
@spoof_thread = nil
|
129
128
|
end
|
130
129
|
|
131
130
|
private
|
@@ -143,7 +142,7 @@ module PacketGen
|
|
143
142
|
# Create spoof thread
|
144
143
|
def create_spoof_thread
|
145
144
|
@spoof_thread = Thread.new(@queue, @timeout, @interval) do |queue, timeout, interval|
|
146
|
-
while timeout.nil? || timeout
|
145
|
+
while timeout.nil? || timeout.positive?
|
147
146
|
packets = queue.pop unless queue.empty?
|
148
147
|
send_packets_on_wire(packets) unless packets.empty?
|
149
148
|
timeout -= interval if timeout
|
@@ -161,9 +160,9 @@ module PacketGen
|
|
161
160
|
# @param [String] target_ip
|
162
161
|
# @return [void]
|
163
162
|
def deactivate(target_ip)
|
164
|
-
@arp_packets.delete
|
163
|
+
@arp_packets.delete(target_ip)
|
165
164
|
if @arp_packets.empty?
|
166
|
-
@spoof_thread
|
165
|
+
@spoof_thread&.kill
|
167
166
|
@spoof_thread = nil
|
168
167
|
else
|
169
168
|
@queue << @arp_packets.values
|
data/lib/packetgen/utils.rb
CHANGED
@@ -31,9 +31,9 @@ module PacketGen
|
|
31
31
|
# @private
|
32
32
|
IP_PATH = '/usr/bin/ip'
|
33
33
|
# @private
|
34
|
-
ARP_LINE_RE = /\((\d+\.\d+\.\d+\.\d+)\) at (([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2})(?: \[ether\])? on (\w+)
|
34
|
+
ARP_LINE_RE = /\((\d+\.\d+\.\d+\.\d+)\) at (([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2})(?: \[ether\])? on (\w+)/
|
35
35
|
# @private
|
36
|
-
IP_LINE_RE = /^(\d+\.\d+\.\d+\.\d+) dev (\w+) lladdr (([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2})
|
36
|
+
IP_LINE_RE = /^(\d+\.\d+\.\d+\.\d+) dev (\w+) lladdr (([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2})/
|
37
37
|
|
38
38
|
# Get local ARP cache
|
39
39
|
# @return [Hash] key: IP address, value: array containing MAC address and
|
data/lib/packetgen/version.rb
CHANGED
data/lib/packetgen.rb
CHANGED
@@ -8,6 +8,7 @@
|
|
8
8
|
# This program is published under MIT license.
|
9
9
|
|
10
10
|
require 'packetgen/version'
|
11
|
+
require 'bin_struct'
|
11
12
|
require 'interfacez'
|
12
13
|
|
13
14
|
# PacketGen is a network packet generator and analyzor.
|
@@ -100,12 +101,13 @@ module PacketGen
|
|
100
101
|
def self.default_iface
|
101
102
|
return @default_iface if defined? @default_iface
|
102
103
|
|
103
|
-
|
104
|
+
Interfacez.raw_interface_addresses.each do |iface|
|
104
105
|
next unless iface.broadaddr
|
105
106
|
next unless Interfacez.ipv4_address_of(iface.name)
|
106
107
|
next unless Interfacez.ipv6_address_of(iface.name)
|
107
108
|
|
108
|
-
|
109
|
+
@default_iface = iface.name
|
110
|
+
break
|
109
111
|
end
|
110
112
|
end
|
111
113
|
|
@@ -133,7 +135,6 @@ end
|
|
133
135
|
|
134
136
|
require 'packetgen/deprecation'
|
135
137
|
require 'packetgen/inspect'
|
136
|
-
require 'packetgen/types'
|
137
138
|
require 'packetgen/pcapng'
|
138
139
|
require 'packetgen/pcap'
|
139
140
|
require 'packetgen/packet'
|
metadata
CHANGED
@@ -1,77 +1,84 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: packetgen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- LemonTree55
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date: 2024-
|
10
|
+
date: 2024-12-28 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
13
|
+
name: bin_struct
|
15
14
|
requirement: !ruby/object:Gem::Requirement
|
16
15
|
requirements:
|
17
16
|
- - "~>"
|
18
17
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
18
|
+
version: 0.3.0
|
20
19
|
type: :runtime
|
21
20
|
prerelease: false
|
22
21
|
version_requirements: !ruby/object:Gem::Requirement
|
23
22
|
requirements:
|
24
23
|
- - "~>"
|
25
24
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
25
|
+
version: 0.3.0
|
27
26
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
27
|
+
name: digest-crc
|
29
28
|
requirement: !ruby/object:Gem::Requirement
|
30
29
|
requirements:
|
31
30
|
- - "~>"
|
32
31
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0
|
32
|
+
version: '0'
|
34
33
|
type: :runtime
|
35
34
|
prerelease: false
|
36
35
|
version_requirements: !ruby/object:Gem::Requirement
|
37
36
|
requirements:
|
38
37
|
- - "~>"
|
39
38
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0
|
39
|
+
version: '0'
|
41
40
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
41
|
+
name: interfacez
|
43
42
|
requirement: !ruby/object:Gem::Requirement
|
44
43
|
requirements:
|
45
44
|
- - "~>"
|
46
45
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0
|
48
|
-
- - ">="
|
49
|
-
- !ruby/object:Gem::Version
|
50
|
-
version: 0.13.1
|
46
|
+
version: '1.0'
|
51
47
|
type: :runtime
|
52
48
|
prerelease: false
|
53
49
|
version_requirements: !ruby/object:Gem::Requirement
|
54
50
|
requirements:
|
55
51
|
- - "~>"
|
56
52
|
- !ruby/object:Gem::Version
|
57
|
-
version: '0
|
58
|
-
|
53
|
+
version: '1.0'
|
54
|
+
- !ruby/object:Gem::Dependency
|
55
|
+
name: pcaprub
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version: 0.13.
|
60
|
+
version: 0.13.0
|
61
|
+
type: :runtime
|
62
|
+
prerelease: false
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 0.13.0
|
61
68
|
- !ruby/object:Gem::Dependency
|
62
|
-
name:
|
69
|
+
name: rasn1
|
63
70
|
requirement: !ruby/object:Gem::Requirement
|
64
71
|
requirements:
|
65
72
|
- - "~>"
|
66
73
|
- !ruby/object:Gem::Version
|
67
|
-
version: '0'
|
74
|
+
version: '0.14'
|
68
75
|
type: :runtime
|
69
76
|
prerelease: false
|
70
77
|
version_requirements: !ruby/object:Gem::Requirement
|
71
78
|
requirements:
|
72
79
|
- - "~>"
|
73
80
|
- !ruby/object:Gem::Version
|
74
|
-
version: '0'
|
81
|
+
version: '0.14'
|
75
82
|
description: |
|
76
83
|
PacketGen is a network packet manipulation library. It allows reading, parsing
|
77
84
|
and sending network packets with fun.
|
@@ -197,24 +204,10 @@ files:
|
|
197
204
|
- lib/packetgen/pcapng/unknown_block.rb
|
198
205
|
- lib/packetgen/pcaprub_wrapper.rb
|
199
206
|
- lib/packetgen/proto.rb
|
200
|
-
- lib/packetgen/types.rb
|
201
|
-
- lib/packetgen/types/abstract_tlv.rb
|
202
|
-
- lib/packetgen/types/array.rb
|
203
|
-
- lib/packetgen/types/cstring.rb
|
204
|
-
- lib/packetgen/types/enum.rb
|
205
|
-
- lib/packetgen/types/fieldable.rb
|
206
|
-
- lib/packetgen/types/fields.rb
|
207
|
-
- lib/packetgen/types/int.rb
|
208
|
-
- lib/packetgen/types/int_string.rb
|
209
|
-
- lib/packetgen/types/length_from.rb
|
210
|
-
- lib/packetgen/types/oui.rb
|
211
|
-
- lib/packetgen/types/string.rb
|
212
|
-
- lib/packetgen/types/tlv.rb
|
213
207
|
- lib/packetgen/unknown_packet.rb
|
214
208
|
- lib/packetgen/utils.rb
|
215
209
|
- lib/packetgen/utils/arp_spoofer.rb
|
216
210
|
- lib/packetgen/version.rb
|
217
|
-
homepage:
|
218
211
|
licenses:
|
219
212
|
- MIT
|
220
213
|
metadata:
|
@@ -223,7 +216,6 @@ metadata:
|
|
223
216
|
bug_tracker_uri: https://github.com/lemontree55/packetgen/issues
|
224
217
|
documentation_uri: https://www.rubydoc.info/gems/packetgen
|
225
218
|
wiki_uri: https://github.com/lemontree55/packetgen/wiki
|
226
|
-
post_install_message:
|
227
219
|
rdoc_options:
|
228
220
|
- "--title"
|
229
221
|
- PacketGen - network packet dissector
|
@@ -237,15 +229,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
237
229
|
requirements:
|
238
230
|
- - ">="
|
239
231
|
- !ruby/object:Gem::Version
|
240
|
-
version:
|
232
|
+
version: 3.0.0
|
241
233
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
242
234
|
requirements:
|
243
235
|
- - ">="
|
244
236
|
- !ruby/object:Gem::Version
|
245
237
|
version: '0'
|
246
238
|
requirements: []
|
247
|
-
rubygems_version: 3.
|
248
|
-
signing_key:
|
239
|
+
rubygems_version: 3.6.2
|
249
240
|
specification_version: 4
|
250
241
|
summary: Network packet generator and dissector
|
251
242
|
test_files: []
|