
Detecting Cyber Threats in AWS Using GuardDuty and CloudTrail
Discover how AWS security teams identify suspicious activities, investigate compromised credentials, analyze security findings, and respond to potential threats using Amazon GuardDuty and AWS CloudTrail.
Detecting Cyber Threats in AWS Using GuardDuty and CloudTrail
Introduction
As organizations increasingly move their infrastructure to cloud environments, protecting cloud resources against cyber threats has become an important responsibility.
AWS provides several security services that help organizations monitor their infrastructure, identify suspicious activities, and investigate potential security incidents.
However, collecting security logs is only one part of the process. Understanding what those logs represent, identifying unusual behavior, and determining whether an activity indicates a potential threat are equally important.
This is where Amazon GuardDuty and AWS CloudTrail become useful.
In this article, we will explore how these two services contribute to cloud security monitoring, how suspicious activities can be investigated, and how security teams can build a basic threat detection workflow within AWS.
1. Understanding AWS CloudTrail
AWS CloudTrail is a service that records account activity and API actions performed within an AWS environment.
Whenever an AWS user, role, or service performs a supported API operation, CloudTrail can capture relevant event information.
For example:
- An IAM user creates an EC2 instance.
- Someone modifies an EC2 Security Group.
- An administrator changes IAM permissions.
- An AWS resource is deleted.
- A user attempts to modify logging configurations.
CloudTrail events generally contain useful information, including:
- Event name
- Event time
- AWS service involved
- User identity
- Source IP address
- AWS region
- Request parameters
- Event outcome
Why is CloudTrail important for security?
Imagine that an EC2 Security Group is modified to allow SSH access from every IP address.
Without proper logging and monitoring, identifying who made this change and when it happened could become difficult.
CloudTrail helps security teams investigate these activities by providing a record of supported API operations.
It can therefore be useful during investigations involving unauthorized access, suspicious administrative changes, and potential account compromise.
2. Understanding Amazon GuardDuty
Amazon GuardDuty is an AWS managed threat detection service that continuously analyzes supported data sources and logs to identify potentially malicious or unauthorized activities.
It uses threat intelligence, machine learning, and anomaly detection techniques to identify suspicious behavior.
GuardDuty can help identify different categories of threats, including:
Reconnaissance
- Unusual network scanning.
- Suspicious port probing.
- Unusual API activity.
Instance compromise
- Communication with known malicious IP addresses.
- Suspicious network behavior.
- Potential malware activity.
- Cryptocurrency mining activity.
Account compromise
- Suspicious API calls.
- Potential credential compromise.
- Unusual activity involving AWS identities.
- Attempts to weaken security configurations.
GuardDuty generates security findings when it identifies activity that may require investigation.
These findings provide information about the potential threat, affected resources, severity, and supporting context.
3. How GuardDuty and CloudTrail Work Together
One of the most useful concepts in AWS security monitoring is understanding how different security services complement each other.
CloudTrail records supported AWS API activity, while GuardDuty analyzes supported data sources to identify potentially suspicious behavior.
A simplified workflow looks like this:
AWS ENVIRONMENT | v AWS API ACTIVITY | v CLOUDTRAIL Records API Events | v GUARDDUTY Threat Detection | v SECURITY FINDING | v SECURITY ANALYST | v INVESTIGATION | v RESPONSE AND REMEDIATIONGuardDuty also analyzes other foundational data sources, including VPC Flow Logs and DNS query logs. It does not simply depend on a manually configured CloudTrail trail to begin foundational threat detection.
This distinction is important when designing an AWS monitoring environment.
4. Common Threat Scenarios in AWS
Let's understand a few realistic scenarios that security teams may encounter.
Scenario 1: Suspicious IAM Activity
Imagine an attacker obtains access to an AWS user's credentials.
The attacker may attempt to:
- Enumerate available AWS resources.
- Access sensitive services.
- Create additional access keys.
- Modify IAM policies.
- Launch unauthorized infrastructure.
CloudTrail can provide records of the API activity associated with the identity.
GuardDuty may identify suspicious patterns and generate a finding indicating potential account compromise.
Investigation approach:
- Identify the affected IAM identity.
- Review the relevant CloudTrail events.
- Check the source IP address and geographical context.
- Identify any unexpected permission changes.
- Review resources accessed by the identity.
- Determine whether credentials need to be revoked or rotated.
Scenario 2: Suspicious EC2 Network Activity
Consider an EC2 instance that begins communicating with an unusual external IP address.
This could indicate legitimate application behavior, but it could also suggest malware communication or command-and-control activity.
GuardDuty can identify certain suspicious network patterns using its supported telemetry and threat detection capabilities.
Investigation approach:
- Identify the affected EC2 instance.
- Review the GuardDuty finding details.
- Examine relevant network activity.
- Check running processes and active connections.
- Review application and operating system logs.
- Determine whether containment is necessary.
Scenario 3: Unauthorized Security Group Modification
Suppose an attacker gains access to an AWS identity and modifies a Security Group to expose an administrative port.
CloudTrail can help establish:
- Which identity performed the change.
- When the modification occurred.
- Which Security Group was affected.
- What source IP address was associated with the API request.
Security teams can then investigate whether the modification was authorized and restore the intended network configuration if necessary.
5. Investigating CloudTrail Events Using AWS CLI
The AWS Command Line Interface (AWS CLI) allows security analysts and administrators to retrieve information about AWS resources and supported API events.
Before running the following commands, configure the AWS CLI with an appropriately authorized identity.
Step 1: Verify your AWS identity
aws sts get-caller-identityThis command displays information about the identity currently being used by the AWS CLI.
It helps confirm which AWS account and identity are associated with your session.
Step 2: Search CloudTrail events
For example, to investigate EC2 instance launch activity:
aws cloudtrail lookup-events \ --lookup-attributes AttributeKey=EventName,AttributeValue=RunInstances \ --max-results 10This retrieves recent matching CloudTrail events.
You can replace
RunInstances with other event names depending on the investigation.Some useful event names include:
Event name | Purpose |
|---|---|
RunInstances | Investigate EC2 instance launches |
AuthorizeSecurityGroupIngress | Investigate inbound firewall rule changes |
CreateAccessKey | Investigate access key creation |
AttachUserPolicy | Investigate IAM policy attachment |
StopLogging | Investigate CloudTrail logging changes |
Note that CloudTrail Event History provides 90 days of management event history per account and Region. It is not a replacement for a properly configured long-term audit trail.
Step 3: Retrieve GuardDuty findings
First, identify your GuardDuty detector ID:
aws guardduty list-detectorsThen retrieve the available finding IDs:
aws guardduty list-findings \ --detector-id <DETECTOR_ID>To inspect specific findings:
aws guardduty get-findings \ --detector-id <DETECTOR_ID> \ --finding-ids <FINDING_ID>These commands help retrieve the findings generated by GuardDuty.
They are useful for understanding the affected resource, finding type, severity, and other investigation details.
6. Building a Basic Threat Detection Workflow
Security teams need more than a detection service. They also need a structured process to investigate and respond to potential threats.
A simple AWS security monitoring workflow can be organized into the following stages.
Stage 1: Monitoring
Use CloudTrail and GuardDuty to maintain visibility into supported AWS activities and potential threats.
Stage 2: Detection
Review GuardDuty findings and identify activities that require further investigation.
Stage 3: Investigation
Examine the finding details, affected resources, identities, API events, and relevant network or system logs.
Stage 4: Classification
Determine whether the activity is:
- Expected and legitimate.
- Suspicious but unconfirmed.
- A confirmed security incident.
Stage 5: Response
Depending on the investigation, appropriate actions may include:
- Restricting affected network access.
- Revoking or rotating compromised credentials.
- Reviewing IAM permissions.
- Isolating affected workloads.
- Restoring secure configurations.
Stage 6: Recovery and Review
Restore affected services safely, validate security controls, document the incident, and identify improvements to prevent recurrence.
7. Automating Security Notifications
Manually checking security findings throughout the day is not always practical.
AWS provides integration capabilities that allow organizations to build automated notification and response workflows.
For example:
AMAZON GUARDDUTY | v SECURITY FINDING | v AMAZON EVENTBRIDGE | v EVENT RULE MATCHES | +----+----+ | | v v AMAZON AWS LAMBDA SNS | | v v AUTOMATED EMAIL RESPONSE ALERTSAmazon EventBridge can receive GuardDuty findings and route matching events to supported targets.
Amazon SNS can distribute notifications, while AWS Lambda can execute predefined response actions.
For example, a security team could configure an EventBridge rule to notify administrators when a high-severity GuardDuty finding is generated.
Automated containment actions should be designed carefully. Automatically modifying network rules or isolating instances without validating the finding could interrupt legitimate business operations.
8. Best Practices for AWS Threat Detection
A reliable cloud security monitoring strategy should include the following practices:
Enable GuardDuty
Enable GuardDuty in the AWS Regions where your resources operate.
Monitor CloudTrail activity
Maintain appropriate CloudTrail configurations and retention for security investigations and compliance requirements.
Apply IAM least privilege
Ensure that users and applications only receive the permissions they actually require.
Monitor Security Group changes
Pay attention to changes that expose administrative services or sensitive applications.
Review GuardDuty findings
Investigate findings according to their severity, context, and potential business impact.
Centralize security monitoring
For larger environments, consider aggregating security findings across AWS accounts and integrating them with existing security operations workflows.
Document incident response procedures
Establish clear processes for investigating, containing, recovering from, and documenting security incidents.
9. What Does This Mean for a SOC Analyst?
Cloud security monitoring introduces another important responsibility for Security Operations Center (SOC) analysts.
Traditional SOC investigations often involve Windows Event Logs, Sysmon telemetry, network traffic, and SIEM alerts.
Cloud environments introduce additional sources of evidence, such as:
- AWS CloudTrail events.
- GuardDuty findings.
- IAM activity.
- VPC Flow Logs.
- EC2 instance information.
- Security Group modifications.
A SOC analyst must understand how these sources relate to each other.
For example, when investigating suspicious AWS account activity, an analyst should not simply rely on a single alert.
They should correlate the finding with relevant API activity, identify the affected identity, understand the potential impact, and determine whether the behavior represents an actual security incident.
This is where cloud security knowledge becomes valuable alongside traditional SOC investigation skills.
Conclusion
Cloud security is not just about preventing unauthorized access. It also involves identifying suspicious activity, understanding what happened, and responding effectively.
Amazon GuardDuty and AWS CloudTrail provide complementary capabilities that help organizations improve their visibility into AWS environments.
CloudTrail provides records of supported API activity, while GuardDuty analyzes supported data sources to identify potential threats.
When combined with structured investigation procedures and appropriate response mechanisms, these services can form an important part of an organization's cloud security monitoring strategy.
For anyone learning cybersecurity or preparing for a cloud security or SOC role, understanding these services is a valuable step toward developing practical cloud threat detection skills.
References and Further Learning
Disclaimer: This article is intended for educational purposes. AWS service availability, capabilities, and pricing may vary by Region and configuration. Always validate commands and response actions in an appropriately controlled AWS environment before using them in production.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article