lib/net/ntlm.rb in rubyntlm-0.1.1 vs lib/net/ntlm.rb in rubyntlm-0.2.0
- old
+ new
@@ -43,18 +43,20 @@
#++
require 'base64'
require 'openssl'
require 'openssl/digest'
+require 'kconv'
+require 'socket'
module Net #:nodoc:
- module NTLM
+ module NTLM #:nodoc:
module VERSION #:nodoc:
MAJOR = 0
- MINOR = 1
- TINY = 1
+ MINOR = 2
+ TINY = 0
STRING = [MAJOR, MINOR, TINY].join('.')
end
SSP_SIGN = "NTLMSSP\0"
BLOB_SIGN = 0x00000101
@@ -603,12 +605,12 @@
Type1 = Message.define {
string :sign, {:size => 8, :value => SSP_SIGN}
int32LE :type, {:value => 1}
int32LE :flag, {:value => DEFAULT_FLAGS[:TYPE1] }
- security_buffer :domain, {:value => "", :active => false}
- security_buffer :workstation, {:value => "", :active => false}
+ security_buffer :domain, {:value => ""}
+ security_buffer :workstation, {:value => Socket.gethostname }
string :padding, {:size => 0, :value => "", :active => false }
}
class Type1
class << Type1
@@ -665,10 +667,11 @@
end
def response(arg, opt = {})
usr = arg[:user]
pwd = arg[:password]
+ domain = arg[:domain] ? arg[:domain] : ""
if usr.nil? or pwd.nil?
raise ArgumentError, "user and password have to be supplied"
end
if opt[:workstation]
@@ -697,17 +700,16 @@
pwd = NTLM::encode_utf16le(pwd)
ws = NTLM::encode_utf16le(ws)
opt[:unicode] = true
end
- tgt = self.target_name
ti = self.target_info
chal = self[:challenge].serialize
-
+
if opt[:ntlmv2]
- ar = {:ntlmv2_hash => NTLM::ntlmv2_hash(usr, pwd, tgt, opt), :challenge => chal, :target_info => ti}
+ ar = {:ntlmv2_hash => NTLM::ntlmv2_hash(usr, pwd, domain, opt), :challenge => chal, :target_info => ti}
lm_res = NTLM::lmv2_response(ar, opt)
ntlm_res = NTLM::ntlmv2_response(ar, opt)
elsif has_flag?(:NTLM2_KEY)
ar = {:ntlm_hash => NTLM::ntlm_hash(pwd, opt), :challenge => chal}
lm_res, ntlm_res = NTLM::ntlm2_session(ar, opt)
@@ -717,11 +719,11 @@
end
Type3.create({
:lm_response => lm_res,
:ntlm_response => ntlm_res,
- :domain => tgt,
+ :domain => domain,
:user => usr,
:workstation => ws,
:flag => self.flag
})
end
@@ -752,11 +754,16 @@
t = new
t.lm_response = arg[:lm_response]
t.ntlm_response = arg[:ntlm_response]
t.domain = arg[:domain]
t.user = arg[:user]
- t.workstation = arg[:workstation]
-
+
+ if arg[:workstation]
+ t.workstation = arg[:workstation]
+ else
+ t.workstation = NTLM.encode_utf16le(Socket.gethostname)
+ end
+
if arg[:session_key]
t.enable(:session_key)
t.session_key = arg[session_key]
end
if arg[:flag]