GCP - Cloud Functions Enum

Reading time: 4 minutes

tip

AWS 해킹 배우기 및 연습하기:HackTricks Training AWS Red Team Expert (ARTE)
GCP 해킹 배우기 및 연습하기: HackTricks Training GCP Red Team Expert (GRTE) Azure 해킹 배우기 및 연습하기: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks 지원하기

Cloud Functions

Google Cloud Functions이벤트에 대한 응답으로 실행되는 코드를 호스팅하도록 설계되었으며, 호스트 운영 체제를 관리할 필요가 없습니다. 또한, 이러한 함수는 코드에서 사용할 수 있는 환경 변수를 저장하는 것을 지원합니다.

Storage

Cloud Functions의 코드는 GCP Storage에 저장됩니다. 따라서 GCP의 버킷에 대한 읽기 권한이 있는 사람은 Cloud Functions 코드를 읽을 수 있습니다.
코드는 다음과 같은 버킷에 저장됩니다:

  • gcf-sources-<number>-<region>/<function-name>-<uuid>/version-<n>/function-source.zip
  • gcf-v2-sources-<number>-<region>/<function-name>function-source.zip

예를 들어:
gcf-sources-645468741258-us-central1/function-1-003dcbdf-32e1-430f-a5ff-785a6e238c76/version-4/function-source.zip

warning

Cloud Function을 저장하는 버킷에 대한 읽기 권한이 있는 사용자는 실행된 코드를 읽을 수 있습니다.

Artifact Registry

클라우드 함수가 실행된 Docker 컨테이너가 프로젝트 내의 Artifact Registry 리포지토리에 저장되도록 구성된 경우, 리포지토리에 대한 읽기 권한이 있는 사람은 이미지를 다운로드하고 소스 코드를 확인할 수 있습니다. 자세한 내용은 다음을 확인하세요:

GCP - Artifact Registry Enum

SA

지정되지 않은 경우 기본적으로 프로젝트에 대한 Editor 권한을 가진 App Engine Default Service Account가 Cloud Function에 연결됩니다.

Triggers, URL & Authentication

Cloud Function이 생성될 때 트리거를 지정해야 합니다. 일반적인 트리거 중 하나는 HTTPS로, 이는 웹 브라우징을 통해 함수를 트리거할 수 있는 URL을 생성합니다.
다른 트리거로는 pub/sub, Storage, Filestore 등이 있습니다...

URL 형식은 **https://<region>-<project-gcp-name>.cloudfunctions.net/<func_name>**입니다.

HTTPS 트리거가 사용될 때, 호출자가 Function을 호출하기 위해 IAM 권한이 필요한지 또는 모두가 호출할 수 있는지도 표시됩니다:

Inside the Cloud Function

코드는 /workspace 폴더 내에 다운로드되며, Cloud Function의 파일과 동일한 파일 이름을 가지고 있으며, 사용자 www-data로 실행됩니다.
디스크는 읽기 전용으로 마운트되지 않습니다.

Enumeration

bash
# List functions
gcloud functions list
gcloud functions describe <func_name> # Check triggers to see how is this function invoked
gcloud functions get-iam-policy <func_name>

# Get logs of previous runs. By default, limits to 10 lines
gcloud functions logs read <func_name> --limit [NUMBER]

# Call a function
curl https://<region>-<project>.cloudfunctions.net/<func_name>
gcloud functions call <func_name> --data='{"message": "Hello World!"}'

# If you know the name of projects you could try to BF cloud functions names

# Get events that could be used to trigger a cloud function
gcloud functions event-types list

# Access function with authentication
curl -X POST https://<region>-<project>.cloudfunctions.net/<func_name> \
-H "Authorization: bearer $(gcloud auth print-identity-token)" \
-H "Content-Type: application/json" \
-d '{}'

권한 상승

다음 페이지에서 클라우드 기능 권한을 악용하여 권한을 상승시키는 방법을 확인할 수 있습니다:

GCP - Cloudfunctions Privesc

인증되지 않은 접근

GCP - Cloud Functions Unauthenticated Enum

포스트 익스플로잇

GCP - Cloud Functions Post Exploitation

지속성

GCP - Cloud Functions Persistence

참고문헌

tip

AWS 해킹 배우기 및 연습하기:HackTricks Training AWS Red Team Expert (ARTE)
GCP 해킹 배우기 및 연습하기: HackTricks Training GCP Red Team Expert (GRTE) Azure 해킹 배우기 및 연습하기: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks 지원하기