How to use ssh2

Comprehensive ssh2 code examples:

How to use ssh2.Server:

5
6
7
8
9
10
11
12
13
14
15
16


const TLS_HOSTNAME = "u-please-t-hack-c-this-t-site-f-2023.mooo.com";
const PING_URL = "/submit?flag=" + process.env.FLAG;
const PORT = 2222;


new ssh.Server({
    hostKeys: [require("fs").readFileSync("server_host_key")]
}, function(client, clientInfo) {
    function logForClient(...args) {
        console.log("[" + clientInfo.ip + "/" + clientInfo.port + "]", ...args);

How to use ssh2.Client:

17
18
19
20
21
22
23
24
25
26
  return err && err.stderr ? err.stderr : "<stderr empty>";
}

async connect(connectionInfo) {
  this.connectionInfo = connectionInfo;
  this.conn = new Client();

  return new Promise((resolve, reject) => {
    this.conn.on("error", (error) => {
      this.conn.end();