Class: Rex::Proto::LDAP::AuthAdapter::RexNTLM::Encryptor

Inherits:
Object
  • Object
show all
Defined in:
lib/rex/proto/ldap/auth_adapter/rex_ntlm/encryptor.rb

Overview

Provide the ability to “wrap” LDAP comms in an NTLM encryption routine The methods herein are set up with the auth_context_setup call below, and are called when reading or writing needs to occur.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ntlm_client) ⇒ Encryptor

Returns a new instance of Encryptor.



12
13
14
# File 'lib/rex/proto/ldap/auth_adapter/rex_ntlm/encryptor.rb', line 12

def initialize(ntlm_client)
  self.ntlm_client = ntlm_client
end

Instance Attribute Details

#ntlm_clientObject

Returns the value of attribute ntlm_client.



44
45
46
# File 'lib/rex/proto/ldap/auth_adapter/rex_ntlm/encryptor.rb', line 44

def ntlm_client
  @ntlm_client
end

Instance Method Details

#read(ciphertext) ⇒ Object

Decrypt the provided ciphertext

Parameters:

  • ciphertext (String)


25
26
27
28
29
30
31
32
33
# File 'lib/rex/proto/ldap/auth_adapter/rex_ntlm/encryptor.rb', line 25

def read(ciphertext)
  message = ntlm_client.session.unseal_message(ciphertext[16..-1])
  if ntlm_client.session.verify_signature(ciphertext[0..15], message)
    return message
  else
    # Some error
    raise Rex::Proto::LDAP::LdapException.new('Received invalid message (NTLM signature verification failed)')
  end
end

#setup(ldap_connection) ⇒ Object

Configure our encryption, and tell the LDAP connection object that we now want to intercept its calls to read and write

Parameters:



19
20
21
# File 'lib/rex/proto/ldap/auth_adapter/rex_ntlm/encryptor.rb', line 19

def setup(ldap_connection)
  ldap_connection.wrap_read_write(self.method(:read), self.method(:write))
end

#write(data) ⇒ Object

Encrypt the provided plaintext

Parameters:

  • data (String)


37
38
39
40
41
42
# File 'lib/rex/proto/ldap/auth_adapter/rex_ntlm/encryptor.rb', line 37

def write(data)
  emessage = ntlm_client.session.seal_message(data)
  signature = ntlm_client.session.sign_message(data)

  signature + emessage
end