Class: RubySMB::Dcerpc::Samr::EncryptedNtOwfPassword
Overview
Class Method Summary
collapse
#initialize_shared_instance, method_missing, validate_conformant_array
Class Method Details
.encrypt_hash(hash:, key:) ⇒ Object
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
|
# File 'lib/ruby_smb/dcerpc/samr.rb', line 347
def self.encrypt_hash(hash:, key:)
block1 = hash[0..7]
block2 = hash[8..]
key1 = to_output_key(key[0..6])
key2 = to_output_key(key[7..13])
cipher1 = OpenSSL::Cipher.new('des-ecb').tap do |cipher|
cipher.encrypt
cipher.key = key1
end
cipher2 = OpenSSL::Cipher.new('des-ecb').tap do |cipher|
cipher.encrypt
cipher.key = key2
end
cipher1.update(block1) + cipher2.update(block2)
end
|
.to_output_key(input_key) ⇒ Object
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
|
# File 'lib/ruby_smb/dcerpc/samr.rb', line 329
def self.to_output_key(input_key)
output_key = []
input_key = input_key.unpack('C'*7)
output_key.append(input_key[0] >> 0x01)
output_key.append(((input_key[0]&0x01)<<6) | (input_key[1]>>2))
output_key.append(((input_key[1]&0x03)<<5) | (input_key[2]>>3))
output_key.append(((input_key[2]&0x07)<<4) | (input_key[3]>>4))
output_key.append(((input_key[3]&0x0F)<<3) | (input_key[4]>>5))
output_key.append(((input_key[4]&0x1F)<<2) | (input_key[5]>>6))
output_key.append(((input_key[5]&0x3F)<<1) | (input_key[6]>>7))
output_key.append(input_key[6] & 0x7F)
output_key = output_key.map {|x| (x << 1) & 0xFE}
output_key.pack('C'*8)
end
|