Class: Net::NTLM::Message::Type2

Inherits:
Net::NTLM::Message show all
Defined in:
lib/net/ntlm/message/type2.rb

Instance Method Summary collapse

Methods inherited from Net::NTLM::Message

#data_edge, #data_size, decode64, #decode64, #deflag, #dump_flags, #encode64, #has_flag?, #head_size, parse, #parse, #security_buffers, #serialize, #set_flag, #size

Methods inherited from FieldSet

#[], #[]=, #disable, #enable, #has_disabled_fields?, #initialize, int16LE, int32LE, int64LE, names, opts, #parse, prototypes, security_buffer, #serialize, #size, string, types

Constructor Details

This class inherits a constructor from Net::NTLM::FieldSet

Instance Method Details

#challengeInt64

Returns:

  • (Int64)


12
# File 'lib/net/ntlm/message/type2.rb', line 12

int64LE         :challenge,   { :value => 0}

#challenge=Int64

Returns:

  • (Int64)


12
# File 'lib/net/ntlm/message/type2.rb', line 12

int64LE         :challenge,   { :value => 0}

#contextInt64

Returns:

  • (Int64)


13
# File 'lib/net/ntlm/message/type2.rb', line 13

int64LE         :context,     { :value => 0, :active => false }

#context=Int64

Returns:

  • (Int64)


13
# File 'lib/net/ntlm/message/type2.rb', line 13

int64LE         :context,     { :value => 0, :active => false }

#flagInt32LE

Returns:



11
# File 'lib/net/ntlm/message/type2.rb', line 11

int32LE         :flag,        { :value => DEFAULT_FLAGS[:TYPE2] }

#flag=Int32LE

Returns:



11
# File 'lib/net/ntlm/message/type2.rb', line 11

int32LE         :flag,        { :value => DEFAULT_FLAGS[:TYPE2] }

#os_versionString

Returns:



15
# File 'lib/net/ntlm/message/type2.rb', line 15

string          :os_version,  { :size => 8, :value => "", :active => false }

#os_version=String

Returns:



15
# File 'lib/net/ntlm/message/type2.rb', line 15

string          :os_version,  { :size => 8, :value => "", :active => false }

#response(arg, opt = {}) ⇒ Type3

Note:

An empty :domain option authenticates to the local machine.

Note:

The :use_default_target has precedence over the :domain option

Generates a Type 3 response based on the Type 2 Information

Parameters:

  • arg (Hash)

    a customizable set of options

  • opt (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arg):

  • :username (String)

    The username to authenticate with

  • :password (String)

    The user’s password

  • :domain (String) — default: ''

    The domain to authenticate to

Options Hash (opt):

  • :workstation (String) — default: Socket.gethostname

    The name of the calling workstation

  • :use_default_target (Boolean) — default: false

    Use the domain supplied by the server in the Type 2 packet

Returns:



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/net/ntlm/message/type2.rb', line 26

def response(arg, opt = {})
  usr = arg[:user]
  pwd = arg[:password]
  domain = arg[:domain] ? arg[:domain].upcase : ""
  if usr.nil? or pwd.nil?
    raise ArgumentError, "user and password have to be supplied"
  end

  if opt[:workstation]
    ws = opt[:workstation]
  else
    ws = Socket.gethostname
  end

  if opt[:client_challenge]
    cc  = opt[:client_challenge]
  else
    cc = rand(MAX64)
  end
  cc = NTLM::pack_int64le(cc) if cc.is_a?(Integer)
  opt[:client_challenge] = cc

  if has_flag?(:OEM) and opt[:unicode]
    usr = NTLM::EncodeUtil.decode_utf16le(usr)
    pwd = NTLM::EncodeUtil.decode_utf16le(pwd)
    ws  = NTLM::EncodeUtil.decode_utf16le(ws)
    domain = NTLM::EncodeUtil.decode_utf16le(domain)
    opt[:unicode] = false
  end

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

  if opt[:use_default_target]
    domain = self.target_name
  end

  ti = self.target_info

  chal = self[:challenge].serialize

  if opt[:ntlmv2]
    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)
  else
    ar = {:lm_hash => NTLM::lm_hash(pwd), :challenge => chal}
    lm_res = NTLM::lm_response(ar)
    ar = {:ntlm_hash => NTLM::ntlm_hash(pwd, opt), :challenge => chal}
    ntlm_res = NTLM::ntlm_response(ar)
  end

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

#signString

Returns:



8
# File 'lib/net/ntlm/message/type2.rb', line 8

string          :sign,        { :size => 8, :value => SSP_SIGN }

#sign=String

Returns:



8
# File 'lib/net/ntlm/message/type2.rb', line 8

string          :sign,        { :size => 8, :value => SSP_SIGN }

#target_infoSecurityBuffer

Returns:



14
# File 'lib/net/ntlm/message/type2.rb', line 14

security_buffer :target_info, { :value => "", :active => false }

#target_info=SecurityBuffer

Returns:



14
# File 'lib/net/ntlm/message/type2.rb', line 14

security_buffer :target_info, { :value => "", :active => false }

#target_nameSecurityBuffer

Returns:



10
# File 'lib/net/ntlm/message/type2.rb', line 10

security_buffer :target_name, { :size => 0, :value => "" }

#target_name=SecurityBuffer

Returns:



10
# File 'lib/net/ntlm/message/type2.rb', line 10

security_buffer :target_name, { :size => 0, :value => "" }

#typeInt32LE

Returns:



9
# File 'lib/net/ntlm/message/type2.rb', line 9

int32LE         :type,        { :value => 2 }

#type=Int32LE

Returns:



9
# File 'lib/net/ntlm/message/type2.rb', line 9

int32LE         :type,        { :value => 2 }