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 { withBannerArray } = require('./lib/with-banner.js');
  5. const { compareAndWriteFile } = require('./lib/string-array-compare');
  6. const { processLine } = require('./lib/process-line.js');
  7. const domainSorter = require('./lib/stable-sort-domain');
  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. (async () => {
  62. const domainSet = Array.from(
  63. (
  64. await processFilterRules('https://curbengh.github.io/phishing-filter/phishing-filter-agh.txt')
  65. ).black
  66. );
  67. const domainCountMap = {};
  68. for (let i = 0, len = domainSet.length; i < len; i++) {
  69. const line = processLine(domainSet[i]);
  70. if (!line) continue;
  71. const domain = line.charCodeAt(0) === 46 ? line.slice(1) : line;
  72. const parsed = parse(domain, { allowPrivateDomains: true });
  73. const apexDomain = parsed.domain;
  74. if (apexDomain) {
  75. if (WHITELIST_DOMAIN.has(apexDomain)) {
  76. continue;
  77. }
  78. domainCountMap[apexDomain] ||= 0;
  79. let isPhishingDomainMockingAmazon = false;
  80. if (domain.startsWith('amaz')) {
  81. domainCountMap[apexDomain] += 0.5;
  82. isPhishingDomainMockingAmazon = true;
  83. if (domain.startsWith('amazon-')) {
  84. domainCountMap[apexDomain] += 4.5;
  85. }
  86. } else if (domain.startsWith('customer')) {
  87. domainCountMap[apexDomain] += 0.25;
  88. }
  89. if (domain.includes('-co-jp')) {
  90. domainCountMap[apexDomain] += (isPhishingDomainMockingAmazon ? 4.5 : 0.5);
  91. }
  92. const tld = parsed.publicSuffix;
  93. if (!tld || !BLACK_TLD.has(tld)) continue;
  94. domainCountMap[apexDomain] += 1;
  95. if (domain.length > 19) {
  96. // Add more weight if the domain is long enough
  97. if (domain.length > 44) {
  98. domainCountMap[apexDomain] += 3.5;
  99. } else if (domain.length > 34) {
  100. domainCountMap[apexDomain] += 2.5;
  101. } else if (domain.length > 29) {
  102. domainCountMap[apexDomain] += 1.5;
  103. } else if (domain.length > 24) {
  104. domainCountMap[apexDomain] += 0.75;
  105. } else if (domain.length > 19) {
  106. domainCountMap[apexDomain] += 0.25;
  107. }
  108. if (domainCountMap[apexDomain] < 5) {
  109. const subdomain = parsed.subdomain;
  110. if (subdomain && subdomain.includes('.')) {
  111. domainCountMap[apexDomain] += 1.5;
  112. }
  113. }
  114. }
  115. }
  116. }
  117. const results = [];
  118. Object.entries(domainCountMap).forEach(([domain, count]) => {
  119. if (count >= 5) {
  120. results.push(`.${domain}`);
  121. }
  122. });
  123. results.sort(domainSorter);
  124. await compareAndWriteFile(
  125. withBannerArray(
  126. 'Sukka\'s Surge Rules - Reject Phishing',
  127. [
  128. 'License: AGPL 3.0',
  129. 'Homepage: https://ruleset.skk.moe',
  130. 'GitHub: https://github.com/SukkaW/Surge',
  131. '',
  132. 'The domainset supports enhanced phishing protection',
  133. 'Build from:',
  134. ' - https://gitlab.com/malware-filter/phishing-filter'
  135. ],
  136. new Date(),
  137. results
  138. ),
  139. path.resolve(__dirname, '../List/domainset/reject_phishing.conf')
  140. );
  141. })();