AWS - Step Functions Enum

Support HackTricks

Step Functions

AWS Step Functions는 여러 AWS 서비스를 서버리스 워크플로로 조정하고 오케스트레이션할 수 있는 워크플로 서비스입니다. AWS Step Functions를 사용하면 AWS Lambda, Amazon S3, Amazon DynamoDB 등 다양한 AWS 서비스를 연결하는 워크플로를 설계하고 실행할 수 있습니다. 이 오케스트레이션 서비스는 시각적 워크플로 인터페이스를 제공하며, 각 워크플로의 단계를 JSON 기반의 Amazon States Language (ASL)를 사용하여 선언적으로 정의할 수 있는 상태 머신 기능을 제공합니다.

Key concepts

Standard vs. Express Workflows

AWS Step Functions는 두 가지 유형의 상태 머신 워크플로를 제공합니다: Standard와 Express.

  • Standard Workflow: 이 기본 워크플로 유형은 장기 실행, 내구성 및 감사 가능한 프로세스를 위해 설계되었습니다. 정확히 한 번 실행을 지원하여, 재시도가 지정되지 않는 한 작업이 한 번만 실행되도록 보장합니다. 자세한 실행 기록이 필요한 워크플로에 적합하며 최대 1년 동안 실행할 수 있습니다.

  • Express Workflow: 이 유형은 고용량, 단기 작업에 적합하며 최대 5분 동안 실행됩니다. 최소 한 번 실행을 지원하며, 데이터 처리와 같은 멱등 작업에 적합합니다. 이러한 워크플로는 비용과 성능을 최적화하여 실행, 지속 시간 및 메모리 사용량에 따라 요금이 부과됩니다.

States

상태는 상태 머신의 필수 단위입니다. 상태는 워크플로 내의 개별 단계를 정의하며, 유형에 따라 다양한 기능을 수행할 수 있습니다:

  • Task: 작업을 실행하며, 종종 Lambda와 같은 AWS 서비스를 사용합니다.

  • Choice: 입력에 따라 결정을 내립니다.

  • Fail/Succeed: 실패 또는 성공으로 실행을 종료합니다.

  • Pass: 입력을 출력으로 전달하거나 데이터를 주입합니다.

  • Wait: 설정된 시간 동안 실행을 지연시킵니다.

  • Parallel: 병렬 분기를 시작합니다.

  • Map: 항목에 대해 단계를 동적으로 반복합니다.

Task

Task 상태는 상태 머신에 의해 실행되는 단일 작업 단위를 나타냅니다. 작업은 활동, Lambda 함수, AWS 서비스 또는 타사 API를 포함한 다양한 리소스를 호출할 수 있습니다.

  • 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 상태 정의를 보여줍니다:

