Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/rex/proto/ntlm/utils.rb
Views: 11704
# -*- coding: binary -*-12module Rex::Proto::NTLM3class Utils45# duplicate from lib/rex/proto/smb/utils cause we only need this function from Rex::Proto::SMB::Utils6# Convert a unix timestamp to a 64-bit signed server time7def self.time_unix_to_smb(unix_time)8t64 = (unix_time + 11644473600) * 100000009thi = (t64 & 0xffffffff00000000) >> 3210tlo = (t64 & 0x00000000ffffffff)11return [thi, tlo]12end1314# Determine whether the password is a known hash format15def self.is_pass_ntlm_hash?(str)16str.downcase =~ /^[0-9a-f]{32}:[0-9a-f]{32}$/17end1819#20# Prepends an ASN1 formatted length field to a piece of data21#22def self.asn1encode(str = '')23res = ''2425# If the high bit of the first byte is 1, it contains the number of26# length bytes that follow2728case str.length29when 0 .. 0x7F30res = [str.length].pack('C') + str31when 0x80 .. 0xFF32res = [0x81, str.length].pack('CC') + str33when 0x100 .. 0xFFFF34res = [0x82, str.length].pack('Cn') + str35when 0x10000 .. 0xffffff36res = [0x83, str.length >> 16, str.length & 0xFFFF].pack('CCn') + str37when 0x1000000 .. 0xffffffff38res = [0x84, str.length].pack('CN') + str39else40raise "ASN1 str too long"41end42return res43end4445# GSS functions4647# GSS BLOB useful for SMB_NEGOCIATE_RESPONSE message48# mechTypes: 2 items :49# -MechType: 1.3.6.1.4.1.311.2.2.30 (SNMPv2-SMI::enterprises.311.2.2.30)50# -MechType: 1.3.6.1.4.1.311.2.2.10 (NTLMSSP - Microsoft NTLM Security Support Provider)51#52# this is the default on Win753def self.make_simple_negotiate_secblob_resp54blob =55"\x60" + self.asn1encode(56"\x06" + self.asn1encode(57"\x2b\x06\x01\x05\x05\x02"58) +59"\xa0" + self.asn1encode(60"\x30" + self.asn1encode(61"\xa0" + self.asn1encode(62"\x30" + self.asn1encode(63"\x06" + self.asn1encode(64"\x2b\x06\x01\x04\x01\x82\x37\x02\x02\x0a"65)66)67)68)69)70)7172return blob73end7475# GSS BLOB useful for SMB_NEGOCIATE_RESPONSE message76# mechTypes: 4 items :77# MechType: 1.2.840.48018.1.2.2 (MS KRB5 - Microsoft Kerberos 5)78# MechType: 1.2.840.113554.1.2.2 (KRB5 - Kerberos 5)79# MechType: 1.2.840.113554.1.2.2.3 (KRB5 - Kerberos 5 - User to User)80# MechType: 1.3.6.1.4.1.311.2.2.10 (NTLMSSP - Microsoft NTLM Security Support Provider)81# mechListMIC:82# principal: account@domain83def self.make_negotiate_secblob_resp(account, domain)84blob =85"\x60" + self.asn1encode(86"\x06" + self.asn1encode(87"\x2b\x06\x01\x05\x05\x02"88) +89"\xa0" + self.asn1encode(90"\x30" + self.asn1encode(91"\xa0" + self.asn1encode(92"\x30" + self.asn1encode(93"\x06" + self.asn1encode(94"\x2a\x86\x48\x82\xf7\x12\x01\x02\x02"95) +96"\x06" + self.asn1encode(97"\x2a\x86\x48\x86\xf7\x12\x01\x02\x02"98) +99"\x06" + self.asn1encode(100"\x2a\x86\x48\x86\xf7\x12\x01\x02\x02\x03"101) +102"\x06" + self.asn1encode(103"\x2b\x06\x01\x04\x01\x82\x37\x02\x02\x0a"104)105)106) +107"\xa3" + self.asn1encode(108"\x30" + self.asn1encode(109"\xa0" + self.asn1encode(110"\x1b" + self.asn1encode(111account + '@' + domain112)113)114)115)116)117)118)119120return blob121end122123# BLOB without GSS useful for ntlmssp type 1 message124def self.make_ntlmssp_blob_init(domain = 'WORKGROUP', name = 'WORKSTATION', flags=0x80201)125blob = "NTLMSSP\x00" +126[1, flags].pack('VV') +127128[129domain.length, #length130domain.length, #max length13132132].pack('vvV') +133134[135name.length, #length136name.length, #max length137domain.length + 32138].pack('vvV') +139140domain + name141return blob142end143144# GSS BLOB useful for ntlmssp type 1 message145def self.make_ntlmssp_secblob_init(domain = 'WORKGROUP', name = 'WORKSTATION', flags=0x80201)146blob =147"\x60" + self.asn1encode(148"\x06" + self.asn1encode(149"\x2b\x06\x01\x05\x05\x02"150) +151"\xa0" + self.asn1encode(152"\x30" + self.asn1encode(153"\xa0" + self.asn1encode(154"\x30" + self.asn1encode(155"\x06" + self.asn1encode(156"\x2b\x06\x01\x04\x01\x82\x37\x02\x02\x0a"157)158)159) +160"\xa2" + self.asn1encode(161"\x04" + self.asn1encode(162make_ntlmssp_blob_init(domain, name, flags)163)164)165)166)167)168169return blob170end171172173# BLOB without GSS useful for ntlm type 2 message174def self.make_ntlmssp_blob_chall(win_domain, win_name, dns_domain, dns_name, chall, flags)175176addr_list = ''177addr_list << [2, win_domain.length].pack('vv') + win_domain178addr_list << [1, win_name.length].pack('vv') + win_name179addr_list << [4, dns_domain.length].pack('vv') + dns_domain180addr_list << [3, dns_name.length].pack('vv') + dns_name181addr_list << [0, 0].pack('vv')182183ptr = 0184blob = "NTLMSSP\x00" +185[2].pack('V') +186[187win_domain.length, # length188win_domain.length, # max length189(ptr += 48) # offset190].pack('vvV') +191[ flags ].pack('V') +192chall +193"\x00\x00\x00\x00\x00\x00\x00\x00" +194[195addr_list.length, # length196addr_list.length, # max length197(ptr += win_domain.length)198].pack('vvV') +199win_domain +200addr_list201return blob202end203204# GSS BLOB useful for ntlmssp type 2 message205def self.make_ntlmssp_secblob_chall(win_domain, win_name, dns_domain, dns_name, chall, flags)206207blob =208"\xa1" + self.asn1encode(209"\x30" + self.asn1encode(210"\xa0" + self.asn1encode(211"\x0a" + self.asn1encode(212"\x01"213)214) +215"\xa1" + self.asn1encode(216"\x06" + self.asn1encode(217"\x2b\x06\x01\x04\x01\x82\x37\x02\x02\x0a"218)219) +220"\xa2" + self.asn1encode(221"\x04" + self.asn1encode(222make_ntlmssp_blob_chall(win_domain, win_name, dns_domain, dns_name, chall, flags)223)224)225)226)227228return blob229end230231# BLOB without GSS Useful for ntlmssp type 3 message232def self.make_ntlmssp_blob_auth(domain, name, user, lm, ntlm, enc_session_key, flags = 0x080201)233lm ||= "\x00" * 24234ntlm ||= "\x00" * 24235236domain_uni = Rex::Text.to_unicode(domain)237user_uni = Rex::Text.to_unicode(user)238name_uni = Rex::Text.to_unicode(name)239session = enc_session_key240241ptr = 64242243blob = "NTLMSSP\x00" +244[ 3 ].pack('V') +245246[ # Lan Manager Response247lm.length,248lm.length,249(ptr)250].pack('vvV') +251252[ # NTLM Manager Response253ntlm.length,254ntlm.length,255(ptr += lm.length)256].pack('vvV') +257258[ # Domain Name259domain_uni.length,260domain_uni.length,261(ptr += ntlm.length)262].pack('vvV') +263264[ # Username265user_uni.length,266user_uni.length,267(ptr += domain_uni.length)268].pack('vvV') +269270[ # Hostname271name_uni.length,272name_uni.length,273(ptr += user_uni.length)274].pack('vvV') +275276[ # Session Key (none)277session.length,278session.length,279(ptr += name_uni.length)280].pack('vvV') +281282[ flags ].pack('V') +283284lm +285ntlm +286domain_uni +287user_uni +288name_uni +289session + "\x00"290return blob291292end293294# GSS BLOB Useful for ntlmssp type 3 message295def self.make_ntlmssp_secblob_auth(domain, name, user, lm, ntlm, enc_session_key, flags = 0x080201)296297blob =298"\xa1" + self.asn1encode(299"\x30" + self.asn1encode(300"\xa2" + self.asn1encode(301"\x04" + self.asn1encode(302make_ntlmssp_blob_auth(domain, name, user, lm, ntlm, enc_session_key, flags )303)304)305)306)307return blob308end309310311# GSS BLOB Useful for SMB Success312def self.make_ntlmv2_secblob_success313blob =314"\xa1" + self.asn1encode(315"\x30" + self.asn1encode(316"\xa0" + self.asn1encode(317"\x0a" + self.asn1encode(318"\x00"319)320)321)322)323return blob324end325326# Return the correct ntlmflags upon the configuration327def self.make_ntlm_flags(opt = {})328329signing = opt[:signing] != nil ? opt[:signing] : false330usentlm2_session = opt[:usentlm2_session] != nil ? opt[:usentlm2_session] : true331use_ntlmv2 = opt[:use_ntlmv2] != nil ? opt[:use_ntlmv2] : false332send_lm = opt[:send_lm] != nil ? opt[:send_lm] : true333send_ntlm = opt[:send_ntlm] != nil ? opt[:send_ntlm] : true334use_lanman_key = opt[:use_lanman_key] != nil ? opt[:use_lanman_key] : false335336if signing337ntlmssp_flags = 0xe2088215338else339340ntlmssp_flags = 0xa2080205341end342343if usentlm2_session344if use_ntlmv2345#set Negotiate Target Info346ntlmssp_flags |= Rex::Proto::NTLM::Constants::NEGOTIATE_TARGET_INFO347end348349else350#remove the ntlm2_session flag351ntlmssp_flags &= 0xfff7ffff352#set lanmanflag only when lm and ntlm are sent353if send_lm354ntlmssp_flags |= Rex::Proto::NTLM::Constants::NEGOTIATE_LMKEY if use_lanman_key355end356end357358#we can also downgrade ntlm2_session when we send only lmv1359ntlmssp_flags &= 0xfff7ffff if usentlm2_session && (not use_ntlmv2) && (not send_ntlm)360361return ntlmssp_flags362end363364365# Parse an ntlm type 2 challenge blob and return useful data366def self.parse_ntlm_type_2_blob(blob)367data = {}368# Extract the NTLM challenge key the lazy way369cidx = blob.index("NTLMSSP\x00\x02\x00\x00\x00")370371if not cidx372raise Rex::Proto::NTLM::Exceptions::NTLMMissingChallenge373end374375data[:challenge_key] = blob[cidx + 24, 8]376377data[:server_ntlmssp_flags] = blob[cidx + 20, 4].unpack("V")[0]378379# Extract the address list from the blob380alist_len,alist_mlen,alist_off = blob[cidx + 40, 8].unpack("vvV")381alist_buf = blob[cidx + alist_off, alist_len]382383while(alist_buf.length > 0)384atype, alen = alist_buf.slice!(0,4).unpack('vv')385break if atype == 0x00386addr = alist_buf.slice!(0, alen)387case atype388when 1389#netbios name390temp_name = addr391temp_name.force_encoding("UTF-16LE")392data[:default_name] = temp_name.encode("UTF-8")393when 2394#netbios domain395temp_domain = addr396temp_domain.force_encoding("UTF-16LE")397data[:default_domain] = temp_domain.encode("UTF-8")398when 3399#dns name400temp_dns = addr401temp_dns.force_encoding("UTF-16LE")402data[:dns_host_name] = temp_dns.encode("UTF-8")403when 4404#dns domain405temp_dns_domain = addr406temp_dns_domain.force_encoding("UTF-16LE")407data[:dns_domain_name] = temp_dns_domain.encode("UTF-8")408when 5409#The FQDN of the forest.410when 6411#A 32-bit value indicating server or client configuration412when 7413#Client time414data[:chall_MsvAvTimestamp] = addr415when 8416#A Restriction_Encoding structure417when 9418#The SPN of the target server.419when 10420#A channel bindings hash.421end422end423return data424end425426# This function return an ntlmv2 client challenge427# This is a partial implementation, full description is in [MS-NLMP].pdf around 3.1.5.2.1 :-/428def self.make_ntlmv2_clientchallenge(win_domain, win_name, dns_domain, dns_name,429client_challenge = nil, chall_MsvAvTimestamp = nil, spnopt = {})430431client_challenge ||= Rex::Text.rand_text(8)432# We have to set the timestamps here to the one in the challenge message from server if present433# If we don't do that, recent server like Seven/2008 will send a STATUS_INVALID_PARAMETER error packet434timestamp = chall_MsvAvTimestamp != '' ? chall_MsvAvTimestamp : self.time_unix_to_smb(::Time.now.to_i).reverse.pack("VV")435# Make those values unicode as requested436win_domain = Rex::Text.to_unicode(win_domain)437win_name = Rex::Text.to_unicode(win_name)438dns_domain = Rex::Text.to_unicode(dns_domain)439dns_name = Rex::Text.to_unicode(dns_name)440# Make the AV_PAIRs441addr_list = ''442addr_list << [2, win_domain.length].pack('vv') + win_domain443addr_list << [1, win_name.length].pack('vv') + win_name444addr_list << [4, dns_domain.length].pack('vv') + dns_domain445addr_list << [3, dns_name.length].pack('vv') + dns_name446addr_list << [7, 8].pack('vv') + timestamp447448# Windows Seven / 2008r2 Request this type if in local security policies,449# Microsoft network server : Server SPN target name validation level is set to <Required from client>450# otherwise it send an STATUS_ACCESS_DENIED packet451if spnopt[:use_spn]452spn= Rex::Text.to_unicode("cifs/#{spnopt[:name] || 'unknown'}")453addr_list << [9, spn.length].pack('vv') + spn454end455456# MAY BE USEFUL FOR FUTURE457# Seven (client) add at least one more av that is of type MsAvRestrictions (8)458# maybe this will be useful with future windows OSs but has no use at all for the moment afaik459# restriction_encoding = [48,0,0,0].pack("VVV") + # Size, Z4, IntegrityLevel, SubjectIntegrityLevel460# Rex::Text.rand_text(32) # MachineId generated on startup on win7 and above461# addr_list << [8, restriction_encoding.length].pack('vv') + restriction_encoding462463# Seven (client) and maybe others versions also add an av of type MsvChannelBindings (10) but the hash is "\x00" * 16464# addr_list << [10, 16].pack('vv') + "\x00" * 16465466467addr_list << [0, 0].pack('vv')468ntlm_clientchallenge = [1,1,0,0].pack("CCvV") + #RespType, HiRespType, Reserved1, Reserved2469timestamp + #Timestamp470client_challenge + #clientchallenge471[0].pack("V") + #Reserved3472addr_list + "\x00" * 4473474end475476# create lm/ntlm responses477def self.create_lm_ntlm_responses(user, pass, challenge_key, domain = '', default_name = '', default_domain = '',478dns_host_name = '', dns_domain_name = '', chall_MsvAvTimestamp = nil, spnopt = {}, opt = {} )479480usentlm2_session = opt[:usentlm2_session] != nil ? opt[:usentlm2_session] : true481use_ntlmv2 = opt[:use_ntlmv2] != nil ? opt[:use_ntlmv2] : false482send_lm = opt[:send_lm] != nil ? opt[:send_lm] : true483send_ntlm = opt[:send_ntlm] != nil ? opt[:send_ntlm] : true484485#calculate the lm/ntlm response486resp_lm = "\x00" * 24487resp_ntlm = "\x00" * 24488489client_challenge = Rex::Text.rand_text(8)490ntlm_cli_challenge = ''491if send_ntlm #should be default492if usentlm2_session493if use_ntlmv2494ntlm_cli_challenge = self.make_ntlmv2_clientchallenge(495default_domain, default_name, dns_domain_name,496dns_host_name,client_challenge,497chall_MsvAvTimestamp, spnopt)498499if self.is_pass_ntlm_hash?(pass)500argntlm = {501:ntlmv2_hash => Rex::Proto::NTLM::Crypt::ntlmv2_hash(502user,503[ pass.upcase()[33,65] ].pack('H32'),504domain,{:pass_is_hash => true}505),506:challenge => challenge_key507}508else509argntlm = {510:ntlmv2_hash => Rex::Proto::NTLM::Crypt::ntlmv2_hash(user, pass, domain),511:challenge => challenge_key512}513end514515optntlm = { :nt_client_challenge => ntlm_cli_challenge}516ntlmv2_response = Rex::Proto::NTLM::Crypt::ntlmv2_response(argntlm,optntlm)517resp_ntlm = ntlmv2_response518519if send_lm520if self.is_pass_ntlm_hash?(pass)521arglm = {522:ntlmv2_hash => Rex::Proto::NTLM::Crypt::ntlmv2_hash(523user,524[ pass.upcase()[33,65] ].pack('H32'),525domain,{:pass_is_hash => true}526),527:challenge => challenge_key528}529else530arglm = {531:ntlmv2_hash => Rex::Proto::NTLM::Crypt::ntlmv2_hash(user,pass, domain),532:challenge => challenge_key533}534end535536optlm = { :client_challenge => client_challenge }537resp_lm = Rex::Proto::NTLM::Crypt::lmv2_response(arglm, optlm)538else539resp_lm = "\x00" * 24540end541542else # ntlm2_session543if self.is_pass_ntlm_hash?(pass)544argntlm = {545:ntlm_hash => [ pass.upcase()[33,65] ].pack('H32'),546:challenge => challenge_key547}548else549argntlm = {550:ntlm_hash => Rex::Proto::NTLM::Crypt::ntlm_hash(pass),551:challenge => challenge_key552}553end554555optntlm = { :client_challenge => client_challenge}556resp_ntlm = Rex::Proto::NTLM::Crypt::ntlm2_session(argntlm,optntlm).join[24,24]557558# Generate the fake LANMAN hash559resp_lm = client_challenge + ("\x00" * 16)560end561562else # we use lmv1/ntlmv1563if self.is_pass_ntlm_hash?(pass)564argntlm = {565:ntlm_hash => [ pass.upcase()[33,65] ].pack('H32'),566:challenge => challenge_key567}568else569argntlm = {570:ntlm_hash => Rex::Proto::NTLM::Crypt::ntlm_hash(pass),571:challenge => challenge_key572}573end574575resp_ntlm = Rex::Proto::NTLM::Crypt::ntlm_response(argntlm)576if send_lm577if self.is_pass_ntlm_hash?(pass)578arglm = {579:lm_hash => [ pass.upcase()[0,32] ].pack('H32'),580:challenge => challenge_key581}582else583arglm = {584:lm_hash => Rex::Proto::NTLM::Crypt::lm_hash(pass),585:challenge => challenge_key586}587end588resp_lm = Rex::Proto::NTLM::Crypt::lm_response(arglm)589else590#when windows does not send lm in ntlmv1 type response,591# it gives lm response the same value as ntlm response592resp_lm = resp_ntlm593end594end595else #send_ntlm = false596#lmv2597if usentlm2_session && use_ntlmv2598if self.is_pass_ntlm_hash?(pass)599arglm = {600:ntlmv2_hash => Rex::Proto::NTLM::Crypt::ntlmv2_hash(601user,602[ pass.upcase()[33,65] ].pack('H32'),603domain,{:pass_is_hash => true}604),605:challenge => challenge_key606}607else608arglm = {609:ntlmv2_hash => Rex::Proto::NTLM::Crypt::ntlmv2_hash(user,pass, domain),610:challenge => challenge_key611}612end613optlm = { :client_challenge => client_challenge }614resp_lm = Rex::Proto::NTLM::Crypt::lmv2_response(arglm, optlm)615else616if self.is_pass_ntlm_hash?(pass)617arglm = {618:lm_hash => [ pass.upcase()[0,32] ].pack('H32'),619:challenge => challenge_key620}621else622arglm = {623:lm_hash => Rex::Proto::NTLM::Crypt::lm_hash(pass),624:challenge => challenge_key625}626end627resp_lm = Rex::Proto::NTLM::Crypt::lm_response(arglm)628end629resp_ntlm = ""630end631return resp_lm, resp_ntlm, client_challenge, ntlm_cli_challenge632end633634# create the session key635def self.create_session_key(ntlmssp_flags, server_ntlmssp_flags, user, pass, domain, challenge_key,636client_challenge = '', ntlm_cli_challenge = '' , opt = {} )637638usentlm2_session = opt[:usentlm2_session] != nil ? opt[:usentlm2_session] : true639use_ntlmv2 = opt[:use_ntlmv2] != nil ? opt[:use_ntlmv2] : false640send_lm = opt[:send_lm] != nil ? opt[:send_lm] : true641send_ntlm = opt[:send_ntlm] != nil ? opt[:send_ntlm] : true642use_lanman_key = opt[:use_lanman_key] != nil ? opt[:use_lanman_key] : false643644# Create the sessionkey (aka signing key, aka mackey) and encrypted session key645# Server will decide for key_size and key_exchange646enc_session_key = ''647signing_key = ''648649# Set default key size and key exchange values650key_size = 40651key_exchange = false652# Remove ntlmssp.negotiate56653ntlmssp_flags &= 0x7fffffff654# Remove ntlmssp.negotiatekeyexch655ntlmssp_flags &= 0xbfffffff656# Remove ntlmssp.negotiate128657ntlmssp_flags &= 0xdfffffff658# Check the keyexchange659if server_ntlmssp_flags & Rex::Proto::NTLM::Constants::NEGOTIATE_KEY_EXCH != 0 then660key_exchange = true661ntlmssp_flags |= Rex::Proto::NTLM::Constants::NEGOTIATE_KEY_EXCH662end663# Check 128bits664if server_ntlmssp_flags & Rex::Proto::NTLM::Constants::NEGOTIATE_128 != 0 then665key_size = 128666ntlmssp_flags |= Rex::Proto::NTLM::Constants::NEGOTIATE_128667ntlmssp_flags |= Rex::Proto::NTLM::Constants::NEGOTIATE_56668# Check 56bits669else670if server_ntlmssp_flags & Rex::Proto::NTLM::Constants::NEGOTIATE_56 != 0 then671key_size = 56672ntlmssp_flags |= Rex::Proto::NTLM::Constants::NEGOTIATE_56673end674end675# Generate the user session key676lanman_weak = false677if send_ntlm # Should be default678if usentlm2_session679if use_ntlmv2680if self.is_pass_ntlm_hash?(pass)681user_session_key = Rex::Proto::NTLM::Crypt::ntlmv2_user_session_key(user,682[ pass.upcase()[33,65] ].pack('H32'),683domain,684challenge_key, ntlm_cli_challenge,685{:pass_is_hash => true})686else687user_session_key = Rex::Proto::NTLM::Crypt::ntlmv2_user_session_key(user, pass, domain,688challenge_key, ntlm_cli_challenge)689end690else691if self.is_pass_ntlm_hash?(pass)692user_session_key = Rex::Proto::NTLM::Crypt::ntlm2_session_user_session_key([ pass.upcase()[33,65] ].pack('H32'),693challenge_key,694client_challenge,695{:pass_is_hash => true})696else697user_session_key = Rex::Proto::NTLM::Crypt::ntlm2_session_user_session_key(pass, challenge_key,698client_challenge)699end700end701else # lmv1/ntlmv1702# lanman_key may also be used without ntlm response but it is not so much used703# so we don't care about this feature704if send_lm && use_lanman_key705if self.is_pass_ntlm_hash?(pass)706user_session_key = Rex::Proto::NTLM::Crypt::lanman_session_key([ pass.upcase()[0,32] ].pack('H32'),707challenge_key,708{:pass_is_hash => true})709else710user_session_key = Rex::Proto::NTLM::Crypt::lanman_session_key(pass, challenge_key)711end712lanman_weak = true713714715else716if self.is_pass_ntlm_hash?(pass)717user_session_key = Rex::Proto::NTLM::Crypt::ntlmv1_user_session_key([ pass.upcase()[33,65] ].pack('H32'),718{:pass_is_hash => true})719else720user_session_key = Rex::Proto::NTLM::Crypt::ntlmv1_user_session_key(pass)721end722end723end724else725if usentlm2_session && use_ntlmv2726if self.is_pass_ntlm_hash?(pass)727user_session_key = Rex::Proto::NTLM::Crypt::lmv2_user_session_key(user, [ pass.upcase()[33,65] ].pack('H32'),728domain,729challenge_key, client_challenge,730{:pass_is_hash => true})731else732user_session_key = Rex::Proto::NTLM::Crypt::lmv2_user_session_key(user, pass, domain,733challenge_key, client_challenge)734end735else736if self.is_pass_ntlm_hash?(pass)737user_session_key = Rex::Proto::NTLM::Crypt::lmv1_user_session_key([ pass.upcase()[0,32] ].pack('H32'),738{:pass_is_hash => true})739else740user_session_key = Rex::Proto::NTLM::Crypt::lmv1_user_session_key(pass)741end742end743end744745user_session_key = Rex::Proto::NTLM::Crypt::make_weak_sessionkey(user_session_key,key_size, lanman_weak)746747# Sessionkey and encrypted session key748if key_exchange749signing_key = Rex::Text.rand_text(16)750enc_session_key = Rex::Proto::NTLM::Crypt::encrypt_sessionkey(signing_key, user_session_key)751else752signing_key = user_session_key753end754755return signing_key, enc_session_key, ntlmssp_flags756end757end758end759760761