Class: Rex::Proto::LDAP::DnBinary

Inherits:
Object
  • Object
show all
Defined in:
lib/rex/proto/ldap/dn_binary.rb

Overview

Handle converting objects into the DN-Binary syntax See: learn.microsoft.com/en-us/windows/win32/adschema/s-object-dn-binary

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dn, data) ⇒ DnBinary

Returns a new instance of DnBinary.



8
9
10
11
# File 'lib/rex/proto/ldap/dn_binary.rb', line 8

def initialize(dn, data)
  self.dn = dn
  self.data = data
end

Instance Attribute Details

#dataObject

Raw bytes



33
34
35
# File 'lib/rex/proto/ldap/dn_binary.rb', line 33

def data
  @data
end

#dnObject

LDAP Distinguished name



34
35
36
# File 'lib/rex/proto/ldap/dn_binary.rb', line 34

def dn
  @dn
end

Class Method Details

.decode(str) ⇒ Object

Turn a DN-Binary string into a structured object containing data and a DN

Parameters:

  • str (String)

    A DN-Binary-formatted string

Raises:

  • (ArgumentError)


15
16
17
18
19
20
21
22
23
# File 'lib/rex/proto/ldap/dn_binary.rb', line 15

def self.decode(str)
  groups = str.match(/B:(\d+):(([a-fA-F0-9]{2})*):(.*)/)
  raise ArgumentError.new('Invalid DN Binary string') if groups.nil?
  length = groups[1].to_i
  raise ArgumentError.new('Invalid DN Binary string length') if groups[2].length != length
  data = [groups[2]].pack('H*')

  DnBinary.new(groups[4], data)
end

Instance Method Details

#encodeString

Turn this structured object containing data and a DN into a DN-Binary string

Returns:

  • (String)

    The DN-Binary-formatted string



27
28
29
30
31
# File 'lib/rex/proto/ldap/dn_binary.rb', line 27

def encode
  data_hex = self.data.unpack('H*')[0]

  "B:#{data_hex.length}:#{data_hex}:#{self.dn}"
end