build-phishing-domainset.js 1.8 KB

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