AWS - CodeBuild Post Exploitation

Tip

AWSハッキングを学び、実践する:HackTricks Training AWS Red Team Expert (ARTE)
GCPハッキングを学び、実践する:HackTricks Training GCP Red Team Expert (GRTE) Azureハッキングを学び、実践する:HackTricks Training Azure Red Team Expert (AzRTE)

HackTricksをサポートする

CodeBuild

For more information, check:

AWS - Codebuild Enum

Check Secrets

もし Codebuild に Github、Gitlab、Bitbucket への接続用の資格情報が personal tokens、passwords、または OAuth token access の形で設定されている場合、これらの credentials are going to be stored as secrets in the secret manager
したがって、secret manager を読み取るアクセスがあれば、これらの secrets を取得して接続されたプラットフォームへ pivot することができます。

AWS - Secrets Manager Privesc

Abuse CodeBuild Repo Access

CodeBuild を設定するには、使用するコードリポジトリへの access to the code repo が必要です。これらのコードは複数のプラットフォームでホスティングされている可能性があります:

The CodeBuild project must have access to the configured source provider, either via IAM role of with a github/bitbucket token or OAuth access.

An attacker with elevated permissions in over a CodeBuild could abuse this configured access to leak the code of the configured repo and others where the set creds have access.
In order to do this, an attacker would just need to change the repository URL to each repo the config credentials have access (note that the aws web will list all of them for you):

And change the Buildspec commands to exfiltrate each repo.

Warning

However, this task is repetitive and tedious and if a github token was configured with write permissions, an attacker won’t be able to (ab)use those permissions as he doesn’t have access to the token.
Or does he? Check the next section

Leaking Access Tokens from AWS CodeBuild

CodeBuild に与えられたアクセスを Github のようなプラットフォームへ leak することができます。外部プラットフォームへのアクセスが付与されているかどうかは次で確認してください:

aws codebuild list-source-credentials

AWS Codebuild - Token Leakage

Untrusted PR execution via webhook filter misconfiguration

webhook filters が弱いと、外部の攻撃者が自分の PR を特権的な CodeBuild プロジェクトでビルドさせ、その後 CI 内で任意のコードを実行できます。

AWS CodeBuild - Untrusted PR Webhook Bypass (CodeBreach-style)

codebuild:DeleteProject

攻撃者は CodeBuild プロジェクト全体を削除でき、プロジェクト設定が失われ、それに依存するアプリケーションに影響を与えます。

aws codebuild delete-project --name <value>

潜在的な影響: プロジェクト構成の喪失および削除されたプロジェクトを使用しているアプリケーションのサービス中断。

codebuild:TagResource , codebuild:UntagResource

攻撃者はCodeBuildリソースのタグを追加、変更、または削除する可能性があり、これにより組織のコスト配分、リソース追跡、およびタグに基づくアクセス制御ポリシーが混乱する可能性があります。

aws codebuild tag-resource --resource-arn <value> --tags <value>
aws codebuild untag-resource --resource-arn <value> --tag-keys <value>

潜在的影響: コスト配分、リソース追跡、タグベースのアクセス制御ポリシーの混乱。

codebuild:DeleteSourceCredentials

攻撃者はGitリポジトリのソース認証情報を削除し、リポジトリに依存するアプリケーションの正常な動作に影響を与える可能性があります。

aws codebuild delete-source-credentials --arn <value>

潜在的な影響: 影響を受けるリポジトリのソース認証情報が削除されることで、当該リポジトリに依存するアプリケーションの通常の動作が妨げられる可能性があります。

Tip

AWSハッキングを学び、実践する:HackTricks Training AWS Red Team Expert (ARTE)
GCPハッキングを学び、実践する:HackTricks Training GCP Red Team Expert (GRTE) Azureハッキングを学び、実践する:HackTricks Training Azure Red Team Expert (AzRTE)

HackTricksをサポートする