@nib/httpntlm

1.7.8 • Public • Published

httpntlm

httpntlm is a Node.js library to do HTTP NTLM authentication

It's a port from the Python libary python-ntml

Install

You can install httpntlm using the Node Package Manager (npm):

npm install httpntlm

How to use

var httpntlm = require('httpntlm');

httpntlm.get({
    url: "https://someurl.com",
    username: 'm$',
    password: 'stinks',
    workstation: 'choose.something',
    domain: ''
}, function (err, res){
    if(err) return err;

    console.log(res.headers);
    console.log(res.body);
});

It supports http and https.

pre-encrypt the password

var httpntlm = require('httpntlm');
var ntlm = httpntlm.ntlm;
var lm = ntlm.create_LM_hashed_password('Azx123456');
var nt = ntlm.create_NT_hashed_password('Azx123456');
console.log(lm);
console.log(Array.prototype.slice.call(lm, 0));
lm = new Buffer([ 183, 180, 19, 95, 163, 5, 118, 130, 30, 146, 159, 252, 1, 57, 81, 39 ]);
console.log(lm);

console.log(nt);
console.log(Array.prototype.slice.call(nt, 0));
nt = new Buffer([150, 27, 7, 219, 220, 207, 134, 159, 42, 60, 153, 28, 131, 148, 14, 1]);
console.log(nt);


httpntlm.get({
    url: "https://someurl.com",
    username: 'm$',
    lm_password: lm,
    nt_password: nt,
    workstation: 'choose.something',
    domain: ''
}, function (err, res){
    if(err) return err;

    console.log(res.headers);
    console.log(res.body);
});

/* you can save the array into your code and use it when you need it

<Buffer b7 b4 13 5f a3 05 76 82 1e 92 9f fc 01 39 51 27>// before convert to array
[ 183, 180, 19, 95, 163, 5, 118, 130, 30, 146, 159, 252, 1, 57, 81, 39 ]// convert to array
<Buffer b7 b4 13 5f a3 05 76 82 1e 92 9f fc 01 39 51 27>//convert back to buffer

<Buffer 96 1b 07 db dc cf 86 9f 2a 3c 99 1c 83 94 0e 01>
[ 150, 27, 7, 219, 220, 207, 134, 159, 42, 60, 153, 28, 131, 148, 14, 1 ]
<Buffer 96 1b 07 db dc cf 86 9f 2a 3c 99 1c 83 94 0e 01>
*/

Options

  • url: {String} URL to connect. (Required)
  • username: {String} Username. (Required)
  • password: {String} Password. (Required)
  • workstation: {String} Name of workstation or ''.
  • domain: {String} Name of domain or ''.

if you already got the encrypted password,you should use this two param to replace the 'password' param.

  • lm_password {Buffer} encrypted lm password.(Required)
  • nt_password {Buffer} encrypted nt password. (Required)

You can also pass along all other options of httpreq, including custom headers, cookies, body data, ... and use POST, PUT or DELETE instead of GET.

Advanced

If you want to use the NTLM-functions yourself, you can access the ntlm-library like this (https example):

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);
});

Download binary files

httpntlm.get({
    url: "https://someurl.com/file.xls",
    username: 'm$',
    password: 'stinks',
    workstation: 'choose.something',
    domain: '',
    binary: true
}, function (err, response) {
    if(err) return console.log(err);
    fs.writeFile("file.xls", response.body, function (err) {
        if(err) return console.log("error writing file");
        console.log("file.xls saved!");
    });
});

More information

Donate

If you like this module or you want me to update it faster, feel free to donate. It helps increasing my dedication to fixing bugs :-)

License (MIT)

Copyright (c) Sam Decrock https://github.com/SamDecrock/

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Readme

Keywords

none

Package Sidebar

Install

npm i @nib/httpntlm

Weekly Downloads

3

Version

1.7.8

License

none

Unpacked Size

27.5 kB

Total Files

6

Last publish

