build-phishing-domainset.js 1.7 KB

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