get-phishing-domains.ts 4.4 KB

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