get-phishing-domains.ts 4.1 KB

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