GCP - Artifact Registry Privesc

Support HackTricks

Artifact Registry

Artifact Registry에 대한 자세한 정보는 다음을 확인하세요:

GCP - Artifact Registry Enum

artifactregistry.repositories.uploadArtifacts

이 권한을 가진 공격자는 Docker 이미지와 같은 악성 코드가 포함된 새로운 artifact 버전을 업로드할 수 있습니다:

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

동일한 이름과 태그를 가진 새로운 악성 도커 이미지를 업로드할 수 있는 것을 확인했으므로, 이전 이미지는 태그를 잃게 되고 해당 태그가 있는 이미지를 다음으로 다운로드할 때 악성 이미지가 다운로드됩니다.

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의 인증 구성 (패키지를 업로드하는 데 사용됨):

  • twine이 설치되어 있는지 확인합니다 (pip 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을 추가하여 작동하는 경우 - Python에서는 작동하지 않음-), 또는 마지막 버전을 삭제하고 새로운 버전을 업로드할 수 있습니다(필요한 artifactregistry.versions.delete):

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

artifactregistry.repositories.downloadArtifacts

이 권한을 사용하면 아티팩트를 다운로드하고 민감한 정보취약점을 검색할 수 있습니다.

도커 이미지를 다운로드하세요:

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

파이썬 라이브러리를 다운로드하세요:

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.delete, artifactregistry.versions.delete, artifactregistry.packages.delete, (artifactregistry.repositories.get, artifactregistry.tags.get, artifactregistry.tags.list)

도커 이미지와 같은 레지스트리에서 아티팩트를 삭제합니다:

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

artifactregistry.repositories.delete

전체 저장소를 삭제합니다 (내용이 있더라도):

gcloud artifacts repositories delete <repo-name> --location=<location>

artifactregistry.repositories.setIamPolicy

이 권한을 가진 공격자는 이전에 언급된 저장소 공격 중 일부를 수행할 수 있는 권한을 부여할 수 있습니다.

HackTricks 지원

Last updated