build-phishing-domainset.js 3.6 KB

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