← Course Index

5.4 Cloud Attack & Defense:
IAM Privilege Paths, Audit Logs & Incident Containment

Analyzing Cloud Identity & Access Risks, Hunting Control-Plane & Data Events, Containing Compromised Identities & Hardening

Module 5: Cloud & Container Security Cloud IAM & Audit Logs Cloud Incident Response

1. Defending Cloud Control Planes & Identities

In cloud environments, identity permissions, trust relationships, and control-plane APIs often serve as the primary pivot points for attackers. Effective cloud defense pairs least-privilege identity design and short-lived credentials with close monitoring of control-plane and audit logs, followed by swift credential/session containment when anomalous actions occur.

Least Privilege & Short-Lived Auth: Favor scoped roles, workload identity/federation, and time-bound access over long-lived static keys or broad administrative assignments.
CLOUD RISK VECTORS Over-Scoped IAM / Roles Stale Keys or Tokens Unusual API / Sign-In Activity DETECT & CONTAIN Audit & Activity Hunting Track actor, API, source IP & target Identity & Session Containment Disable/rotate keys, revoke sessions Scope & Harden Check created resources/rules Tighten policies & guardrails RESILIENT CLOUD • Narrower Privilege Blast Radius • Faster Control-Plane Triage • Clean Recovery & Verification
Figure 5.4: Cloud Identity & Control-Plane Defense from Risk Identification to Hunting, Containment, and Hardening.

2. Key Cloud IAM & Incident Response Practices

Focus Area What to Check Operational Guidance
Permission & Role Scope Broad wildcard permissions, privilege escalation paths, or overly permissive trusts. Grant only required actions/resources and review privileged assignments regularly.
Audit & Sign-In Telemetry Control-plane mutations, identity/role changes, and unusual source IPs or clients. Correlate actor, timestamp, source IP, and target resource across cloud logs.
Containment & Follow-Through Compromised credentials, active sessions, or unauthorized resources created during an event. Revoke/rotate affected credentials, inspect created assets/rules, and check adjacent accounts.
Check Created Artifacts During Response: When an identity or session is suspected of compromise, check what new users, keys, roles, rules, or resources were created or modified during the activity window.

3. Practical Cloud IAM, Audit & Response Examples (10 Scenarios)

Example 1: Hunting Control-Plane Mutations by Caller & Action (KQL)

KQL (Microsoft Sentinel) — Reviewing Cloud Control-Plane Write/Delete Operations
AzureActivity
| where TimeGenerated > ago(24h)
| where OperationNameValue has_any ("/WRITE", "/DELETE", "/ACTION")
| summarize
    Operations = count(),
    DistinctOps = dcount(OperationNameValue),
    SampleOps = make_set(OperationNameValue, 8)
  by Caller, CallerIpAddress, ActivityStatusValue
| order by Operations desc
SAMPLE OUTPUT
Caller                   CallerIpAddress ActivityStatusValue Operations DistinctOps SampleOps
------                   --------------- ------------------- ---------- ----------- ---------
svc-deploy@corp.example  198.51.100.44   Succeeded           19         4           ["MICROSOFT.AUTHORIZATION/ROLEASSIGNMENTS/WRITE",...]

Example 2: Hunting Failed or Unusual Cloud Sign-Ins by User & IP (KQL)

KQL (Microsoft Sentinel) — Summarizing Sign-In Outcomes and Source IPs
SigninLogs
| where TimeGenerated > ago(24h)
| summarize
    TotalSignIns = count(),
    FailedSignIns = countif(ResultType != 0),
    UniqueIPs = dcount(IPAddress),
    SampleIPs = make_set(IPAddress, 8)
  by UserPrincipalName
| where FailedSignIns >= 5 or UniqueIPs >= 4
| order by FailedSignIns desc, UniqueIPs desc
SAMPLE OUTPUT
UserPrincipalName          TotalSignIns FailedSignIns UniqueIPs SampleIPs
-----------------          ------------ ------------- --------- ---------
r.kapoor@corp.example.com  14           9             5         ["203.0.113.10","198.51.100.84",...]

Example 3: Listing IAM Roles or Policies on AWS (Read-Only Audit)

