Attachment: Microsoft OAuth credential harvesting via EML with embedded malicious links
Detects inbound messages containing EML attachments with embedded links targeting Microsoft OAuth authentication flows. The rule identifies suspicious Microsoft login URLs with specific query parameters indicating credential harvesting attempts, including offline access permissions, read/write scopes, and reprocessing endpoints. Links are detected within EML body content, embedded PDF/HTML attachments, and ICS calendar files.
Sublime rule (View on GitHub)
1name: "Attachment: Microsoft OAuth credential harvesting via EML with embedded malicious links"
2description: "Detects inbound messages containing EML attachments with embedded links targeting Microsoft OAuth authentication flows. The rule identifies suspicious Microsoft login URLs with specific query parameters indicating credential harvesting attempts, including offline access permissions, read/write scopes, and reprocessing endpoints. Links are detected within EML body content, embedded PDF/HTML attachments, and ICS calendar files."
3type: "rule"
4severity: "high"
5source: |
6 type.inbound
7 and any(attachments,
8 (.content_type == "message/rfc822" or .file_extension in ("eml"))
9 and (
10 // links in attached EML body
11 any(file.parse_eml(.).body.links,
12 (
13 (
14 .href_url.domain.domain in (
15 'login.microsoftonline.com',
16 'login.microsoft.com'
17 )
18 or strings.icontains(.href_url.query_params,
19 "login.microsoftonline.com",
20 'login.microsoft.com'
21 )
22 )
23 and (
24 strings.ilike(.href_url.query_params,
25 '*offline_access*',
26 '*.readwrite*',
27 '*.read*',
28 '*ctx=*',
29 '*prompt=none*'
30 )
31 or (
32 (
33 strings.icontains(.href_url.path, '/common/reprocess')
34 or strings.icontains(.href_url.query_params,
35 "/common/reprocess"
36 )
37 )
38 and strings.icontains(.href_url.query_params, 'ctx=')
39 and strings.icontains(.href_url.query_params, 'sessionId=')
40 )
41 )
42 )
43 or any(flatten(values(.href_url.query_params_decoded)),
44 any(strings.scan_base64(., ignore_padding=true),
45 strings.icontains(., "login.microsoftonline.com")
46 and strings.ilike(.,
47 '*offline_access*',
48 '*.readwrite*',
49 '*.read*',
50 '*prompt=none*'
51 )
52 )
53 )
54 )
55 // links in PDF and HTML attachments inside the EML
56 or any(filter(file.parse_eml(.).attachments,
57 .file_type in ("pdf", "html", "docx", "pptx")
58 ),
59 any(file.explode(.),
60 any(.scan.url.urls,
61 (
62 (
63 .domain.domain in (
64 'login.microsoftonline.com',
65 'login.microsoft.com'
66 )
67 or strings.icontains(.query_params,
68 "login.microsoftonline.com",
69 'login.microsoft.com'
70 )
71 )
72 and (
73 strings.ilike(.query_params,
74 '*offline_access*',
75 '*.readwrite*',
76 '*.read*',
77 '*ctx=*',
78 '*prompt=none*'
79 )
80 or (
81 strings.icontains(.path, '/common/reprocess')
82 and strings.icontains(.query_params, 'ctx=')
83 and strings.icontains(.query_params,
84 'sessionId='
85 )
86 )
87 )
88 )
89 or any(flatten(values(.query_params_decoded)),
90 any(strings.scan_base64(., ignore_padding=true),
91 strings.icontains(.,
92 "login.microsoftonline.com"
93 )
94 and strings.ilike(.,
95 '*offline_access*',
96 '*.readwrite*',
97 '*.read*',
98 '*prompt=none*'
99 )
100 )
101 )
102 )
103 )
104 )
105 // links in ICS attachments inside the EML
106 or any(filter(file.parse_eml(.).attachments,
107 .file_type == "ics"
108 or .file_extension == "ics"
109 or .content_type in ("application/ics", "text/calendar")
110 ),
111 //
112 // This rule makes use of a beta feature and is subject to change without notice
113 // using the beta feature in custom rules is not suggested until it has been formally released
114 //
115 any(beta.file.parse_ics(.).events,
116 any(.links,
117 (
118 (
119 .href_url.domain.domain in (
120 'login.microsoftonline.com',
121 'login.microsoft.com'
122 )
123 or strings.icontains(.href_url.query_params,
124 "login.microsoftonline.com",
125 'login.microsoft.com'
126 )
127 )
128 and (
129 strings.ilike(.href_url.query_params,
130 '*offline_access*',
131 '*.readwrite*',
132 '*.read*',
133 '*ctx=*',
134 '*prompt=none*'
135 )
136 or (
137 strings.icontains(.href_url.path,
138 '/common/reprocess'
139 )
140 and strings.icontains(.href_url.query_params,
141 'ctx='
142 )
143 and strings.icontains(.href_url.query_params,
144 'sessionId='
145 )
146 )
147 )
148 )
149 or any(flatten(values(.href_url.query_params_decoded)),
150 any(strings.scan_base64(., ignore_padding=true),
151 strings.icontains(.,
152 "login.microsoftonline.com"
153 )
154 and strings.ilike(.,
155 '*offline_access*',
156 '*.readwrite*',
157 '*.read*',
158 '*prompt=none*'
159 )
160 )
161 )
162 )
163 )
164 )
165 )
166 )
167attack_types:
168 - "Credential Phishing"
169tactics_and_techniques:
170 - "Impersonation: Brand"
171 - "Evasion"
172 - "PDF"
173detection_methods:
174 - "File analysis"
175 - "URL analysis"
176 - "Content analysis"
177related_detections:
178 - "link_office365_suspicious_app_authorization.yml"
179 - "attachment_link_office365_suspicious_app_authorization.yml"
180 - "attachment_ics_link_office365_suspicious_app_authorization.yml"
181 - "link_self_service_platform_link_to_microsoft_redirect.yml"
182id: "6788a4c8-699b-53af-8f2d-5dafcff63843"