1

同様の質問をstackoverflowで検索しようとしましたが、ほとんどの人がNTLMv2プロトコルのクライアント側について尋ねています. プロキシに接続するユーザーを認証するために、プロトコルのサーバー側を実行するプロキシを実装しています。私は多くのプロトコルをコーディングしましたが、さらに先に進むべきドキュメントを理解するのが難しいため、今は行き詰まっています。

これは私がこれまでに見つけた最高のドキュメントです: http://www.innovation.ch/personal/ronald/ntlm.htmlですが、LM と NT の応答を処理する方法は私にはわかりません。

プロキシはアプリケーション サーバー上にあります。ドメイン サーバーは別のマシンです。

ノード プロキシのコード例:

var http = require('http')
    , request = require('request')
    , ProxyAuth = require('./proxyAuth');

function handlerProxy(req, res) {
    ProxyAuth.authorize(req, res);
    var options = {
        url: req.url,
        method: req.method,
        headers: req.headers
    }
    req.pipe(request(options)).pipe(res)
}

var server = http.createServer(handlerProxy);


server.listen(3000, function(){
    console.log('Express server listening on port ' + 3000);
});

ProxyAuth.js コード:

ProxyAuth = {
    parseType3Msg: function(buf) {
        var lmlen = buf.readUInt16LE(12);
        var lmoff = buf.readUInt16LE(16);
        var ntlen = buf.readUInt16LE(20);
        var ntoff = buf.readUInt16LE(24);
        var dlen = buf.readUInt16LE(28);
        var doff = buf.readUInt16LE(32);
        var ulen = buf.readUInt16LE(36);
        var uoff = buf.readUInt16LE(40);
        var hlen = buf.readUInt16LE(44);
        var hoff = buf.readUInt16LE(48);
        var domain = buf.slice(doff, doff+dlen).toString('utf8');
        var user = buf.slice(uoff, uoff+ulen).toString('utf8');
        var host = buf.slice(hoff, hoff+hlen).toString('utf8');
        var lmresp = buf.slice(lmoff, lmoff+lmlen).toString('utf8');
        var ntresp = buf.slice(ntoff, ntoff+ntlen).toString('utf8');
        console.log(user, lmresp, ntresp);
        /* NOW WHAT DO I DO? */
    },
    authorize: function(req, res) {
        var auth = req.headers['authorization'];
        if (!auth) {
            res.writeHead(401, {
                'WWW-Authenticate': 'NTLM',
            });
            res.end('<html><body>Proxy Authentication Required</body></html>');
        }
        else if(auth) {
            var header = auth.split(' ');
            var buf = new Buffer(header[1], 'base64');
            var msg = buf.toString('utf8');
            console.log("Decoded", msg);
            if (header[0] == "NTLM") {
                if (msg.substring(0,8) != "NTLMSSP\x00") {
                    res.writeHead(401, {
                        'WWW-Authenticate': 'NTLM',
                    });
                    res.end('<html><body>Header not recognized</body></html>');
                }
                // Type 1 message
                if (msg[8] == "\x01") {
                    console.log(buf.toString('hex'));
                    var challenge = require('crypto').randomBytes(8);
                    var type2msg = "NTLMSSP\x00"+
                        "\x02\x00\x00\x00"+ // 8 message type
                        "\x00\x00\x00\x00"+ // 12 target name len/alloc
                        "\x00\x00\x00\x00"+ // 16 target name offset
                        "\x01\x82\x00\x00"+ // 20 flags
                        challenge.toString('utf8')+ // 24 challenge
                        "\x00\x00\x00\x00\x00\x00\x00\x00"+ // 32 context
                        "\x00\x00\x00\x00\x00\x00\x00\x00"; // 40 target info len/alloc/offset

                    type2msg = new Buffer(type2msg).toString('base64');

                    res.writeHead(401, {
                        'WWW-Authenticate': 'NTLM '+type2msg.trim(),
                    });
                    res.end();
                }
                else if (msg[8] == "\x03") {
                    console.log(buf.toString('hex'));
                    ProxyAuth.parseType3Msg(buf);
                    /* NOW WHAT DO I DO? */
                }
            }
            else if (header[0] == "Basic") {
            }
        }
    }
};

module.exports = ProxyAuth;

/* 今、私は何をしますか? */ コメントは、私が立ち往生している場所を示しています。

そこに十分な情報を記載したいと思いますが、他に何か必要な場合はお知らせください。

4

0 に答える 0