"HelloWorld": {
"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.

  • Comparison: 각 선택 규칙에는 입력 변수를 지정된 값 또는 다른 변수와 비교하는 비교 연산자(예: NumericEquals, StringEquals)가 포함됩니다.

  • Next Field: Choice 상태는 End 필드를 지원하지 않으며, 대신 비교가 참일 경우 전환할 Next 상태를 정의합니다.

Example of Choice state:

{
"Variable": "$.timeStamp",
"TimestampEquals": "2000-01-01T00:00:00Z",
"Next": "TimeState"
}

Fail/Succeed

Fail 상태는 상태 기계의 실행을 중지하고 이를 실패로 표시합니다. 이는 오류 이름과 원인을 지정하는 데 사용되며, 실패에 대한 세부 정보를 제공합니다. 이 상태는 단말 상태로, 실행 흐름을 종료합니다.

Succeed 상태는 실행을 성공적으로 중지합니다. 이는 일반적으로 워크플로우가 성공적으로 완료될 때 종료하는 데 사용됩니다. 이 상태는 Next 필드를 필요로 하지 않습니다.

"FailState": {
"Type": "Fail",
"Error": "ErrorName",
"Cause": "Error details"
}

Pass

Pass 상태는 작업을 수행하지 않거나 JSON 상태 입력을 필터를 사용하여 변환한 후 변환된 데이터를 다음 상태로 전달하여 입력을 출력으로 전달합니다. 이는 상태 머신을 테스트하고 구성하는 데 유용하며, 정적 데이터를 주입하거나 변환할 수 있습니다.

"PassState": {
"Type": "Pass",
"Result": {"key": "value"},
"ResultPath": "$.newField",
"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:

  • X Seconds: 대기할 고정 초 수.

"WaitState": {
"Type": "Wait",
"Seconds": 10,
"Next": "NextState"
}
  • Absolute Timestamp: 대기할 정확한 시간.

"WaitState": {
"Type": "Wait",
"Timestamp": "2024-03-14T01:59:00Z",
"Next": "NextState"
}
  • Dynamic Wait: SecondsPath 또는 **TimestampPath**를 사용하여 입력에 따라 결정됨.

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: 병렬 실행 경로를 정의하는 배열. 각 브랜치는 별도의 상태 머신입니다.

  • ResultPath: 브랜치의 결합된 출력을 어디에 (입력에서) 배치할지를 정의합니다.

  • Retry and Catch: 병렬 상태에 대한 오류 처리 구성입니다.

"ParallelState": {
"Type": "Parallel",
"Branches": [
{
"StartAt": "Task1",
"States": { ... }
},
{
"StartAt": "Task2",
"States": { ... }
}
],
"Next": "NextState"
}

Map

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: 각 JSON 배열 항목에 대해 상태의 하위 집합을 실행합니다. 40개 미만의 병렬 반복이 있는 소규모 작업에 적합하며, Map 상태를 포함하는 워크플로우의 맥락에서 각 작업을 실행합니다.

"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: 높은 동시성을 가진 대규모 병렬 처리를 위해 설계되었습니다. Amazon S3에 저장된 대량의 데이터 세트를 처리할 수 있으며, 최대 10,000개의 병렬 자식 워크플로우 실행을 지원합니다. 이 자식들은 별도의 자식 실행으로 실행됩니다.

"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.

  • Versions: 이러한 불변 스냅샷은 해당 상태 기계의 가장 최근 수정본에서 생성됩니다. 각 버전은 상태 기계 ARN과 버전 번호를 콜론으로 구분하여 결합한 고유 ARN으로 식별됩니다 (arn:aws:states:region:account-id:stateMachine:StateMachineName:version-number). 버전은 편집할 수 없지만, 상태 기계를 업데이트하고 새 버전을 게시하거나 원하는 상태 기계 버전을 사용할 수 있습니다.

  • Aliases: 이러한 포인터는 동일한 상태 기계의 최대 두 버전을 참조할 수 있습니다. 단일 상태 기계에 대해 여러 개의 별칭을 생성할 수 있으며, 각 별칭은 상태 기계 ARN과 별칭 이름을 콜론으로 구분하여 결합한 고유 ARN으로 식별됩니다 (arn:aws:states:region:account-id:stateMachine:StateMachineName:aliasName). 별칭은 상태 기계의 두 버전 중 하나 간의 트래픽 라우팅을 가능하게 합니다. 또는 별칭은 상태 기계의 특정 버전을 가리킬 수 있지만 다른 별칭을 가리킬 수는 없습니다. 필요에 따라 다른 버전의 상태 기계로 리디렉션하도록 업데이트할 수 있어, 제어된 배포 및 워크플로우 관리를 용이하게 합니다.

For more detailed information about ASL, check: Amazon States Language.

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:

  • 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.

# State machines #

## List state machines
aws stepfunctions list-state-machines
## Retrieve informatio about the specified state machine
aws stepfunctions describe-state-machine --state-machine-arn <value>

## List versions for the specified state machine
aws stepfunctions list-state-machine-versions --state-machine-arn <value>
## List aliases for the specified state machine
aws stepfunctions list-state-machine-aliases --state-machine-arn <value>
## Retrieve information about the specified state machine alias
aws stepfunctions describe-state-machine-alias --state-machine-alias-arn <value>

## List executions of a state machine
aws stepfunctions list-executions --state-machine-arn <value> [--status-filter <RUNNING | SUCCEEDED | FAILED | TIMED_OUT | ABORTED | PENDING_REDRIVE>] [--redrive-filter <REDRIVEN | NOT_REDRIVEN>]
## Retrieve information and relevant metadata about a state machine execution (output included)
aws stepfunctions describe-execution --execution-arn <value>
## Retrieve information about the state machine associated to the specified execution
aws stepfunctions describe-state-machine-for-execution --execution-arn <value>
## Retrieve the history of the specified execution as a list of events
aws stepfunctions get-execution-history --execution-arn <value> [--reverse-order | --no-reverse-order] [--include-execution-data | --no-include-execution-data]

## List tags for the specified step Functions resource
aws stepfunctions list-tags-for-resource --resource-arn <value>

## Validate the definition of a state machine without creating the resource
aws stepfunctions validate-state-machine-definition --definition <value> [--type <STANDARD | EXPRESS>]

# Activities #

## List existing activities
aws stepfunctions list-activities
## Retrieve information about the specified activity
aws stepfunctions describe-activity --activity-arn <value>

# Map Runs #

## List map runs of an execution
aws stepfunctions list-map-runs --execution-arn <value>
## Provide information about the configuration, progress and results of a Map Run
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

다음 페이지에서 Step Functions 권한을 악용하여 권한 상승하는 방법을 확인할 수 있습니다:

AWS - Step Functions Privesc

Post Exploitation

AWS - Step Functions Post Exploitation

Persistence

AWS - Step Functions Persistence

References

HackTricks 지원하기

Last updated