httpntlm
repository·master·Indexed 41 days ago
https://github.com/samdecrock/node-http-ntlmA Node.js library for performing HTTP requests with NTLM authentication, including NTLMv2 support. Version 1.8.13 provides methods for authenticated GET, POST, PUT, and DELETE requests, as well as a sub-module for manually managing the NTLM handshake and pre-encrypting passwords using LM and NT hashes.
What's inside httpntlm
- This library assumes the server supports NTLMv2 when extended security and target information can be negotiated. It will create responses according to the NTLMv2 specification. If NTLMv2 is not supported, it falls back to NTLMv1 or NTLMv1 with NTLMv2 extended security.
Install httpntlm via npm
masterYou can install the
httpntlmlibrary using the Node Package Manager (npm).npm install httpntlmManually manage the NTLM handshake using NTLM functions
masterFor advanced control, you can use the
httpntlm.ntlmmethods directly to manage the three-step NTLM handshake:createType1Message(options): Generates the initial challenge request.parseType2Message(authHeader): Parses the server's challenge from thewww-authenticateheader.createType3Message(type2msg, options): Generates the final response message.
var ntlm = require('httpntlm').ntlm; var async = require('async'); var httpreq = require('httpreq'); var HttpsAgent = require('agentkeepalive').HttpsAgent; var keepaliveAgent = new HttpsAgent(); var options = { url: "https://someurl.com", username: 'm$', password: 'stinks', workstation: 'choose.something', domain: '' }; async.waterfall([ function (callback){ var type1msg = ntlm.createType1Message(options); httpreq.get(options.url, { headers:{ 'Connection' : 'keep-alive', 'Authorization': type1msg }, agent: keepaliveAgent }, callback); }, function (res, callback){ if(!res.headers['www-authenticate']) return callback(new Error('www-authenticate not found on response of second request')); var type2msg = ntlm.parseType2Message(res.headers['www-authenticate']); var type3msg = ntlm.createType3Message(type2msg, options); setImmediate(function() { httpreq.get(options.url, { headers: { 'Connection' : 'Close', 'Authorization': type3msg }, allowRedirects: false, agent: keepaliveAgent }, callback); }); } ], function (err, res) { if(err) return console.log(err); console.log(res.headers); console.log(res.body); });Perform an NTLM authenticated GET request
masterUse
httpntlm.get()to perform an HTTP GET request with NTLM authentication. You must provide aurland can optionally provideusername,password,workstation, anddomain.var httpntlm = require('httpntlm'); httpntlm.get({ url: "https://someurl.com", username: 'm$', password: 'stinks', workstation: 'choose.something', domain: '' }, function (err, res){ if(err) return console.log(err); console.log(res.headers); console.log(res.body); });Pre-encrypt passwords using the NTLM module
masterIf you already have the encrypted LM and NT hashes, you can use the
httpntlm.ntlmsub-module to generate them and pass them to the request instead of a plain-text password. Usentlm.create_LM_hashed_password(password)andntlm.create_NT_hashed_password(password)to generate the requiredBufferobjects.var httpntlm = require('httpntlm'); var ntlm = httpntlm.ntlm; var lm = ntlm.create_LM_hashed_password('Azx123456'); var nt = ntlm.create_NT_hashed_password('Azx123456'); httpntlm.get({ url: "https://someurl.com", username: 'm$', lm_password: lm, nt_password: nt, workstation: 'choose.something', domain: '' }, function (err, res){ if(err) return console.log(err); console.log(res.headers); console.log(res.body); });Reference: httpntlm.get() options
masterThe following options are available for the
httpntlm.get()method (and other HTTP methods likePOST,PUT, orDELETEwhich inherit options fromhttpreq):Option Type Description urlStringURL to connect. (Required) usernameStringUsername (optional, default: '') passwordStringPassword (optional, default: '') workstationStringName of workstation (optional, default: '') domainStringName of domain (optional, default: '') agentAgentAn agent to reuse the keepaliveAgent over different calls (optional) headersObjectCustom headers. Note: ConnectionandAuthorizationare used by NTLM and cannot be passed manually.lm_passwordBufferEncrypted LM password. Use this instead of passwordif you have the hash.nt_passwordBufferEncrypted NT password. Use this instead of passwordif you have the hash.binaryBooleanSet to truefor downloading binary files.