build-phishing-domainset.js 1.7 KB

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