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)


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

define_bit_attr :capabilities, endian: :little,
cap_rsv: 25, cap_encryption: 1, cap_dir_leasing: 1,
cap_persistent_handles: 1, cap_multi_channel: 1,
cap_large_mtu: 1, cap_leasing: 1, cap_dfs: 1

#cap_dir_leasingBoolean

Indicates if directory leasing is supported

Returns:

  • (Boolean)


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

define_bit_attr :capabilities, endian: :little,
cap_rsv: 25, cap_encryption: 1, cap_dir_leasing: 1,
cap_persistent_handles: 1, cap_multi_channel: 1,
cap_large_mtu: 1, cap_leasing: 1, cap_dfs: 1

#cap_encryptionBoolean

Indicates if encryption is supported

Returns:

  • (Boolean)


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

define_bit_attr :capabilities, endian: :little,
cap_rsv: 25, cap_encryption: 1, cap_dir_leasing: 1,
cap_persistent_handles: 1, cap_multi_channel: 1,
cap_large_mtu: 1, cap_leasing: 1, cap_dfs: 1

#cap_large_mtuBoolean

Indicates if multi credit operations are supported

Returns:

  • (Boolean)


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

define_bit_attr :capabilities, endian: :little,
cap_rsv: 25, cap_encryption: 1, cap_dir_leasing: 1,
cap_persistent_handles: 1, cap_multi_channel: 1,
cap_large_mtu: 1, cap_leasing: 1, cap_dfs: 1

#cap_leasingBoolean

Indicates if leasing is supported

Returns:

  • (Boolean)


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

define_bit_attr :capabilities, endian: :little,
cap_rsv: 25, cap_encryption: 1, cap_dir_leasing: 1,
cap_persistent_handles: 1, cap_multi_channel: 1,
cap_large_mtu: 1, cap_leasing: 1, cap_dfs: 1

#cap_multi_channelBoolean

Indicates if multiple channels are supported for a single session

Returns:

  • (Boolean)


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

define_bit_attr :capabilities, endian: :little,
cap_rsv: 25, cap_encryption: 1, cap_dir_leasing: 1,
cap_persistent_handles: 1, cap_multi_channel: 1,
cap_large_mtu: 1, cap_leasing: 1, cap_dfs: 1

#cap_persistent_handlesBoolean

Indicates if persisten handles are supported

Returns:

  • (Boolean)


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

define_bit_attr :capabilities, endian: :little,
cap_rsv: 25, cap_encryption: 1, cap_dir_leasing: 1,
cap_persistent_handles: 1, cap_multi_channel: 1,
cap_large_mtu: 1, cap_leasing: 1, cap_dfs: 1

#capabilitiesInteger

32-bit capabilities field.

Returns:

  • (Integer)


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

define_bit_attr :capabilities, endian: :little,
cap_rsv: 25, cap_encryption: 1, cap_dir_leasing: 1,
cap_persistent_handles: 1, cap_multi_channel: 1,
cap_large_mtu: 1, cap_leasing: 1, cap_dfs: 1

#client_guidObject

Returns [].

Returns:



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

define_attr :client_guid, GUID

#context_countInteger

Only for SMB3 dialect.

Returns:

  • (Integer)


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

define_attr :context_count, BinStruct::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_attr :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_attr :context_offset, BinStruct::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_attr :dialect_count, BinStruct::Int16le

#dialectsArray<BinStruct::Int16le>

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

Returns:

  • (Array<BinStruct::Int16le>)


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

define_attr :dialects, BinStruct::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_attr :reserved, BinStruct::Int16le

#reserved2Integer

Only for SMB3 dialect.

Returns:

  • (Integer)


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

define_attr :reserved2, BinStruct::Int16le

#security_modeInteger

16-bit security mode field.

Returns:

  • (Integer)


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

define_attr :security_mode, BinStruct::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_attr :structure_size, BinStruct::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)


153
154
155
156
157
158
159
# File 'lib/packetgen/plugin/smb2/negotiate/request.rb', line 153

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
# File 'lib/packetgen/plugin/smb2/negotiate/request.rb', line 134

def inspect # rubocop:disable Metrics/AbcSize
  super do |attr|
    case attr
    when :capabilities
      value = bits_on(attr).select { |b| respond_to?("#{b}?") && send("#{b}?") }
                           .map { |v| v.to_s.delete_prefix('cap_') }
                           .join(',')
      value = '%-16s (0x%08x)' % [value, self[attr].to_i]
      inspect_attr(attr, value)
    when :dialects
      list = self.dialects.map { |v| '%#x' % v.to_i }.join(',')
      inspect_attr(attr, list)
    end
  end
end