-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathevent.js
More file actions
414 lines (352 loc) · 14 KB
/
event.js
File metadata and controls
414 lines (352 loc) · 14 KB
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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
// Function to slow down the pace of attack
function sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if (new Date().getTime() - start > milliseconds) {
break;
}
}
}
function getpn() {
var url = 'https://raw.githubusercontent.com/shellfarmer/WeakestLink/master/postnominals.txt';
var pn = [];
fetch(url)
.then((resp) => resp.text())
.then(function (data) {
var lines = data.split(/\n/);
for (var i = 0; i < lines.length; i++) {
// only push this line if it contains a non whitespace character.
if (/\S/.test(lines[i])) {
pn.push(lines[i].replace(/\n|\r/g, '').trim());
}
}
});
return pn;
}
function getHonorifics() {
var url = 'https://raw.githubusercontent.com/shellfarmer/WeakestLink/master/honorifics.txt';
var honorifics = [];
fetch(url)
.then((resp) => resp.text())
.then(function (data) {
var lines = data.split(/\n/);
for (var i = 0; i < lines.length; i++) {
// only push this line if it contains a non whitespace character.
if (/\S/.test(lines[i])) {
honorifics.push(lines[i].replace(/\n|\r/g, '').trim());
}
}
});
return honorifics;
}
function getnicknames() {
var url = 'https://raw.githubusercontent.com/shellfarmer/WeakestLink/master/nicknames.txt';
var nicknames = [];
fetch(url)
.then((resp) => resp.text())
.then(function (data) {
var lines = data.split(/\n/);
for (var i = 0; i < lines.length; i++) {
// only push this line if it contains a non whitespace character.
if (/\S/.test(lines[i])) {
parts = lines[i].replace(/\n|\r/g, '').trim().split(':');
nicknames[parts[0]] = parts[1];
}
}
});
return nicknames;
}
var urls = [];
var count = 0;
var finished = '';
var page = '';
var postnominals = [];
var honorifics = [];
var nicknames = [];
var filename = '';
var userdata = '';
var shortnames = '';
var lastnameprefix = ['o', 'da', 'de', 'di', 'al', 'ul', 'el'];
var junk = false;
var headline = false;
var count = 0;
var run = false;
var maxrequests = 0;
var tabid = 0;
function completed(data, finished, count, filename, tabid) {
var blob = new Blob([data], {
type: 'text/csv;charset=utf-8',
});
var downloadid = 0;
chrome.downloads.onChanged.addListener(function (delta) {
if (!delta.state || delta.state.current != 'complete' || delta.id != downloadid) {
return;
}
chrome.downloads.search({ id: downloadid }, function (results) {
var downloadpath = results[0]['filename'];
var message = '';
var code = '';
var url = '';
message =
'<html><body><style>.body{background-color:#f7f7f7}.flex-container{height:100%;padding:0;margin:0;display:-webkit-box;display:-moz-box;display:-ms-flexbox;display:-webkit-flex;display:flex;align-items:center;justify-content:center;flex-direction:column;margin-top:50px}.row{width:auto;border:1px;border-radius:5px;box-shadow:0 4px 8px 0 rgba(0,0,0,.2),0 6px 20px 0 rgba(0,0,0,.19);text-align:center}.inner{padding:10px}table{border-collapse:collapse;width:100%}td,th{padding:15px}table,td,th{border:1px solid #ddd;text-align:left}</style><div class=flex-container> <img src=https://github.com/shellfarmer/WeakestLink/blob/master/images/logo128.png?raw=true /> <h2> WeakestLink Dump Finished </h2><div class=row><div class=inner><table><tr><td>Final Status</td><td>$$STATUS$$</td> </tr> <tr> <td>Total Users Identified</td><td>$$COUNT$$</td></tr><tr><td>Downloaded File</td><td>"$$FILENAME$$"</td></tr></table><p>Click <a href=$$URL$$>here</a> to return to the first search page</p></div></div></div></body></html>';
message = message.replace('$$STATUS$$', finished);
message = message.replace('$$COUNT$$', count);
message = message.replace('$$FILENAME$$', downloadpath);
message = message.replace('$$URL$$', url);
code = 'document.body.innerHTML = "' + message + '";';
chrome.tabs.executeScript(tabid, {
code: code,
});
//chrome.runtime.reload();
});
});
chrome.downloads.download(
{
url: URL.createObjectURL(blob),
filename: filename,
},
function (id) {
downloadid = id;
}
);
}
function addPerson(personarray) {
person = personarray[0];
person = person.replace('"', '');
if (person === '') {
return;
}
if (person.includes('LinkedIn')) {
return;
}
var short = false;
if (junk || genusers || nickname) {
// try and catch well known accrediations
var username = person.toLowerCase();
// Replace diacritics with standard characters then remove any none ascii chars - technically not needed for AD but may avoid some problems
username = username
.normalize('NFD')
.replace(/[\u0300-\u036f]/g, '')
.replace(/[^\x20-\x7E]/g, '');
// clear out any possible dividers
username = username.replace(/\//g, ' ');
username = username.replace(/\\/g, ' ');
username = username.replace(/\"/g, ' ');
username = username.replace(/\(.*\)/gi, ' ');
username = username.replace(/\[.*\]/gi, ' ');
// Remove any random bits after commas such as accrediations
if (username.includes(',')) {
username = username.split(',')[0].trim();
}
// Remove any random bits after hyphens such as accrediations
if (username.includes(' - ')) {
username = username.split(' - ')[0].trim();
}
// Remove postnominals - Switch this to regex
for (var index in postnominals) {
//regex failing?
//username = username.replace(new RegExp("\\b" + postnominals[index] + "\\b"), " ");
username = username.replace(' ' + postnominals[index] + ' ', ' ');
if (username.toUpperCase().endsWith(' ' + postnominals[index].toUpperCase())) {
username = username.substring(0, username.lastIndexOf(' '));
}
}
// Remove honorifics - Switch this to regex
for (var index in honorifics) {
if (username.toUpperCase().startsWith(honorifics[index].toUpperCase() + ' ') || username.toUpperCase().startsWith(honorifics[index].toUpperCase() + '. ')) {
username = username.substring(username.indexOf(' '));
}
}
username = username.trim();
var nameparts = username.split(' ');
var firstname = nameparts[0];
var lastname = nameparts[nameparts.length - 1];
// Handle lastnames with prefixes such as de or el
if (nameparts.length > 2) {
var prefix = nameparts[nameparts.length - 2];
for (var index in lastnameprefix) {
if (prefix.toLowerCase() == lastnameprefix[index]) {
lastname = lastnameprefix[index] + lastname;
}
}
}
// Hidden lastname (M.) chop off final dot, need to exclude some some username permitations
if (lastname.length == 2 && lastname.charAt(1) == '.') {
lastname = lastname.charAt(0);
short = true;
}
// remove any redundant spaces and drop to lowercase.
firstname = firstname.trim().toLowerCase();
lastname = lastname.trim().toLowerCase();
username = username.trim().toLowerCase();
}
var firstnames = [firstname];
var headlinedata = "";
if (nickname) {
if (typeof nicknames[firstname] != 'undefined') {
firstnames.push(nicknames[firstname]);
}
}
if (headline) {
headlinedata = '"' + personarray[1] + '","' + personarray[2] + '","'+ personarray[3] + '",';
}
for (var index in firstnames) {
firstname = firstnames[index];
if (genusers) {
// first anna
var user1 = firstname;
// firstlast annakey
var user2 = firstname + lastname;
// first.last anna.key
var user3 = firstname + '.' + lastname;
// firstl annak
var user4 = firstname + lastname.charAt(0);
// f.last a.key
var user5 = username.charAt(0) + '.' + lastname;
// flast akey
var user6 = username.charAt(0) + lastname;
// lfirst kanna
var user7 = lastname.charAt(0) + firstname;
// l.first k.anna
var user8 = lastname.charAt(0) + '.' + firstname;
// lastf keya
var user9 = lastname + firstname.charAt(0);
// last key
var user10 = lastname;
// last.f key.a
var user11 = lastname + '.' + firstname.charAt(0);
// last.first key.anna
var user12 = lastname + '.' + firstname;
// fl ak
var user13 = firstname.charAt(0) + lastname.charAt(0);
var personline = '"' + person + '",' + headlinedata + firstname + ' ' + lastname + ',' + user1 + ',' + user2 + ',' + user3 + ',' + user4 + ',' + user5 + ',' + user6 + ',' + user7 + ',' + user8 + ',' + user9 + ',' + user10 + ',' + user11 + ',' + user12 + ',' + user13 + '\n';
if (short) {
shortnames = shortnames.concat(personline);
} else {
userdata = userdata.concat(personline);
}
} else if (junk) {
if (short) {
shortnames = shortnames.concat('"' + person + '",' + headlinedata + firstname + ' ' + lastname + '\n');
} else {
userdata = userdata.concat('"' + person + '",' + headlinedata + firstname + ' ' + lastname + '\n');
}
} else {
if(headline)
userdata = userdata.concat('"' + person + '",' + headlinedata + '\n');
else
userdata = userdata.concat('"' + person + '"\n');
}
short = false;
}
count++;
}
// This function is called onload in the popup code
function dumpCurrentPage(url, intabid, junkoption, genusersoption, headlinoption, nicknameoption) {
if (run) return;
postnominals = getpn();
honorifics = getHonorifics();
junk = junkoption;
headline = headlinoption;
genusers = genusersoption;
nickname = nicknameoption;
tabid = intabid;
chrome.tabs.onRemoved.addListener(function (tabid, removed) {
chrome.runtime.reload();
});
// This is sloppy, swap with loading from file and find a decent source of names! What to do with multiples such as Elizabeth
if (nickname) {
nicknames = getnicknames();
}
var headlinetitles = '';
if (headline) {
headlinetitles = ',headline,subline,handle';
}
var header = 'LinkedIn Name' + headlinetitles;
if (junk) {
header = 'LinkedIn Name' + headlinetitles + ',clean name';
}
if (genusers) {
header = 'LinkedIn Name' + headlinetitles + ',clean name,first,firstlast,first.last,firstl,f.last,flast,lfirst,l.first,lastf,last,last.f,last.first,fl';
}
userdata = header + '\n';
chrome.webNavigation.onCompleted.addListener(
function (details) {
if (details.tabId == tabid && finished === '') {
sleep(250);
chrome.tabs.executeScript(tabid, {
file: 'content.js',
});
}
},
{ url: [{ hostContains: 'linkedin.com' }] }
);
chrome.tabs.update(tabid, {
url: url,
});
var today = new Date();
filename = 'WeakestLinkDump-' + today.toISOString().replace(/:/g, '-') + '.csv';
var worker = new Worker('eventWorker.js');
worker.addEventListener(
'message',
function (e) {
e = e.data;
if (e.type == 'persondata') {
for (i = 0; i < e.users.length; i++) {
addPerson(e.users[i]);
}
finished = 'Completed';
completed(userdata.concat(shortnames), finished, count, filename, tabid);
} else if (e.type == 'status'){
message =
'<html><body><style>.body{background-color:#f7f7f7}.flex-container{height:100%;padding:0;margin:0;display:-webkit-box;display:-moz-box;display:-ms-flexbox;display:-webkit-flex;display:flex;align-items:center;justify-content:center;flex-direction:column;margin-top:50px}.row{width:auto;border:1px;border-radius:5px;box-shadow:0 4px 8px 0 rgba(0,0,0,.2),0 6px 20px 0 rgba(0,0,0,.19);text-align:center}.inner{padding:10px}table{border-collapse:collapse;width:100%}td,th{padding:15px}table,td,th{border:1px solid #ddd;text-align:left}</style><div class=flex-container> <img src=https://github.com/shellfarmer/WeakestLink/blob/master/images/logo128.png?raw=true /> <h2> WeakestLink Dump Running </h2><div class=row><div class=inner><table> <td>Retrieved $$PAGE$$ of $$COUNT$$ page results</td></table><p>Close this tab to stop dumping</p></div></div></div></body></html>';
message = message.replace('$$PAGE$$', e.page);
message = message.replace('$$COUNT$$', e.totalResultCount);
code = 'document.body.innerHTML = "' + message + '";';
chrome.tabs.executeScript(e.tabid, {
code: code,
});
}
else {
finished = "Data Collection Error: " + e.message;
completed(userdata.concat(shortnames), finished, count, filename, tabid);
}
},
false
);
// Listener that recieves messages from injected content.js
chrome.runtime.onMessage.addListener(function (message) {
try {
if (run) return;
var cookie = '';
// No more results return data to popup
if (message.body.includes('Your search returned no results. Try removing filters or rephrasing your search') && finished === '') {
finished = 'Completed';
completed(userdata.concat(shortnames), finished, count, filename, tabid);
return;
}
// Out of search credits
if (
(message.body.includes('upgrade to Premium to continue searching') ||
message.body.includes('Search limit reached') ||
message.body.includes('You’ve reached the monthly limit for profile searches')) &&
finished === ''
) {
finished = 'search limit hit';
completed(userdata.concat(shortnames), finished, count, filename, tabid);
return;
}
chrome.cookies.get({ url: 'https://www.linkedin.com', name: 'JSESSIONID' }, function (cookie) {
worker.postMessage({
csrftoken: cookie.value.replace(/['"]+/g, ''),
url: message.url,
});
});
run = true;
} catch (err) {
console.log(err.message);
finished = 'Error - ' + err.message;
completed(userdata.concat(shortnames), finished, count, filename, tabid);
}
});
}