build-phishing-domainset.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. '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 (line.length > 25) {
  53. const parsed = psl.parse(domain);
  54. if (parsed.input === parsed.tld) {
  55. continue;
  56. }
  57. const apexDomain = parsed.domain
  58. if (WHITELIST_DOMAIN.has(apexDomain)) {
  59. continue;
  60. }
  61. domainCountMap[apexDomain] ||= 0;
  62. domainCountMap[apexDomain] += 1;
  63. }
  64. }
  65. const results = [];
  66. Object.entries(domainCountMap).forEach(([domain, count]) => {
  67. if (
  68. count >= 8
  69. && BLACK_TLD.some(tld => domain.endsWith(tld))
  70. ) {
  71. results.push('.' + domain);
  72. }
  73. });
  74. const filePath = path.resolve(__dirname, '../List/domainset/reject_phishing.conf');
  75. await fs.promises.writeFile(filePath, results.join('\n'), 'utf-8');
  76. })();