UNPKG

13.9 kBSource Map (JSON)View Raw
1{"version":3,"file":"ntlm-payload.js","names":["_writableTrackingBuffer","_interopRequireDefault","require","crypto","_interopRequireWildcard","_jsMd","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","obj","NTLMResponsePayload","constructor","loginData","data","createResponse","toString","indent","challenge","client_nonce","createClientNonce","lmv2len","ntlmv2len","domain","username","userName","password","ntlmData","ntlmpacket","server_data","target","server_nonce","nonce","bufferLength","length","WritableTrackingBuffer","position","writeString","writeUInt32LE","baseIdx","dnIdx","unIdx","l2Idx","ntIdx","writeUInt16LE","lmv2Data","lmv2Response","copyFrom","genTime","Date","getTime","ntlmDataBuffer","ntlmv2Response","timestamp","createTimestamp","Buffer","alloc","nidx","writeUInt8","Math","ceil","random","user","serverNonce","targetInfo","clientNonce","mytime","hash","ntv2Hash","dataLength","copy","hmacMD5","time","tenthsOfAMicrosecond","BigInt","lo","Number","hi","result","newhash","response","ntHash","identity","from","toUpperCase","text","unicodeString","md4","arrayBuffer","key","createHmac","update","digest","_default","exports","module"],"sources":["../src/ntlm-payload.ts"],"sourcesContent":["import WritableTrackingBuffer from './tracking-buffer/writable-tracking-buffer';\nimport * as crypto from 'crypto';\nimport md4 from 'js-md4';\n\ninterface Options {\n domain: string;\n userName: string;\n password: string;\n ntlmpacket: {\n target: Buffer;\n nonce: Buffer;\n };\n}\n\nclass NTLMResponsePayload {\n declare data: Buffer;\n\n constructor(loginData: Options) {\n this.data = this.createResponse(loginData);\n }\n\n toString(indent = '') {\n return indent + 'NTLM Auth';\n }\n\n createResponse(challenge: Options) {\n const client_nonce = this.createClientNonce();\n const lmv2len = 24;\n const ntlmv2len = 16;\n const domain = challenge.domain;\n const username = challenge.userName;\n const password = challenge.password;\n const ntlmData = challenge.ntlmpacket;\n const server_data = ntlmData.target;\n const server_nonce = ntlmData.nonce;\n const bufferLength = 64 + (domain.length * 2) + (username.length * 2) + lmv2len + ntlmv2len + 8 + 8 + 8 + 4 + server_data.length + 4;\n const data = new WritableTrackingBuffer(bufferLength);\n data.position = 0;\n data.writeString('NTLMSSP\\u0000', 'utf8');\n data.writeUInt32LE(0x03);\n const baseIdx = 64;\n const dnIdx = baseIdx;\n const unIdx = dnIdx + domain.length * 2;\n const l2Idx = unIdx + username.length * 2;\n const ntIdx = l2Idx + lmv2len;\n data.writeUInt16LE(lmv2len);\n data.writeUInt16LE(lmv2len);\n data.writeUInt32LE(l2Idx);\n data.writeUInt16LE(ntlmv2len);\n data.writeUInt16LE(ntlmv2len);\n data.writeUInt32LE(ntIdx);\n data.writeUInt16LE(domain.length * 2);\n data.writeUInt16LE(domain.length * 2);\n data.writeUInt32LE(dnIdx);\n data.writeUInt16LE(username.length * 2);\n data.writeUInt16LE(username.length * 2);\n data.writeUInt32LE(unIdx);\n data.writeUInt16LE(0);\n data.writeUInt16LE(0);\n data.writeUInt32LE(baseIdx);\n data.writeUInt16LE(0);\n data.writeUInt16LE(0);\n data.writeUInt32LE(baseIdx);\n data.writeUInt16LE(0x8201);\n data.writeUInt16LE(0x08);\n data.writeString(domain, 'ucs2');\n data.writeString(username, 'ucs2');\n const lmv2Data = this.lmv2Response(domain, username, password, server_nonce, client_nonce);\n data.copyFrom(lmv2Data);\n const genTime = new Date().getTime();\n const ntlmDataBuffer = this.ntlmv2Response(domain, username, password, server_nonce, server_data, client_nonce, genTime);\n data.copyFrom(ntlmDataBuffer);\n data.writeUInt32LE(0x0101);\n data.writeUInt32LE(0x0000);\n const timestamp = this.createTimestamp(genTime);\n data.copyFrom(timestamp);\n data.copyFrom(client_nonce);\n data.writeUInt32LE(0x0000);\n data.copyFrom(server_data);\n data.writeUInt32LE(0x0000);\n return data.data;\n }\n\n createClientNonce() {\n const client_nonce = Buffer.alloc(8, 0);\n let nidx = 0;\n while (nidx < 8) {\n client_nonce.writeUInt8(Math.ceil(Math.random() * 255), nidx);\n nidx++;\n }\n return client_nonce;\n }\n\n ntlmv2Response(domain: string, user: string, password: string, serverNonce: Buffer, targetInfo: Buffer, clientNonce: Buffer, mytime: number) {\n const timestamp = this.createTimestamp(mytime);\n const hash = this.ntv2Hash(domain, user, password);\n const dataLength = 40 + targetInfo.length;\n const data = Buffer.alloc(dataLength, 0);\n serverNonce.copy(data, 0, 0, 8);\n data.writeUInt32LE(0x101, 8);\n data.writeUInt32LE(0x0, 12);\n timestamp.copy(data, 16, 0, 8);\n clientNonce.copy(data, 24, 0, 8);\n data.writeUInt32LE(0x0, 32);\n targetInfo.copy(data, 36, 0, targetInfo.length);\n data.writeUInt32LE(0x0, 36 + targetInfo.length);\n return this.hmacMD5(data, hash);\n }\n\n createTimestamp(time: number) {\n const tenthsOfAMicrosecond = (BigInt(time) + BigInt(11644473600)) * BigInt(10000000);\n\n const lo = Number(tenthsOfAMicrosecond & BigInt(0xffffffff));\n const hi = Number((tenthsOfAMicrosecond >> BigInt(32)) & BigInt(0xffffffff));\n\n const result = Buffer.alloc(8);\n result.writeUInt32LE(lo, 0);\n result.writeUInt32LE(hi, 4);\n return result;\n }\n\n lmv2Response(domain: string, user: string, password: string, serverNonce: Buffer, clientNonce: Buffer) {\n const hash = this.ntv2Hash(domain, user, password);\n const data = Buffer.alloc(serverNonce.length + clientNonce.length, 0);\n\n serverNonce.copy(data);\n clientNonce.copy(data, serverNonce.length, 0, clientNonce.length);\n\n const newhash = this.hmacMD5(data, hash);\n const response = Buffer.alloc(newhash.length + clientNonce.length, 0);\n\n newhash.copy(response);\n clientNonce.copy(response, newhash.length, 0, clientNonce.length);\n\n return response;\n }\n\n ntv2Hash(domain: string, user: string, password: string) {\n const hash = this.ntHash(password);\n const identity = Buffer.from(user.toUpperCase() + domain.toUpperCase(), 'ucs2');\n return this.hmacMD5(identity, hash);\n }\n\n ntHash(text: string) {\n const unicodeString = Buffer.from(text, 'ucs2');\n return Buffer.from(md4.arrayBuffer(unicodeString));\n }\n\n hmacMD5(data: Buffer, key: Buffer)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