Skip to content

Commit 126ea66

Browse files
authored
Merge pull request #266 from HackTricks-wiki/update_How_to_detect_and_respond_to_OAuth_consent_attacks_20260304_184649
How to detect and respond to OAuth consent attacks in Google...
2 parents 2bd82aa + 028c571 commit 126ea66

2 files changed

Lines changed: 58 additions & 2 deletions

File tree

src/pentesting-cloud/azure-security/az-lateral-movement-cloud-on-prem/az-exchange-hybrid-impersonation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@ When this technique is abused, audit events can show identity mismatches where t
4242

4343
## References
4444

45-
- https://www.youtube.com/watch?v=rzfAutv6sB8
45+
- [https://www.youtube.com/watch?v=rzfAutv6sB8](https://www.youtube.com/watch?v=rzfAutv6sB8)
4646

4747
{{#include ../../../banners/hacktricks-training.md}}

src/pentesting-cloud/workspace-security/gws-google-platforms-phishing/README.md

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,67 @@ Moreover, even not alowing to trust external third-party apps it's possible to a
165165

166166
<figure><img src="../../../images/workspace_oauth.png" alt=""><figcaption></figcaption></figure>
167167

168+
### OAuth Consent Grant Abuse: Detection & Response (Admin Reports)
169+
170+
When a user authorizes an OAuth app, Google Workspace records it in the **Admin Reports OAuth Token Audit Activity** (application name `token`) with `events.name` set to `authorize`. These events are the best telemetry to detect consent phishing and track the client ID and scopes that were granted.
171+
172+
Key fields to extract from the audit event:
173+
174+
- `id.time`, `id.customerId`
175+
- `actor.email`, `actor.profileId`
176+
- `ipAddress`, `networkInfo.regionCode`, `networkInfo.subdivisionCode`
177+
- `events[0]['parameters']` values for `client_id`, `app_name`, `scope`, `scope_data`
178+
179+
**Baseline first (reduce noise):** build an inventory of existing client IDs and scopes, then alert on new/rare consents.
180+
181+
```bash
182+
gam all users print tokens todrive
183+
```
184+
185+
**Detection ideas (new/rare app + risky scopes):**
186+
187+
- Alert if a `client_id` is **not in an approved allowlist** and **not seen in the last X days** (e.g., 90).
188+
- Alert if granted `scope` includes **high-risk or rare** scopes, especially those that allow bulk data access or supply-chain impact, such as:
189+
- `https://mail.google.com/`
190+
- `https://www.googleapis.com/auth/gmail.readonly`
191+
- `https://www.googleapis.com/auth/drive`
192+
- `https://www.googleapis.com/auth/drive.readonly`
193+
- `https://www.googleapis.com/auth/chat.messages`
194+
- `https://www.googleapis.com/auth/chromewebstore`
195+
196+
```text
197+
client_id NOT IN approved_client_ids
198+
AND client_id NOT IN last_seen_90d
199+
AND scope CONTAINS any(high_risk_scopes OR rare_scopes)
200+
```
201+
202+
**Response / containment:**
203+
204+
- Revoke tokens for the malicious OAuth client ID:
205+
206+
```bash
207+
gam all users delete tokens clientId <client_id>
208+
```
209+
210+
- Block the OAuth client ID in the Admin Console by revoking the application’s access to Google data.
211+
212+
**Threat hunting pivots:**
213+
214+
- List external apps consented by fewer than N users (rare adoption).
215+
- Review app name, publisher, permissions/scopes, and unique application ID.
216+
- Look for dormant apps that suddenly use risky permissions (possible follow-on actions like internal phishing or data theft).
217+
218+
**Mitigations:**
219+
220+
- Restrict all third-party app access (admin-approved only).
221+
- Allow limited access so users can only consent to basic “Sign in with Google” profile info.
222+
168223
## References
169224

170225
- [https://www.youtube-nocookie.com/embed/6AsVUS79gLw](https://www.youtube-nocookie.com/embed/6AsVUS79gLw) - Matthew Bryant - Hacking G Suite: The Power of Dark Apps Script Magic
171226
- [https://www.youtube.com/watch?v=KTVHLolz6cE](https://www.youtube.com/watch?v=KTVHLolz6cE) - Mike Felch and Beau Bullock - OK Google, How do I Red Team GSuite?
227+
- [https://redcanary.com/blog/threat-detection/google-workspace-oauth-attack/](https://redcanary.com/blog/threat-detection/google-workspace-oauth-attack/)
228+
- [https://github.com/GAM-team/GAM](https://github.com/GAM-team/GAM)
172229

173230
{{#include ../../../banners/hacktricks-training.md}}
174231

175-

0 commit comments

Comments
 (0)