Collaborators

  • eina-chan
  • digio-shanefitzgerald
  • darcymerrickmudbath
  • deepaaravindan_nib
  • yparulkar-nib
  • saranya-nibtravel
  • aktb-nib
  • trentontws
  • izabelawojciak
  • krut
  • eddylj
  • georgia-batson
  • adamgonlag
  • paul-neville-thompson
  • terencesunendava
  • nathanpiper-nib
  • sylvia.zh
  • sophiebclewis
  • dluong.mud
  • ryanforteendava
  • jaredgold
  • dylanfu
  • karlb_nz
  • steve.goodwin.mudbath
  • neon-inkblast
  • paritoshdhebar_endava
  • bencoll
  • amelialuwia
  • lareinamarieyu
  • cooldesignluke
  • julie.li
  • connorpmcbride
  • tarantoj
  • samreedy
  • caleb.faith
  • shirleyshao
  • kieranjogrady
  • samjwillis-nib
  • nathan.ford-nib
  • sumo_nib
  • domcorso-nib
  • jmatas
  • kentran.mudbath
  • ki-nibnz
  • mthamyeeznib
  • swaff-y
  • humanforklift
  • nathananstess.nib
  • aidan.mccormack.nib
  • matthewchambers-nib
  • lewis.kwong.nib
  • parisa.heyd
  • delucasnz
  • stephen.wong
  • thomasc42
  • sameer-e-digio
  • fiona.wang
  • elias.tran.nib
  • pkernaghan
  • ruilunli
  • nadeeth.nib
  • alankirknibtravel
  • mgw114
  • gaurijadhav
  • sannat-digar
  • bradley.williams
  • sheren
  • ash-tulett-nib
  • damodaran
  • joshgermon-nib
  • joshua.coleiro
  • juliexxvi
  • t.mazzoni
  • breynol5
  • zoechainib
  • john.hartmann.nib
  • darren.inwood.nib
  • johnpaulvaughan
  • meltemcicekbuzcu
  • georgia.batson
  • joshgerlach
  • blakehattingh
  • chris.close.nib
  • phanipericherla-nib
  • dsmitham
  • buxtonk
  • c.rhind
  • vinualwisnib
  • tristancampbellmb
  • danieltran-nib
  • dguilbert
  • tejaswikota
  • tjodzio-nib
  • mitchellharrold
  • denniskhormb
  • billthomas-nib
  • harshahr1994
  • dimi7ri
  • jkumaranc
  • akash.prakash
  • henry.shen
  • jairmud
  • vivien_clifford_nib
  • jakeherington-nib
  • pallavi.barna
  • raghu9405
  • callumwk-mudbath
  • bendharvey
  • rahulrathodmudbath
  • khtat
  • s.hossain
  • brad.turner
  • scottwalkerau
  • phillip.eade
  • johanjarvi
  • msikkema
  • alunarzewski
  • jnwest
  • wdvalena
  • blake_spiers
  • sbista
  • mleontieff
  • envoy49
  • amy.tait.nib
  • aschofield-nib
  • ian.darroch
  • syed.husain
  • nib-admin
  • lauriejones
  • cmayson
  • ken-ky-wong
  • stribs
  • wng-services
  • eastwood
  • mattbourke
  • narcher
  • tmcclenahan
  • gui99
  • nib-nz-build
  • chloewicks
  • tgoldthorpe-nib
  • nib-build-agent
  • hlee
  • jackmennienib
  • dariasu
  • bennettsolnet
  • airfan
  • samdiamond
  • rovacsek
  • roland.molina
  • gnguyennib
  • tom.mok
  • gl0206
  • tbrown-nib
  • vicvinegar
  • oshan.kottege
  • xiaoxinghu
  • rbowen006
  • seanw.nib
  • anishmat27
  • sean0x42
  • zander-mudbath
  • sbeliak-nib
  • c.lassen
  • aglazyrin-mb
  • dmitrymatveev
  • vaishalibhakhar
  • alejop-mudbath
  • r3gm1
  • maraza1721
  • d-martin-nib
  • apnib
  • siyengar94