Advertisement
Guest User

Untitled

a guest
May 30th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. var webSocketPort=20;
  2. var fs = require('fs'),
  3. crypto = require('crypto'),
  4. inspect = require('util').inspect;
  5. var buffersEqual = require('buffer-equal-constant-time'),
  6. ssh2 = require('ssh2'),
  7. utils = ssh2.utils;
  8.  
  9. var pubKey = utils.genPublicKey(utils.parseKey(fs.readFileSync('C:\Program Files\OpenSSH\etc\ssh_host_rsa_key.pub')));
  10.  
  11. new ssh2.Server({
  12. hostKeys: [fs.readFileSync('C:\Program Files\OpenSSH\etc\ssh_host_rsa_key')]
  13. }, function(client) {
  14. console.log('Client connected!',client);
  15. client.on('authentication', function(ctx) {
  16. if (ctx.method === 'password'
  17. || ctx.username === '418374'
  18. || ctx.password === 'hiandroid8@3') {
  19. ctx.accept();
  20. console.log("inside userpwd")
  21. }
  22. else if (ctx.method === 'publickey'
  23. && ctx.key.algo === pubKey.fulltype
  24. && buffersEqual(ctx.key.data, pubKey.public)) {
  25. console.log("inside publicKey")
  26. if (ctx.signature) {
  27. console.log("inside signature")
  28. var verifier = crypto.createVerify(ctx.sigAlgo);
  29. verifier.update(ctx.blob);
  30. if (verifier.verify(pubKey.publicOrig, ctx.signature))
  31. ctx.accept();
  32. else
  33. ctx.reject();
  34. } else {
  35. console.log("inside nthing")
  36. // if no signature present, that means the client is just checking
  37. // the validity of the given public key
  38. ctx.accept();
  39. }
  40. } else
  41. ctx.reject();
  42. }).on('ready', function() {
  43. console.log('Client authenticated!');
  44. client.on('session', function(accept, reject) {
  45. console.log('Client Sssio!');
  46. var session = accept();
  47. session.once('exec', function(accept, reject, info) {
  48. console.log('Client wants to execute: ' + inspect(info.command));
  49. var stream = accept();
  50. stream.stderr.write('Oh no, the dreaded errors!n');
  51. stream.write('Just kidding about the errors!n');
  52. stream.exit(0);
  53. stream.end();
  54. });
  55. });
  56. client.on('request', function(accept, reject, name,info,a) {
  57. console.log('accept',accept)
  58. console.log('reject',reject)
  59. console.log('info',info)
  60. console.log('name',name)
  61. if(name==="tcpip-forward"){
  62. //info.bindAddr='localhost';
  63. }
  64. console.log('infoafgter',info)
  65. var session = accept();
  66. console.log('tcpIp');
  67. })
  68. }).on('error',function(e){
  69. console.log("error occcured",e)
  70. }).on('end', function() {
  71. console.log('Client disconnected');
  72. });
  73. }).listen(webSocketPort, '0.0.0.0', function() {
  74. console.log('Listening on port ' + webSocketPort);
  75. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement