build-phishing-domainset.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. 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] += 4;
  69. } else if (domain.length > 35) {
  70. domainCountMap[apexDomain] += 3;
  71. } else if (domain.length > 30) {
  72. domainCountMap[apexDomain] += 2;
  73. } else if (domain.length > 25) {
  74. domainCountMap[apexDomain] += 1;
  75. }
  76. const subdomain = tldts.getSubdomain(domain, { allowPrivateDomains: true });
  77. if (subdomain && subdomain.includes('.')) {
  78. domainCountMap[apexDomain] += 0.5;
  79. }
  80. }
  81. }
  82. }
  83. console.log(domainCountMap);
  84. const results = [];
  85. Object.entries(domainCountMap).forEach(([domain, count]) => {
  86. if (
  87. count >= 5
  88. ) {
  89. results.push('.' + domain);
  90. }
  91. });
  92. results.sort();
  93. await compareAndWriteFile(
  94. withBannerArray(
  95. 'Sukka\'s Surge Rules - Reject Phishing',
  96. [
  97. 'License: AGPL 3.0',
  98. 'Homepage: https://ruleset.skk.moe',
  99. 'GitHub: https://github.com/SukkaW/Surge',
  100. '',
  101. 'The domainset supports enhanced phishing protection',
  102. 'Build from:',
  103. ' - https://gitlab.com/malware-filter/phishing-filter'
  104. ],
  105. new Date(),
  106. results
  107. ),
  108. path.resolve(__dirname, '../List/domainset/reject_phishing.conf')
  109. )
  110. })();