GCP - AppEngine Privesc
Tip
学习并练习 AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
学习并练习 GCP Hacking:HackTricks Training GCP Red Team Expert (GRTE)
学习并练习 Az Hacking:HackTricks Training Azure Red Team Expert (AzRTE)
支持 HackTricks
- 查看 subscription plans!
- 加入 💬 Discord group 或者 telegram group 或 关注 我们的 Twitter 🐦 @hacktricks_live.
- 通过向 HackTricks 和 HackTricks Cloud github 仓库 提交 PRs 来分享 hacking tricks。
App Engine
有关 App Engine 的更多信息,请查看:
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 部署应用所需的权限。也许那些 get 和 list 权限可以省略。
你可以在以下地址找到 python 示例代码: https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/appengine
By default, the name of the App service is going to be default, and there can be only 1 instance with the same name.
要更改名称并创建第二个 App,请在 app.yaml 中将根键的值改为类似 service: my-second-app 的内容。
部署 App Engine 应用
```bash cd python-docs-samples/appengine/flexible/hello_world gcloud app deploy #Upload and start application inside the folder ```请至少等待 10–15 分钟,如果不成功,请尝试 deploy another of times 并再等待几分钟。
Note
可以指定要使用的 Service Account,但默认情况下会使用 App Engine 的默认 SA。
The URL of the application is something like https://<proj-name>.oa.r.appspot.com/ or https://<service_name>-dot-<proj-name>.oa.r.appspot.com
更新等效权限
您可能拥有更新 App Engine 的足够权限,但没有创建新应用的权限。在这种情况下,您可以按如下方式更新当前的 App Engine:
更新现有 App Engine 应用
```bash # Find the code of the App Engine in the buckets gsutil lsDownload 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=
</details>
如果你已经**already compromised a AppEngine**,并且拥有权限**`appengine.applications.update`**,并且对要使用的服务账号拥有**actAs**,你可以通过以下方式修改 AppEngine 使用的服务账号:
<details>
<summary>Update App Engine service account</summary>
```bash
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
有了这些权限,就可以通过 ssh 登录 App Engine 实例,前提是实例类型为 flexible(非 standard)。某些 list 和 get 权限可能并非真正必要。
通过 SSH 登录 App Engine 实例
```bash gcloud app instances ssh --serviceappengine.applications.update, appengine.operations.get
我认为这只是更改 google 在设置应用程序时将使用的后台 SA,所以我觉得你无法滥用它来窃取 service account。
Update application service account
```bash gcloud app update --service-account=appengine.versions.getFileContents, appengine.versions.update
不确定如何使用这些权限或它们是否有用(注意当你更改代码时会创建一个新版本,所以我不知道你是否可以仅更新代码或其中一个的 IAM 角色,但我想你应该可以,也许通过更改 bucket 内的代码??)。
Write Access over the buckets
如前所述,appengine versions 会在一个名为:staging.<project-id>.appspot.com 的 bucket 中生成一些数据。注意无法 pre-takeover 该 bucket,因为 GCP 用户没有权限使用域名 appspot.com 创建 buckets。
然而,具有该 bucket 的读写访问后,可以通过监视 bucket 并在任何更改发生时尽快修改代码,从而将权限升级到附加在 AppEngine version 上的 SA。这样,由该代码创建的容器将会 execute the backdoored code。
For more information and a PoC check the relevant information from this page:
Write Access over the Artifact Registry
尽管 App Engine 在 Artifact Registry 中创建 docker 镜像,经测试,even if you modify the image inside this service 并移除 App Engine 实例(因此会部署一个新的实例),code executed doesn’t change。
可能存在通过执行 Race Condition attack like with the buckets it might be possible to overwrite the executed code 来覆盖被执行代码的可能性,但这未被测试。
Tip
学习并练习 AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
学习并练习 GCP Hacking:HackTricks Training GCP Red Team Expert (GRTE)
学习并练习 Az Hacking:HackTricks Training Azure Red Team Expert (AzRTE)
支持 HackTricks
- 查看 subscription plans!
- 加入 💬 Discord group 或者 telegram group 或 关注 我们的 Twitter 🐦 @hacktricks_live.
- 通过向 HackTricks 和 HackTricks Cloud github 仓库 提交 PRs 来分享 hacking tricks。
HackTricks Cloud

