build-phishing-domainset.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 WHITELIST_DOMAIN = new Set([
  7. 'w3s.link',
  8. 'dweb.link',
  9. 'nftstorage.link',
  10. 'square.site',
  11. 'business.site'
  12. ]);
  13. const BLACK_TLD = Array.from(new Set([
  14. 'xyz',
  15. 'top',
  16. 'win',
  17. 'vip',
  18. 'site',
  19. 'space',
  20. 'online',
  21. 'icu',
  22. 'fun',
  23. 'shop',
  24. 'cool',
  25. 'cyou',
  26. 'id',
  27. 'pro',
  28. 'za.com',
  29. 'sa.com',
  30. 'ltd',
  31. 'group',
  32. 'rest',
  33. 'tech',
  34. 'link',
  35. 'ink',
  36. 'bar',
  37. 'tokyo'
  38. ]));
  39. (async () => {
  40. const domainSet = Array.from(
  41. (
  42. await processFilterRules('https://curbengh.github.io/phishing-filter/phishing-filter-agh.txt')
  43. ).black
  44. );
  45. const domainCountMap = {};
  46. for (let i = 0, len = domainSet.length; i < len; i++) {
  47. const line = domainSet[i];
  48. // starts with #
  49. if (line.charCodeAt(0) === 35) {
  50. continue;
  51. }
  52. if (line.trim().length === 0) {
  53. continue;
  54. }
  55. const domain = line.charCodeAt(0) === 46 ? line.slice(1) : line;
  56. if (domain.length > 19) {
  57. const apexDomain = tldts.getDomain(domain, { allowPrivateDomains: true });
  58. if (apexDomain) {
  59. if (WHITELIST_DOMAIN.has(apexDomain)) {
  60. continue;
  61. }
  62. const tld = tldts.getPublicSuffix(domain, { allowPrivateDomains: true });
  63. if (!tld || !BLACK_TLD.includes(tld)) continue;
  64. domainCountMap[apexDomain] ||= 0;
  65. domainCountMap[apexDomain] += 1;
  66. // Add more weight if the domain is long enough
  67. if (domain.length > 45) {
  68. domainCountMap[apexDomain] += 3.5;
  69. } else if (domain.length > 35) {
  70. domainCountMap[apexDomain] += 2.5;
  71. } else if (domain.length > 30) {
  72. domainCountMap[apexDomain] += 1.5;
  73. } else if (domain.length > 25) {
  74. domainCountMap[apexDomain] += 0.75;
  75. } else if (domain.length > 21) {
  76. domainCountMap[apexDomain] += 0.25;
  77. }
  78. if (domainCountMap[apexDomain] < 5) {
  79. const subdomain = tldts.getSubdomain(domain, { allowPrivateDomains: true });
  80. if (subdomain && subdomain.includes('.')) {
  81. domainCountMap[apexDomain] += 1.5;
  82. }
  83. }
  84. }
  85. }
  86. }
  87. const results = [];
  88. Object.entries(domainCountMap).forEach(([domain, count]) => {
  89. if (
  90. count >= 5
  91. ) {
  92. results.push('.' + domain);
  93. }
  94. });
  95. results.sort();
  96. await compareAndWriteFile(
  97. withBannerArray(
  98. 'Sukka\'s Surge Rules - Reject Phishing',
  99. [
  100. 'License: AGPL 3.0',
  101. 'Homepage: https://ruleset.skk.moe',
  102. 'GitHub: https://github.com/SukkaW/Surge',
  103. '',
  104. 'The domainset supports enhanced phishing protection',
  105. 'Build from:',
  106. ' - https://gitlab.com/malware-filter/phishing-filter'
  107. ],
  108. new Date(),
  109. results
  110. ),
  111. path.resolve(__dirname, '../List/domainset/reject_phishing.conf')
  112. )
  113. })();