build-phishing-domainset.js 3.7 KB

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