build-phishing-domainset.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 = [
  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. ];
  22. (async () => {
  23. const domainSet = Array.from(
  24. (
  25. await processFilterRules('https://curbengh.github.io/phishing-filter/phishing-filter-agh.txt')
  26. ).black
  27. );
  28. const domainCountMap = {};
  29. for (let i = 0, len = domainSet.length; i < len; i++) {
  30. const line = domainSet[i];
  31. // starts with #
  32. if (line.charCodeAt(0) === 35) {
  33. continue;
  34. }
  35. if (line.trim().length === 0) {
  36. continue;
  37. }
  38. const domain = line.charCodeAt(0) === 46 ? line.slice(1) : line;
  39. if (line.length > 25) {
  40. const parsed = psl.parse(domain);
  41. if (parsed.input === parsed.tld) {
  42. continue;
  43. }
  44. const apexDomain = parsed.domain
  45. if (WHITELIST_DOMAIN.has(apexDomain)) {
  46. continue;
  47. }
  48. domainCountMap[apexDomain] ||= 0;
  49. domainCountMap[apexDomain] += 1;
  50. }
  51. }
  52. const results = [];
  53. Object.entries(domainCountMap).forEach(([domain, count]) => {
  54. if (
  55. count >= 8
  56. && BLACK_TLD.some(tld => domain.endsWith(tld))
  57. ) {
  58. results.push('.' + domain);
  59. }
  60. });
  61. const filePath = path.resolve(__dirname, '../List/domainset/reject_phishing.conf');
  62. await fs.promises.writeFile(filePath, results.join('\n'), 'utf-8');
  63. })();