Translated ['src/README.md', 'src/banners/hacktricks-training.md', 'src/

This commit is contained in:
Translator
2024-12-31 20:45:32 +00:00
parent ea3a11546a
commit 3c2f3f44a7
245 changed files with 9950 additions and 12671 deletions

View File

@@ -4,266 +4,253 @@
## Step Functions
AWS Step Functions is a workflow service that enables you to coordinate and orchestrate multiple AWS services into serverless workflows. By using AWS Step Functions, you can design and run workflows that connect various AWS services such as AWS Lambda, Amazon S3, Amazon DynamoDB, and many more, in a sequence of steps. This orchestration service provides a visual workflow interface and offers **state machine** capabilities, allowing you to define each step of the workflow in a declarative manner using JSON-based **Amazon States Language** (ASL).
AWS Step Functionsは、複数のAWSサービスをサーバーレスワークフローに調整および編成するためのワークフローサービスです。AWS Step Functionsを使用することで、AWS LambdaAmazon S3Amazon DynamoDBなどのさまざまなAWSサービスをステップのシーケンスで接続するワークフローを設計および実行できます。このオーケストレーションサービスは、視覚的なワークフローインターフェースを提供し、**状態マシン**機能を提供し、JSONベースの**Amazon States Language**ASLを使用してワークフローの各ステップを宣言的に定義できます。
## Key concepts
### Standard vs. Express Workflows
AWS Step Functions offers two types of **state machine workflows**: Standard and Express.
AWS Step Functionsは、2種類の**状態マシンワークフロー**を提供します:StandardExpress
- **Standard Workflow**: This default workflow type is designed for long-running, durable, and auditable processes. It supports **exactly-once execution**, ensuring tasks run only once unless retries are specified. It is ideal for workflows needing detailed execution history and can run for up to one year.
- **Express Workflow**: This type is ideal for high-volume, short-duration tasks, running up to five minutes. They support **at-least-once execution**, suitable for idempotent tasks like data processing. These workflows are optimized for cost and performance, charging based on executions, duration, and memory usage.
- **Standard Workflow**:このデフォルトのワークフロータイプは、長時間実行される耐久性があり、監査可能なプロセス向けに設計されています。**exactly-once execution**をサポートし、リトライが指定されない限り、タスクは一度だけ実行されることを保証します。詳細な実行履歴が必要なワークフローに最適で、最大1年間実行できます。
- **Express Workflow**このタイプは、高ボリュームで短期間のタスクに最適で、最大5分間実行されます。**at-least-once execution**をサポートし、データ処理のような冪等タスクに適しています。これらのワークフローは、実行、期間、およびメモリ使用量に基づいて課金され、コストとパフォーマンスが最適化されています。
### States
States are the essential units of state machines. They define the individual steps within a workflow, being able to perform a variety of functions depending on its type:
Statesは状態マシンの基本単位です。ワークフロー内の個々のステップを定義し、そのタイプに応じてさまざまな機能を実行できます:
- **Task:** Executes a job, often using an AWS service like Lambda.
- **Choice:** Makes decisions based on input.
- **Fail/Succeed:** Ends the execution with a failure or success.
- **Pass:** Passes input to output or injects data.
- **Wait:** Delays execution for a set time.
- **Parallel:** Initiates parallel branches.
- **Map:** Dynamically iterates steps over items.
- **Task:** ジョブを実行し、通常はLambdaのようなAWSサービスを使用します。
- **Choice:** 入力に基づいて決定を下します。
- **Fail/Succeed:** 失敗または成功で実行を終了します。
- **Pass:** 入力を出力に渡すか、データを注入します。
- **Wait:** 設定された時間だけ実行を遅延させます。
- **Parallel:** 並列ブランチを開始します。
- **Map:** アイテムに対して動的にステップを反復します。
### Task
A **Task** state represents a single unit of work executed by a state machine. Tasks can invoke various resources, including activities, Lambda functions, AWS services, or third-party APIs.
**Task**状態は、状態マシンによって実行される単一の作業単位を表します。タスクは、アクティビティ、Lambda関数、AWSサービス、またはサードパーティAPIなど、さまざまなリソースを呼び出すことができます。
- **Activities**: Custom workers you manage, suitable for long-running processes.
- Resource: **`arn:aws:states:region:account:activity:name`**.
- **Lambda Functions**: Executes AWS Lambda functions.
- Resource: **`arn:aws:lambda:region:account:function:function-name`**.
- **AWS Services**: Integrates directly with other AWS services, like DynamoDB or S3.
- Resource: **`arn:partition:states:region:account:servicename:APIname`**.
- **HTTP Task**: Calls third-party APIs.
- Resource field: **`arn:aws:states:::http:invoke`**. Then, you should provide the API endpoint configuration details, such as the API URL, method, and authentication details.
The following example shows a Task state definition that invokes a Lambda function called HelloWorld:
- **Activities**: あなたが管理するカスタムワーカーで、長時間実行されるプロセスに適しています。
- Resource: **`arn:aws:states:region:account:activity:name`**.
- **Lambda Functions**: AWS Lambda関数を実行します。
- Resource: **`arn:aws:lambda:region:account:function:function-name`**.
- **AWS Services**: DynamoDBやS3など、他のAWSサービスと直接統合します。
- Resource: **`arn:partition:states:region:account:servicename:APIname`**.
- **HTTP Task**: サードパーティAPIを呼び出します。
- Resource field: **`arn:aws:states:::http:invoke`**. 次に、API URL、メソッド、および認証の詳細など、APIエンドポイントの構成詳細を提供する必要があります。
以下の例は、HelloWorldというLambda関数を呼び出すTask状態の定義を示しています
```json
"HelloWorld": {
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"Parameters": {
"Payload.$": "$",
"FunctionName": "arn:aws:lambda:<region>:<account-id>:function:HelloWorld"
},
"End": true
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"Parameters": {
"Payload.$": "$",
"FunctionName": "arn:aws:lambda:<region>:<account-id>:function:HelloWorld"
},
"End": true
}
```
### Choice
A **Choice** state adds conditional logic to a workflow, enabling decisions based on input data. It evaluates the specified conditions and transitions to the corresponding state based on the results.
**Choice** ステートは、ワークフローに条件付きロジックを追加し、入力データに基づいて決定を可能にします。指定された条件を評価し、結果に基づいて対応するステートに遷移します。
- **Comparison**: Each choice rule includes a comparison operator (e.g., **`NumericEquals`**, **`StringEquals`**) that compares an input variable to a specified value or another variable.
- **Next Field**: Choice states do not support don't support the **`End`** field, instead, they define the **`Next`** state to transition to if the comparison is true.
- **Comparison**: 各選択ルールには、入力変数を指定された値または別の変数と比較する比較演算子(例:**`NumericEquals`**、**`StringEquals`**)が含まれています。
- **Next Field**: Choice ステートは **`End`** フィールドをサポートしていません。代わりに、比較が真である場合に遷移する **`Next`** ステートを定義します。
Example of **Choice** state:
```json
{
"Variable": "$.timeStamp",
"TimestampEquals": "2000-01-01T00:00:00Z",
"Next": "TimeState"
"Variable": "$.timeStamp",
"TimestampEquals": "2000-01-01T00:00:00Z",
"Next": "TimeState"
}
```
### 失敗/成功
### Fail/Succeed
**`Fail`** ステートは、ステートマシンの実行を停止し、それを失敗としてマークします。エラー名と原因を指定し、失敗に関する詳細を提供するために使用されます。このステートは終端であり、実行フローを終了します。
A **`Fail`** state stops the execution of a state machine and marks it as a failure. It is used to specify an error name and a cause, providing details about the failure. This state is terminal, meaning it ends the execution flow.
A **`Succeed`** state stops the execution successfully. It is typically used to terminate the workflow when it completes successfully. This state does not require a **`Next`** field.
**`Succeed`** ステートは、実行を成功裏に停止します。通常、ワークフローが成功裏に完了したときに終了するために使用されます。このステートは **`Next`** フィールドを必要としません。
{{#tabs }}
{{#tab name="Fail example" }}
{{#tab name="失敗の例" }}
```json
"FailState": {
"Type": "Fail",
"Error": "ErrorName",
"Cause": "Error details"
"Type": "Fail",
"Error": "ErrorName",
"Cause": "Error details"
}
```
{{#endtab }}
{{#tab name="Succeed example" }}
{{#tab name="成功例" }}
```json
"SuccessState": {
"Type": "Succeed"
"Type": "Succeed"
}
```
{{#endtab }}
{{#endtabs }}
### Pass
A **Pass** state passes its input to its output either without performing any work or transformin JSON state input using filters, and then passing the transformed data to the next state. It is useful for testing and constructing state machines, allowing you to inject static data or transform it.
**Pass**ステートは、作業を行うことなく、またはフィルターを使用してJSONステート入力を変換することによって、その入力を出力に渡し、変換されたデータを次のステートに渡します。これは、静的データを注入したり、データを変換したりすることを可能にするため、ステートマシンのテストや構築に役立ちます。
```json
"PassState": {
"Type": "Pass",
"Result": {"key": "value"},
"ResultPath": "$.newField",
"Next": "NextState"
"Type": "Pass",
"Result": {"key": "value"},
"ResultPath": "$.newField",
"Next": "NextState"
}
```
### Wait
**Wait**ステートは、指定された期間、ステートマシンの実行を遅延させます。待機時間を設定するための主な方法は3つあります。
- **X秒**: 待機する固定の秒数。
```json
"WaitState": {
"Type": "Wait",
"Seconds": 10,
"Next": "NextState"
}
```
### Wait
- **絶対タイムスタンプ**: 待機する正確な時間。
A **Wait** state delays the execution of the state machine for a specified duration. There are three primary methods to configure the wait time:
```json
"WaitState": {
"Type": "Wait",
"Timestamp": "2024-03-14T01:59:00Z",
"Next": "NextState"
}
```
- **X Seconds**: A fixed number of seconds to wait.
- **動的待機**: **`SecondsPath`**または**`TimestampPath`**を使用して入力に基づく。
```json
"WaitState": {
"Type": "Wait",
"Seconds": 10,
"Next": "NextState"
}
```
- **Absolute Timestamp**: An exact time to wait until.
```json
"WaitState": {
"Type": "Wait",
"Timestamp": "2024-03-14T01:59:00Z",
"Next": "NextState"
}
```
- **Dynamic Wait**: Based on input using **`SecondsPath`** or **`TimestampPath`**.
```json
jsonCopiar código
"WaitState": {
"Type": "Wait",
"TimestampPath": "$.expirydate",
"Next": "NextState"
}
```
```json
jsonCopiar código
"WaitState": {
"Type": "Wait",
"TimestampPath": "$.expirydate",
"Next": "NextState"
}
```
### Parallel
A **Parallel** state allows you to execute multiple branches of tasks concurrently within your workflow. Each branch runs independently and processes its own sequence of states. The execution waits until all branches complete before proceeding to the next state. Its key fields are:
- **Branches**: An array defining the parallel execution paths. Each branch is a separate state machine.
- **ResultPath**: Defines where (in the input) to place the combined output of the branches.
- **Retry and Catch**: Error handling configurations for the parallel state.
**Parallel**ステートは、ワークフロー内で複数のタスクのブランチを同時に実行することを可能にします。各ブランチは独立して実行され、それぞれのステートのシーケンスを処理します。実行は、すべてのブランチが完了するまで待機し、その後次のステートに進みます。主なフィールドは次のとおりです。
- **Branches**: 並列実行パスを定義する配列。各ブランチは別々のステートマシンです。
- **ResultPath**: ブランチの結合出力をどこに(入力内で)配置するかを定義します。
- **Retry and Catch**: 並列ステートのエラーハンドリング設定。
```json
"ParallelState": {
"Type": "Parallel",
"Branches": [
{
"StartAt": "Task1",
"States": { ... }
},
{
"StartAt": "Task2",
"States": { ... }
}
],
"Next": "NextState"
"Type": "Parallel",
"Branches": [
{
"StartAt": "Task1",
"States": { ... }
},
{
"StartAt": "Task2",
"States": { ... }
}
],
"Next": "NextState"
}
```
### Map
**Map** ステートは、データセット内の各アイテムに対して一連のステップを実行することを可能にします。データの並列処理に使用されます。データセットのアイテムをどのように処理したいかに応じて、Step Functions は以下のモードを提供します。
- **Inline Mode**: 各 JSON 配列アイテムに対してステートのサブセットを実行します。40 未満の並列反復を持つ小規模なタスクに適しており、**`Map`** ステートを含むワークフローのコンテキスト内でそれぞれを実行します。
```json
"MapState": {
"Type": "Map",
"ItemsPath": "$.arrayItems",
"ItemProcessor": {
"ProcessorConfig": {
"Mode": "INLINE"
},
"StartAt": "AddState",
"States": {
"AddState": {
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"OutputPath": "$.Payload",
"Parameters": {
"FunctionName": "arn:aws:lambda:<region>:<account-id>:function:add-function"
},
"End": true
}
}
},
"End": true
"ResultPath": "$.detail.added",
"ItemsPath": "$.added"
}
```
### Map
- **Distributed Mode**: 高い同時実行性を持つ大規模な並列処理のために設計されています。Amazon S3 に保存されているような大規模データセットの処理をサポートし、最大 10,000 の並列子ワークフロー実行を高い同時実行性で実行します。これらの子は別の子実行として実行されます。
A **Map** state enables the execution of a set of steps for each item in an dataset. It's used for parallel processing of data. Depending on how you want to process the items of the dataset, Step Functions provides the following modes:
- **Inline Mode**: Executes a subset of states for each JSON array item. Suitable for small-scale tasks with less than 40 parallel iterations, running each of them in the context of the workflow that contains the **`Map`** state.
```json
"MapState": {
"Type": "Map",
"ItemsPath": "$.arrayItems",
"ItemProcessor": {
"ProcessorConfig": {
"Mode": "INLINE"
},
"StartAt": "AddState",
"States": {
"AddState": {
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"OutputPath": "$.Payload",
"Parameters": {
"FunctionName": "arn:aws:lambda:<region>:<account-id>:function:add-function"
},
"End": true
}
}
},
"End": true
"ResultPath": "$.detail.added",
"ItemsPath": "$.added"
}
```
- **Distributed Mode**: Designed for large-scale parallel processing with high concurrency. Supports processing large datasets, such as those stored in Amazon S3, enabling a high concurrency of up 10,000 parallel child workflow executions, running these child as a separate child execution.
```json
"DistributedMapState": {
"Type": "Map",
"ItemReader": {
"Resource": "arn:aws:states:::s3:getObject",
"Parameters": {
"Bucket": "my-bucket",
"Key": "data.csv"
}
},
"ItemProcessor": {
"ProcessorConfig": {
"Mode": "DISTRIBUTED",
"ExecutionType": "EXPRESS"
},
"StartAt": "ProcessItem",
"States": {
"ProcessItem": {
"Type": "Task",
"Resource": "arn:aws:lambda:region:account-id:function:my-function",
"End": true
}
}
},
"End": true
"ResultWriter": {
"Resource": "arn:aws:states:::s3:putObject",
"Parameters": {
"Bucket": "myOutputBucket",
"Prefix": "csvProcessJobs"
}
}
}
```
```json
"DistributedMapState": {
"Type": "Map",
"ItemReader": {
"Resource": "arn:aws:states:::s3:getObject",
"Parameters": {
"Bucket": "my-bucket",
"Key": "data.csv"
}
},
"ItemProcessor": {
"ProcessorConfig": {
"Mode": "DISTRIBUTED",
"ExecutionType": "EXPRESS"
},
"StartAt": "ProcessItem",
"States": {
"ProcessItem": {
"Type": "Task",
"Resource": "arn:aws:lambda:region:account-id:function:my-function",
"End": true
}
}
},
"End": true
"ResultWriter": {
"Resource": "arn:aws:states:::s3:putObject",
"Parameters": {
"Bucket": "myOutputBucket",
"Prefix": "csvProcessJobs"
}
}
}
```
### Versions and aliases
Step Functions also lets you manage workflow deployments through **versions** and **aliases** of state machines. A version represents a snapshot of a state machine that can be executed. Aliases serve as pointers to up to two versions of a state machine.
Step Functions は、**バージョン** と **エイリアス** を通じてワークフローデプロイメントを管理することもできます。バージョンは、実行可能なステートマシンのスナップショットを表します。エイリアスは、ステートマシンの最大 2 つのバージョンへのポインタとして機能します。
- **Versions**: These immutable snapshots of a state machine are created from the most recent revision of that state machine. Each version is identified by a unique ARN that combines the state machine ARN with the version number, separated by a colon (**`arn:aws:states:region:account-id:stateMachine:StateMachineName:version-number`**). Versions cannot be edited, but you can update the state machine and publish a new version, or use the desired state machine version.
- **Aliases**: These pointers can reference up to two versions of the same state machine. Multiple aliases can be created for a single state machine, each identified by a unique ARN constructed by combining the state machine ARN with the alias name, separated by a colon (**`arn:aws:states:region:account-id:stateMachine:StateMachineName:aliasName`**). Aliases enable routing of traffic between one of the two versions of a state machine. Alternatively, an alias can point to a single specific version of the state machine, but not to other aliases. They can be updated to redirect to a different version of the state machine as needed, facilitating controlled deployments and workflow management.
- **Versions**: これらの不変のステートマシンのスナップショットは、そのステートマシンの最新のリビジョンから作成されます。各バージョンは、ステートマシン ARN とバージョン番号をコロンで区切って組み合わせた一意の ARN によって識別されます (**`arn:aws:states:region:account-id:stateMachine:StateMachineName:version-number`**)。バージョンは編集できませんが、ステートマシンを更新して新しいバージョンを公開するか、希望するステートマシンバージョンを使用できます。
- **Aliases**: これらのポインタは、同じステートマシンの最大 2 つのバージョンを参照できます。単一のステートマシンに対して複数のエイリアスを作成でき、それぞれはステートマシン ARN とエイリアス名をコロンで区切って組み合わせた一意の ARN によって識別されます (**`arn:aws:states:region:account-id:stateMachine:StateMachineName:aliasName`**)。エイリアスは、ステートマシンの 2 つのバージョンのいずれかの間でトラフィックをルーティングすることを可能にします。あるいは、エイリアスはステートマシンの特定のバージョンを指すことができますが、他のエイリアスには指しません。必要に応じて、異なるバージョンのステートマシンにリダイレクトするように更新でき、制御されたデプロイメントとワークフロー管理を促進します。
For more detailed information about **ASL**, check: [**Amazon States Language**](https://states-language.net/spec.html).
**ASL** に関する詳細情報については、次を確認してください: [**Amazon States Language**](https://states-language.net/spec.html)。
## IAM Roles for State machines
AWS Step Functions utilizes AWS Identity and Access Management (IAM) roles to control access to resources and actions within state machines. Here are the key aspects related to security and IAM roles in AWS Step Functions:
AWS Step Functions は、AWS Identity and Access Management (IAM) ロールを利用して、ステートマシン内のリソースとアクションへのアクセスを制御します。AWS Step Functions におけるセキュリティと IAM ロールに関連する重要な側面は以下の通りです。
- **Execution Role**: Each state machine in AWS Step Functions is associated with an IAM execution role. This role defines what actions the state machine can perform on your behalf. When a state machine transitions between states that interact with AWS services (like invoking Lambda functions, accessing DynamoDB, etc.), it assumes this execution role to carry out those actions.
- **Permissions**: The IAM execution role must be configured with permissions that allow the necessary actions on other AWS services. For example, if your state machine needs to invoke AWS Lambda functions, the IAM role must have **`lambda:InvokeFunction`** permissions. Similarly, if it needs to write to DynamoDB, appropriate permissions (**`dynamodb:PutItem`**, **`dynamodb:UpdateItem`**, etc.) must be granted.
- **Execution Role**: AWS Step Functions の各ステートマシンは IAM 実行ロールに関連付けられています。このロールは、ステートマシンがあなたの代わりに実行できるアクションを定義します。ステートマシンが AWS サービスと相互作用するステート間を遷移する際Lambda 関数の呼び出し、DynamoDB へのアクセスなど)、この実行ロールを引き受けてそれらのアクションを実行します。
- **Permissions**: IAM 実行ロールは、他の AWS サービスに対する必要なアクションを許可する権限で構成する必要があります。たとえば、ステートマシンが AWS Lambda 関数を呼び出す必要がある場合、IAM ロールには **`lambda:InvokeFunction`** 権限が必要です。同様に、DynamoDB に書き込む必要がある場合、適切な権限 (**`dynamodb:PutItem`**, **`dynamodb:UpdateItem`** など) を付与する必要があります。
## Enumeration
ReadOnlyAccess policy is enough for all the following enumeration actions.
ReadOnlyAccess ポリシーは、以下のすべての列挙アクションに対して十分です。
```bash
# State machines #
@@ -310,35 +297,30 @@ aws stepfunctions describe-map-run --map-run-arn <value>
## Lists executions of a Map Run
aws stepfunctions list-executions --map-run-arn <value> [--status-filter <RUNNING | SUCCEEDED | FAILED | TIMED_OUT | ABORTED | PENDING_REDRIVE>] [--redrive-filter <REDRIVEN | NOT_REDRIVEN>]
```
## プライベートエスカレーション
## Privesc
In the following page, you can check how to **abuse Step Functions permissions to escalate privileges**:
次のページでは、**Step Functionsの権限を悪用して特権を昇格させる方法**を確認できます:
{{#ref}}
../aws-privilege-escalation/aws-stepfunctions-privesc.md
{{#endref}}
## Post Exploitation
## ポストエクスプロイテーション
{{#ref}}
../aws-post-exploitation/aws-stepfunctions-post-exploitation.md
{{#endref}}
## Persistence
## 永続性
{{#ref}}
../aws-persistence/aws-step-functions-persistence.md
{{#endref}}
## References
## 参考文献
- [https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsstepfunctions.html](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsstepfunctions.html)
- [https://docs.aws.amazon.com/step-functions/latest/dg/welcome.html](https://docs.aws.amazon.com/step-functions/latest/dg/welcome.html)
- [https://states-language.net/spec.html](https://states-language.net/spec.html)
{{#include ../../../banners/hacktricks-training.md}}