build-phishing-domainset.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. const tldts = require('tldts');
  2. const { processFilterRules } = require('./lib/parse-filter.js');
  3. const fs = require('fs');
  4. const path = require('path');
  5. const WHITELIST_DOMAIN = new Set([
  6. 'w3s.link',
  7. 'dweb.link',
  8. 'nftstorage.link'
  9. ]);
  10. const BLACK_TLD = Array.from(new Set([
  11. '.xyz',
  12. '.top',
  13. '.win',
  14. '.vip',
  15. '.site',
  16. '.space',
  17. '.online',
  18. '.icu',
  19. '.fun',
  20. '.shop',
  21. '.cool',
  22. '.cyou',
  23. '.id',
  24. '.pro',
  25. '.za.com',
  26. '.sa.com',
  27. '.ltd',
  28. '.group',
  29. '.rest',
  30. '.tech',
  31. '.link',
  32. '.ink',
  33. '.bar',
  34. '.tokyo'
  35. ]));
  36. (async () => {
  37. const domainSet = Array.from(
  38. (
  39. await processFilterRules('https://curbengh.github.io/phishing-filter/phishing-filter-agh.txt')
  40. ).black
  41. );
  42. const domainCountMap = {};
  43. for (let i = 0, len = domainSet.length; i < len; i++) {
  44. const line = domainSet[i];
  45. // starts with #
  46. if (line.charCodeAt(0) === 35) {
  47. continue;
  48. }
  49. if (line.trim().length === 0) {
  50. continue;
  51. }
  52. const domain = line.charCodeAt(0) === 46 ? line.slice(1) : line;
  53. if (domain.length > 19) {
  54. const apexDomain = tldts.getDomain(domain, { allowPrivateDomains: true });
  55. if (apexDomain) {
  56. if (WHITELIST_DOMAIN.has(apexDomain)) {
  57. continue;
  58. }
  59. domainCountMap[apexDomain] ||= 0;
  60. domainCountMap[apexDomain] += 1;
  61. if (domain.length > 45) {
  62. // Add more weight if the domain is long enough
  63. domainCountMap[apexDomain] += 1;
  64. }
  65. }
  66. }
  67. }
  68. const results = [];
  69. Object.entries(domainCountMap).forEach(([domain, count]) => {
  70. if (
  71. count >= 5
  72. && BLACK_TLD.some(tld => domain.endsWith(tld))
  73. ) {
  74. results.push('.' + domain);
  75. }
  76. });
  77. const filePath = path.resolve(__dirname, '../List/domainset/reject_phishing.conf');
  78. await fs.promises.writeFile(filePath, results.join('\n') + '\n', 'utf-8');
  79. })();