GCP - Cloud Functions Enum

htARTE (HackTricks AWS Red Team Expert)에서 AWS 해킹을 처음부터 전문가까지 배우세요!

HackTricks를 지원하는 다른 방법:

Cloud Functions

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

저장소

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

gcf-sources-<number>-<region>/<function-name>-<uuid>/version-<n>/function-source.zip 예시: gcf-sources-645468741258-us-central1/function-1-003dcbdf-32e1-430f-a5ff-785a6e238c76/version-4/function-source.zip

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

SA

지정되지 않은 경우, 기본적으로 App Engine Default Service Account가 Cloud Function에 부착되며 프로젝트에 대한 Editor 권한이 있습니다.

트리거, URL 및 인증

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

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

HTTPS 트리거를 사용할 때, 호출자가 함수를 호출할 때 IAM 권한이 필요한지 또는 모두가 호출할 수 있는지도 나와 있습니다:

Cloud Function 내부

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

열거

# 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 '{}'

권한 상승

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

pageGCP - Cloudfunctions Privesc

인증되지 않은 액세스

pageGCP - Cloud Functions Unauthenticated Enum

사후 공격

pageGCP - Cloud Functions Post Exploitation

지속성

pageGCP - Cloud Functions Persistence

참고 자료

htARTE (HackTricks AWS Red Team Expert)를 통해 제로부터 영웅이 될 때까지 AWS 해킹을 배우세요!

HackTricks를 지원하는 다른 방법:

最終更新