build-phishing-domainset.js 3.7 KB

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