build-phishing-domainset.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. const tldts = require('tldts');
  2. const { processFilterRules } = require('./lib/parse-filter.js');
  3. const path = require('path');
  4. const { withBannerArray } = require('./lib/with-banner.js');
  5. const { compareAndWriteFile } = require('./lib/string-array-compare');
  6. const WHITELIST_DOMAIN = new Set([
  7. 'w3s.link',
  8. 'dweb.link',
  9. 'nftstorage.link',
  10. 'square.site',
  11. 'business.site',
  12. 'page.link' // Firebase URL Shortener
  13. ]);
  14. const BLACK_TLD = Array.from(new Set([
  15. 'xyz',
  16. 'top',
  17. 'win',
  18. 'vip',
  19. 'site',
  20. 'space',
  21. 'online',
  22. 'icu',
  23. 'fun',
  24. 'shop',
  25. 'cool',
  26. 'cyou',
  27. 'id',
  28. 'pro',
  29. 'za.com',
  30. 'sa.com',
  31. 'ltd',
  32. 'group',
  33. 'rest',
  34. 'tech',
  35. 'link',
  36. 'ink',
  37. 'bar',
  38. 'tokyo'
  39. ]));
  40. (async () => {
  41. const domainSet = Array.from(
  42. (
  43. await processFilterRules('https://curbengh.github.io/phishing-filter/phishing-filter-agh.txt')
  44. ).black
  45. );
  46. const domainCountMap = {};
  47. for (let i = 0, len = domainSet.length; i < len; i++) {
  48. const line = domainSet[i];
  49. // starts with #
  50. if (line.charCodeAt(0) === 35) {
  51. continue;
  52. }
  53. if (line.trim().length === 0) {
  54. continue;
  55. }
  56. const domain = line.charCodeAt(0) === 46 ? line.slice(1) : line;
  57. if (domain.length > 19) {
  58. const apexDomain = tldts.getDomain(domain, { allowPrivateDomains: true });
  59. if (apexDomain) {
  60. if (WHITELIST_DOMAIN.has(apexDomain)) {
  61. continue;
  62. }
  63. const tld = tldts.getPublicSuffix(domain, { allowPrivateDomains: true });
  64. if (!tld || !BLACK_TLD.includes(tld)) continue;
  65. domainCountMap[apexDomain] ||= 0;
  66. domainCountMap[apexDomain] += 1;
  67. // Add more weight if the domain is long enough
  68. if (domain.length > 44) {
  69. domainCountMap[apexDomain] += 3.5;
  70. } else if (domain.length > 34) {
  71. domainCountMap[apexDomain] += 2.5;
  72. } else if (domain.length > 29) {
  73. domainCountMap[apexDomain] += 1.5;
  74. } else if (domain.length > 24) {
  75. domainCountMap[apexDomain] += 0.75;
  76. } else if (domain.length > 19) {
  77. domainCountMap[apexDomain] += 0.25;
  78. }
  79. if (domainCountMap[apexDomain] < 5) {
  80. const subdomain = tldts.getSubdomain(domain, { allowPrivateDomains: true });
  81. if (subdomain && subdomain.includes('.')) {
  82. domainCountMap[apexDomain] += 1.5;
  83. }
  84. }
  85. }
  86. }
  87. }
  88. const results = [];
  89. Object.entries(domainCountMap).forEach(([domain, count]) => {
  90. if (
  91. count >= 5
  92. ) {
  93. results.push('.' + domain);
  94. }
  95. });
  96. results.sort();
  97. await compareAndWriteFile(
  98. withBannerArray(
  99. 'Sukka\'s Surge Rules - Reject Phishing',
  100. [
  101. 'License: AGPL 3.0',
  102. 'Homepage: https://ruleset.skk.moe',
  103. 'GitHub: https://github.com/SukkaW/Surge',
  104. '',
  105. 'The domainset supports enhanced phishing protection',
  106. 'Build from:',
  107. ' - https://gitlab.com/malware-filter/phishing-filter'
  108. ],
  109. new Date(),
  110. results
  111. ),
  112. path.resolve(__dirname, '../List/domainset/reject_phishing.conf')
  113. )
  114. })();