build-phishing-domainset.js 3.1 KB

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