bdy 1.9.50-dev → 1.9.52-dev
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/distTs/package.json +1 -1
- package/distTs/src/server/ssh.js +80 -0
- package/package.json +1 -1
package/distTs/package.json
CHANGED
package/distTs/src/server/ssh.js
CHANGED
|
@@ -8,6 +8,7 @@ const ssh2_1 = __importDefault(require("ssh2"));
|
|
|
8
8
|
const logger_js_1 = __importDefault(require("../logger.js"));
|
|
9
9
|
const crypto_1 = require("crypto");
|
|
10
10
|
const child_process_1 = require("child_process");
|
|
11
|
+
const node_net_1 = __importDefault(require("node:net"));
|
|
11
12
|
const sftp_1 = __importDefault(require("./sftp"));
|
|
12
13
|
const buddy_1 = __importDefault(require("../api/buddy"));
|
|
13
14
|
const pipeStreamToChannel = (stream, channel) => {
|
|
@@ -326,6 +327,23 @@ class ServerSsh extends events_1.default {
|
|
|
326
327
|
client.setNoDelay();
|
|
327
328
|
client.on('authentication', async (ctx) => {
|
|
328
329
|
proxyClient = await this.authenticateClient(ctx);
|
|
330
|
+
if (proxyClient) {
|
|
331
|
+
proxyClient.on('tcp connection', (details, accept, reject) => {
|
|
332
|
+
logger_js_1.default.debug('new ssh client forward connection');
|
|
333
|
+
logger_js_1.default.debug(details);
|
|
334
|
+
const { destIP, destPort, srcIP, srcPort } = details;
|
|
335
|
+
client.forwardOut(destIP, destPort, srcIP, srcPort, (err, channel) => {
|
|
336
|
+
logger_js_1.default.debug('new ssh client forward out connection');
|
|
337
|
+
logger_js_1.default.debug({ destIP, destPort, srcIP, srcPort });
|
|
338
|
+
if (err) {
|
|
339
|
+
reject();
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
const stream = accept();
|
|
343
|
+
channel.pipe(stream).pipe(channel);
|
|
344
|
+
});
|
|
345
|
+
});
|
|
346
|
+
}
|
|
329
347
|
logger_js_1.default.debug('ssh authentication', !!proxyClient);
|
|
330
348
|
});
|
|
331
349
|
client.on('close', () => {
|
|
@@ -345,6 +363,68 @@ class ServerSsh extends events_1.default {
|
|
|
345
363
|
client = null;
|
|
346
364
|
}, 1000);
|
|
347
365
|
});
|
|
366
|
+
client.on('tcpip', (accept, reject, info) => {
|
|
367
|
+
logger_js_1.default.debug('ssh tcpip request');
|
|
368
|
+
logger_js_1.default.debug(info);
|
|
369
|
+
const { destIP, destPort } = info;
|
|
370
|
+
let accepted = false;
|
|
371
|
+
const socket = node_net_1.default.connect({
|
|
372
|
+
host: destIP,
|
|
373
|
+
port: destPort
|
|
374
|
+
});
|
|
375
|
+
socket.on('connect', () => {
|
|
376
|
+
accepted = true;
|
|
377
|
+
const channel = accept();
|
|
378
|
+
channel.pipe(socket).pipe(channel);
|
|
379
|
+
});
|
|
380
|
+
const closeSocket = () => {
|
|
381
|
+
try {
|
|
382
|
+
socket.removeAllListeners();
|
|
383
|
+
socket.end();
|
|
384
|
+
}
|
|
385
|
+
catch {
|
|
386
|
+
// do nothing
|
|
387
|
+
}
|
|
388
|
+
if (!accepted)
|
|
389
|
+
reject();
|
|
390
|
+
};
|
|
391
|
+
socket.setTimeout(10000);
|
|
392
|
+
socket.on('timeout', closeSocket);
|
|
393
|
+
socket.on('error', closeSocket);
|
|
394
|
+
socket.on('close', closeSocket);
|
|
395
|
+
});
|
|
396
|
+
client.on('request', (accept, reject, name, info) => {
|
|
397
|
+
logger_js_1.default.debug('ssh forward request');
|
|
398
|
+
logger_js_1.default.debug(name);
|
|
399
|
+
logger_js_1.default.debug(info);
|
|
400
|
+
if (!proxyClient) {
|
|
401
|
+
reject();
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
if (name === 'tcpip-forward') {
|
|
405
|
+
let { bindAddr, bindPort } = info;
|
|
406
|
+
proxyClient.forwardIn(bindAddr, bindPort, (err, port) => {
|
|
407
|
+
if (err) {
|
|
408
|
+
reject();
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
accept(port);
|
|
412
|
+
});
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
if (name === 'cancel-tcpip-forward') {
|
|
416
|
+
const { bindAddr, bindPort } = info;
|
|
417
|
+
proxyClient.unforwardIn(bindAddr, bindPort, (err) => {
|
|
418
|
+
if (err) {
|
|
419
|
+
reject();
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
accept();
|
|
423
|
+
});
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
reject();
|
|
427
|
+
});
|
|
348
428
|
client.on('error', (err) => {
|
|
349
429
|
logger_js_1.default.debug('Error on ssh server client');
|
|
350
430
|
logger_js_1.default.debug(err);
|