Lesson 6 of 10
Cloud Threat Detection & Response
Detecting threats in cloud environments requires cloud-native security services and an understanding of how attackers abuse cloud APIs and services differently from traditional infrastructure.
AWS Security Services
# AWS security monitoring stack
# 1. AWS CloudTrail - ALL API calls logged
# Every action in AWS is an API call (console clicks included)
# Logged to S3 with optional CloudWatch integration
# Search CloudTrail logs for suspicious activity:
aws cloudtrail lookup-events \
--lookup-attributes AttributeKey=EventName,AttributeValue=ConsoleLogin \
--start-time 2025-01-01 \
--end-time 2025-01-02
# Athena query for suspicious CloudTrail events:
SELECT eventTime, userIdentity.arn, sourceIPAddress, eventName, errorCode
FROM cloudtrail_logs
WHERE eventName IN ('GetSecretValue', 'AssumeRole', 'CreateUser', 'AttachUserPolicy')
AND errorCode IS NULL
AND sourceIPAddress NOT LIKE '%.amazonaws.com'
ORDER BY eventTime DESC;
# 2. AWS GuardDuty - ML-based threat detection
# Analyzes: CloudTrail, VPC Flow Logs, DNS logs, EKS audit logs
# Finding types:
# UnauthorizedAccess:IAMUser/ConsoleLoginSuccess.B → Console login from Tor
# CryptoCurrency:EC2/BitcoinTool → Crypto mining detected
# Recon:IAMUser/MaliciousIPCaller → API calls from known malicious IPs
# Exfiltration:S3/ObjectRead → S3 data access anomaly
# Enable GuardDuty
aws guardduty create-detector --enable --finding-publishing-frequency FIFTEEN_MINUTES
# 3. AWS Security Hub - centralized security findings
# Aggregates: GuardDuty, Inspector, Macie, IAM Access Analyzer, Config
# Provides: security score, compliance dashboard, finding aggregation
# 4. AWS Macie - sensitive data discovery in S3
# ML-based detection of PII, financial data, credentials in S3 buckets
# Critical for GDPR/HIPAA compliance - know where your sensitive data livesCloud Attack Patterns
- Credential theft via IMDSv1: HTTP request to 169.254.169.254 from EC2 returns IAM role credentials. Defense: Enforce IMDSv2 (requires PUT request with a session token - SSRF cannot make PUT requests by default)
- Privilege escalation via IAM: User with iam:CreatePolicyVersion can add a new policy version with *:* permissions to themselves. Defense: AWS Permission Boundaries, IAM Access Analyzer
- S3 bucket takeover: If an S3 bucket used as website hosting or CloudFront origin is deleted, an attacker can re-create it and serve malicious content to your website's visitors
- Lambda event injection: Lambda functions processing SNS, SQS, or API Gateway events may be vulnerable to injection if they build SQL queries or shell commands from event data
- Cross-account role assumption: Misconfigured trust policies in IAM roles may allow any AWS account (or 'Principal: *') to assume the role - attacker from any account gains access
Common Mistakes
- Disabling CloudTrail to reduce costs - CloudTrail is essential for security; the cost (~$2/100K events) is negligible compared to a breach investigation without logs
- Single-region GuardDuty - attackers spin up resources in rarely-used regions; enable GuardDuty in ALL regions, not just your primary region
- Not reviewing GuardDuty findings - GuardDuty generates findings but won't take action; you need a process to review, investigate, and respond to findings
Tip
Tip
Practice Cloud Threat Detection Response in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.
The foundational security model: Confidentiality (privacy), Integrity (trust), and Availability (uptime).
Practice Task
Note
Practice Task - (1) Write a working example of Cloud Threat Detection Response from scratch without looking at notes. (2) Modify it to handle an edge case (empty input, null value, or error state). (3) Share your solution in the Priygop community for feedback.
Quick Quiz
Common Mistake
Warning
A common mistake with Cloud Threat Detection Response is skipping edge case testing - empty inputs, null values, and unexpected data types. Always validate boundary conditions to write robust, production-ready cybersecurity code.
Key Takeaways
- Detecting threats in cloud environments requires cloud-native security services and an understanding of how attackers abuse cloud APIs and services differently from traditional infrastructure.
- Credential theft via IMDSv1: HTTP request to 169.254.169.254 from EC2 returns IAM role credentials. Defense: Enforce IMDSv2 (requires PUT request with a session token - SSRF cannot make PUT requests by default)
- Privilege escalation via IAM: User with iam:CreatePolicyVersion can add a new policy version with *:* permissions to themselves. Defense: AWS Permission Boundaries, IAM Access Analyzer
- S3 bucket takeover: If an S3 bucket used as website hosting or CloudFront origin is deleted, an attacker can re-create it and serve malicious content to your website's visitors
Finished this lesson?