get-phishing-domains.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. import { processDomainLists } from './parse-filter';
  2. import { parse } from 'tldts-experimental';
  3. import type { Span } from '../trace';
  4. import { appendArrayInPlaceCurried } from './append-array-in-place';
  5. import { PHISHING_DOMAIN_LISTS } from './reject-data-source';
  6. import { looseTldtsOpt } from '../constants/loose-tldts-opt';
  7. import picocolors from 'picocolors';
  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 domainArr = await span.traceChildAsync('download/parse/merge phishing domains', async (curSpan) => {
  103. const domainArr: string[] = [];
  104. (await Promise.all(PHISHING_DOMAIN_LISTS.map(entry => processDomainLists(curSpan, ...entry))))
  105. .forEach(appendArrayInPlaceCurried(domainArr));
  106. return domainArr;
  107. });
  108. const domainCountMap: Record<string, number> = {};
  109. span.traceChildSync('process phishing domain set', () => {
  110. for (let i = 0, len = domainArr.length; i < len; i++) {
  111. const line = domainArr[i];
  112. const {
  113. publicSuffix: tld,
  114. domain: apexDomain,
  115. subdomain
  116. } = parse(line, looseTldtsOpt);
  117. if (!tld) {
  118. console.log(picocolors.yellow('[phishing domains] E0001'), 'missing tld', { line, tld });
  119. continue;
  120. }
  121. if (!apexDomain) {
  122. console.log(picocolors.yellow('[phishing domains] E0002'), 'missing domain', { line, apexDomain });
  123. continue;
  124. }
  125. if (!BLACK_TLD.has(tld) && tld.length < 7) continue;
  126. domainCountMap[apexDomain] ||= 0;
  127. domainCountMap[apexDomain] += calcDomainAbuseScore(line, subdomain);
  128. }
  129. });
  130. for (const domain in domainCountMap) {
  131. if (domainCountMap[domain] >= 8 && !WHITELIST_MAIN_DOMAINS.has(domain)) {
  132. domainArr.push(`.${domain}`);
  133. }
  134. }
  135. return domainArr;
  136. });
  137. export function calcDomainAbuseScore(line: string, subdomain: string | null) {
  138. let weight = 1;
  139. const isPhishingDomainMockingCoJp = line.includes('-co-jp');
  140. if (isPhishingDomainMockingCoJp) {
  141. weight += 0.5;
  142. }
  143. if (line.startsWith('.amaz')) {
  144. weight += 0.5;
  145. if (line.startsWith('.amazon-')) {
  146. weight += 4.5;
  147. }
  148. if (isPhishingDomainMockingCoJp) {
  149. weight += 4;
  150. }
  151. }
  152. if (line.includes('.customer')) {
  153. weight += 0.25;
  154. }
  155. const lineLen = line.length;
  156. if (lineLen > 19) {
  157. // Add more weight if the domain is long enough
  158. if (lineLen > 44) {
  159. weight += 3.5;
  160. } else if (lineLen > 34) {
  161. weight += 2.5;
  162. } else if (lineLen > 29) {
  163. weight += 1.5;
  164. } else if (lineLen > 24) {
  165. weight += 0.75;
  166. } else {
  167. weight += 0.25;
  168. }
  169. }
  170. if (subdomain) {
  171. if (subdomain.slice(1).includes('.')) {
  172. weight += 1;
  173. }
  174. if (subdomain.length > 40) {
  175. weight += 3;
  176. } else if (subdomain.length > 30) {
  177. weight += 1.5;
  178. } else if (subdomain.length > 20) {
  179. weight += 1;
  180. } else if (subdomain.length > 10) {
  181. weight += 0.1;
  182. }
  183. }
  184. return weight;
  185. }