Path: blob/master/lib/rex/proto/ldap/dn_binary.rb
19591 views
module Rex1module Proto2module LDAP34# Handle converting objects into the DN-Binary syntax5# See: https://learn.microsoft.com/en-us/windows/win32/adschema/s-object-dn-binary6class DnBinary7def initialize(dn, data)8self.dn = dn9self.data = data10end1112# Turn a DN-Binary string into a structured object containing data and a DN13# @param str [String] A DN-Binary-formatted string14def self.decode(str)15groups = str.match(/B:(\d+):(([a-fA-F0-9]{2})*):(.*)/)16raise ArgumentError.new('Invalid DN Binary string') if groups.nil?17length = groups[1].to_i18raise ArgumentError.new('Invalid DN Binary string length') if groups[2].length != length19data = [groups[2]].pack('H*')2021DnBinary.new(groups[4], data)22end2324# Turn this structured object containing data and a DN into a DN-Binary string25# @return [String] The DN-Binary-formatted string26def encode27data_hex = self.data.unpack('H*')[0]2829"B:#{data_hex.length}:#{data_hex}:#{self.dn}"30end3132attr_accessor :data # Raw bytes33attr_accessor :dn # LDAP Distinguished name34end35end36end37end3839