build-phishing-domainset.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. const tldts = require('tldts');
  2. const { processFilterRules } = require('./lib/parse-filter.js');
  3. const fs = require('fs');
  4. const path = require('path');
  5. const { withBannerArray } = require('./lib/with-banner.js');
  6. const { stringArrayCompare, compareAndWriteFile } = require('./lib/string-array-compare');
  7. const WHITELIST_DOMAIN = new Set([
  8. 'w3s.link',
  9. 'dweb.link',
  10. 'nftstorage.link',
  11. 'square.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. domainCountMap[apexDomain] ||= 0;
  63. domainCountMap[apexDomain] += 1;
  64. // Add more weight if the domain is long enough
  65. if (domain.length > 45) {
  66. domainCountMap[apexDomain] += 1.5;
  67. } else if (domain.length > 35) {
  68. domainCountMap[apexDomain] += 1;
  69. } else if (domain.length > 30) {
  70. domainCountMap[apexDomain] += 0.5;
  71. } else if (domain.length > 25) {
  72. domainCountMap[apexDomain] += 0.25;
  73. }
  74. const subdomain = tldts.getSubdomain(domain, { allowPrivateDomains: true });
  75. if (subdomain && subdomain.includes('.')) {
  76. domainCountMap[apexDomain] += 0.5;
  77. }
  78. }
  79. }
  80. }
  81. const results = [];
  82. Object.entries(domainCountMap).forEach(([domain, count]) => {
  83. if (
  84. count >= 5
  85. && BLACK_TLD.some(tld => domain.endsWith(tld))
  86. ) {
  87. results.push('.' + domain);
  88. }
  89. });
  90. results.sort();
  91. await compareAndWriteFile(
  92. withBannerArray(
  93. 'Sukka\'s Surge Rules - Reject Phishing',
  94. [
  95. 'License: AGPL 3.0',
  96. 'Homepage: https://ruleset.skk.moe',
  97. 'GitHub: https://github.com/SukkaW/Surge',
  98. '',
  99. 'The domainset supports enhanced phishing protection',
  100. 'Build from:',
  101. ' - https://gitlab.com/malware-filter/phishing-filter'
  102. ],
  103. new Date(),
  104. results
  105. ),
  106. path.resolve(__dirname, '../List/domainset/reject_phishing.conf')
  107. )
  108. })();