Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ Ruby/NTLM provides message creator and parser for the NTLM authentication.

Some features:
* Independent from non-standard Ruby libraries.
* Supports NTLM and NTLMv2 reponses.
* Supports NTLM and NTLMv2 responses.

== Changes made by CloudVolumes

* Force the domain to be target_name (not sure why this is needed - may be removed)
* UTF8 character encoding for Ruby 1.9 when converting from UTF16

== Simple Example

Expand Down
33 changes: 24 additions & 9 deletions lib/net/ntlm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ module NTLM #:nodoc:
module VERSION #:nodoc:
MAJOR = 0
MINOR = 1
TINY = 2
STRING = [MAJOR, MINOR, TINY].join('.')
TINY = 3
STRING = [MAJOR, MINOR, TINY, 'cv'].join('.')
end

SSP_SIGN = "NTLMSSP\0"
Expand Down Expand Up @@ -97,17 +97,29 @@ module VERSION #:nodoc:
# module functions
class << self
def decode_utf16le(str)
Kconv.kconv(swap16(str), Kconv::ASCII, Kconv::UTF16)
if RUBY_VERSION < "1.9"
Kconv.kconv(swap16(str), Kconv::ASCII, Kconv::UTF16)
else
#str.dup.force_encoding('UTF-16LE').encode('ASCII-8BIT')
#str.dup.force_encoding('UTF-16LE').encode('UTF-8')
str.dup.force_encoding('UTF-16LE').encode('UTF-8')
end
end

def encode_utf16le(str)
swap16(Kconv.kconv(str, Kconv::UTF16, Kconv::ASCII))
if RUBY_VERSION < "1.9"
swap16(Kconv.kconv(str, Kconv::UTF16, Kconv::ASCII))
else
#str.dup.force_encoding('ASCII-8BIT').encode('UTF-16LE')
#str.dup.force_encoding('UTF-8').encode('UTF-16LE')
str.dup.encode('UTF-8').encode('UTF-16LE').force_encoding('ASCII-8BIT')
end
end

def pack_int64le(val)
[val & 0x00000000ffffffff, val >> 32].pack("V2")
end

def swap16(str)
str.unpack("v*").pack("n*")
end
Expand All @@ -127,7 +139,7 @@ def gen_keys(str)
[bits].pack("B*")
}
end

def apply_des(plain, keys)
dec = OpenSSL::Cipher::DES.new
keys.map {|k|
Expand Down Expand Up @@ -691,16 +703,19 @@ def response(arg, opt = {})
usr = NTLM::decode_utf16le(usr)
pwd = NTLM::decode_utf16le(pwd)
ws = NTLM::decode_utf16le(ws)
domain = NTLM::decode_utf16le(domain) unless domain.blank?
opt[:unicode] = false
end

if has_flag?(:UNICODE) and !opt[:unicode]
usr = NTLM::encode_utf16le(usr)
pwd = NTLM::encode_utf16le(pwd)
ws = NTLM::encode_utf16le(ws)
domain = NTLM::encode_utf16le(domain) unless domain.blank?
opt[:unicode] = true
end

domain = self.target_name if domain.blank?
ti = self.target_info

chal = self[:challenge].serialize
Expand All @@ -718,9 +733,9 @@ def response(arg, opt = {})
end

Type3.create({
:lm_response => lm_res,
:ntlm_response => ntlm_res,
:domain => domain,
:lm_response => lm_res,
:ntlm_response => ntlm_res,
:domain => domain,
:user => usr,
:workstation => ws,
:flag => self.flag
Expand Down