build-phishing-domainset.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. const { parse } = require('tldts');
  2. const { processFilterRules } = require('./lib/parse-filter.js');
  3. const path = require('path');
  4. const { createRuleset } = require('./lib/create-file');
  5. const { processLine } = require('./lib/process-line.js');
  6. const domainSorter = require('./lib/stable-sort-domain');
  7. const WHITELIST_DOMAIN = new Set([
  8. 'w3s.link',
  9. 'dweb.link',
  10. 'nftstorage.link',
  11. 'square.site',
  12. 'business.site',
  13. 'page.link', // Firebase URL Shortener
  14. 'fleek.cool',
  15. 'notion.site'
  16. ]);
  17. const BLACK_TLD = new Set([
  18. 'xyz',
  19. 'top',
  20. 'win',
  21. 'vip',
  22. 'site',
  23. 'space',
  24. 'online',
  25. 'icu',
  26. 'fun',
  27. 'shop',
  28. 'cool',
  29. 'cyou',
  30. 'id',
  31. 'pro',
  32. 'za.com',
  33. 'sa.com',
  34. 'ltd',
  35. 'group',
  36. 'rest',
  37. 'tech',
  38. 'link',
  39. 'ink',
  40. 'bar',
  41. 'tokyo',
  42. 'tk',
  43. 'cf',
  44. 'gq',
  45. 'ga',
  46. 'ml',
  47. 'cc',
  48. 'cn',
  49. 'codes',
  50. 'cloud',
  51. 'club',
  52. 'click',
  53. 'cfd',
  54. 'fit',
  55. 'mobi',
  56. 'buzz',
  57. 'one',
  58. 'com.cn'
  59. ]);
  60. (async () => {
  61. const domainSet = Array.from(
  62. (
  63. await processFilterRules('https://curbengh.github.io/phishing-filter/phishing-filter-agh.txt')
  64. ).black
  65. );
  66. const domainCountMap = {};
  67. for (let i = 0, len = domainSet.length; i < len; i++) {
  68. const line = processLine(domainSet[i]);
  69. if (!line) continue;
  70. const domain = line.charCodeAt(0) === 46 ? line.slice(1) : line;
  71. const parsed = parse(domain, { allowPrivateDomains: true });
  72. const apexDomain = parsed.domain;
  73. if (apexDomain) {
  74. if (WHITELIST_DOMAIN.has(apexDomain)) {
  75. continue;
  76. }
  77. domainCountMap[apexDomain] ||= 0;
  78. let isPhishingDomainMockingAmazon = false;
  79. if (domain.startsWith('amaz')) {
  80. domainCountMap[apexDomain] += 0.5;
  81. isPhishingDomainMockingAmazon = true;
  82. if (domain.startsWith('amazon-')) {
  83. domainCountMap[apexDomain] += 4.5;
  84. }
  85. } else if (domain.startsWith('customer')) {
  86. domainCountMap[apexDomain] += 0.25;
  87. }
  88. if (domain.includes('-co-jp')) {
  89. domainCountMap[apexDomain] += (isPhishingDomainMockingAmazon ? 4.5 : 0.5);
  90. }
  91. const tld = parsed.publicSuffix;
  92. if (!tld || !BLACK_TLD.has(tld)) continue;
  93. domainCountMap[apexDomain] += 1;
  94. if (domain.length > 19) {
  95. // Add more weight if the domain is long enough
  96. if (domain.length > 44) {
  97. domainCountMap[apexDomain] += 3.5;
  98. } else if (domain.length > 34) {
  99. domainCountMap[apexDomain] += 2.5;
  100. } else if (domain.length > 29) {
  101. domainCountMap[apexDomain] += 1.5;
  102. } else if (domain.length > 24) {
  103. domainCountMap[apexDomain] += 0.75;
  104. } else if (domain.length > 19) {
  105. domainCountMap[apexDomain] += 0.25;
  106. }
  107. if (domainCountMap[apexDomain] < 5) {
  108. const subdomain = parsed.subdomain;
  109. if (subdomain && subdomain.includes('.')) {
  110. domainCountMap[apexDomain] += 1.5;
  111. }
  112. }
  113. }
  114. }
  115. }
  116. const results = [];
  117. Object.entries(domainCountMap).forEach(([domain, count]) => {
  118. if (count >= 5) {
  119. results.push(`.${domain}`);
  120. }
  121. });
  122. results.sort(domainSorter);
  123. const description = [
  124. 'License: AGPL 3.0',
  125. 'Homepage: https://ruleset.skk.moe',
  126. 'GitHub: https://github.com/SukkaW/Surge',
  127. '',
  128. 'The domainset supports enhanced phishing protection',
  129. 'Build from:',
  130. ' - https://gitlab.com/malware-filter/phishing-filter'
  131. ];
  132. await Promise.all(createRuleset(
  133. 'Sukka\'s Ruleset - Reject Phishing',
  134. description,
  135. new Date(),
  136. results,
  137. 'domainset',
  138. path.resolve(__dirname, '../List/domainset/reject_phishing.conf'),
  139. path.resolve(__dirname, '../Clash/domainset/reject_phishing.txt')
  140. ));
  141. })();