Skip to content

Under Construction

This page is under construction. Please check back later for comprehensive guidance

Google Workspace Log Analysis and Threat Hunting Guide

This comprehensive guide provides security professionals with actionable strategies for performing effective log analysis and threat hunting within Google Workspace environments, with a focus on techniques applicable for MSPs managing multiple client environments.

Understanding Google Workspace Logs

Key Log Sources

Google Workspace provides several critical log types that security teams should leverage:

Log Type Description Key Use Cases
Admin Audit Log Records administrative changes to Google Workspace configuration Detecting unauthorized admin actions, privilege escalation, security control changes
Login Audit Log Records user authentication events, including successes, failures, and challenges Identifying account compromise, credential stuffing, phishing attacks
Token Audit Log Records OAuth token issuance and usage Detecting OAuth abuse, unauthorized application access
SAML Audit Log Records SAML authentication events Monitoring SSO implementation, detecting federation attacks
Access Transparency Log Records Google staff access to customer content Ensuring appropriate Google access to customer data
Drive Audit Log Records file access, sharing, and modifications Detecting data exfiltration, unauthorized sharing
Gmail Log Records email delivery, processing, and user actions Identifying email security incidents, data loss via email
Mobile Audit Log Records mobile device activities and management actions Monitoring mobile device security, detecting compromised devices
Rules Log Records creation and modification of rules like email routing Detecting persistence mechanisms, unauthorized mail forwarding
Groups Audit Log Records changes to group membership and settings Monitoring unauthorized access changes, detecting privilege changes

Log Collection Strategies

Depending on your environment and requirements, consider these collection approaches:

  1. Google Cloud-Native
  2. Log Exports to Cloud Logging: Direct integration with Google Cloud monitoring
  3. BigQuery Export: For advanced analytics and long-term retention
  4. Pub/Sub Integration: For real-time processing and custom workflows

  5. Third-Party SIEM Integration

  6. API-Based Collection: Regular polling of Admin SDK APIs
  7. Webhook Notifications: Event-driven collection via push notifications
  8. Pre-built Connectors: Using vendor-provided Google Workspace integrations

  9. MSP Multi-Tenant Collection

  10. Aggregation Service: Central collection point for multiple tenant logs
  11. Tenant Identification: Ensuring proper segregation and identification
  12. Normalized Schema: Consistent format across different tenant configurations

Log Retention Considerations

  • Default Retention: Understand Google's default retention periods by log type
  • Extended Retention: Implementation of custom retention policies
  • Compliance Requirements: Adjusting retention to meet regulatory needs
  • Investigation Support: Ensuring sufficient history for security investigations
  • Cost Optimization: Balancing security needs with storage costs

Log Analysis Framework

Foundation: The OODA Loop for Log Analysis

Apply the Observe-Orient-Decide-Act framework to Google Workspace logs:

  1. Observe: Collect comprehensive logs from all relevant sources
  2. Orient: Contextualize log data with threat intelligence and environment understanding
  3. Decide: Determine if observed patterns indicate normal behavior or security incidents
  4. Act: Implement appropriate response actions based on analysis

Essential Analysis Techniques

Baseline Establishment

  • Authentication Patterns: Understand normal login times, locations, and devices
  • Administrative Actions: Document expected administrative activity cadence
  • Service Usage: Establish normal usage patterns for each Google service
  • Data Access: Identify typical data access and sharing patterns
  • Application Usage: Document normal third-party application utilization

Anomaly Detection Approaches

  • Statistical Deviation: Identifying activity outside normal standard deviations
  • Peer Group Analysis: Comparing user activity to similar role peers
  • Temporal Analysis: Identifying unusual timing of activities
  • Volume Analysis: Detecting unusual quantities of events
  • Sequence Analysis: Identifying atypical sequences of actions

Context Enhancement

  • User Context: Enriching logs with HR data, role information, and department
  • Asset Context: Adding device ownership, management status, and compliance state
  • Location Context: Enhancing with office locations, remote work status, and travel data
  • Business Context: Incorporating project assignments, access requirements
  • Threat Context: Adding known IOCs, threat actor TTPs, and intelligence

Threat Hunting Playbooks

1. Account Compromise Hunt

Objective: Identify potentially compromised user accounts

Log Sources: - Login Audit Log - Token Audit Log - Admin Audit Log

Hunt Techniques:

  1. Authentication Anomaly Detection
  2. Query unusual login times outside user's typical pattern
  3. Identify authentications from unusual geographies
  4. Detect rapid authentications from distant locations (impossible travel)
  5. Monitor for changes in authentication factors or methods

  6. Post-Compromise Activity Analysis

  7. Track password or recovery option changes after suspicious logins
  8. Identify mail forwarding rules created after unusual access
  9. Detect unusual Drive sharing or download activity following authentication
  10. Monitor for OAuth token issuance to new applications

