2017-07-27 01:46:59 +02:00
|
|
|
const levenshtein = require('fast-levenshtein')
|
|
|
|
const LEVENSHTEIN_TOLERANCE = 4
|
|
|
|
|
|
|
|
// credit to @sogoiii and @409H for their help!
|
|
|
|
// Return a boolean on whether or not a phish is detected.
|
2017-08-03 00:54:59 +02:00
|
|
|
function isPhish({ hostname, blacklist, whitelist, fuzzylist }) {
|
2017-07-27 01:46:59 +02:00
|
|
|
|
|
|
|
// check if the domain is part of the whitelist.
|
2017-08-03 00:54:59 +02:00
|
|
|
if (whitelist && whitelist.includes(hostname)) return false
|
2017-07-27 01:46:59 +02:00
|
|
|
|
|
|
|
// check if the domain is part of the blacklist.
|
2017-08-03 00:54:59 +02:00
|
|
|
if (blacklist && blacklist.includes(hostname)) return true
|
2017-07-27 01:46:59 +02:00
|
|
|
|
|
|
|
// check for similar values.
|
2017-08-03 00:54:59 +02:00
|
|
|
const levenshteinForm = hostname.replace(/\./g, '')
|
|
|
|
const levenshteinMatched = fuzzylist.some((element) => {
|
|
|
|
return levenshtein.get(element, levenshteinForm) <= LEVENSHTEIN_TOLERANCE
|
2017-07-27 01:46:59 +02:00
|
|
|
})
|
|
|
|
|
2017-08-03 00:54:59 +02:00
|
|
|
return levenshteinMatched
|
2017-07-27 01:46:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = isPhish
|