build-phishing-domainset.js 2.3 KB

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