Sample Hunt Query (SQL-like):

SELECT user_email, login_timestamp, ip_address, country, user_agent
FROM login_audit_logs
WHERE login_success = true
  AND login_timestamp > TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 14 DAY)
  AND user_email NOT IN ('admin1@example.com', 'service-account@example.com')
GROUP BY user_email, DATE(login_timestamp)
HAVING COUNT(DISTINCT country) > 2
ORDER BY user_email, login_timestamp;

2. Data Exfiltration Hunt

Objective: Identify potential data theft or unauthorized data access

Log Sources: - Drive Audit Log - Gmail Log - Admin Audit Log (for Takeout requests)

Hunt Techniques:

  1. Excessive Access Detection
  2. Identify users accessing unusually high volumes of documents
  3. Detect access to documents outside normal job function
  4. Monitor for systematic access to sensitive document categories
  5. Track unusual search patterns across document repositories

  6. Suspicious Export Activities

  7. Identify bulk downloads from Drive
  8. Detect unusual usage of Google Takeout
  9. Monitor for mass printing activities
  10. Track unusual email attachment patterns

Sample Hunt Query (SQL-like):

SELECT actor_email, COUNT(DISTINCT doc_id) as accessed_docs,
       SUM(CASE WHEN visibility = 'private' THEN 1 ELSE 0 END) as private_docs,
       SUM(CASE WHEN doc_type = 'sensitive' THEN 1 ELSE 0 END) as sensitive_docs
FROM drive_audit_logs
WHERE event_type IN ('view', 'download')
  AND timestamp > TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 7 DAY)
GROUP BY actor_email
HAVING COUNT(DISTINCT doc_id) > 
  (SELECT AVG(doc_count) + 2*STDDEV(doc_count) 
   FROM (
     SELECT actor_email, COUNT(DISTINCT doc_id) as doc_count 
     FROM drive_audit_logs 
     WHERE timestamp > TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 30 DAY)
     GROUP BY actor_email
   ))
ORDER BY accessed_docs DESC;

3. Privilege Escalation Hunt

Objective: Identify unauthorized elevation of privileges

Log Sources: - Admin Audit Log - Groups Audit Log - SAML Audit Log

Hunt Techniques:

  1. Administrative Role Changes
  2. Detect new admin role assignments
  3. Identify unusual delegation of administrative privileges
  4. Monitor for changes to powerful groups membership
  5. Track privilege assignments outside change management windows

  6. Admin Activity Analysis

  7. Identify first-time admin actions by user accounts
  8. Detect unusual sequences of administrative actions
  9. Monitor for sensitive setting modifications
  10. Track changes to security controls or monitoring settings

Sample Hunt Query (SQL-like):

SELECT actor_email, affected_email, role_name, timestamp
FROM admin_audit_logs
WHERE event_type = 'ADMIN_ROLE_CHANGE'
  AND action = 'ASSIGN'
  AND timestamp > TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 30 DAY)
  AND NOT EXISTS (
    SELECT 1 FROM change_management_records
    WHERE change_type = 'ROLE_ASSIGNMENT'
      AND affected_user = affected_email
      AND planned_date BETWEEN TIMESTAMP_SUB(timestamp, INTERVAL 1 DAY) 
                          AND TIMESTAMP_ADD(timestamp, INTERVAL 1 DAY)
  )
ORDER BY timestamp;

4. OAuth Application Abuse Hunt

Objective: Identify potentially malicious third-party applications

Log Sources: - Token Audit Log - Admin Audit Log

Hunt Techniques:

  1. Suspicious Application Detection
  2. Identify new applications with sensitive scope requests
  3. Detect applications with unusual user adoption patterns
  4. Monitor for applications accessing unusual combinations of services
  5. Track applications with abnormal token usage patterns

  6. Permission Scope Analysis

  7. Identify overprivileged application authorizations
  8. Detect scope escalation in existing applications
  9. Monitor for sensitive scope approvals (Gmail, Drive, Admin)
  10. Track unusual scope usage patterns

Sample Hunt Query (SQL-like):

SELECT application_name, client_id, requested_scopes, 
       COUNT(DISTINCT user_email) as user_count
FROM token_audit_logs
WHERE event_type = 'AUTHORIZE'
  AND timestamp > TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 14 DAY)
  AND (
    requested_scopes LIKE '%gmail.modify%' OR
    requested_scopes LIKE '%drive%' OR
    requested_scopes LIKE '%admin%'
  )
  AND client_id NOT IN (SELECT client_id FROM approved_applications)
GROUP BY application_name, client_id, requested_scopes
ORDER BY user_count DESC;

5. Persistence Mechanism Hunt

