GCP - AppEngine Privesc

HackTricks 지원하기

App Engine

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

GCP - App Engine Enum

appengine.applications.get, appengine.instances.get, appengine.instances.list, appengine.operations.get, appengine.operations.list, appengine.services.get, appengine.services.list, appengine.versions.create, appengine.versions.get, appengine.versions.list, cloudbuild.builds.get,iam.serviceAccounts.actAs, resourcemanager.projects.get, storage.objects.create, storage.objects.list

이것들은 gcloud cli를 사용하여 App을 배포하기 위해 필요한 권한입니다. 아마도 getlist 권한은 피할 수 있을 것입니다.

https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/appengine에서 python 코드 예제를 찾을 수 있습니다.

기본적으로, App 서비스의 이름은 **default**가 될 것이며, 동일한 이름을 가진 인스턴스는 하나만 있을 수 있습니다. 이를 변경하고 두 번째 App을 만들려면, **app.yaml**에서 루트 키의 값을 **service: my-second-app**와 같이 변경하세요.

cd python-docs-samples/appengine/flexible/hello_world
gcloud app deploy #Upload and start application inside the folder

적어도 10-15분 정도 기다리세요. 작동하지 않으면 여러 번 배포를 호출하고 몇 분 더 기다리세요.

사용할 서비스 계정을 지정할 수 있습니다만 기본적으로 App Engine 기본 SA가 사용됩니다.

애플리케이션의 URL은 https://<proj-name>.oa.r.appspot.com/ 또는 https://<service_name>-dot-<proj-name>.oa.r.appspot.com와 같습니다.

동등한 권한 업데이트

AppEngine을 업데이트할 수 있는 충분한 권한이 있지만 새로 만들 권한이 없는 경우, 현재 App Engine을 업데이트하는 방법은 다음과 같습니다:

# Find the code of the App Engine in the buckets
gsutil ls

# Download code
mkdir /tmp/appengine2
cd /tmp/appengine2
## In this case it was found in this custom bucket but you could also use the
## buckets generated when the App Engine is created
gsutil cp gs://appengine-lab-1-gcp-labs-4t04m0i6-3a97003354979ef6/labs_appengine_1_premissions_privesc.zip .
unzip labs_appengine_1_premissions_privesc.zip

## Now modify the code..

## If you don't have an app.yaml, create one like:
cat >> app.yaml <<EOF
runtime: python312

entrypoint: gunicorn -b :\$PORT main:app

env_variables:
A_VARIABLE: "value"
EOF

# Deploy the changes
gcloud app deploy

# Update the SA if you need it (and if you have actas permissions)
gcloud app update --service-account=<sa>@$PROJECT_ID.iam.gserviceaccount.com

만약 이미 AppEngine을 손상시켰고 appengine.applications.update 권한과 actAs 권한을 가지고 있다면, AppEngine에서 사용하는 서비스 계정을 다음과 같이 수정할 수 있습니다:

gcloud app update --service-account=<sa>@$PROJECT_ID.iam.gserviceaccount.com

appengine.instances.enableDebug, appengine.instances.get, appengine.instances.list, appengine.operations.get, appengine.services.get, appengine.services.list, appengine.versions.get, appengine.versions.list, compute.projects.get

이 권한들로, 유연한(flexible) 유형의 App Engine 인스턴스에 ssh로 로그인할 수 있습니다 (표준 유형은 아님). 일부 listget 권한은 실제로 필요하지 않을 수 있습니다.

gcloud app instances ssh --service <app-name> --version <version-id> <ID>

appengine.applications.update, appengine.operations.get

이것은 단지 google이 애플리케이션을 설정하는 데 사용할 백그라운드 SA를 변경하는 것 같아서, 이 권한을 남용하여 서비스 계정을 훔칠 수는 없을 것 같습니다.

gcloud app update --service-account=<sa_email>

appengine.versions.getFileContents, appengine.versions.update

이 권한을 어떻게 사용해야 할지 또는 유용한지 확실하지 않습니다 (코드를 변경할 때 새 버전이 생성되므로 코드를 업데이트하거나 IAM 역할을 업데이트할 수 있는지 모르겠지만, 아마도 버킷 내부의 코드를 변경할 수 있을 것입니다??).

버킷에 대한 쓰기 권한

소스 코드가 위치한 버킷에 대한 쓰기 권한이 있어도 소스 코드와 manifest.json을 수정하여 임의의 코드를 실행할 수 없었습니다. 아마도 버킷을 모니터링하고 새 버전이 생성되고 소스 코드와 매니페스트가 업로드되는 순간을 감지하면, 새 버전이 백도어된 것을 사용하도록 변경할 수 있을까요??

또한 컨테이너 레이어가 버킷에 저장되는 것처럼 보이는데, 그것들을 변경할 수 있을까요?

HackTricks 지원하기

Last updated