Class: PacketGen::Plugin::SMB2::Negotiate::Request

Inherits:
Base
  • Object
show all
Defined in:
lib/packetgen/plugin/smb2/negotiate/request.rb

Overview

SMB2 Negotiate request structure

 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|        StructureSize          |          DialectCount         |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|         SecurityMode          |            Reserved           |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                         Capabilities                          |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                          ClientGUID                           |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                         ContextOffset                         |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|        ContextCount           |            Reserved2          |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                       Dialects (variable)                     |
+                                                               +
|                              ...                              |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                         Pad (variable)                        |
+                                                               +
|                              ...                              |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                     ContextList (variable)                    |
+                                                               +
|                              ...                              |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Author:

  • Sylvain Daubert

Constant Summary collapse

SECURITY_MODES =

Security modes

{
  'signing_enabled' => 1,
  'signing required' => 2
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

define_smb2_pad_field

Instance Attribute Details

#cap_dfsBoolean

Indicates if Distributed File system (DFS) is supported

Returns:

  • (Boolean)


94
95
96
# File 'lib/packetgen/plugin/smb2/negotiate/request.rb', line 94

define_bit_fields_on :capabilities, :cap_rsv, 25, :cap_encryption, :cap_dir_leasing,
:cap_persistent_handles, :cap_multi_channel,
:cap_large_mtu, :cap_leasing, :cap_dfs

#cap_dir_leasingBoolean

Indicates if directory leasing is supported

Returns:

  • (Boolean)


94
95
96
# File 'lib/packetgen/plugin/smb2/negotiate/request.rb', line 94

define_bit_fields_on :capabilities, :cap_rsv, 25, :cap_encryption, :cap_dir_leasing,
:cap_persistent_handles, :cap_multi_channel,
:cap_large_mtu, :cap_leasing, :cap_dfs

#cap_encryptionBoolean

Indicates if encryption is supported

Returns:

  • (Boolean)


94
95
96
# File 'lib/packetgen/plugin/smb2/negotiate/request.rb', line 94

define_bit_fields_on :capabilities, :cap_rsv, 25, :cap_encryption, :cap_dir_leasing,
:cap_persistent_handles, :cap_multi_channel,
:cap_large_mtu, :cap_leasing, :cap_dfs

#cap_large_mtuBoolean

Indicates if multi credit operations are supported

Returns:

  • (Boolean)


94
95
96
# File 'lib/packetgen/plugin/smb2/negotiate/request.rb', line 94

define_bit_fields_on :capabilities, :cap_rsv, 25, :cap_encryption, :cap_dir_leasing,
:cap_persistent_handles, :cap_multi_channel,
:cap_large_mtu, :cap_leasing, :cap_dfs

#cap_leasingBoolean

Indicates if leasing is supported

Returns:

  • (Boolean)


94
95
96
# File 'lib/packetgen/plugin/smb2/negotiate/request.rb', line 94

define_bit_fields_on :capabilities, :cap_rsv, 25, :cap_encryption, :cap_dir_leasing,
:cap_persistent_handles, :cap_multi_channel,
:cap_large_mtu, :cap_leasing, :cap_dfs

#cap_multi_channelBoolean

Indicates if multiple channels are supported for a single session

Returns:

  • (Boolean)


94
95
96
# File 'lib/packetgen/plugin/smb2/negotiate/request.rb', line 94

define_bit_fields_on :capabilities, :cap_rsv, 25, :cap_encryption, :cap_dir_leasing,
:cap_persistent_handles, :cap_multi_channel,
:cap_large_mtu, :cap_leasing, :cap_dfs

#cap_persistent_handlesBoolean

Indicates if persisten handles are supported

Returns:

  • (Boolean)


94
95
96
# File 'lib/packetgen/plugin/smb2/negotiate/request.rb', line 94

define_bit_fields_on :capabilities, :cap_rsv, 25, :cap_encryption, :cap_dir_leasing,
:cap_persistent_handles, :cap_multi_channel,
:cap_large_mtu, :cap_leasing, :cap_dfs

#capabilitiesInteger

32-bit capabilities field.

Returns:

  • (Integer)


72
# File 'lib/packetgen/plugin/smb2/negotiate/request.rb', line 72

define_field :capabilities, PacketGen::Types::Int32le

#client_guidObject

Returns [].

Returns:



99
# File 'lib/packetgen/plugin/smb2/negotiate/request.rb', line 99

define_field :client_guid, GUID

#context_countInteger

Only for SMB3 dialect.

Returns:

  • (Integer)


107
# File 'lib/packetgen/plugin/smb2/negotiate/request.rb', line 107

define_field :context_count, PacketGen::Types::Int16le

#context_listArrayOfContext

If #dialects contains the value 0x0311, then this field must contain an array of Context

Returns:



125
# File 'lib/packetgen/plugin/smb2/negotiate/request.rb', line 125

define_field :context_list, ArrayOfContext, builder: ->(h, t) { t.new(counter: h[:context_count]) }

#context_offsetInteger

Only for SMB3 dialect.

Returns:

  • (Integer)


103
# File 'lib/packetgen/plugin/smb2/negotiate/request.rb', line 103

define_field :context_offset, PacketGen::Types::Int32le

#dialect_countInteger

16-bit number of dialects that are contained in #dialects.

Returns:

  • (Integer)


60
# File 'lib/packetgen/plugin/smb2/negotiate/request.rb', line 60

define_field :dialect_count, PacketGen::Types::Int16le

#dialectsArray<PacketGen::Types::Int16le>

Array of 16-bit integers specifying the supported dialtec revisions.

Returns:

  • (Array<PacketGen::Types::Int16le>)


115
# File 'lib/packetgen/plugin/smb2/negotiate/request.rb', line 115

define_field :dialects, PacketGen::Types::ArrayOfInt16le, builder: ->(h, t) { t.new(counter: h[:dialect_count]) }

#padString

Optional padding between the end of the #dialects array and the first negotiate context in #context_list so that the first negotiate context is 8-byte aligned.

Returns:

  • (String)


120
# File 'lib/packetgen/plugin/smb2/negotiate/request.rb', line 120

define_smb2_pad_field :pad

#reservedInteger

16-bit reserved field.

Returns:

  • (Integer)


68
# File 'lib/packetgen/plugin/smb2/negotiate/request.rb', line 68

define_field :reserved, PacketGen::Types::Int16le

#reserved2Integer

Only for SMB3 dialect.

Returns:

  • (Integer)


111
# File 'lib/packetgen/plugin/smb2/negotiate/request.rb', line 111

define_field :reserved2, PacketGen::Types::Int16le

#security_modeInteger

16-bit security mode field.

Returns:

  • (Integer)


64
# File 'lib/packetgen/plugin/smb2/negotiate/request.rb', line 64

define_field :security_mode, PacketGen::Types::Int16leEnum, enum: SECURITY_MODES

#structure_sizeInteger

16-bit negotiate request structure size. Should be 36.

Returns:

  • (Integer)


56
# File 'lib/packetgen/plugin/smb2/negotiate/request.rb', line 56

define_field :structure_size, PacketGen::Types::Int16le, default: 36

Class Method Details

.protocol_nameString

Protocol name

Returns:

  • (String)


129
130
131
# File 'lib/packetgen/plugin/smb2/negotiate/request.rb', line 129

def self.protocol_name
  'SMB2::Negotiate::Request'
end

Instance Method Details

#calc_lengthInteger

Calculate and set #context_offset and #pad fields. Also calculate lengths in contexts.

Returns:

  • (Integer)


160
161
162
163
164
165
166
# File 'lib/packetgen/plugin/smb2/negotiate/request.rb', line 160

def calc_length
  self[:pad].read SMB2::MAX_PADDING

  self.context_offset = 0
  self.context_offset = SMB2::HEADER_SIZE + offset_of(:context_list) unless context_list.empty?
  context_list.each { |ctx| ctx.calc_length if ctx.respond_to? :calc_length }
end

#inspectString

Returns:

  • (String)


134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/packetgen/plugin/smb2/negotiate/request.rb', line 134

def inspect
  super do |attr|
    case attr
    when :capabilities
      value = bits_on(attr).reject { |_, v| v > 1 }
                           .keys
                           .select { |b| send("#{b}?") }
                           .map(&:to_s)
                           .join(',')
                           .gsub!(/cap_/, '')
      value = '%-16s (0x%08x)' % [value, self[attr].to_i]
      str = PacketGen::Inspect.shift_level
      str << PacketGen::Inspect::FMT_ATTR % [self[attr].class.to_s.sub(/.*::/, ''),
                                             attr, value]
    when :dialects
      list = self.dialects.map { |v| '%#x' % v.to_i }.join(',')
      str = PacketGen::Inspect.shift_level
      str << PacketGen::Inspect::FMT_ATTR % [self[attr].class.to_s.sub(/.*::/, ''),
                                             attr, list]
    end
  end
end