Service abuse: SendGrid impersonation via Sendgrid from new sender

Detects messages impersonating SendGrid from new senders, while routing through legitimate SendGrid infrastructure. This pattern is commonly used to abuse trusted email services for malicious purposes.

Sublime rule (View on GitHub)

 1name: "Service abuse: SendGrid impersonation via Sendgrid from new sender"
 2description: "Detects messages impersonating SendGrid from new senders, while routing through legitimate SendGrid infrastructure. This pattern is commonly used to abuse trusted email services for malicious purposes."
 3type: "rule"
 4severity: "high"
 5source: |
 6  type.inbound
 7  // SendGrid impersonation patterns
 8  and (
 9    strings.ilike(strings.replace_confusables(sender.display_name), '*sendgrid*')
10    or strings.ilevenshtein(strings.replace_confusables(sender.display_name),
11                            'sendgrid'
12    ) <= 1
13    or (
14      strings.ilike(strings.replace_confusables(sender.email.local_part),
15                    '*sendgrid*'
16      )
17      and (
18        sender.display_name is null
19        or strings.ilike(strings.replace_confusables(subject.base), '*sendgrid*')
20      )
21    )
22    or any(ml.logo_detect(file.message_screenshot()).brands,
23           .name == "SendGrid" and .confidence == "high"
24    )
25    or any(html.xpath(body.html, '//img/@src').nodes,
26           regex.contains(.raw, 'sendgrid-?logo')
27           and not strings.contains(.raw, sender.email.domain.sld)
28    )
29    or regex.icontains(body.current_thread.text, 'sendgrid\s*20[0-9]{2}')
30    or (
31      (
32        strings.icontains(body.current_thread.text, 'sendgrid')
33        or strings.icontains(sender.display_name, 'sendgrid')
34      )
35      and any(body.current_thread.links,
36              any(ml.link_analysis(., mode="aggressive").tags,
37                  . in ('phishkit:encrypted_email', 'fake:cloudflare_challenge')
38              )
39      )
40    )
41    or regex.icontains(body.current_thread.text,
42                       '\bthe\s+(?:twilio\s+)?sendgrid\s+(?:\w+\s+)?team\b',
43                       '\b(?:to|by)\s+(?:your|the)\s+sendgrid\s+(?:account|api|integration)\b',
44                       '(?:^|\n)\s*your\s+sendgrid\s+(?:account|api|integration)\b',
45                       '\breceipt\s+from\s+(?:twilio\s+)?sendgrid\b',
46                       '\b(?:\w+\s+)*team\s+at\s+(?:twilio\s+)?sendgrid\b'
47    )
48  )
49  // sent through a sendgrid account... sendgrid stamps X-SG-EID/X-SG-ID on every
50  // send, including white-labelled dedicated IPs that hide sendgrid.net
51  and any(headers.hops, any(.fields, .name in~ ("X-SG-EID", "X-SG-ID")))
52  // not common senders with valid domains
53  // this catches cases where the domain is invalid and senders become common
54  and not (
55    profile.by_sender_email().prevalence == "common" and sender.email.domain.valid
56  )
57  // negate legit sendgrid messages
58  and not (
59    sender.email.domain.root_domain in ("sendgrid.com", "kke.co.jp")
60    and coalesce(headers.auth_summary.dmarc.pass, false)
61  )  
62attack_types:
63  - "Credential Phishing"
64tactics_and_techniques:
65  - "Impersonation: Brand"
66  - "Social engineering"
67detection_methods:
68  - "Header analysis"
69  - "Sender analysis"
70id: "aa5d18ca-665a-5817-89d6-d76e29c44580"
to-top