-
Notifications
You must be signed in to change notification settings - Fork 1
/
categorize.js
110 lines (100 loc) · 4.8 KB
/
categorize.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
const json = require('json');
const idnanormalizer = require('idna-normalize')
const punycode = require('punycode')
const falsepositivetest = require('./tests/falsepositivetest.js')
const levenshteintest = require('./tests/levenshteintest.js')
const stringtokentest = require('./tests/stringtokentest.js')
const containsstringtest = require('./tests/containsstringtest.js')
const config = require('./config.js')
class categorize {
test (inputdata) {
return new Promise(async (resolve, reject) => {
var inputdomain = inputdata.domain
var returnjson = {}
if (inputdata.description) {
returnjson.description = inputdata.description
}
if (inputdata.addresses) {
returnjson.addresses = inputdata.addresses
}
returnjson.input = inputdomain
returnjson.categorized = false
/* remove unneeded shit */
var editeddomain = inputdomain.replace('http://','').replace('https://','').replace('[.]','.').replace('www.','').toLowerCase();
var editeddowndomain = editeddomain.split(/[/?#]/)[0]
var processdomain = punycode.toUnicode(editeddomain);
/* normalize process */
var domainnormalize = new idnanormalizer()
var normalizedinput = domainnormalize.normalize(processdomain)
returnjson.name = editeddowndomain
/* detect if idn homograph attack */
if (processdomain != editeddomain) {
returnjson.idnhomograph = true
returnjson.unicodeinput = processdomain
returnjson.normalizedinput = normalizedinput
}
else {
returnjson.idnhomograph = false
}
returnjson.detectedbytest = []
if (!config.runfalsepositivetest && !config.runlevenshteintest && !config.runstringtokentest && !config.runcontainsstringtest) {
console.log("Didnt select any tests to run. Edit the config.js file to do so.")
}
// checks to see if false-positive
if (config.runfalsepositivetest) {
var falsepositivetestresults = await falsepositivetest(editeddomain)
if (falsepositivetestresults.result) {
if (returnjson.categorized === false ) {
returnjson.categorized = true
}
returnjson.category = falsepositivetestresults.category
returnjson.subcategory = falsepositivetestresults.subcategory
returnjson.detectedbytest.push('falsepositivetest')
resolve(returnjson)
}
}
// starts testing
if (config.runlevenshteintest) {
var levenshteintestresults = await levenshteintest(normalizedinput)
if (levenshteintestresults.result) {
if (returnjson.categorized === false) {
returnjson.categorized = true
}
returnjson.category = levenshteintestresults.category
returnjson.subcategory = levenshteintestresults.subcategory
returnjson.detectedbytest.push('levenshteintest')
}
}
if (config.runstringtokentest) {
var stringtokentestresults = await stringtokentest(normalizedinput)
if (stringtokentestresults.result) {
if (returnjson.categorized === false) {
returnjson.categorized = true
}
returnjson.category = stringtokentestresults.category
returnjson.subcategory = stringtokentestresults.subcategory
returnjson.detectedbytest.push('stringtokentest')
}
}
if (config.runcontainsstringtest) {
var containsstringtestresults = await containsstringtest(editeddomain)
if (containsstringtestresults.result) {
if (returnjson.categorized === false) {
returnjson.categorized = true
}
returnjson.status = containsstringtestresults.status
returnjson.category = containsstringtestresults.category
returnjson.subcategory = containsstringtestresults.subcategory
returnjson.detectedbytest.push('containsstringtest')
}
if (!containsstringtestresults.result) {
if (containsstringtestresults.status) {
returnjson.status = containsstringtestresults.status
}
}
}
resolve(returnjson)
})
}
}
module.exports = categorize