Class: RubySMB::Dcerpc::Samr::SamprEncryptedUserPasswordNew
- Inherits:
-
BinData::Record
- Object
- BinData::Record
- RubySMB::Dcerpc::Samr::SamprEncryptedUserPasswordNew
- Defined in:
- lib/ruby_smb/dcerpc/samr.rb
Overview
Class Method Summary collapse
Class Method Details
.encrypt_password(password, key) ⇒ Object
416 417 418 419 420 421 422 423 424 425 426 427 |
# File 'lib/ruby_smb/dcerpc/samr.rb', line 416 def self.encrypt_password(password, key) # see: https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-samr/5fe3c4c4-e71b-440d-b2fd-8448bfaf6e04 password = password.encode('UTF-16LE').force_encoding('ASCII-8BIT') buffer = password.rjust(512, "\x00") + [ password.length ].pack('V') salt = SecureRandom.random_bytes(16) key = OpenSSL::Digest::MD5.new(salt + key).digest cipher = OpenSSL::Cipher.new('RC4').tap do |cipher| cipher.encrypt cipher.key = key end cipher.update(buffer) + salt end |