packetgen-plugin-smb 0.1.0 → 0.2.0
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/.rubocop.yml +29 -0
- data/README.md +5 -0
- data/lib/packetgen-plugin-smb.rb +7 -0
- data/lib/packetgen/plugin/smb.rb +26 -2
- data/lib/packetgen/plugin/smb/blocks.rb +1 -2
- data/lib/packetgen/plugin/smb/browser.rb +90 -0
- data/lib/packetgen/plugin/smb/browser/domain_announcement.rb +33 -0
- data/lib/packetgen/plugin/smb/browser/host_announcement.rb +71 -0
- data/lib/packetgen/plugin/smb/browser/local_master_announcement.rb +28 -0
- data/lib/packetgen/plugin/smb/close.rb +13 -2
- data/lib/packetgen/plugin/smb/filetime.rb +2 -14
- data/lib/packetgen/plugin/smb/nt_create_and_x.rb +8 -8
- data/lib/packetgen/plugin/smb/string.rb +28 -9
- data/lib/packetgen/plugin/smb/trans.rb +5 -6
- data/lib/packetgen/plugin/smb_version.rb +1 -1
- data/packetgen-plugin-smb.gemspec +3 -1
- metadata +10 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b854bf1526a2a21067f2a2620c5b36fcd129509bd78ed450c04caf9d6070ed6
|
4
|
+
data.tar.gz: c2e0de100ede2ffc1d10e88261fc6b97a38267800d6f7a92ed73e76e4f09ac4f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b225195fc718a67bcbc0410c9cf0aa3e9f0825410270c8c8a0a3e97aed0ceb82ed36f07f50a52665f894928fefdfbd6ad6fa57466e8da5d213a545a3248504ad
|
7
|
+
data.tar.gz: e4c0f6f4d4af861ce63c8cf11d9b672fc070d6ad6215dcc441662eeb7445d98710aff05330a38e640d805c82372b5ba4b1076e9edfc5ef4ab4a313839d26d5f5
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
TargetRubyVersion: 2.3
|
2
|
+
Layout/SpaceAroundEqualsInParameterDefault:
|
3
|
+
EnforcedStyle: no_space
|
4
|
+
Lint/EmptyWhen:
|
5
|
+
Enabled: false
|
6
|
+
Lint/Void:
|
7
|
+
Enabled: false
|
8
|
+
Metrics:
|
9
|
+
Enabled: false
|
10
|
+
Style/AsciiComments:
|
11
|
+
Enabled: false
|
12
|
+
Style/Encoding:
|
13
|
+
Enabled: false
|
14
|
+
Style/EvalWithLocation:
|
15
|
+
Enabled: false
|
16
|
+
Style/FormatString:
|
17
|
+
EnforcedStyle: percent
|
18
|
+
Style/FormatStringToken:
|
19
|
+
EnforcedStyle: unannotated
|
20
|
+
Style/PerlBackrefs:
|
21
|
+
Enabled: false
|
22
|
+
Style/RedundantSelf:
|
23
|
+
Enabled: false
|
24
|
+
Style/StructInheritance:
|
25
|
+
Enabled: false
|
26
|
+
Style/TrailingCommaInArrayLiteral:
|
27
|
+
Enabled: false
|
28
|
+
Style/TrailingCommaInHashLiteral:
|
29
|
+
Enabled: false
|
data/README.md
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
[](https://badge.fury.io/rb/packetgen-plugin-smb)
|
1
2
|
[](https://travis-ci.com/sdaubert/packetgen-plugin-smb)
|
2
3
|
|
3
4
|
# Packetgen::Plugin::SMB
|
@@ -24,6 +25,10 @@ Or install it yourself as:
|
|
24
25
|
|
25
26
|
TODO
|
26
27
|
|
28
|
+
## License
|
29
|
+
|
30
|
+
MIT License (see [LICENSE](https://github.com/sdaubert/packetgen-plugin-smb/blob/master/LICENSE))
|
31
|
+
|
27
32
|
## Contributing
|
28
33
|
|
29
34
|
Bug reports and pull requests are welcome on GitHub at https://github.com/sdaubert/packetgen-plugin-smb.
|
data/lib/packetgen-plugin-smb.rb
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
# This file is part of PacketGen
|
2
|
+
# See https://github.com/sdaubert/packetgen-plugin-smb for more informations
|
3
|
+
# Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
|
4
|
+
# This program is published under MIT license.
|
5
|
+
|
6
|
+
# frozen_string_literal: true
|
7
|
+
|
1
8
|
require "packetgen"
|
2
9
|
require_relative "packetgen/plugin/smb_version"
|
3
10
|
require_relative "packetgen/plugin/smb"
|
data/lib/packetgen/plugin/smb.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# This file is part of PacketGen
|
2
|
-
# See https://github.com/sdaubert/packetgen for more informations
|
2
|
+
# See https://github.com/sdaubert/packetgen-plugin-smb for more informations
|
3
3
|
# Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
|
4
4
|
# This program is published under MIT license.
|
5
5
|
|
@@ -8,7 +8,6 @@
|
|
8
8
|
module PacketGen::Plugin
|
9
9
|
# Server Message Block (SMB) header.
|
10
10
|
# @author Sylvain Daubert
|
11
|
-
# @since 0.1.0
|
12
11
|
class SMB < PacketGen::Header::Base
|
13
12
|
# Known commands
|
14
13
|
COMMANDS = {
|
@@ -171,6 +170,30 @@ module PacketGen::Plugin
|
|
171
170
|
PacketGen::Header.add_class kresponse
|
172
171
|
self.bind kresponse, command: SMB::COMMANDS[command], flags: ->(v) { v.nil? ? 0 : (v & 0x80 == 0x80) }
|
173
172
|
end
|
173
|
+
|
174
|
+
def inspect
|
175
|
+
str = PacketGen::Inspect.dashed_line(self.class, 1)
|
176
|
+
fields.each do |attr|
|
177
|
+
next if attr == :body
|
178
|
+
|
179
|
+
case attr
|
180
|
+
when :flags, :flags2
|
181
|
+
value = bits_on(attr).reject { |_, v| v > 1 }
|
182
|
+
.keys
|
183
|
+
.select { |b| send("#{b}?") }
|
184
|
+
.map(&:to_s)
|
185
|
+
.join(',')
|
186
|
+
.gsub!(/#{attr}_/, '')
|
187
|
+
value = '%-16s (0x%02x)' % [value, self[attr].to_i]
|
188
|
+
str << PacketGen::Inspect.shift_level(1)
|
189
|
+
str << PacketGen::Inspect::FMT_ATTR % [self[attr].class.to_s.sub(/.*::/, ''),
|
190
|
+
attr, value]
|
191
|
+
else
|
192
|
+
str << PacketGen::Inspect.inspect_attribute(attr, self[attr], 1)
|
193
|
+
end
|
194
|
+
end
|
195
|
+
str
|
196
|
+
end
|
174
197
|
end
|
175
198
|
PacketGen::Header.add_class SMB
|
176
199
|
PacketGen::Header::NetBIOS::Session.bind SMB, body: ->(val) { val.nil? ? SMB::MARKER : val[0..3] == SMB::MARKER }
|
@@ -182,4 +205,5 @@ require_relative 'smb/filetime'
|
|
182
205
|
require_relative 'smb/close'
|
183
206
|
require_relative 'smb/trans'
|
184
207
|
require_relative 'smb/nt_create_and_x'
|
208
|
+
require_relative 'smb/browser'
|
185
209
|
require_relative 'smb/blocks'
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# This file is part of PacketGen
|
2
|
-
# See https://github.com/sdaubert/packetgen for more informations
|
2
|
+
# See https://github.com/sdaubert/packetgen-plugin-smb for more informations
|
3
3
|
# Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
|
4
4
|
# This program is published under MIT license.
|
5
5
|
|
@@ -17,7 +17,6 @@ module PacketGen::Plugin
|
|
17
17
|
# * a little endian 16-bit {#byte_count} field,
|
18
18
|
# * a {#bytes} field, an array of +PacketGen::Types::Int8+.
|
19
19
|
# @author Sylvain Daubert
|
20
|
-
# @since 0.1.0
|
21
20
|
class Blocks < PacketGen::Header::Base
|
22
21
|
# @!attribute word_count
|
23
22
|
# The size, in 2-byte words, of the {#words} field.
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# This file is part of PacketGen
|
2
|
+
# See https://github.com/sdaubert/packetgen-plugin-smb for more informations
|
3
|
+
# Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
|
4
|
+
# This program is published under MIT license.
|
5
|
+
|
6
|
+
# frozen_string_literal: true
|
7
|
+
|
8
|
+
module PacketGen::Plugin
|
9
|
+
class SMB
|
10
|
+
# Browser Trans sub-protocol.
|
11
|
+
# See subclasses.
|
12
|
+
# @author Sylvain Daubert
|
13
|
+
class Browser < PacketGen::Header::Base
|
14
|
+
OPCODES = {
|
15
|
+
'HostAnnouncement' => 1,
|
16
|
+
'HostAnnouncementReq' => 2,
|
17
|
+
'RequestElection' => 8,
|
18
|
+
'GetBackupListReq' => 9,
|
19
|
+
'GetBackupListResp' => 10,
|
20
|
+
'BecomeBackup' => 11,
|
21
|
+
'DomainAnnouncement' => 12,
|
22
|
+
'MasterAnnouncement' => 13,
|
23
|
+
'ResetStateRequest' => 14,
|
24
|
+
'LocalMasterAnnouncement' => 15
|
25
|
+
}.freeze
|
26
|
+
|
27
|
+
# @!attribute opcode
|
28
|
+
# 8-bit opcode
|
29
|
+
# @return [Integer]
|
30
|
+
define_field :opcode, PacketGen::Types::Int8Enum, enum: OPCODES
|
31
|
+
# @!attribute body
|
32
|
+
# @return [String]
|
33
|
+
define_field :body, PacketGen::Types::String
|
34
|
+
|
35
|
+
alias old_read read
|
36
|
+
private :old_read
|
37
|
+
|
38
|
+
# Populate object from a binary string
|
39
|
+
# @param [String] str
|
40
|
+
# @return [Browser] may return a subclass object if a more specific class
|
41
|
+
# may be determined
|
42
|
+
def read(str)
|
43
|
+
if self.class == Browser
|
44
|
+
return self if str.nil?
|
45
|
+
|
46
|
+
PacketGen.force_binary str
|
47
|
+
self[:opcode].read str[0]
|
48
|
+
|
49
|
+
opcode_klass = Browser.const_get(self[:opcode].to_human) if Browser.const_defined?(self[:opcode].to_human)
|
50
|
+
if opcode_klass
|
51
|
+
opcode_klass.new.read str
|
52
|
+
else
|
53
|
+
private_read str
|
54
|
+
end
|
55
|
+
else
|
56
|
+
private_read str
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# Give protocol name for this class
|
61
|
+
# @return [String]
|
62
|
+
def protocol_name
|
63
|
+
'SMB::Browser'
|
64
|
+
end
|
65
|
+
|
66
|
+
# Callback called when a Browser header is added to a packet.
|
67
|
+
# Here, add +#smb_browser+ method as a shortcut to existing
|
68
|
+
# +#smb_browser_*+ method.
|
69
|
+
# @param [Packet] packet
|
70
|
+
# @return [void]
|
71
|
+
def added_to_packet(packet)
|
72
|
+
return if packet.respond_to? :smb_browser
|
73
|
+
|
74
|
+
packet.instance_eval("def smb_browser(arg=nil); header(#{self.class}, arg); end")
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
def private_read(str)
|
80
|
+
old_read str
|
81
|
+
end
|
82
|
+
end
|
83
|
+
PacketGen::Header.add_class Browser
|
84
|
+
SMB::TransRequest.bind Browser, name: '\\MAILSLOT\\BROWSE'
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
require_relative 'browser/host_announcement'
|
89
|
+
require_relative 'browser/domain_announcement'
|
90
|
+
require_relative 'browser/local_master_announcement'
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# This file is part of PacketGen
|
2
|
+
# See https://github.com/sdaubert/packetgen-plugin-smb for more informations
|
3
|
+
# Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
|
4
|
+
# This program is published under MIT license.
|
5
|
+
|
6
|
+
# frozen_string_literal: true
|
7
|
+
|
8
|
+
module PacketGen::Plugin
|
9
|
+
class SMB
|
10
|
+
class Browser
|
11
|
+
# Local master announcement browser frame.
|
12
|
+
#
|
13
|
+
# Such a frame is used by a local master of a machine group to
|
14
|
+
# announce the machine group it serves.
|
15
|
+
# @author Sylvain Daubert
|
16
|
+
class DomainAnnouncement < HostAnnouncement
|
17
|
+
update_field :opcode, default: 12
|
18
|
+
|
19
|
+
alias browser_conf_ver_maj os_ver_maj
|
20
|
+
alias browser_conf_ver_min os_ver_min
|
21
|
+
alias machine_group server_name
|
22
|
+
alias local_master_name comment
|
23
|
+
|
24
|
+
# @return [String]
|
25
|
+
def protocol_name
|
26
|
+
'SMB::Browser::DomainAnnouncement'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
PacketGen::Header.add_class DomainAnnouncement
|
30
|
+
SMB::TransRequest.bind DomainAnnouncement, name: '\\MAILSLOT\\BROWSE', body: ->(v) { v[0] == OPCODES['DomainAnnouncement'] }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# This file is part of PacketGen
|
2
|
+
# See https://github.com/sdaubert/packetgen-plugin-smb for more informations
|
3
|
+
# Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
|
4
|
+
# This program is published under MIT license.
|
5
|
+
|
6
|
+
# frozen_string_literal: true
|
7
|
+
|
8
|
+
module PacketGen::Plugin
|
9
|
+
class SMB
|
10
|
+
class Browser
|
11
|
+
# Host announcement browser frame.
|
12
|
+
#
|
13
|
+
# Such a frame is used by a server to advertise its presence and
|
14
|
+
# specify the types of resources and services it supports.
|
15
|
+
# @author Sylvain Daubert
|
16
|
+
class HostAnnouncement < Browser
|
17
|
+
delete_field :body
|
18
|
+
update_field :opcode, default: 1
|
19
|
+
# @!attribute update_count
|
20
|
+
# 8-bit integer. Not used. Should be 0
|
21
|
+
# @return [Integer]
|
22
|
+
define_field :update_count, PacketGen::Types::Int8, default: 0
|
23
|
+
# @!attribute periodicity
|
24
|
+
# 32-bit integer that must be the announcement frequency of the
|
25
|
+
# server in milliseconds.
|
26
|
+
# @return [Integer]
|
27
|
+
define_field :periodicity, PacketGen::Types::Int32le
|
28
|
+
# @!attribute server_name
|
29
|
+
# Null-terminated ASCII string of 16-byte length. Used to identify
|
30
|
+
# server.
|
31
|
+
# @return [String]
|
32
|
+
define_field :server_name, PacketGen::Types::CString, static_length: 16
|
33
|
+
# @!attribute os_ver_maj
|
34
|
+
# 8-bit integer indicating the OS major version number
|
35
|
+
# @return [Integer]
|
36
|
+
define_field :os_ver_maj, PacketGen::Types::Int8
|
37
|
+
# @!attribute os_ver_min
|
38
|
+
# 8-bit integer indicating the OS minor version number
|
39
|
+
# @return [Integer]
|
40
|
+
define_field :os_ver_min, PacketGen::Types::Int8
|
41
|
+
# @!attribute server_type
|
42
|
+
# 32-bit integer indicating the type of the server
|
43
|
+
# @return [Integer]
|
44
|
+
define_field :server_type, PacketGen::Types::Int32le
|
45
|
+
# @!attribute browser_ver_maj
|
46
|
+
# 8-bit Browser protocol major version number. Should be 15.
|
47
|
+
# @return [Integer]
|
48
|
+
define_field :browser_ver_maj, PacketGen::Types::Int8, default: 15
|
49
|
+
# @!attribute browser_ver_min
|
50
|
+
# 8-bit Browser protocol minor version number. Should be 1.
|
51
|
+
# @return [Integer]
|
52
|
+
define_field :browser_ver_min, PacketGen::Types::Int8, default: 1
|
53
|
+
# @!attribute signature
|
54
|
+
# 16-bit sinature integer. Should be 0xAA55.
|
55
|
+
# @return [Integer]
|
56
|
+
define_field :signature, PacketGen::Types::Int16le, default: 0xaa55
|
57
|
+
# @!attribute comment
|
58
|
+
# Null-terminated ASCII string.
|
59
|
+
# @return [String]
|
60
|
+
define_field :comment, PacketGen::Types::CString
|
61
|
+
|
62
|
+
# @return [String]
|
63
|
+
def protocol_name
|
64
|
+
'SMB::Browser::HostAnnouncement'
|
65
|
+
end
|
66
|
+
end
|
67
|
+
PacketGen::Header.add_class HostAnnouncement
|
68
|
+
SMB::TransRequest.bind HostAnnouncement, name: '\\MAILSLOT\\BROWSE', body: ->(v) { v[0] == OPCODES['HostAnnouncement'] }
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# This file is part of PacketGen
|
2
|
+
# See https://github.com/sdaubert/packetgen-plugin-smb for more informations
|
3
|
+
# Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
|
4
|
+
# This program is published under MIT license.
|
5
|
+
|
6
|
+
# frozen_string_literal: true
|
7
|
+
|
8
|
+
module PacketGen::Plugin
|
9
|
+
class SMB
|
10
|
+
class Browser
|
11
|
+
# Local master announcement browser frame.
|
12
|
+
#
|
13
|
+
# Such a frame is used by a local master of a machine group to
|
14
|
+
# advertise its presence.
|
15
|
+
# @author Sylvain Daubert
|
16
|
+
class LocalMasterAnnouncement < HostAnnouncement
|
17
|
+
update_field :opcode, default: 15
|
18
|
+
|
19
|
+
# @return [String]
|
20
|
+
def protocol_name
|
21
|
+
'SMB::Browser::LocalMasterAnnouncement'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
PacketGen::Header.add_class LocalMasterAnnouncement
|
25
|
+
SMB::TransRequest.bind LocalMasterAnnouncement, name: '\\MAILSLOT\\BROWSE', body: ->(v) { v[0] == OPCODES['LocalMasterAnnouncement'] }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# This file is part of PacketGen
|
2
|
-
# See https://github.com/sdaubert/packetgen for more informations
|
2
|
+
# See https://github.com/sdaubert/packetgen-plugin-smb for more informations
|
3
3
|
# Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
|
4
4
|
# This program is published under MIT license.
|
5
5
|
|
@@ -9,7 +9,6 @@ module PacketGen::Plugin
|
|
9
9
|
class SMB
|
10
10
|
# Close Request.
|
11
11
|
# @author Sylvain Daubert
|
12
|
-
# @since 0.1.0
|
13
12
|
class CloseRequest < PacketGen::Header::Base
|
14
13
|
# @!attribute word_count
|
15
14
|
# The size, in 2-byte words, of the SMB command parameters. It should
|
@@ -32,6 +31,12 @@ module PacketGen::Plugin
|
|
32
31
|
# Should be 0.
|
33
32
|
# @return [Integer]
|
34
33
|
define_field :byte_count, PacketGen::Types::Int16le, default: 0
|
34
|
+
|
35
|
+
# Give protocol name for this class
|
36
|
+
# @return [String]
|
37
|
+
def protocol_name
|
38
|
+
'SMB::CloseRequest'
|
39
|
+
end
|
35
40
|
end
|
36
41
|
|
37
42
|
# Close Response.
|
@@ -50,6 +55,12 @@ module PacketGen::Plugin
|
|
50
55
|
# Should be 0.
|
51
56
|
# @return [Integer]
|
52
57
|
define_field :byte_count, PacketGen::Types::Int16le, default: 0
|
58
|
+
|
59
|
+
# Give protocol name for this class
|
60
|
+
# @return [String]
|
61
|
+
def protocol_name
|
62
|
+
'SMB::CloseResponse'
|
63
|
+
end
|
53
64
|
end
|
54
65
|
|
55
66
|
self.bind_command 'close'
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# This file is part of PacketGen
|
2
|
-
# See https://github.com/sdaubert/packetgen for more informations
|
2
|
+
# See https://github.com/sdaubert/packetgen-plugin-smb for more informations
|
3
3
|
# Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
|
4
4
|
# This program is published under MIT license.
|
5
5
|
|
@@ -7,20 +7,8 @@
|
|
7
7
|
|
8
8
|
module PacketGen::Plugin
|
9
9
|
class SMB
|
10
|
-
# 64-bit signed integer, little endian representation
|
11
|
-
# @author Sylvain Daubert
|
12
|
-
# @private
|
13
|
-
# @since 0.1.0
|
14
|
-
class SInt64le < PacketGen::Types::Int64le
|
15
|
-
def initialize(value=nil)
|
16
|
-
super
|
17
|
-
@packstr[:little] = 'q<'
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
10
|
# SMB FILETIME.
|
22
11
|
# @author Sylvain Daubert
|
23
|
-
# @since 0.1.0
|
24
12
|
class Filetime
|
25
13
|
# Base time for SMB FILETIME.
|
26
14
|
# This value also indicate no time.
|
@@ -35,7 +23,7 @@ module PacketGen::Plugin
|
|
35
23
|
raise ArgumentError, ':time and :filetime options are both given'
|
36
24
|
end
|
37
25
|
|
38
|
-
@int = SInt64le.new(options[:filetime])
|
26
|
+
@int = PacketGen::Types::SInt64le.new(options[:filetime])
|
39
27
|
if options[:time]
|
40
28
|
@time = options[:time]
|
41
29
|
@int.value = time2filetime
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# This file is part of PacketGen
|
2
|
-
# See https://github.com/sdaubert/packetgen for more informations
|
2
|
+
# See https://github.com/sdaubert/packetgen-plugin-smb for more informations
|
3
3
|
# Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
|
4
4
|
# This program is published under MIT license.
|
5
5
|
|
@@ -37,7 +37,6 @@ module PacketGen::Plugin
|
|
37
37
|
# 1. Only the first command is properly handled. Chained commands are not.
|
38
38
|
# 2. {#filename} is mandatory handled as Windows Unicode string.
|
39
39
|
# @author Sylvain Daubert
|
40
|
-
# @since 0.1.0
|
41
40
|
class NtCreateAndXRequest < PacketGen::Header::Base
|
42
41
|
# Commands that may follow this one in a SMB packet
|
43
42
|
COMMANDS = {
|
@@ -124,18 +123,19 @@ module PacketGen::Plugin
|
|
124
123
|
# @return [Integer]
|
125
124
|
define_field :byte_count, PacketGen::Types::Int16le
|
126
125
|
# @!attribute pad1
|
127
|
-
# Padding before {#filename} to align it on 16-bit boundary
|
126
|
+
# Padding before {#filename} to align it on 16-bit boundary. Only present
|
127
|
+
# if {SMB#flags2_unicode?} is +true+.
|
128
128
|
# @return [Integer]
|
129
|
-
define_field :pad1, PacketGen::Types::Int8
|
129
|
+
define_field :pad1, PacketGen::Types::Int8, optional: ->(h) { h.packet && h.packet.smb.flags2_unicode? }
|
130
130
|
# @!attribute filename
|
131
131
|
# A string that represents the fully qualified name of the file
|
132
132
|
# relative to the supplied TID
|
133
133
|
# @return [String]
|
134
|
-
define_field :filename, SMB::String
|
134
|
+
define_field :filename, SMB::String, builder: ->(h, t) { t.new(unicode: !h.packet || h.packet.smb.flags2_unicode?) }
|
135
135
|
# @!attribute extra_bytes
|
136
136
|
# @return [Integer]
|
137
137
|
define_field :extra_bytes, PacketGen::Types::String,
|
138
|
-
builder: ->(h, t) { t.new(length_from: -> { h.byte_count - 1 - h[:filename].sz }) }
|
138
|
+
builder: ->(h, t) { t.new(length_from: -> { h.byte_count - (h.present?(:pad1) ? 1 : 0) - h[:filename].sz }) }
|
139
139
|
|
140
140
|
# Give protocol name for this class
|
141
141
|
# @return [String]
|
@@ -147,14 +147,14 @@ module PacketGen::Plugin
|
|
147
147
|
# @return [void]
|
148
148
|
def calc_length
|
149
149
|
self.filename_len = self[:filename].sz
|
150
|
-
|
150
|
+
pad1sz = self.present?(:pad1) ? 1 : 0
|
151
|
+
bcount = pad1sz + filename_len + self[:extra_bytes].sz
|
151
152
|
self.byte_count = bcount
|
152
153
|
end
|
153
154
|
end
|
154
155
|
|
155
156
|
# SMB Command NtCreateAndX response
|
156
157
|
# @author Sylvain Daubert
|
157
|
-
# @since 0.1.0
|
158
158
|
class NtCreateAndXResponse < PacketGen::Header::Base
|
159
159
|
# OpLock levels
|
160
160
|
OP_LOCK_LEVELS = {
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# This file is part of PacketGen
|
2
|
-
# See https://github.com/sdaubert/packetgen for more informations
|
2
|
+
# See https://github.com/sdaubert/packetgen-plugin-smb for more informations
|
3
3
|
# Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
|
4
4
|
# This program is published under MIT license.
|
5
5
|
|
@@ -9,14 +9,25 @@ module PacketGen::Plugin
|
|
9
9
|
class SMB
|
10
10
|
# SMB strings (UTF-16 little-endian).
|
11
11
|
# @author Sylvain Daubert
|
12
|
-
# @since 0.1.0
|
13
12
|
class String < PacketGen::Types::CString
|
13
|
+
# @param [Boolean] unicode
|
14
|
+
attr_writer :unicode
|
15
|
+
|
14
16
|
# @param [Boolean, Proc] is string UTF-16 encoded?
|
15
17
|
# @param [Hash] options
|
16
18
|
# @option options [Integer] :static_length set a static length for this string
|
19
|
+
# @option options [Boolean] :unicode If +true+, string is encoded as a UTF-16
|
20
|
+
# unicode string. If +false+, string is encode in ASCII. Defaults to +true+.
|
17
21
|
def initialize(options={})
|
18
22
|
super
|
19
|
-
|
23
|
+
@unicode = options.key?(:unicode) ? options[:unicode] : true
|
24
|
+
self.encode!('UTF-16LE') if @unicode
|
25
|
+
self.encode!('ASCII-8BIT') unless @unicode
|
26
|
+
end
|
27
|
+
|
28
|
+
# @return [Boolean]
|
29
|
+
def unicode?
|
30
|
+
@unicode
|
20
31
|
end
|
21
32
|
|
22
33
|
# @param [::String] str
|
@@ -28,25 +39,33 @@ module PacketGen::Plugin
|
|
28
39
|
when Encoding::BINARY
|
29
40
|
binidx = nil
|
30
41
|
0.step(to: str.size, by: 2) do |i|
|
31
|
-
binidx = i if str[i, 2] ==
|
42
|
+
binidx = i if str[i, 2] == binary_terminator
|
32
43
|
end
|
33
44
|
s = if binidx.nil?
|
34
45
|
str
|
35
46
|
else
|
36
47
|
str[0, binidx]
|
37
48
|
end
|
38
|
-
s.force_encoding(
|
39
|
-
when Encoding::UTF_16LE
|
40
|
-
str
|
49
|
+
s.force_encoding(self_encoding)
|
41
50
|
else
|
42
|
-
str.encode(
|
51
|
+
str.encode(self_encoding)
|
43
52
|
end
|
44
53
|
str2 = str2[0, @static_length / 2] if @static_length.is_a? Integer
|
45
|
-
idx = str2.index(+"\x00".encode(
|
54
|
+
idx = str2.index(+"\x00".encode(self_encoding))
|
46
55
|
str2 = str2[0, idx] unless idx.nil?
|
47
56
|
self.replace str2
|
48
57
|
self
|
49
58
|
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def self_encoding
|
63
|
+
@unicode ? Encoding::UTF_16LE : Encoding:: ASCII_8BIT
|
64
|
+
end
|
65
|
+
|
66
|
+
def binary_terminator
|
67
|
+
@unicode ? "\x00\x00" : "\x00"
|
68
|
+
end
|
50
69
|
end
|
51
70
|
end
|
52
71
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# This file is part of PacketGen
|
2
|
-
# See https://github.com/sdaubert/packetgen for more informations
|
2
|
+
# See https://github.com/sdaubert/packetgen-plugin-smb for more informations
|
3
3
|
# Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
|
4
4
|
# This program is published under MIT license.
|
5
5
|
|
@@ -12,7 +12,6 @@ module PacketGen::Plugin
|
|
12
12
|
# See also {Blocks}, as {TransRequest} is a specialization of {Blocks#words}
|
13
13
|
# and {Blocks#bytes}.
|
14
14
|
# @author Sylvain Daubert
|
15
|
-
# @since 0.1.0
|
16
15
|
class TransRequest < PacketGen::Header::Base
|
17
16
|
# @!attribute word_count
|
18
17
|
# The size, in 2-byte words, of the SMB command parameters. It should
|
@@ -93,13 +92,14 @@ module PacketGen::Plugin
|
|
93
92
|
# @return [Integer]
|
94
93
|
define_field :byte_count, PacketGen::Types::Int16le
|
95
94
|
# @!attribute padname
|
96
|
-
# 8-bit optional padding to align {#name} on a 2-byte boundary.
|
95
|
+
# 8-bit optional padding to align {#name} on a 2-byte boundary. Only present
|
96
|
+
# if {SMB#flags2_unicode?} is +true+.
|
97
97
|
# @return [Integer]
|
98
|
-
define_field :padname, PacketGen::Types::Int8
|
98
|
+
define_field :padname, PacketGen::Types::Int8, optional: ->(h) { h.packet && h.packet.smb.flags2_unicode? }
|
99
99
|
# @!attribute name
|
100
100
|
# Pathname of the mailslot or named pipe.
|
101
101
|
# @return [String]
|
102
|
-
define_field :name, SMB::String
|
102
|
+
define_field :name, SMB::String, builder: ->(h, t) { t.new(unicode: !h.packet || h.packet.smb.flags2_unicode?) }
|
103
103
|
# @!attribute pad1
|
104
104
|
# Padding to align {#body} on 4-byte boundary.
|
105
105
|
# @return [String]
|
@@ -119,7 +119,6 @@ module PacketGen::Plugin
|
|
119
119
|
# See also {Blocks}, as {TransResponse} is a specialization of {Blocks#words}
|
120
120
|
# and {Blocks#bytes}.
|
121
121
|
# @author Sylvain Daubert
|
122
|
-
# @since 0.1.0
|
123
122
|
class TransResponse < PacketGen::Header::Base
|
124
123
|
# @!attribute word_count
|
125
124
|
# The size, in 2-byte words, of the SMB command parameters. It should
|
@@ -17,7 +17,9 @@ Gem::Specification.new do |spec|
|
|
17
17
|
end
|
18
18
|
spec.require_paths = ['lib']
|
19
19
|
|
20
|
-
spec.
|
20
|
+
spec.required_ruby_version = '>= 2.3.0'
|
21
|
+
|
22
|
+
spec.add_dependency 'packetgen', '~>2.8', '>= 2.8.4'
|
21
23
|
|
22
24
|
spec.add_development_dependency 'bundler', '~> 1.16'
|
23
25
|
spec.add_development_dependency 'rake', '~> 10.0'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: packetgen-plugin-smb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sylvain Daubert
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: packetgen
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: '2.8'
|
20
20
|
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 2.8.
|
22
|
+
version: 2.8.4
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
version: '2.8'
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 2.8.
|
32
|
+
version: 2.8.4
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: bundler
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,6 +108,7 @@ extensions: []
|
|
108
108
|
extra_rdoc_files: []
|
109
109
|
files:
|
110
110
|
- ".gitignore"
|
111
|
+
- ".rubocop.yml"
|
111
112
|
- ".travis.yml"
|
112
113
|
- Gemfile
|
113
114
|
- LICENSE
|
@@ -116,6 +117,10 @@ files:
|
|
116
117
|
- lib/packetgen-plugin-smb.rb
|
117
118
|
- lib/packetgen/plugin/smb.rb
|
118
119
|
- lib/packetgen/plugin/smb/blocks.rb
|
120
|
+
- lib/packetgen/plugin/smb/browser.rb
|
121
|
+
- lib/packetgen/plugin/smb/browser/domain_announcement.rb
|
122
|
+
- lib/packetgen/plugin/smb/browser/host_announcement.rb
|
123
|
+
- lib/packetgen/plugin/smb/browser/local_master_announcement.rb
|
119
124
|
- lib/packetgen/plugin/smb/close.rb
|
120
125
|
- lib/packetgen/plugin/smb/filetime.rb
|
121
126
|
- lib/packetgen/plugin/smb/nt_create_and_x.rb
|
@@ -134,7 +139,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
134
139
|
requirements:
|
135
140
|
- - ">="
|
136
141
|
- !ruby/object:Gem::Version
|
137
|
-
version:
|
142
|
+
version: 2.3.0
|
138
143
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
144
|
requirements:
|
140
145
|
- - ">="
|