Class: SSHClient

ssh.SSHClient

SSHClient is a client for SSH servers. Internally client uses github.com/zmap/zgrab2/lib/ssh driver.

Example

const ssh = require('nuclei/ssh');
const client = new ssh.SSHClient();

Table of contents

Constructors

Methods

Constructors

constructor

new SSHClient(): SSHClient

Returns

SSHClient

Defined in

ssh.ts:16

Methods

Close

Close(): boolean

Close closes the SSH connection and destroys the client Returns the success state and error. If error is not nil, state will be false

Returns

boolean

Example

const ssh = require('nuclei/ssh');
const client = new ssh.SSHClient();
client.Connect('acme.com', 22, 'username', 'password');
const closed = client.Close();

Defined in

ssh.ts:118


Connect

Connect(host, port, username): boolean

Connect tries to connect to provided host and port with provided username and password with ssh. Returns state of connection and error. If error is not nil, state will be false

Parameters

NameType
hoststring
portnumber
usernamestring

Returns

boolean

Example

const ssh = require('nuclei/ssh');
const client = new ssh.SSHClient();
const connected = client.Connect('acme.com', 22, 'username', 'password');

Defined in

ssh.ts:43


ConnectSSHInfoMode

ConnectSSHInfoMode(host, port): HandshakeLog

ConnectSSHInfoMode tries to connect to provided host and port with provided host and port Returns HandshakeLog and error. If error is not nil, state will be false HandshakeLog is a struct that contains information about the ssh connection

Parameters

NameType
hoststring
portnumber

Returns

HandshakeLog

Example

const ssh = require('nuclei/ssh');
const client = new ssh.SSHClient();
const info = client.ConnectSSHInfoMode('acme.com', 22);
log(to_json(info));

Defined in

ssh.ts:81


ConnectWithKey

ConnectWithKey(host, port, username): boolean

ConnectWithKey tries to connect to provided host and port with provided username and private_key. Returns state of connection and error. If error is not nil, state will be false

Parameters

NameType
hoststring
portnumber
usernamestring

Returns

boolean

Example

const ssh = require('nuclei/ssh');
const client = new ssh.SSHClient();
const privateKey = `-----BEGIN RSA PRIVATE KEY----- ...`;
const connected = client.ConnectWithKey('acme.com', 22, 'username', privateKey);

Defined in

ssh.ts:61


Run

Run(cmd): string

Run tries to open a new SSH session, then tries to execute the provided command in said session Returns string and error. If error is not nil, state will be false The string contains the command output

Parameters

NameType
cmdstring

Returns

string

Example

const ssh = require('nuclei/ssh');
const client = new ssh.SSHClient();
client.Connect('acme.com', 22, 'username', 'password');
const output = client.Run('id');
log(output);

Defined in

ssh.ts:101


SetTimeout

SetTimeout(sec): void

SetTimeout sets the timeout for the SSH connection in seconds

Parameters

NameType
secnumber

Returns

void

Example

const ssh = require('nuclei/ssh');
const client = new ssh.SSHClient();
client.SetTimeout(10);

Defined in

ssh.ts:26