-
Notifications
You must be signed in to change notification settings - Fork 276
New technique: invoke bedrock model in multiple regions #689
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
udgover
wants to merge
12
commits into
main
Choose a base branch
from
invoke-model-multiple-region
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
81b9388
Add new technique to invoke bedrock model in multiple regions
udgover 1b047f9
Merge branch 'main' into invoke-model-multiple-region
udgover 8df6fae
Map Stratus Attack Techniques to the AWS Threat Catalogue (#691)
christophetd cd951b8
Fix CloudTrail event name
christophetd 21c077f
Remove debug code
christophetd 389894e
Fix prompt and implement additional error handling
christophetd ebc3117
Improve logging
christophetd e802a8b
Changed behavior to use MaxTokensToSample=1 and better mimick enumera…
christophetd 55b50b4
Update docs
christophetd 25dd5c1
Autogenerate docs
christophetd 9efe7b0
Add mappings to the AWS Threat Catalog
christophetd c0fd781
Merge branch 'main' into invoke-model-multiple-region
udgover File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
...ttack-techniques/AWS/aws.discovery.bedrock-enumerate-models-multiple-regions.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| --- | ||
| title: Enumerate Bedrock models in multiple regions | ||
| --- | ||
|
|
||
| # Enumerate Bedrock models in multiple regions | ||
|
|
||
|
|
||
| <span class="smallcaps w3-badge w3-blue w3-round w3-text-white" title="This attack technique can be detonated multiple times">idempotent</span> | ||
|
|
||
| Platform: AWS | ||
|
|
||
| ## Mappings | ||
|
|
||
| - MITRE ATT&CK | ||
| - Discovery | ||
|
|
||
|
|
||
| - Threat Technique Catalog for AWS: | ||
|
|
||
| - [Resource Hijacking: Cloud Service Hijacking - Bedrock LLM Abuse](https://aws-samples.github.io/threat-technique-catalog-for-aws/Techniques/T1496.A007.html) (T1496.A007) | ||
|
|
||
|
|
||
|
|
||
| ## Description | ||
|
|
||
|
|
||
| Simulates an attacker enumerating Bedrock models in multiple regions. Attackers frequently use this enumeration technique after having compromised an access key, to use it to answer their prompts. | ||
|
|
||
| <span style="font-variant: small-caps;">Warm-up</span>: None. | ||
|
|
||
| <span style="font-variant: small-caps;">Detonation</span>: | ||
|
|
||
| - Perform <code>bedrock:InvokeModel</code> with <code>MaxTokensToSample = -1</code> in several regions to check if the Bedrock model <code>anthropic.claude-3-5-sonnet-20241022-v2:0</code> is available for use. | ||
|
|
||
| References: | ||
|
|
||
| - https://permiso.io/blog/exploiting-hosted-models | ||
| - https://sysdig.com/blog/llmjacking-stolen-cloud-credentials-used-in-new-ai-attack/ | ||
|
|
||
|
|
||
| ## Instructions | ||
|
|
||
| ```bash title="Detonate with Stratus Red Team" | ||
| stratus detonate aws.discovery.bedrock-enumerate-models-multiple-regions | ||
| ``` | ||
| ## Detection | ||
|
|
||
|
|
||
| Through CloudTrail's <code>InvokeModel</code> events. | ||
| These can be considered suspicious especially when performed by a long-lived access key, or when the calls span across multiple regions. | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
v2/internal/attacktechniques/aws/discovery/bedrock-enumerate-models-multiple-regions/main.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| package aws | ||
|
|
||
| import ( | ||
| "context" | ||
| _ "embed" | ||
| "encoding/json" | ||
| "fmt" | ||
| "github.com/aws/aws-sdk-go-v2/aws" | ||
| "github.com/aws/aws-sdk-go-v2/service/bedrockruntime" | ||
| "github.com/datadog/stratus-red-team/v2/pkg/stratus" | ||
| "github.com/datadog/stratus-red-team/v2/pkg/stratus/mitreattack" | ||
| "log" | ||
| "strings" | ||
| ) | ||
|
|
||
| const MODEL = "anthropic.claude-3-5-sonnet-20241022-v2:0" | ||
|
|
||
| func init() { | ||
| stratus.GetRegistry().RegisterAttackTechnique(&stratus.AttackTechnique{ | ||
| ID: "aws.discovery.bedrock-enumerate-models-multiple-regions", | ||
| FriendlyName: "Enumerate Bedrock models in multiple regions", | ||
| Description: ` | ||
| Simulates an attacker enumerating Bedrock models in multiple regions. Attackers frequently use this enumeration technique after having compromised an access key, to use it to answer their prompts. | ||
|
|
||
| Warm-up: None. | ||
|
|
||
| Detonation: | ||
|
|
||
| - Perform <code>bedrock:InvokeModel</code> with <code>MaxTokensToSample = -1</code> in several regions to check if the Bedrock model <code>` + MODEL + `</code> is available for use. | ||
|
|
||
| References: | ||
|
|
||
| - https://permiso.io/blog/exploiting-hosted-models | ||
| - https://sysdig.com/blog/llmjacking-stolen-cloud-credentials-used-in-new-ai-attack/ | ||
| `, | ||
| Detection: ` | ||
| Through CloudTrail's <code>InvokeModel</code> events. | ||
| These can be considered suspicious especially when performed by a long-lived access key, or when the calls span across multiple regions. | ||
| `, | ||
| Platform: stratus.AWS, | ||
| IsIdempotent: true, | ||
| MitreAttackTactics: []mitreattack.Tactic{mitreattack.Discovery}, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note to self:
|
||
| FrameworkMappings: []stratus.FrameworkMappings{ | ||
| { | ||
| Framework: stratus.ThreatTechniqueCatalogAWS, | ||
| Techniques: []stratus.TechniqueMapping{ | ||
| { | ||
| Name: "Resource Hijacking: Cloud Service Hijacking - Bedrock LLM Abuse", | ||
| ID: "T1496.A007", | ||
| URL: "https://aws-samples.github.io/threat-technique-catalog-for-aws/Techniques/T1496.A007.html", | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
|
|
||
| Detonate: detonate, | ||
| }) | ||
| } | ||
|
|
||
| type minimalPromptBody struct { | ||
| Prompt string `json:"prompt"` | ||
| MaxTokensToSample int `json:"max_tokens_to_sample"` | ||
| } | ||
|
|
||
| func detonate(_ map[string]string, providers stratus.CloudProviders) error { | ||
| awsConnection := providers.AWS().GetConnection() | ||
| regions := []string{"us-east-1", "us-west-2", "eu-west-2", "eu-west-3", "ap-northeast-2", "ap-southeast-2"} | ||
udgover marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| log.Printf("Attempting to invoke Bedrock model %s in regions: %v", MODEL, regions) | ||
|
|
||
| requestBody := minimalPromptBody{ | ||
| Prompt: "", | ||
| MaxTokensToSample: -1, | ||
| } | ||
| bodyBytes, err := json.Marshal(requestBody) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to marshal request body: %w", err) | ||
| } | ||
|
|
||
| for _, region := range regions { | ||
| regionalConfig := awsConnection.Copy() | ||
| regionalConfig.Region = region | ||
| bedrockClient := bedrockruntime.NewFromConfig(regionalConfig) | ||
|
|
||
| params := &bedrockruntime.InvokeModelInput{ | ||
| ModelId: aws.String(MODEL), | ||
| Body: bodyBytes, | ||
| ContentType: aws.String("application/json"), | ||
| Accept: aws.String("*/*"), | ||
| } | ||
|
|
||
| _, invokeErr := bedrockClient.InvokeModel(context.Background(), params) | ||
| if invokeErr == nil { | ||
| return fmt.Errorf("expected an error when invoking model %s in %s, but got none", MODEL, region) | ||
| } | ||
| if strings.Contains(invokeErr.Error(), "AccessDeniedException") { | ||
| log.Printf("%s: Got an AccessDeniedException indicating that the model isn't available or the current user doesn't have permissions to invoke models", region) | ||
| } else if strings.Contains(invokeErr.Error(), "ValidationException") && strings.Contains(invokeErr.Error(), "StatusCode: 400") { | ||
| log.Printf("%s: Got a ValidationException indicating that the model isn't available in this region", region) | ||
| } else { | ||
| return fmt.Errorf("failed to invoke model %s in %s with an unexpected error: %w", MODEL, region, invokeErr) | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.