GCP - Artifact Registry Privesc

htARTE (HackTricks AWS Red Team Expert)를 통해 AWS 해킹을 처음부터 전문가까지 배워보세요!

HackTricks를 지원하는 다른 방법:

Artifact Registry

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

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

이미 존재하는 동일한 이름과 태그를 가진 악성 도커 이미지를 업로드할 수 있는 것을 확인했습니다. 따라서 이전 이미지는 태그를 잃게 되고, 해당 태그로 이미지를 다운로드할 때 악성 이미지가 다운로드됩니다.

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

이미 존재하는 버전과 동일한 파이썬 라이브러리를 업로드하는 것은 불가능하지만, 더 높은 버전을 업로드하거나 (또는 버전 끝에 .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
  • 원격 및 표준 레지스트리가 가상 레지스트리에 혼합되고 패키지가 둘 다 존재하는 경우에는 어떻게 될까요? 이 페이지를 확인하세요:

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

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

htARTE (HackTricks AWS Red Team Expert)를 통해 제로에서 영웅까지 AWS 해킹을 배워보세요!

HackTricks를 지원하는 다른 방법:

最終更新