Shell (aws iam) — Listing IAM Roles in an Account
aws iam list-roles --query "Roles[].{RoleName:RoleName,CreateDate:CreateDate}" --output table
SAMPLE OUTPUT
---------------------------------------------------------------------
|                             ListRoles                             |
+------------------------+------------------------------------------+
|       CreateDate       |                 RoleName                 |
+------------------------+------------------------------------------+
|  2026-06-12T08:15:00Z  |  SecurityAuditReadOnly                   |
|  2026-08-04T11:20:00Z  |  AppWorkloadRole-Prod                    |
+------------------------+------------------------------------------+

Example 4: Listing Azure Role Assignments for a Scope

Shell (az role) — Auditing Role Assignments in a Subscription
az role assignment list --query "[].{Principal:principalName,Role:roleDefinitionName,Scope:scope}" -o table
SAMPLE OUTPUT
Principal                  Role            Scope
-------------------------  --------------  --------------------------------------
ops-deploy@corp.example    Contributor     /subscriptions/11111111-2222-3333-4444-555555555555

Example 5: Checking Policy Document Statements for Wildcard Actions (Python)

Python (json) — Flagging Statements with "*" Action or Resource
import json

policy = {
    "Version": "2012-10-17",
    "Statement": [
        {"Effect": "Allow", "Action": "*", "Resource": "*"},
        {"Effect": "Allow", "Action": "s3:GetObject", "Resource": "arn:aws:s3:::app-bucket/*"},
    ],
}

for idx, stmt in enumerate(policy.get("Statement", [])):
    if stmt.get("Effect") == "Allow" and (stmt.get("Action") == "*" or stmt.get("Resource") == "*"):
        print(f"Broad allow in statement {idx}: Action={stmt.get('Action')} Resource={stmt.get('Resource')}")
SAMPLE OUTPUT
Broad allow in statement 0: Action=* Resource=*

Example 6: Hunting Cloud / Identity Events in SIEM Logs (SPL)

SPL (Splunk) — Summarizing Cloud Audit Events by Actor and Action
index=cloud_audit earliest=-24h
| stats count AS events dc(target_resource) AS targets values(action) AS actions
  BY actor, src_ip
| where events >= 10
| sort -events
SAMPLE OUTPUT
actor                   src_ip        events targets actions
-----                   ------        ------ ------- -------
svc-deploy@corp.example 198.51.100.44 19     3       PutRolePolicy UpdateAssumeRolePolicy

Example 7: Velociraptor VQL — Checking Environment Variables on a Host

VQL (Velociraptor) — Listing Process Environment Details
SELECT
  Pid,
  Name,
  Exe
FROM pslist()
WHERE Name =~ "(?i)^(aws|az|gcloud|python3|node)\\.exe$"
SAMPLE OUTPUT
Pid   Name       Exe
---   ----       ---
4190  python3    /usr/bin/python3

Example 8: Wazuh Rule — Alerting on Cloud Audit / Auth Anomalies

XML (Wazuh Rule) — Flagging Cloud Identity / Audit Events

  
    80200
    CreateAccessKey|PutRolePolicy|roleAssignments/write
    Privileged cloud identity or policy action observed on $(agent.name)
  
SAMPLE OUTPUT
** Alert 1795692104.44810: - local,cloud_iam,audit
2026 Nov 26 11:18:04 (cloud-audit-collector) 10.20.1.9->cloudtrail
Rule: 101201 (level 11) -> 'Privileged cloud identity or policy action observed on cloud-audit-collector'

Example 9: Checking Local CLI / Credential Cache Presence on Linux

Bash (ls) — Inspecting User Config Directories (Without Printing Secrets)
ls -la "$HOME/.aws" "$HOME/.azure" "$HOME/.config/gcloud" 2>/dev/null || true
SAMPLE OUTPUT
/home/devuser/.aws:
total 12
drwx------ 2 devuser devuser 4096 Nov 26 09:10 .
-rw------- 1 devuser devuser  184 Nov 26 09:10 config

Example 10: Summarizing High-Risk Cloud Actions in Python

Python (Counter) — Counting Sensitive Control-Plane Actions
from collections import Counter

actions = [
    "roleAssignments/write",
    "roleAssignments/write",
    "securityGroups/write",
    "policyAssignments/delete",
]

for act, cnt in Counter(actions).most_common():
    print(f"{act}: {cnt}")
SAMPLE OUTPUT
roleAssignments/write: 2
securityGroups/write: 1
policyAssignments/delete: 1

4. Interactive Cloud Attack & Defense Simulator

Select a cloud scenario below to review the triage steps and containment guidance:

← Previous: 5.3 eBPF Runtime Security 5.5 Software Supply Chain & SBOMs: →