class Rex::Proto::NTLM::Message::Type2

Public Class Methods

parse(str) click to toggle source
# File lib/rex/proto/ntlm/message.rb, line 184
def parse(str)
  t = new
  t.parse(str)
  t
end

Public Instance Methods

parse(str) click to toggle source
Calls superclass method
# File lib/rex/proto/ntlm/message.rb, line 191
def parse(str)
  super(str)
  if has_flag?(:TARGET_INFO)
    enable(:context)
    enable(:target_info)
    super(str)
  end
  if ( (len = data_edge - head_size) > 0)
    self.padding = "\0" * len
    super(str)
  end
end
response(arg, opt = {}) click to toggle source

create a type 3 response base on a type2

This mehod is not compatible with windows 7 / 2008 r2
to make it compatible avpair Time and SPN must be handle as in utils
# File lib/rex/proto/ntlm/message.rb, line 206
def response(arg, opt = {})
  usr = arg[:user]
  pwd = arg[:password]
  if usr.nil? or pwd.nil?
    raise ArgumentError, "user and password have to be supplied"
  end

  if opt[:workstation]
    ws = opt[:workstation]
  else
    ws = ""
  end

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

  if has_flag?(:OEM) and opt[:unicode]
    usr = Rex::Text::to_ascii(usr,'utf-16le')
    pwd = Rex::Text::to_ascii(pwd,'utf-16le')
    ws  = Rex::Text::to_ascii(ws,'utf-16le')
    opt[:unicode] = false
  end

  if has_flag?(:UNICODE) and !opt[:unicode]
    usr = Rex::Text::to_unicode(usr,'utf-16le')
    pwd = Rex::Text::to_unicode(pwd,'utf-16le')
    ws  = Rex::Text::to_unicode(ws,'utf-16le')
    opt[:unicode] = true
  end

  tgt = self.target_name
  ti = self.target_info

  chal = self[:challenge].serialize

  if opt[:ntlmv2]
    ar = {  :ntlmv2_hash => CRYPT::ntlmv2_hash(usr, pwd, tgt, opt),
      :challenge => chal, :target_info => ti}
    lm_res = CRYPT::lmv2_response(ar, opt)
    ntlm_res = CRYPT::ntlmv2_response(ar, opt)
  elsif has_flag?(:NTLM2_KEY)
    ar = {:ntlm_hash => CRYPT::ntlm_hash(pwd, opt), :challenge => chal}
    lm_res, ntlm_res = CRYPT::ntlm2_session(ar, opt)
  else
    lm_res = CRYPT::lm_response(pwd, chal)
    ntlm_res = CRYPT::ntlm_response(pwd, chal)
  end

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