Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var webSocketPort=20;
- var fs = require('fs'),
- crypto = require('crypto'),
- inspect = require('util').inspect;
- var buffersEqual = require('buffer-equal-constant-time'),
- ssh2 = require('ssh2'),
- utils = ssh2.utils;
- var pubKey = utils.genPublicKey(utils.parseKey(fs.readFileSync('C:\Program Files\OpenSSH\etc\ssh_host_rsa_key.pub')));
- new ssh2.Server({
- hostKeys: [fs.readFileSync('C:\Program Files\OpenSSH\etc\ssh_host_rsa_key')]
- }, function(client) {
- console.log('Client connected!',client);
- client.on('authentication', function(ctx) {
- if (ctx.method === 'password'
- || ctx.username === '418374'
- || ctx.password === 'hiandroid8@3') {
- ctx.accept();
- console.log("inside userpwd")
- }
- else if (ctx.method === 'publickey'
- && ctx.key.algo === pubKey.fulltype
- && buffersEqual(ctx.key.data, pubKey.public)) {
- console.log("inside publicKey")
- if (ctx.signature) {
- console.log("inside signature")
- var verifier = crypto.createVerify(ctx.sigAlgo);
- verifier.update(ctx.blob);
- if (verifier.verify(pubKey.publicOrig, ctx.signature))
- ctx.accept();
- else
- ctx.reject();
- } else {
- console.log("inside nthing")
- // if no signature present, that means the client is just checking
- // the validity of the given public key
- ctx.accept();
- }
- } else
- ctx.reject();
- }).on('ready', function() {
- console.log('Client authenticated!');
- client.on('session', function(accept, reject) {
- console.log('Client Sssio!');
- var session = accept();
- session.once('exec', function(accept, reject, info) {
- console.log('Client wants to execute: ' + inspect(info.command));
- var stream = accept();
- stream.stderr.write('Oh no, the dreaded errors!n');
- stream.write('Just kidding about the errors!n');
- stream.exit(0);
- stream.end();
- });
- });
- client.on('request', function(accept, reject, name,info,a) {
- console.log('accept',accept)
- console.log('reject',reject)
- console.log('info',info)
- console.log('name',name)
- if(name==="tcpip-forward"){
- //info.bindAddr='localhost';
- }
- console.log('infoafgter',info)
- var session = accept();
- console.log('tcpIp');
- })
- }).on('error',function(e){
- console.log("error occcured",e)
- }).on('end', function() {
- console.log('Client disconnected');
- });
- }).listen(webSocketPort, '0.0.0.0', function() {
- console.log('Listening on port ' + webSocketPort);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement