Skip to main content

类: SSHClient

ssh.SSHClient SSHClient 是用于 SSH 服务器的客户端。 内部客户端使用 github.com/zmap/zgrab2/lib/ssh 驱动程序。 示例
const ssh = require('nuclei/ssh');
const client = new ssh.SSHClient();

目录

构造函数

方法

构造函数

constructor

new SSHClient(): SSHClient

返回

SSHClient

定义于

ssh.ts:16

方法

Close

Close(): boolean Close 关闭 SSH 连接并销毁客户端 返回成功状态和错误。如果错误不为 nil, 状态将为 false

返回

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

定义于

ssh.ts:118

Connect

Connect(host, port, username): boolean Connect 尝试使用提供的用户名和密码通过 ssh 连接到提供的主机和端口。 返回连接状态和错误。如果错误不为 nil, 状态将为 false

参数

名称类型
hoststring
portnumber
usernamestring

返回

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

定义于

ssh.ts:43

ConnectSSHInfoMode

ConnectSSHInfoMode(host, port): HandshakeLog ConnectSSHInfoMode 尝试连接到提供的主机和端口 返回 HandshakeLog 和错误。如果错误不为 nil, 状态将为 false HandshakeLog 是一个包含有关 SSH 连接信息的结构体

参数

名称类型
hoststring
portnumber

返回

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

定义于

ssh.ts:81

ConnectWithKey

ConnectWithKey(host, port, username): boolean ConnectWithKey 尝试使用提供的用户名和私钥连接到提供的主机和端口。 返回连接状态和错误。如果错误不为 nil, 状态将为 false

参数

名称类型
hoststring
portnumber
usernamestring

返回

boolean 示例
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);

定义于

ssh.ts:61

Run

Run(cmd): string Run 尝试打开一个新的 SSH 会话,然后尝试在该会话中执行提供的命令 返回字符串和错误。如果错误不为 nil, 状态将为 false 字符串包含命令输出

参数

名称类型
cmdstring

返回

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

定义于

ssh.ts:101

SetTimeout

SetTimeout(sec): void SetTimeout 设置 SSH 连接的超时时间(以秒为单位)

参数

名称类型
secnumber

返回

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

定义于

ssh.ts:26