-
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
81b9388
1b047f9
8df6fae
cd951b8
21c077f
389894e
ebc3117
e802a8b
55b50b4
25dd5c1
9efe7b0
c0fd781
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| package aws | ||
|
|
||
| import ( | ||
| "context" | ||
| _ "embed" | ||
| "encoding/json" | ||
| "fmt" | ||
| "github.com/aws/aws-sdk-go-v2/aws" | ||
| "github.com/datadog/stratus-red-team/v2/pkg/stratus" | ||
| "github.com/datadog/stratus-red-team/v2/pkg/stratus/mitreattack" | ||
| "log" | ||
| "github.com/aws/aws-sdk-go-v2/service/bedrockruntime" | ||
| ) | ||
|
|
||
| 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> to check if bedrock model is available. | ||
|
||
| `, | ||
| Detection: ` | ||
| Through CloudTrail's <code>InvokModel</code> events. | ||
udgover marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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:
|
||
| 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 { | ||
| log.Printf("Get aws connection") | ||
|
||
| 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
|
||
| modelId := "anthropic.claude-3-sonnet-20240229-v1:0" | ||
|
|
||
| log.Printf("Attempting to invoke Bedrock model %s in regions: %v", modelId, regions) | ||
|
|
||
| requestBody := minimalPromptBody{ | ||
| Prompt: "Human: story of dogs", | ||
| MaxTokensToSample: 300, | ||
| } | ||
| bodyBytes, err := json.Marshal(requestBody) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to marshal request body: %w", err) | ||
| } | ||
|
|
||
| for _, region := range regions { | ||
| log.Printf("Attempting InvokeModel for %s in region: %s", modelId, region) | ||
|
|
||
| regionalConfig := awsConnection.Copy() | ||
| regionalConfig.Region = region | ||
| bedrockClient := bedrockruntime.NewFromConfig(regionalConfig) | ||
|
|
||
| params := &bedrockruntime.InvokeModelInput{ | ||
| ModelId: aws.String(modelId), | ||
| Body: bodyBytes, | ||
| ContentType: aws.String("application/json"), | ||
| Accept: aws.String("*/*"), | ||
| } | ||
|
|
||
| _, invokeErr := bedrockClient.InvokeModel(context.Background(), params) | ||
| if invokeErr != nil { | ||
| log.Printf("Error invoking model %s in region %s: %v.", modelId, region, invokeErr) | ||
| } else { | ||
| log.Printf("Successfully invoked model %s in region %s (or the call was accepted without immediate error).", modelId, region) | ||
| } | ||
| } | ||
| log.Println("Finished InvokeModel attempts across regions.") | ||
| return nil | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.