-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreaver-ui.js
executable file
·277 lines (208 loc) · 7.16 KB
/
reaver-ui.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
#!/usr/bin/env node
var Legobox = require("legobox"),
stream = require("stream"),
spawn = require("child_process").spawn;
if (process.argv.length < 4) {
console.warn("Usage: reaver-ui <interface> <channel>");
process.exit(1);
}
var interface = process.argv[2],
channel = process.argv[3];
var LineSplitter = function LineSplitter(options) {
options = options || {};
options.objectMode = true;
options.highWaterMark = options.highWaterMark || 1;
stream.Transform.call(this, options);
this.buffer = "";
};
LineSplitter.prototype = Object.create(stream.Transform.prototype);
LineSplitter.prototype._transform = function _transform(input, encoding, done) {
this.buffer += Buffer(input, encoding).toString();
var lines = this.buffer.split(/[\r\n]+/);
this.buffer = lines.pop();
lines.forEach(function(line) {
this.push(line);
}.bind(this));
return done();
};
var Reaver = function Reaver(options) {
options = options || {};
options.objectMode = true;
options.highWaterMark = options.highWaterMark || 1;
stream.Writable.call(this, options);
options.args = options.args || [];
var args = options.args.reduce(function(i, v) {
for (var k in v) {
i.push(k);
if (v[k] !== null) {
i.push(v[k]);
}
}
return i;
}, []);
this.process = spawn("reaver", args);
this.process.stdout.pipe(new LineSplitter()).pipe(this);
this.process.stderr.pipe(new LineSplitter()).pipe(this);
};
Reaver.prototype = Object.create(stream.Writable.prototype);
Reaver.prototype._write = function _write(input, encoding, done) {
this.emit("line", input);
var matches;
if (matches = input.match(/Associated with .+? \(ESSID: (.+)\)/)) {
this.emit("associated");
this.emit("essid", matches[1]);
}
if (matches = input.match(/Trying pin ([0-9]+)/)) {
this.emit("trying", matches[1]);
}
if (matches = input.match(/([0-9]+) seconds\/pin/)) {
this.emit("speed", parseInt(matches[1]));
}
if (matches = input.match(/([0-9\.]+)% complete/)) {
this.emit("percent", parseFloat(matches[1]));
}
if (matches = input.match(/waiting ([0-9]+) seconds before/)) {
this.emit("waiting", parseInt(matches[1]));
}
return done();
};
var container = new Legobox.Container({
width: process.stdout.columns,
height: process.stdout.rows,
split: Legobox.Container.SPLIT.vertical,
});
container.pipe(process.stdout);
container.clear().hide();
var current_time = new Legobox.Text({content: "", align: "center"});
setInterval(function() {
current_time.content = (new Date()).toISOString();
current_time.reflow();
}, 1000);
container.addWidget(current_time, {height: 2});
var addTarget = function addTarget(target) {
var outer = new Legobox.Container({split: Legobox.Container.SPLIT.vertical}, {height: 2});
var info_container = new Legobox.Container({split: Legobox.Container.SPLIT.horizontal}, {height: 1});
var bssid_label = new Legobox.Text({content: target, align: "left"}),
current_label = new Legobox.Text({content: "", align: "left"}),
locked_label = new Legobox.Text({content: "[ ]", align: "left"}),
finish_label = new Legobox.Text({content: " ", align: "left"}),
essid_label = new Legobox.Text({content: "()", align: "left"});
info_container.addWidget(bssid_label, {width: 18}).addWidget(current_label, {width: 9}).addWidget(locked_label, {width: 5}).addWidget(finish_label, {width: 25}).addWidget(essid_label);
outer.addWidget(info_container);
var progress_container = new Legobox.Container({split: Legobox.Container.SPLIT.horizontal}, {height: 1});
var progress_label = new Legobox.Text({content: "", align: "right"}),
progress_bar = new Legobox.Progress({total: 100, align: "left"});
progress_label.content = "0%";
progress_bar.progress = 0;
progress_container.addWidget(progress_bar).addWidget(progress_label, {width: 7});
outer.addWidget(progress_container);
var lines = [];
var text = new Legobox.Text({content: "", align: "left"});
var reaver = new Reaver({
args: [
{
"-vv": null,
"-i": interface,
"-c": channel,
"-b": target,
},
],
});
reaver.once("essid", function() {
container.addWidget(outer, {height: 2});
container.reflow();
});
reaver.on("line", function(line) {
lines.push(line);
if (lines.length > 3) {
lines.shift();
}
text.content = lines.join("\n");
text.reflow();
});
var speed = 0;
reaver.on("speed", function(e) {
speed = e;
});
reaver.on("essid", function(essid) {
essid_label.content = "(" + essid + ")";
essid_label.reflow();
});
reaver.on("percent", function(percent) {
progress_label.content = percent.toString() + "%";
progress_label.reflow();
progress_bar.progress = Math.round(percent);
progress_bar.reflow();
if (speed !== 0) {
finish_label.content = (new Date(Date.now() + (speed * 100 * (100 - percent) * 1000))).toISOString();
finish_label.reflow();
}
});
reaver.on("waiting", function(time) {
var when = new Date(Date.now() + time * 1000);
var update = function() {
locked_label.content = "[" + Math.floor((when.valueOf() - Date.now()) / 1000) + "]";
locked_label.reflow();
};
var iv = setInterval(update, 1000);
setTimeout(function() {
clearInterval(iv);
locked_label.content = "[ ]";
locked_label.reflow();
}, time * 1000);
});
reaver.on("trying", function(key) {
current_label.content = key.toString();
current_label.reflow();
});
};
// fire up airodump to look for new targets
function extractInformation() {
var s = new stream.Transform({objectMode: true});
s.cache = {};
s._transform = function _transform(input, encoding, done) {
var matches = Buffer(input, encoding).toString().match(/([0-9A-F:]+)\s+([0-9\-]+)\s+([0-9\-]+)\s+([0-9\-]+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(.+?)\s+(WPA.+?)\s+(.+?)\s+(.+?)\s+/);
if (matches) {
var d = {
bssid: matches[1],
power: parseInt(matches[2], 10),
rxq: parseInt(matches[3], 10),
beacons: parseInt(matches[4], 10),
data: parseInt(matches[5], 10),
channel: parseInt(matches[7], 10),
speed: parseInt(matches[8], 10),
encryption: matches[9],
cipher: matches[10],
auth: matches[11],
};
if (!this.cache[d.bssid] || d.beacons !== this.cache[d.bssid].beacons || d.data !== this.cache[d.bssid].data) {
this.push(d);
}
this.cache[d.bssid] = d;
}
return done();
};
return s;
}
var ad = spawn("airodump-ng", ["-c", channel, interface]);
var targets = {};
ad.stderr.pipe(new LineSplitter()).pipe(extractInformation()).on("readable", function() {
var record;
while (record = this.read()) {
if (!targets[record.bssid]) {
targets[record.bssid] = true;
addTarget(record.bssid);
}
}
});
// force initial (re)flow
container.reflow();
container.reflow();
// make sure we reflow when we need to
process.stdout.on("resize", function() {
container.width = process.stdout.columns;
container.height = process.stdout.rows;
container.clear().reflow();
});
// this just stops the app from closing right away
process.stdin.resume();