build-phishing-domainset.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 WHITELIST_DOMAIN = new Set([
  6. 'w3s.link',
  7. 'dweb.link'
  8. ]);
  9. const BLACK_TLD = Array.from(new Set([
  10. '.xyz',
  11. '.top',
  12. '.win',
  13. '.vip',
  14. '.site',
  15. '.space',
  16. '.online',
  17. '.icu',
  18. '.fun',
  19. '.shop',
  20. '.cool',
  21. '.cyou',
  22. '.id',
  23. '.pro',
  24. '.za.com',
  25. '.sa.com',
  26. '.ltd',
  27. '.group',
  28. '.rest',
  29. '.tech',
  30. '.link',
  31. '.ink',
  32. '.bar',
  33. '.tokyo'
  34. ]));
  35. (async () => {
  36. const domainSet = Array.from(
  37. (
  38. await processFilterRules('https://curbengh.github.io/phishing-filter/phishing-filter-agh.txt')
  39. ).black
  40. );
  41. const domainCountMap = {};
  42. for (let i = 0, len = domainSet.length; i < len; i++) {
  43. const line = domainSet[i];
  44. // starts with #
  45. if (line.charCodeAt(0) === 35) {
  46. continue;
  47. }
  48. if (line.trim().length === 0) {
  49. continue;
  50. }
  51. const domain = line.charCodeAt(0) === 46 ? line.slice(1) : line;
  52. if (domain.length > 25) {
  53. const apexDomain = tldts.getDomain(domain, { allowPrivateDomains: true });
  54. if (apexDomain) {
  55. if (WHITELIST_DOMAIN.has(apexDomain)) {
  56. continue;
  57. }
  58. domainCountMap[apexDomain] ||= 0;
  59. domainCountMap[apexDomain] += 1;
  60. }
  61. }
  62. }
  63. const results = [];
  64. Object.entries(domainCountMap).forEach(([domain, count]) => {
  65. if (
  66. count >= 5
  67. && BLACK_TLD.some(tld => domain.endsWith(tld))
  68. ) {
  69. results.push('.' + domain);
  70. }
  71. });
  72. const filePath = path.resolve(__dirname, '../List/domainset/reject_phishing.conf');
  73. await fs.promises.writeFile(filePath, results.join('\n') + '\n', 'utf-8');
  74. })();