Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
The Node.js ssh2-exec
package extends the ssh2
module to provide transparent usage between the child_process.exec
and ssh2.prototype.exec
functions.
This is OSS and licensed under the new BSD license.
npm install ssh2-exec
ssh2-exec
module usageThe default module expose an API similar to the native NodeJS API. Its signature is:
exec(sshOrNull, command, [options], [callback])
Or
exec(options, [callback])
Like in the native NodeJS API, the callback is not required in case you wish to work with the returned child stream. The "sshOrNull" and "command" arguments are also facultative because they could be provided respectively as the "ssh" and "command" property of the options object.
Valid options
properties are:
ssh
command
cwd
end
env
pty
cwd
uid
gid
See the ssh2 and ssh2-connect modules on how to create a new SSH connection.
ssh2-exec/promise
module usageThe promise module is an alternative to the callback usage. Like with the callback, use it if stdout
and stderr
are not too large and fit in memory.
const {stdout, stderr, code} = await exec(sshOrNull, command, [options])
Or
const {stdout, stderr, code} = await exec(options)
If the exit code is not 0
, the thrown error object contains the stdout
, stderr
, and code
properties.
A command, a configuration object and a callback:
connect = require('ssh2-connect');
exec = require('ssh2-exec');
connect({host: localhost}, function(err, ssh){
exec('ls -la', {ssh: ssh}, (err, stdout, stderr, code){
console.info(stdout, stderr, code);
});
});
A configuration object with a ssh2 connection and working a the return child object:
connect = require('ssh2-connect');
exec = require('ssh2-exec');
connect({host: localhost}, function(err, ssh){
child = exec({
command: 'ls -la',
ssh: ssh
}, function(err, stdout, stderr, code){
console.info(stdout);
});
child.stdout.on('data', function(data){
console.info(data);
});
child.stderr.on('data', function(data){
console.error(data);
});
child.on('exit', function(code){
console.info('Exit', code);
});
})
Tests are executed with mocha. To install it, simple run npm install
, it will install mocha and its dependencies in your project "node_modules" directory.
To run the tests:
npm test
The test suite is run online with Travis.
FAQs
Transparent usage between `child_process.exec` and `ssh2.prototype.exec`
The npm package ssh2-exec receives a total of 1,105 weekly downloads. As such, ssh2-exec popularity was classified as popular.
We found that ssh2-exec demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.