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.
telnet-client
Advanced tools
The telnet-client npm package is a simple and easy-to-use library for creating and managing Telnet connections in Node.js. It allows you to connect to Telnet servers, send commands, and receive responses, making it useful for automating tasks, remote server management, and network device configuration.
Establishing a Telnet Connection
This feature allows you to establish a connection to a Telnet server using specified parameters such as host, port, shell prompt, and timeout.
const Telnet = require('telnet-client');
let connection = new Telnet();
let params = {
host: '127.0.0.1',
port: 23,
shellPrompt: '/ # ',
timeout: 1500
};
connection.connect(params)
.then(() => {
console.log('Connected to the Telnet server');
})
.catch((error) => {
console.error('Connection failed:', error);
});
Sending Commands
Once connected, you can send commands to the Telnet server and handle the responses. This is useful for executing remote commands and automating tasks.
connection.send('ls -l')
.then((response) => {
console.log('Command response:', response);
})
.catch((error) => {
console.error('Command failed:', error);
});
Handling Connection Events
You can handle various connection events such as timeout and close to manage the connection lifecycle and handle errors or disconnections gracefully.
connection.on('timeout', () => {
console.log('Connection timed out');
connection.end();
});
connection.on('close', () => {
console.log('Connection closed');
});
node-telnet-client is another Telnet client library for Node.js. It offers similar functionalities to telnet-client, such as establishing connections, sending commands, and handling responses. However, it provides a more extensive set of options for connection parameters and event handling, making it a bit more flexible for advanced use cases.
telnet-stream is a low-level Telnet client library that provides a stream-based interface for Telnet communication. It is more suitable for developers who need fine-grained control over the Telnet protocol and want to build custom Telnet clients. Compared to telnet-client, it requires more effort to set up and use but offers greater flexibility.
A simple telnet client for node.js
Locally in your project or globally:
npm install telnet-client
npm install -g telnet-client
var telnet = require('telnet-client');
var connection = new telnet();
var params = {
host: 127.0.0.1,
port: 23,
shellPrompt: '/ # ',
timeout: 1500,
// removeEcho: 4
};
connection.on('ready', function(prompt) {
connection.exec(cmd, function(response) {
console.log(response);
});
});
connection.on('timeout', function() {
console.log('socket timeout!')
connection.end();
);
connection.on('close', function() {
console.log('connection closed');
});
connection.connect(params);
var telnet = require('telnet-client');
var connection = new telnet();
Creates a new TCP connection to the specified host, where 'options' is an object which can include following properties:
Sends data on the socket (should be a compatible remote host's command if sane information is wanted). The optional callback parameter will be executed when the data is finally written out - this may not be immediately.
Half-closes the socket. i.e., it sends a FIN packet. It is possible the server will still send some data.
Ensures that no more I/O activity happens on this socket. Only necessary in case of errors (parse error or so).
Emitted when a socket connection is successfully established and the client is successfully connected to the specified remote host.
Emitted when the write of given data is sent to the socket.
Emitted if the socket times out from inactivity. This is only to notify that the socket has been idle. The user must manually close the connection.
Emitted when an error occurs. The 'close' event will be called directly following this event.
Emitted when the other end of the socket (remote host) sends a FIN packet.
Emitted once the socket is fully closed.
FAQs
A simple node.js telnet client
The npm package telnet-client receives a total of 256,425 weekly downloads. As such, telnet-client popularity was classified as popular.
We found that telnet-client 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.
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.