Objective: Identify attacker persistence techniques

Log Sources: - Admin Audit Log - Gmail Log - Rules Log - Groups Audit Log

Hunt Techniques:

  1. Account Manipulation Detection
  2. Identify changes to account recovery options
  3. Detect modifications to user authentication settings
  4. Monitor for password changes after suspicious events
  5. Track MFA disablement or changes

  6. Rule-Based Persistence Identification

  7. Identify creation of suspicious email forwarding rules
  8. Detect unusual filter creations in Gmail
  9. Monitor for scheduled jobs or triggers in Google environment
  10. Track automated script deployment or modification

Sample Hunt Query (SQL-like):

SELECT user_email, rule_id, rule_criteria, forward_destination, creation_time
FROM mail_rules_logs
WHERE event_type = 'CREATE_RULE'
  AND rule_action = 'FORWARD'
  AND creation_time > TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 30 DAY)
  AND forward_destination NOT LIKE '%@company.com'
  AND forward_destination NOT IN (SELECT email FROM approved_forwarding_destinations)
ORDER BY creation_time DESC;

Advanced Threat Hunting Techniques

User Behavior Analytics (UBA)

Implement advanced behavioral analytics:

  1. User Risk Scoring
  2. Develop multi-factor risk scoring based on log patterns
  3. Weight different anomalies based on security impact
  4. Adjust baselines based on role, department, and activity history
  5. Combine multiple low-risk indicators to identify high-risk patterns

  6. Peer Group Analysis

  7. Group users by role, department, and function
  8. Establish behavioral norms within each peer group
  9. Compare individual activity against peer group
  10. Identify significant deviations from peer behavior

  11. Session Analysis

  12. Track full user sessions rather than isolated events
  13. Analyze activity sequences within sessions
  14. Identify unusual transitions between services
  15. Detect abnormal session duration or activity volume

Threat Intelligence Integration

Enhance log analysis with threat intelligence:

  1. Indicator Matching
  2. Compare observed IP addresses against known threat infrastructure
  3. Match user agents against known malicious patterns
  4. Identify access from high-risk geographies
  5. Detect connections to known command and control domains

  6. TTP Pattern Matching

  7. Create detection rules based on known attacker techniques
  8. Match event sequences against documented attack patterns
  9. Develop specific detections for Google Workspace attack techniques
  10. Adjust detections based on emerging threat intelligence

  11. Custom Threat Feeds

  12. Develop Google Workspace-specific IoC feeds
  13. Share intelligence across multiple tenant environments
  14. Create MSP-specific intelligence based on cross-client observations
  15. Develop vertical-specific threat indicators

MSP-Specific Considerations

Multi-Tenant Monitoring Strategies

  1. Cross-Tenant Analysis
  2. Implement normalized logging across all clients
  3. Develop cross-tenant correlation capabilities
  4. Create consistent detection rules applicable to all environments
  5. Enable comparative analysis between similar organizations

  6. Tenant Isolation

  7. Maintain strict data segregation between tenants
  8. Implement tenant-specific access controls for logs
  9. Create role-based access to log analysis capabilities
  10. Ensure client confidentiality in multi-tenant SOC

  11. Scalable Detection Engineering

  12. Develop reusable detection content
  13. Implement programmatic rule deployment across tenants
  14. Create tenant-specific tuning capabilities
  15. Balance standardization with client-specific requirements

Client Reporting and Dashboards

  1. Executive-Level Reporting
  2. Create high-level security posture dashboards
  3. Develop trend analysis for key security metrics
  4. Implement comparative benchmarking against industry peers
  5. Provide actionable security improvement recommendations

  6. Technical Reporting

  7. Create detailed logs of security events
  8. Provide technical indicators for client security teams
  9. Implement drill-down capabilities for investigations
  10. Offer raw log access for client-directed analysis

  11. Compliance-Focused Reporting

  12. Map log analysis to compliance frameworks
  13. Create audit-ready reports for regulatory requirements
  14. Provide evidence of security control effectiveness
  15. Document security incidents and resolution actions

Implementation Roadmap

Phase 1: Foundation

  • Implement comprehensive log collection from all critical sources
  • Establish baseline visibility and basic alerting
  • Develop initial detection use cases for high-risk scenarios
  • Create basic reporting capabilities

Phase 2: Enhancement

  • Implement advanced correlation between log sources
  • Develop user and entity behavioral baselines
  • Create threat hunting program and initial playbooks
  • Enhance detection coverage for known attack techniques

Phase 3: Optimization

  • Implement machine learning for anomaly detection
  • Develop automated response workflows
  • Create advanced threat hunting capabilities
  • Establish continuous improvement processes

Useful Resources


Note: This guide should be adapted to your organization's specific environment, requirements, and security maturity level.