build-phishing-domainset.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. 'tk',
  40. 'cf',
  41. 'gq',
  42. 'ga',
  43. 'ml'
  44. ]));
  45. (async () => {
  46. const domainSet = Array.from(
  47. (
  48. await processFilterRules('https://curbengh.github.io/phishing-filter/phishing-filter-agh.txt')
  49. ).black
  50. );
  51. const domainCountMap = {};
  52. for (let i = 0, len = domainSet.length; i < len; i++) {
  53. const line = domainSet[i];
  54. // starts with #
  55. if (line.charCodeAt(0) === 35) {
  56. continue;
  57. }
  58. if (line.trim().length === 0) {
  59. continue;
  60. }
  61. const domain = line.charCodeAt(0) === 46 ? line.slice(1) : line;
  62. if (domain.length > 19) {
  63. const apexDomain = tldts.getDomain(domain, { allowPrivateDomains: true });
  64. if (apexDomain) {
  65. if (WHITELIST_DOMAIN.has(apexDomain)) {
  66. continue;
  67. }
  68. const tld = tldts.getPublicSuffix(domain, { allowPrivateDomains: true });
  69. if (!tld || !BLACK_TLD.includes(tld)) continue;
  70. domainCountMap[apexDomain] ||= 0;
  71. domainCountMap[apexDomain] += 1;
  72. // Add more weight if the domain is long enough
  73. if (domain.length > 44) {
  74. domainCountMap[apexDomain] += 3.5;
  75. } else if (domain.length > 34) {
  76. domainCountMap[apexDomain] += 2.5;
  77. } else if (domain.length > 29) {
  78. domainCountMap[apexDomain] += 1.5;
  79. } else if (domain.length > 24) {
  80. domainCountMap[apexDomain] += 0.75;
  81. } else if (domain.length > 19) {
  82. domainCountMap[apexDomain] += 0.25;
  83. }
  84. if (domainCountMap[apexDomain] < 5) {
  85. const subdomain = tldts.getSubdomain(domain, { allowPrivateDomains: true });
  86. if (subdomain && subdomain.includes('.')) {
  87. domainCountMap[apexDomain] += 1.5;
  88. }
  89. }
  90. }
  91. }
  92. }
  93. const results = [];
  94. Object.entries(domainCountMap).forEach(([domain, count]) => {
  95. if (
  96. count >= 5
  97. ) {
  98. results.push('.' + domain);
  99. }
  100. });
  101. results.sort();
  102. await compareAndWriteFile(
  103. withBannerArray(
  104. 'Sukka\'s Surge Rules - Reject Phishing',
  105. [
  106. 'License: AGPL 3.0',
  107. 'Homepage: https://ruleset.skk.moe',
  108. 'GitHub: https://github.com/SukkaW/Surge',
  109. '',
  110. 'The domainset supports enhanced phishing protection',
  111. 'Build from:',
  112. ' - https://gitlab.com/malware-filter/phishing-filter'
  113. ],
  114. new Date(),
  115. results
  116. ),
  117. path.resolve(__dirname, '../List/domainset/reject_phishing.conf')
  118. )
  119. })();