Module: RubySMB::NTLM
- Included in:
- Client, Gss::Provider::NTLM
- Defined in:
- lib/ruby_smb/ntlm.rb,
lib/ruby_smb/ntlm/client.rb,
lib/ruby_smb/ntlm/custom/string_encoder.rb
Defined Under Namespace
Modules: Custom, Message Classes: Client, OSVersion
Constant Summary collapse
- NEGOTIATE_FLAGS =
{ :UNICODE => 1 << 0, :OEM => 1 << 1, :REQUEST_TARGET => 1 << 2, :SIGN => 1 << 4, :SEAL => 1 << 5, :DATAGRAM => 1 << 6, :LAN_MANAGER_KEY => 1 << 7, :NTLM => 1 << 9, :NT_ONLY => 1 << 10, :ANONYMOUS => 1 << 11, :OEM_DOMAIN_SUPPLIED => 1 << 12, :OEM_WORKSTATION_SUPPLIED => 1 << 13, :ALWAYS_SIGN => 1 << 15, :TARGET_TYPE_DOMAIN => 1 << 16, :TARGET_TYPE_SERVER => 1 << 17, :TARGET_TYPE_SHARE => 1 << 18, :EXTENDED_SECURITY => 1 << 19, :IDENTIFY => 1 << 20, :NON_NT_SESSION => 1 << 22, :TARGET_INFO => 1 << 23, :VERSION_INFO => 1 << 25, :KEY128 => 1 << 29, :KEY_EXCHANGE => 1 << 30, :KEY56 => 1 << 31 }.freeze
- DEFAULT_CLIENT_FLAGS =
NEGOTIATE_FLAGS[:UNICODE] | NEGOTIATE_FLAGS[:SIGN] | NEGOTIATE_FLAGS[:SEAL] | NEGOTIATE_FLAGS[:REQUEST_TARGET] | NEGOTIATE_FLAGS[:NTLM] | NEGOTIATE_FLAGS[:ALWAYS_SIGN] | NEGOTIATE_FLAGS[:EXTENDED_SECURITY] | NEGOTIATE_FLAGS[:KEY128] | NEGOTIATE_FLAGS[:KEY_EXCHANGE] | NEGOTIATE_FLAGS[:KEY56] | NEGOTIATE_FLAGS[:TARGET_INFO] | NEGOTIATE_FLAGS[:VERSION_INFO]
Class Method Summary collapse
-
.ntlmv2_hash(user, password, target, opt = {}) ⇒ Object
Generate a NTLMv2 Hash.
Class Method Details
.ntlmv2_hash(user, password, target, opt = {}) ⇒ Object
Generate a NTLMv2 Hash
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/ruby_smb/ntlm.rb', line 69 def ntlmv2_hash(user, password, target, opt={}) if Net::NTLM.is_ntlm_hash? password decoded_password = Net::NTLM::EncodeUtil.decode_utf16le(password) ntlmhash = [decoded_password.upcase[33,65]].pack('H32') else ntlmhash = Net::NTLM.ntlm_hash(password, opt) end if opt[:unicode] # Uppercase operation on username containing non-ASCII characters # after being unicode encoded with `EncodeUtil.encode_utf16le` # doesn't play well. Upcase should be done before encoding. user_upcase = Net::NTLM::EncodeUtil.decode_utf16le(user).upcase user_upcase = Net::NTLM::EncodeUtil.encode_utf16le(user_upcase) else user_upcase = user.upcase end userdomain = user_upcase + target unless opt[:unicode] userdomain = Net::NTLM::EncodeUtil.encode_utf16le(userdomain) end OpenSSL::HMAC.digest(OpenSSL::Digest::MD5.new, ntlmhash, userdomain) end |