Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
ya-express-ntlm
Advanced tools
An express middleware to have basic NTLM-authentication in node.js.
The project express-ntlm was taken as a basis and rewritten in TypeScript.
npm install ya-express-ntlm
const dotenv = require('dotenv');
dotenv.config();
const express = require('express');
const { authNTLM } = require('ya-express-ntlm');
process.env.DEBUG = 'ntlm:auth-flow,ntlm:ldap-proxy,ntlm:ldap-proxy-id';
const app = express();
const port = Number(process.env.TEST_PORT) || 8080;
app.use(authNTLM({
getDomain: () => process.env.DOMAIN || 'MYDOMAIN',
getDomainControllers: () => [process.env.LDAP_ADDRESS || 'ldap://dc.mydomain.myorg.com'],
}));
app.all('*', (req, res) => {
res.end(JSON.stringify({ ts: Date.now(), ...req.ntlm }));
// {"domain": "MYDOMAIN", "username": "MYUSER", "workstation": "MYWORKSTATION"}
});
app.listen(port);
console.log(`Server listening on http://localhost:${port}`);
import * as dotenv from 'dotenv';
import express, { Request, Response } from 'express';
dotenv.config();
process.env.DEBUG = 'ntlm:auth-flow,ntlm:ldap-proxy,ntlm:ldap-proxy-id';
import { authNTLM, EAuthStrategy } from 'ya-express-ntlm';
const app: express.Express = express();
const port = Number(process.env.TEST_PORT) || 8080;
app.use(authNTLM({
getDomain: () => process.env.DOMAIN || 'MYDOMAIN',
getDomainControllers: () => [process.env.LDAP_ADDRESS || 'ldap://dc.mydomain.myorg.com'],
}));
app.all('*', (req: Request, res: Response) => {
res.end(JSON.stringify({ ts: Date.now(), ...req.ntlm }));
// {"domain": "MYDOMAIN", "username": "MYUSER", "workstation": "MYWORKSTATION"}
});
app.listen(port);
console.log(`Server listening on http://localhost:${port}`);
To use the req.ntlm
object in your TypeScript project, add the file express-augmented.d.ts
declare global {
namespace Express {
export interface Request {
ntlm: {
username?: string,
domain?: string,
workstation?: string,
isAuthenticated?: boolean,
uri?: string,
},
}
}
}
It's not recommended, but it's possible to add NTLM-Authentication without validation. This means you can authenticate without providing valid credentials.
app.use(authNTLM({
getStrategy: () => 'NTLM_STUB',
getDomain: () => process.env.DOMAIN || 'MYDOMAIN',
}));
All parameters are optional functions listed here
Default values are here.
All NTLM-fields (username
, domain
, workstation
) are also available within
response.locals.ntlm
, which means you can access it through your template
engine (e.g. jade or ejs) while rendering (e.g. <%= ntlm.username %>
).
You can view the entire authorization process in detail.
To enable debug mode, you need to set ENV DEBUG
DEBUG=ntlm:auth-flow,ntlm:ldap-proxy,ntlm:ldap-proxy-id
Typical NTLM handshake looks like this
To experiment with NTLM messages:
import { startCoder } from 'ya-express-ntlm';
startCoder();
Let's say you host the site my-intranet-site.corp.com
for your corporate
network and configure NTLM authentication on it using ya-express-ntml
.
Your users log in to their Windows computers in the MYDOMAIN
domain.
If you do not take additional measures, then the first time after launching the browser,
when going to the site, the WWW-Authenticate: NTLM
header will be sent in response to the HTTP request
and the browser will display a pop-up dialog for entering your login and password:
But Windows already has information about what login the user is logged in under. And you can ensure that such login popup will not be displayed. The login under which the user logged into Windows will be automatically used.
To do this, you need to ask your domain administrator to add the site https://my-intranet-site.corp.com
to Intranet zone
.
As a result of ya-express-ntml
operation, res.ntlm
will contain the name of the authenticated user,
and then it can be used in the authorization logic on your site.
FAQs
ya-express-ntlm
The npm package ya-express-ntlm receives a total of 7 weekly downloads. As such, ya-express-ntlm popularity was classified as not popular.
We found that ya-express-ntlm demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.