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

Inherits:
Object
  • Object
show all
Defined in:
lib/net/ntlm.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse(str) ⇒ Object



647
648
649
650
651
# File 'lib/net/ntlm.rb', line 647

def parse(str)
  t = new
  t.parse(str)
  t
end

Instance Method Details

#parse(str) ⇒ Object



654
655
656
657
658
659
660
661
662
663
664
665
# File 'lib/net/ntlm.rb', line 654

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 = {}) ⇒ Object



667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
# File 'lib/net/ntlm.rb', line 667

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(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::decode_utf16le(usr)
    pwd = NTLM::decode_utf16le(pwd)
    ws  = NTLM::decode_utf16le(ws)
    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)
    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}
    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
    lm_res = NTLM::lm_response(pwd, chal)
    ntlm_res = NTLM::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