-
Notifications
You must be signed in to change notification settings - Fork 19
/
index.js
231 lines (172 loc) · 6.88 KB
/
index.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
/**
* Github
* https://github.com/6IX7ine/certstreamcatcher
*
* Copyright (c) 2017 Fábio Castro
* Licensed under the MIT license.
*/
'use strict'
const tld = require('tldjs');
const lodash = require('lodash');
const color = require('cli-color');
const status = require('node-status');
const punycode = require('punycode');
const yellow = color.yellow.underline;
const danger = color.redBright.underline;
const white = color.white.underline;
const certificates = status.addItem('certificates');
const mapping = {
"a": ["à", "á", "â", "ã", "ä", "å", "ā", "ă", "ą", "ǎ", "ȁ", "ȃ", "ȧ", "ḁ", "ẚ", "ạ"],
"b": ["ḃ", "ḅ", "ḇ", "ƀ"],
"c": ["ç", "ć", "ĉ", "ċ", "č"],
"d": ["ḋ", "ḍ", "ḏ", "ḑ", "ḓ", "đ"],
"e": ["è", "é", "ê", "ë", "ĕ", "ė", "ę", "ě", "ȅ", "ȇ", "ȩ", "ḙ", "ḛ", "ẹ", "ẽ"],
"f": ["ḟ"],
"g": ["ĝ", "ğ", "ġ", "ģ", "ǧ", "ǵ", "ḡ"],
"h": ["ĥ", "ȟ", "ḣ", "ḥ", "ḧ", "ḩ", "ḫ", "ẖ"],
"i": ["ì", "í", "î", "ï", "ĩ", "ī", "ĭ", "į", "ǐ", "ȉ", "ȋ", "ḭ", "ị"],
"j": ["ĵ", "ǰ"],
"k": ["ķ", "ǩ", "ḱ", "ḳ", "ḵ"],
"l": ["ĺ", "ļ", "ľ", "ŀ", "ḷ", "ḻ", "ḽ", "ι", "ł"],
"m": ["ḿ", "ṁ", "ṃ", "ϻ"],
"n": ["ñ", "ń", "ņ", "ň", "ʼn", "ǹ", "ṅ", "ṇ", "ṉ", "ṋ"],
"o": ["ò", "ó", "ô", "õ", "ö", "ō", "ŏ", "ő", "ơ", "ǒ", "ǫ", "ố", "ȍ", "ȏ", "ȯ", "ọ", "ø", "ộ"],
"p": ["ṕ", "ṗ", "ϸ"],
"r": ["ŕ", "ŗ", "ř", "ȑ", "ȓ", "ṙ", "ṛ", "ṟ", "ґ"],
"s": ["ŝ", "ş", "š", "ș", "ṡ", "ṣ"],
"t": ["ţ", "ť", "ț", "ṫ", "ṭ", "ṯ", "ṱ", "ẗ"],
"u": ["ù", "ú", "û", "ü", "ũ", "ū", "ŭ", "ů", "ű", "ų", "ư", "ǔ", "ȕ", "ȗ", "ṳ", "ṵ", "ṷ", "ụ"],
"v": ["ṽ", "ṿ"],
"w": ["ŵ", "ẁ", "ẃ", "ẅ", "ẇ", "ẉ", "ẘ"],
"x": ["ẋ", "ẍ"],
"y": ["ý", "ÿ", "ŷ", "ȳ", "ẏ", "ẙ", "ỳ", "ỵ", "ỹ"],
"z": ["ź", "ż", "ž", "ẑ", "ẓ", "ẕ"]
}
module.exports = {
certstreamClientPhishing: function (certstream, regex, tlds, options) {
this.certstream = certstream;
this.regex = regex;
this.tlds = tlds;
let settings = { tlds: false };
if (!options) { options = {}; }
for(var option in settings) {
if (typeof options[option] !== 'undefined') {
settings[option] = options[option];
} else {
settings[option] = settings[option];
}
}
// Retorna vazio se não retornar uma messagem de atualização
if (!lodash.includes(certstream, 'certificate_update')) {
return;
}
let domains = certstream.data.leaf_cert.all_domains;
let certs = certstream.data.chain;
lodash.forEach(domains, function(domains) {
if (lodash.startsWith(domains, '*.')) {
domains = lodash.replace(domains, '*.', '', 0);
}
// Expressões regulares criadas com base no comportamento dos sites de phishing
let keywords = (domains.match(regex) || []); // Keywords do dominio inteiro
// Filter o dominio
let domain = tld.parse(domains).domain;
// Filter subdominio
let subdomain = tld.parse(domains).subdomain;
let tlddomain = tld.parse(domains).publicSuffix;
if ((lodash.isNull(subdomain) && lodash.isEmpty(subdomain))) { return; } // Dominios com o subdomain vazio ou null
if ((lodash.isNull(domain) && lodash.isEmpty(domain))) { return; }
subdomain = (subdomain.match(regex) || []); // Subdomain Keywords
domain = (domain.match(regex) || []); // Domain Keywords
const dashed = (domains.match(/\-/g) || []).length;
const points = (domains.match(/(\.)/g) || []).length;
// Certificados gratuitos são mais propensos a serem utilizados para phishing
let suspicious = false;
lodash.forEach(certs, function(cert) {
if (lodash.hasIn(cert,"subject")) {
lodash.forOwn(cert, function(keyword) {
if (lodash.includes(cert.subject.aggregated, "Let's Encrypt") || lodash.includes(cert.subject.aggregated, "CACert free certificate")
|| lodash.includes(cert.subject.aggregated, "StartSSL"
|| lodash.includes(cert.subject.aggregated, "Cloudflare")
|| lodash.includes(cert.subject.aggregated, "Free SSL")))
{
suspicious = true;
}
});
}
});
if (lodash.startsWith(domains, 'xn--', 0)) {
let punyencode = punycode.toUnicode(domains);
let punydecode = punycode.ucs2.decode(punyencode);
lodash.forEach(punydecode, function(punycode) {
if (punycode >= 128) {
for(var keyword in mapping) {
var maps = mapping[keyword];
for(var keywords in maps ) {
punyencode = punyencode.replace(maps[keywords], keyword);
}
}
}
});
var punykeywords = (punyencode.match(regex) || []).length;
if (punykeywords >= 1) {
console.log(`[!] Punycode ${danger(`${domains}`)}`);
}
return;
}
if (settings.tlds) {
// Retorn apenas os tlds passados como parametro
lodash.forEach(tlds, function(tld) {
if (lodash.includes(tld, tlddomain)) {
lodash.forEach(keywords, function(keyword) {
if (suspicious) {
if (lodash.startsWith(subdomain, keyword, 0) && subdomain.length >= 1) {
console.log(`[!] Suspicious ${danger(`${domains}`)}`);
return;
}
if (lodash.startsWith(domain, keyword, 0) && domain.length >= 1) {
console.log(`[!] Suspicious ${danger(`${domains}`)}`);
return;
}
} else {
if (lodash.startsWith(subdomain, keyword, 0) && subdomain.length >= 1) {
console.log(`[!] Likely ${yellow(`${domains}`)}`);
return;
}
if ((subdomain.length >= 1 || domain.length >= 1) || (dashed >= 3 || points >= 2)) {
console.log(`[!] Potential ${white(`${domains}`)}`);
return;
}
}
});
}
});
} else {
lodash.forEach(keywords, function(keyword) {
if (suspicious) {
if (lodash.startsWith(subdomain, keyword, 0) && subdomain.length >= 1) {
console.log(`[!] Suspicious ${danger(`${domains}`)}`);
return;
}
if (lodash.startsWith(domain, keyword, 0) && domain.length >= 1) {
console.log(`[!] Likely ${yellow(`${domains}`)}`);
return;
}
} else {
if (lodash.startsWith(subdomain, keyword, 0) && subdomain.length >= 1) {
console.log(`[!] Likely ${yellow(`${domains}`)}`);
return;
}
if ((subdomain.length >= 1 || domain.length >= 1) || (dashed >= 3 || points >= 2)) {
console.log(`[!] Potential ${white(`${domains}`)}`);
return;
}
}
});
}
});
certificates.inc();
}
}
status.start({
pattern: '{spinner.cyan} {certificates} Certs'
});