get-phishing-domains.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. import { getGorhillPublicSuffixPromise } from './get-gorhill-publicsuffix';
  2. import { processDomainLists } from './parse-filter';
  3. import { getSubdomain, getPublicSuffix } from 'tldts-experimental';
  4. import type { Span } from '../trace';
  5. import { appendArrayInPlaceCurried } from './append-array-in-place';
  6. import { PHISHING_DOMAIN_LISTS } from './reject-data-source';
  7. import { looseTldtsOpt } from '../constants/loose-tldts-opt';
  8. const BLACK_TLD = new Set([
  9. 'accountant',
  10. 'autos',
  11. 'bar',
  12. 'bid',
  13. 'biz',
  14. 'bond',
  15. 'business',
  16. 'buzz',
  17. 'cc',
  18. 'cf',
  19. 'cfd',
  20. 'click',
  21. 'cloud',
  22. 'club',
  23. 'cn',
  24. 'codes',
  25. 'co.uk',
  26. 'co.in',
  27. 'com.br',
  28. 'com.cn',
  29. 'com.pl',
  30. 'com.vn',
  31. 'cool',
  32. 'cricket',
  33. 'cyou',
  34. 'date',
  35. 'download',
  36. 'faith',
  37. 'fit',
  38. 'fun',
  39. 'ga',
  40. 'gd',
  41. 'gq',
  42. 'group',
  43. 'host',
  44. 'icu',
  45. 'id',
  46. 'info',
  47. 'ink',
  48. 'life',
  49. 'live',
  50. 'link',
  51. 'loan',
  52. 'ltd',
  53. 'men',
  54. 'ml',
  55. 'mobi',
  56. 'net.pl',
  57. 'one',
  58. 'online',
  59. 'party',
  60. 'pro',
  61. 'pl',
  62. 'pw',
  63. 'racing',
  64. 'rest',
  65. 'review',
  66. 'rf.gd',
  67. 'sa.com',
  68. 'sbs',
  69. 'science',
  70. 'shop',
  71. 'site',
  72. 'space',
  73. 'store',
  74. 'stream',
  75. 'tech',
  76. 'tk',
  77. 'tokyo',
  78. 'top',
  79. 'trade',
  80. 'vip',
  81. 'vn',
  82. 'webcam',
  83. 'website',
  84. 'win',
  85. 'xyz',
  86. 'za.com',
  87. 'lat',
  88. 'design'
  89. ]);
  90. export const WHITELIST_MAIN_DOMAINS = new Set([
  91. 'w3s.link', // ipfs gateway
  92. 'dweb.link', // ipfs gateway
  93. 'nftstorage.link', // ipfs gateway
  94. 'fleek.cool', // ipfs gateway
  95. 'business.site', // Drag'n'Drop site building platform
  96. 'page.link', // Firebase URL Shortener
  97. 'notion.site'
  98. ]);
  99. export const getPhishingDomains = (parentSpan: Span) => parentSpan.traceChild('get phishing domains').traceAsyncFn(async (span) => {
  100. const gorhill = await getGorhillPublicSuffixPromise();
  101. const domainArr = await span.traceChildAsync('download/parse/merge phishing domains', async (curSpan) => {
  102. const domainSet: string[] = [];
  103. (await Promise.all(PHISHING_DOMAIN_LISTS.map(entry => processDomainLists(curSpan, ...entry))))
  104. .forEach(appendArrayInPlaceCurried(domainSet));
  105. return domainSet;
  106. });
  107. const domainCountMap: Record<string, number> = {};
  108. span.traceChildSync('process phishing domain set', () => {
  109. for (let i = 0, len = domainArr.length; i < len; i++) {
  110. const line = domainArr[i];
  111. const safeGorhillLine = line[0] === '.' ? line.slice(1) : line;
  112. const apexDomain = gorhill.getDomain(safeGorhillLine);
  113. if (!apexDomain) {
  114. continue;
  115. }
  116. const tld = getPublicSuffix(safeGorhillLine, looseTldtsOpt);
  117. if (!tld || !BLACK_TLD.has(tld)) continue;
  118. domainCountMap[apexDomain] ||= 0;
  119. domainCountMap[apexDomain] += calcDomainAbuseScore(line);
  120. }
  121. });
  122. for (const domain in domainCountMap) {
  123. if (domainCountMap[domain] >= 8 && !WHITELIST_MAIN_DOMAINS.has(domain)) {
  124. domainArr.push(`.${domain}`);
  125. }
  126. }
  127. return domainArr;
  128. });
  129. export function calcDomainAbuseScore(line: string) {
  130. let weight = 1;
  131. const isPhishingDomainMockingCoJp = line.includes('-co-jp');
  132. if (isPhishingDomainMockingCoJp) {
  133. weight += 0.5;
  134. }
  135. if (line.startsWith('.amaz')) {
  136. weight += 0.5;
  137. if (line.startsWith('.amazon-')) {
  138. weight += 4.5;
  139. }
  140. if (isPhishingDomainMockingCoJp) {
  141. weight += 4;
  142. }
  143. } else if (line.includes('.customer')) {
  144. weight += 0.25;
  145. }
  146. const lineLen = line.length;
  147. if (lineLen > 19) {
  148. // Add more weight if the domain is long enough
  149. if (lineLen > 44) {
  150. weight += 3.5;
  151. } else if (lineLen > 34) {
  152. weight += 2.5;
  153. } else if (lineLen > 29) {
  154. weight += 1.5;
  155. } else if (lineLen > 24) {
  156. weight += 0.75;
  157. } else {
  158. weight += 0.25;
  159. }
  160. }
  161. const subdomain = getSubdomain(line, looseTldtsOpt);
  162. if (subdomain) {
  163. if (subdomain.slice(1).includes('.')) {
  164. weight += 1;
  165. }
  166. if (subdomain.length > 40) {
  167. weight += 3;
  168. } else if (subdomain.length > 30) {
  169. weight += 1.5;
  170. } else if (subdomain.length > 20) {
  171. weight += 1;
  172. } else if (subdomain.length > 10) {
  173. weight += 0.1;
  174. }
  175. }
  176. return weight;
  177. }