httpntlm

repository·master·Indexed 41 days ago

https://github.com/samdecrock/node-http-ntlm

A 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.

Tokens
1.6K
Snippets
4
Records
6
Agent score
2%

What's inside httpntlm

  1. How NTLMv2 is handled

    master
    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.
  2. Manually manage the NTLM handshake using NTLM functions

    master

    For advanced control, you can use the httpntlm.ntlm methods directly to manage the three-step NTLM handshake:

    1. createType1Message(options): Generates the initial challenge request.
    2. parseType2Message(authHeader): Parses the server's challenge from the www-authenticate header.
    3. 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);
    });
  3. Perform an NTLM authenticated GET request

    master

    Use httpntlm.get() to perform an HTTP GET request with NTLM authentication. You must provide a url and can optionally provide username, password, workstation, and domain.

    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);
    });
  4. Pre-encrypt passwords using the NTLM module

    master

    If you already have the encrypted LM and NT hashes, you can use the httpntlm.ntlm sub-module to generate them and pass them to the request instead of a plain-text password. Use ntlm.create_LM_hashed_password(password) and ntlm.create_NT_hashed_password(password) to generate the required Buffer objects.

    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);
    });
  5. Reference: httpntlm.get() options

    master

    The following options are available for the httpntlm.get() method (and other HTTP methods like POST, PUT, or DELETE which inherit options from httpreq):

    OptionTypeDescription
    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: Connection and Authorization are used by NTLM and cannot be passed manually.
    lm_passwordBufferEncrypted LM password. Use this instead of password if you have the hash.
    nt_passwordBufferEncrypted NT password. Use this instead of password if you have the hash.
    binaryBooleanSet to true for downloading binary files.