AWS - Step Functions Enum

Support HackTricks

Step Functions

AWS Step Functions एक वर्कफ़्लो सेवा है जो आपको कई AWS सेवाओं को सर्वरलेस वर्कफ़्लो में समन्वयित और व्यवस्थित करने की अनुमति देती है। AWS Step Functions का उपयोग करके, आप विभिन्न AWS सेवाओं जैसे AWS Lambda, Amazon S3, Amazon DynamoDB, और कई अन्य को एक क्रम में जोड़ने वाले वर्कफ़्लो को डिज़ाइन और चलाने के लिए कर सकते हैं। यह ऑर्केस्ट्रेशन सेवा एक दृश्य वर्कफ़्लो इंटरफ़ेस प्रदान करती है और स्टेट मशीन क्षमताएँ प्रदान करती है, जिससे आप JSON-आधारित Amazon States Language (ASL) का उपयोग करके वर्कफ़्लो के प्रत्येक चरण को घोषणात्मक तरीके से परिभाषित कर सकते हैं।

Key concepts

Standard vs. Express Workflows

AWS Step Functions दो प्रकार के स्टेट मशीन वर्कफ़्लो प्रदान करता है: Standard और Express।

  • Standard Workflow: यह डिफ़ॉल्ट वर्कफ़्लो प्रकार लंबे समय तक चलने वाली, टिकाऊ, और ऑडिट करने योग्य प्रक्रियाओं के लिए डिज़ाइन किया गया है। यह exactly-once execution का समर्थन करता है, यह सुनिश्चित करते हुए कि कार्य केवल एक बार चलते हैं जब तक कि पुनः प्रयास निर्दिष्ट न किए जाएं। यह उन वर्कफ़्लो के लिए आदर्श है जिन्हें विस्तृत निष्पादन इतिहास की आवश्यकता होती है और यह एक वर्ष तक चल सकता है।

  • Express Workflow: यह प्रकार उच्च मात्रा, छोटे समयावधि के कार्यों के लिए आदर्श है, जो पांच मिनट तक चलते हैं। वे at-least-once execution का समर्थन करते हैं, जो डेटा प्रोसेसिंग जैसे idempotent कार्यों के लिए उपयुक्त है। ये वर्कफ़्लो लागत और प्रदर्शन के लिए अनुकूलित होते हैं, निष्पादन, अवधि, और मेमोरी उपयोग के आधार पर चार्ज करते हैं।

States

States स्टेट मशीनों के आवश्यक इकाइयाँ हैं। वे वर्कफ़्लो के भीतर व्यक्तिगत चरणों को परिभाषित करते हैं, जो इसके प्रकार के आधार पर विभिन्न कार्य कर सकते हैं:

  • Task: एक कार्य को निष्पादित करता है, अक्सर AWS सेवा जैसे Lambda का उपयोग करते हुए।

  • Choice: इनपुट के आधार पर निर्णय लेता है।

  • Fail/Succeed: निष्पादन को विफलता या सफलता के साथ समाप्त करता है।

  • Pass: इनपुट को आउटपुट में पास करता है या डेटा को इंजेक्ट करता है।

  • Wait: सेट समय के लिए निष्पादन में देरी करता है।

  • Parallel: समानांतर शाखाएँ आरंभ करता है।

  • Map: आइटम पर चरणों को गतिशील रूप से दोहराता है।

Task

एक Task स्टेट एक स्टेट मशीन द्वारा निष्पादित कार्य की एकल इकाई का प्रतिनिधित्व करता है। कार्य विभिन्न संसाधनों को आमंत्रित कर सकते हैं, जिसमें गतिविधियाँ, Lambda फ़ंक्शन, AWS सेवाएँ, या तृतीय-पक्ष APIs शामिल हैं।

  • Activities: कस्टम श्रमिक जिन्हें आप प्रबंधित करते हैं, लंबे समय तक चलने वाली प्रक्रियाओं के लिए उपयुक्त।

  • Resource: arn:aws:states:region:account:activity:name.

  • Lambda Functions: AWS Lambda फ़ंक्शंस को निष्पादित करता है।

  • Resource: arn:aws:lambda:region:account:function:function-name.

  • AWS Services: अन्य AWS सेवाओं के साथ सीधे एकीकृत करता है, जैसे DynamoDB या S3।

  • Resource: arn:partition:states:region:account:servicename:APIname.

  • HTTP Task: तृतीय-पक्ष APIs को कॉल करता है।

  • Resource field: arn:aws:states:::http:invoke. फिर, आपको API एंडपॉइंट कॉन्फ़िगरेशन विवरण प्रदान करना चाहिए, जैसे API URL, विधि, और प्रमाणीकरण विवरण।

The following example shows a Task state definition that invokes a Lambda function called HelloWorld:

"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: 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 don't support the End field, instead, they define the Next state to transition to if the comparison is true.

Example of Choice state:

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

Fail/Succeed

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.

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

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

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

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

Enumeration

ReadOnlyAccess नीति सभी निम्नलिखित enumeration क्रियाओं के लिए पर्याप्त है।

# 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

In the following page, you can check how to Step Functions अनुमतियों का दुरुपयोग करके विशेषाधिकार बढ़ाना:

AWS - Step Functions Privesc

Post Exploitation

AWS - Step Functions Post Exploitation

Persistence

AWS - Step Functions Persistence

References

Support HackTricks

Last updated