build-phishing-domainset.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 { withBanner } = require('./lib/with-banner.js');
  6. const WHITELIST_DOMAIN = new Set([
  7. 'w3s.link',
  8. 'dweb.link',
  9. 'nftstorage.link',
  10. 'square.site'
  11. ]);
  12. const BLACK_TLD = Array.from(new Set([
  13. '.xyz',
  14. '.top',
  15. '.win',
  16. '.vip',
  17. '.site',
  18. '.space',
  19. '.online',
  20. '.icu',
  21. '.fun',
  22. '.shop',
  23. '.cool',
  24. '.cyou',
  25. '.id',
  26. '.pro',
  27. '.za.com',
  28. '.sa.com',
  29. '.ltd',
  30. '.group',
  31. '.rest',
  32. '.tech',
  33. '.link',
  34. '.ink',
  35. '.bar',
  36. '.tokyo'
  37. ]));
  38. (async () => {
  39. const domainSet = Array.from(
  40. (
  41. await processFilterRules('https://curbengh.github.io/phishing-filter/phishing-filter-agh.txt')
  42. ).black
  43. );
  44. const domainCountMap = {};
  45. for (let i = 0, len = domainSet.length; i < len; i++) {
  46. const line = domainSet[i];
  47. // starts with #
  48. if (line.charCodeAt(0) === 35) {
  49. continue;
  50. }
  51. if (line.trim().length === 0) {
  52. continue;
  53. }
  54. const domain = line.charCodeAt(0) === 46 ? line.slice(1) : line;
  55. if (domain.length > 19) {
  56. const apexDomain = tldts.getDomain(domain, { allowPrivateDomains: true });
  57. if (apexDomain) {
  58. if (WHITELIST_DOMAIN.has(apexDomain)) {
  59. continue;
  60. }
  61. domainCountMap[apexDomain] ||= 0;
  62. domainCountMap[apexDomain] += 1;
  63. // Add more weight if the domain is long enough
  64. if (domain.length > 45) {
  65. domainCountMap[apexDomain] += 1.5;
  66. } else if (domain.length > 35) {
  67. domainCountMap[apexDomain] += 1;
  68. } else if (domain.length > 30) {
  69. domainCountMap[apexDomain] += 0.5;
  70. } else if (domain.length > 25) {
  71. domainCountMap[apexDomain] += 0.25;
  72. }
  73. const subdomain = tldts.getSubdomain(domain, { allowPrivateDomains: true });
  74. if (subdomain && subdomain.includes('.')) {
  75. domainCountMap[apexDomain] += 0.5;
  76. }
  77. }
  78. }
  79. }
  80. const results = [];
  81. Object.entries(domainCountMap).forEach(([domain, count]) => {
  82. if (
  83. count >= 5
  84. && BLACK_TLD.some(tld => domain.endsWith(tld))
  85. ) {
  86. results.push('.' + domain);
  87. }
  88. });
  89. const filePath = path.resolve(__dirname, '../List/domainset/reject_phishing.conf');
  90. await fs.promises.writeFile(
  91. filePath,
  92. withBanner(
  93. 'Reject Domain Set for Surge',
  94. [
  95. '(Enhanced Phishing Protection)',
  96. 'Build from:',
  97. '- https://gitlab.com/malware-filter/phishing-filter'
  98. ],
  99. new Date(),
  100. results
  101. ),
  102. 'utf-8'
  103. );
  104. })();