keepcalculator

06 Numbers and Powers

Spot a Compromised AI Agent in AWS

Card No. 06·32179 · Updated · Standard formula, shown below

This guide helps you detect whether an AI agent running in AWS has been compromised, covering signs of tampering, unusual behavior, and concrete checks. You’ll learn what to look for in logs, IAM policies, and network activity, and how to respond if you find a problem.

What You’ll Need

  • AWS account access with permissions to view CloudTrail, CloudWatch Logs, IAM, and the AI agent’s resources (e.g., Lambda, SageMaker, Bedrock).
  • Basic familiarity with AWS console navigation and CLI.
  • Knowledge of your agent’s normal behavior and expected inputs/outputs.

Step-by-Step

  1. Review CloudTrail for unusual API calls. Open CloudTrail in the AWS Console, look for events from the agent’s role or resource. Filter by user name or resource ARN. Look for actions the agent shouldn’t perform, like iam:CreateUser, s3:PutBucketPolicy, or lambda:InvokeFunction on unrelated functions. Use the event history to spot anomalies like calls from unexpected IPs or at odd hours.
  2. Inspect IAM role permissions and trust policy. Navigate to IAM > Roles, find the role used by your agent. Check the trust policy—does it allow AssumeRole from accounts or services you don’t recognize? Review attached policies for overly broad permissions (e.g., s3:* on all buckets). If you see changes you didn’t make, that’s a red flag.
  3. Examine CloudWatch Logs for abnormal output. Go to CloudWatch > Log Groups, find the log group for your agent. Look for error messages, stack traces, or unexpected output that could indicate prompt injection or data exfiltration. Search for patterns like long strings of base64 or URLs to external domains.
  4. Check network traffic and VPC flow logs. If your agent runs in a VPC, enable VPC Flow Logs and review them. Look for connections to IP addresses outside your allowed list, especially on unusual ports. Use services like GuardDuty to detect suspicious network activity.
  5. Monitor model behavior in Bedrock or SageMaker. For agents using Bedrock, check model invocation logs—are there calls to models you didn’t configure? For SageMaker, review endpoint invocations and look for abnormal request patterns, such as high frequency or large payloads.
  6. Verify agent configuration and code integrity. Check the agent’s source code or container image for unauthorized changes. Use AWS CodeCommit or ECR to compare current versions with known-good hashes. Look for injected code that modifies behavior or sends data externally.
  7. Set up anomaly detection. Use CloudWatch Anomaly Detection on metrics like invocation count, duration, and error rate. A sudden spike or drop could indicate compromise. Also enable AWS Config rules to detect resource changes.
  8. Check for new or modified resources. Use AWS Config to list resources created or modified recently. Look for unexpected S3 buckets, Lambda functions, or EC2 instances that could be used for exfiltration or persistence.
  9. Review Secrets Manager and Parameter Store access. If your agent accesses secrets, check audit logs for retrieval of secrets it doesn’t normally use. Unusual access could mean the agent is being used to harvest credentials.

Common Mistakes

  • Ignoring minor anomalies: A single unusual log entry might be dismissed, but small deviations can be the first sign of compromise.
  • Only checking the agent’s own logs: Attackers may use the agent as a pivot to access other AWS services; you must review broader CloudTrail and resource activity.
  • Not understanding normal behavior: Without a baseline, you can’t identify what’s abnormal. Document expected API calls, IPs, and output formats.
  • Overlooking trust policy changes: The trust policy is rarely checked, but a malicious AssumeRole can grant external access.
  • Assuming the agent is the only compromised component: The agent might be a symptom; check for compromised credentials or other resources.

Tips

  • Enable CloudTrail across all regions and set up a trail that sends events to S3 and CloudWatch for centralized analysis.
  • Use AWS Organizations and Service Control Policies to restrict what the agent’s role can do, even if the agent is compromised.
  • Implement least privilege from the start—give the agent only the permissions it needs, and regularly review them.
  • Use GuardDuty and Security Hub for automated threat detection; they can alert you to suspicious activity.
  • Tag all resources and use resource-based policies to limit access to the agent’s resources.
  • Rotate credentials regularly and use short-lived credentials (e.g., via IAM Roles Anywhere) to reduce risk.

Troubleshooting

If you suspect compromise but can’t confirm, or if you’ve found issues, here’s what to do:

  • If you can’t find the source: Check CloudTrail for AssumeRole events and look for sessions with unusual session names. Also review AWS Organizations activity if you have it.
  • If logs are missing: Ensure CloudTrail is enabled and the agent’s role has permissions to write logs. Check if logs are being delivered to the correct bucket.
  • If you see unexpected charges: Examine Cost Explorer for spikes in services like SageMaker, Bedrock, or EC2. This could indicate resource abuse.
  • If the agent behaves erratically: Check for prompt injection by reviewing input logs—malicious prompts can cause the agent to take unintended actions.
  • If you need to respond immediately: Revoke the agent’s IAM role permissions, detach it from resources, and terminate any suspicious instances. Then investigate before restoring.

Frequently Asked Questions

What are the most common signs of a compromised AI agent?

Unusual API calls, unexpected network connections, changes to IAM policies, and abnormal model behavior (e.g., returning data it shouldn’t) are top indicators.

Can I detect compromise using only CloudWatch?

CloudWatch can help, but you need CloudTrail and VPC Flow Logs for comprehensive visibility. CloudWatch alone may miss API-level anomalies.

How do I prevent prompt injection attacks?

Validate and sanitize inputs, use system prompts to restrict actions, and implement human approval for critical operations. Also, monitor for unexpected tool calls.

What should I do if I find a compromised agent?

Isolate it by revoking IAM permissions, disconnect from networks, and take a snapshot for forensic analysis. Then rotate all credentials and review your security posture.

Does AWS have built-in tools for this?

Yes, GuardDuty, Security Hub, and CloudWatch Anomaly Detection can help. AWS also offers AI-specific security features in Bedrock, like model invocation logging.

How often should I check for compromise?

Set up continuous monitoring with alerts, and conduct manual reviews at least monthly or after any change to the agent.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →