AWS - EMR Privesc

支持HackTricks

EMR

有关EMR的更多信息,请参阅:

AWS - EMR Enum

iam:PassRoleelasticmapreduce: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角色,在InstanceProfile中的--ec2-attributes中指定了ec2角色。然而,这种技术只允许窃取EC2角色凭证(因为您将通过ssh连接),而不是EMR IAM角色。

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

elasticmapreduce:CreateEditoriam:ListRoleselasticmapreduce:ListClustersiam:PassRoleelasticmapreduce:DescribeEditorelasticmapreduce:OpenEditorInConsole

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

即使您在笔记本实例中附加了IAM角色,在我的测试中我注意到我能够窃取AWS托管凭证,而不是与IAM角色相关的凭证。

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

elasticmapreduce:OpenEditorInConsole

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

即使您在笔记本实例中附加了IAM角色,在我的测试中我注意到我能够窃取AWS托管凭证,而不是与IAM角色相关的凭证。

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

支持HackTricks

Last updated