GCP - Artifact Registry Privesc

支持HackTricks

Artifact Registry

有关Artifact Registry的更多信息,请查看:

GCP - Artifact Registry Enum

artifactregistry.repositories.uploadArtifacts

具有此权限的攻击者可以上传带有恶意代码的新版本的工件,如Docker镜像:

# Configure docker to use gcloud to authenticate with Artifact Registry
gcloud auth configure-docker <location>-docker.pkg.dev

# tag the image to upload it
docker tag <local-img-name>:<local-tag> <location>-docker.pkg.dev/<proj-name>/<repo-name>/<img-name>:<tag>

# Upload it
docker push <location>-docker.pkg.dev/<proj-name>/<repo-name>/<img-name>:<tag>

已经检查过,可以上传一个新的恶意docker镜像,与已经存在的同名和标签相同,因此旧的镜像将失去标签,下次下载带有该标签的镜像时,将会下载恶意镜像

上传一个Python库

首先创建要上传的库(如果可以从注册表中下载最新版本,则可以跳过此步骤):

  1. 设置项目结构

  • 为您的库创建一个新目录,例如 hello_world_library

  • 在此目录内,创建另一个目录,使用您的包名称,例如 hello_world

  • 在您的包目录内,创建一个 __init__.py 文件。此文件可以为空,也可以包含对您的包的初始化。

mkdir hello_world_library
cd hello_world_library
mkdir hello_world
touch hello_world/__init__.py
  1. 编写您的库代码

  • hello_world 目录内,为您的模块创建一个新的Python文件,例如 greet.py

  • 编写您的“Hello, World!”函数:

# hello_world/greet.py
def say_hello():
return "Hello, World!"
  1. 创建一个 setup.py 文件

  • 在您的 hello_world_library 目录的根目录中,创建一个 setup.py 文件。

  • 此文件包含有关您的库的元数据,并告诉Python如何安装它。

# setup.py
from setuptools import setup, find_packages

setup(
name='hello_world',
version='0.1',
packages=find_packages(),
install_requires=[
# 您的库需要的任何依赖项
],
)

现在,让我们上传库:

  1. 构建您的包

  • 从您的 hello_world_library 目录的根目录运行:

python3 setup.py sdist bdist_wheel
  1. 为 twine 配置身份验证(用于上传您的包):

  • 确保已安装 twinepip install twine)。

  • 使用 gcloud 配置凭据:

twine upload --username 'oauth2accesstoken' --password "$(gcloud auth print-access-token)" --repository-url https://<location>-python.pkg.dev/<project-id>/<repo-name>/ dist/*
  1. 清理构建

rm -rf dist build hello_world.egg-info

无法上传与已存在版本相同的Python库,但可以上传更高版本(或在版本末尾添加额外的**.0(如果适用的话),或者删除最后一个版本并上传一个新版本**(需要artifactregistry.versions.delete)

gcloud artifacts versions delete <version> --repository=<repo-name> --location=<location> --package=<lib-name>

artifactregistry.repositories.downloadArtifacts

拥有此权限,您可以下载工件并搜索敏感信息漏洞

下载一个Docker镜像:

# Configure docker to use gcloud to authenticate with Artifact Registry
gcloud auth configure-docker <location>-docker.pkg.dev

# Dowload image
docker pull <location>-docker.pkg.dev/<proj-name>/<repo-name>/<img-name>:<tag>

下载一个 python 库:

pip install <lib-name> --index-url "https://oauth2accesstoken:$(gcloud auth print-access-token)@<location>-python.pkg.dev/<project-id>/<repo-name>/simple/" --trusted-host <location>-python.pkg.dev --no-cache-dir
  • 如果在虚拟存储库中混合了远程存储库和标准存储库,并且一个软件包同时存在于两者中会发生什么?请查看此页面:

GCP - Artifact Registry Persistence

artifactregistry.tags.deleteartifactregistry.versions.deleteartifactregistry.packages.delete、(artifactregistry.repositories.getartifactregistry.tags.getartifactregistry.tags.list)

从存储库中删除工件,如 Docker 镜像:

# Delete a docker image
gcloud artifacts docker images delete <location>-docker.pkg.dev/<proj-name>/<repo-name>/<img-name>:<tag>

artifactregistry.repositories.setIamPolicy

拥有此权限的攻击者可以给自己授予权限,以执行先前提到的一些存储库攻击。

支持HackTricks

Last updated