mirror of
https://github.com/BishopFox/cloudfox.git
synced 2026-11-07 09:56:01 -10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
29bfd2c863 | ||
|
|
40e0c92ef1 | ||
|
|
9f8ae08262 | ||
|
|
c85aa5de89 | ||
|
|
42d7cfef1e | ||
|
|
a5bce5ad8c | ||
|
|
8221b5ff6d | ||
|
|
aa42c8b808 | ||
|
|
5aab3b4bea | ||
|
|
01d320d64d | ||
|
|
5132622a13 | ||
|
|
08b5cd17af | ||
|
|
102b91e2c7 | ||
|
|
3a19fdb2fe | ||
|
|
d94fafe2b4 | ||
|
|
00ed8a7336 | ||
|
|
60daff386c | ||
|
|
cef1aa3a82 | ||
|
|
e88cb77394 | ||
|
|
fc52e01192 | ||
|
|
659b2e7248 | ||
|
|
06a7e7ec28 | ||
|
|
602332a0c5 | ||
|
|
471da59da2 | ||
|
|
d4ae745e8e | ||
|
|
dc0396ff33 | ||
|
|
c11ebf9a07 | ||
|
|
6c8936cfe4 | ||
|
|
fca0c4da14 | ||
|
|
2c5fec49c3 | ||
|
|
a9b95d9142 | ||
|
|
0a74adea9a | ||
|
|
adb9bcd55a | ||
|
|
03177e8726 | ||
|
|
1fb9f4c3e0 |
No files matched your search
+2
-1
@@ -69,4 +69,5 @@ cloudfox
|
||||
*.txt
|
||||
*.json
|
||||
*.csv
|
||||
*.log
|
||||
*.log
|
||||
dist/
|
||||
+2
-2
@@ -78,7 +78,7 @@ func (m *AccessKeysModule) PrintAccessKeys(filter string, outputFormat string, o
|
||||
fmt.Printf("[%s][%s] Only active access keys are shown.\n", cyan(m.output.CallingModule), cyan(m.AWSProfile))
|
||||
//fmt.Printf("[%s][%s] Preparing output.\n\n")
|
||||
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
//m.output.OutputSelector(outputFormat)
|
||||
//utils.OutputSelector(verbosity, outputFormat, m.output.Headers, m.output.Body, m.output.FilePath, m.output.CallingModule, m.output.CallingModule)
|
||||
//internal.OutputSelector(verbosity, outputFormat, m.output.Headers, m.output.Body, m.output.FilePath, m.output.CallingModule, m.output.CallingModule, m.WrapTable, m.AWSProfile)
|
||||
@@ -95,7 +95,7 @@ func (m *AccessKeysModule) PrintAccessKeys(filter string, outputFormat string, o
|
||||
Name: m.output.CallingModule,
|
||||
})
|
||||
o.PrefixIdentifier = m.AWSProfile
|
||||
o.Table.DirectoryName = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
o.Table.DirectoryName = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
o.WriteFullOutput(o.Table.TableFiles, nil)
|
||||
m.writeLoot(o.Table.DirectoryName, verbosity)
|
||||
//m.writeLoot(m.output.FilePath, verbosity)
|
||||
|
||||
+2
-2
@@ -65,7 +65,7 @@ func (m *BucketsModule) PrintBuckets(outputFormat string, outputDirectory string
|
||||
if m.AWSProfile == "" {
|
||||
m.AWSProfile = internal.BuildAWSPath(m.Caller)
|
||||
}
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
|
||||
fmt.Printf("[%s][%s] Enumerating buckets for account %s.\n", cyan(m.output.CallingModule), cyan(m.AWSProfile), aws.ToString(m.Caller.Account))
|
||||
|
||||
@@ -135,7 +135,7 @@ func (m *BucketsModule) PrintBuckets(outputFormat string, outputDirectory string
|
||||
Name: m.output.CallingModule,
|
||||
})
|
||||
o.PrefixIdentifier = m.AWSProfile
|
||||
o.Table.DirectoryName = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
o.Table.DirectoryName = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
o.WriteFullOutput(o.Table.TableFiles, nil)
|
||||
m.writeLoot(o.Table.DirectoryName, verbosity, m.AWSProfile)
|
||||
|
||||
|
||||
+1
-1
@@ -112,7 +112,7 @@ func TestListBuckets(t *testing.T) {
|
||||
t.Run(subtest.name, func(t *testing.T) {
|
||||
subtest.testModule.PrintBuckets(subtest.testModule.OutputFormat, subtest.outputDirectory, subtest.verbosity)
|
||||
for index, expectedBucket := range subtest.expectedResult {
|
||||
resultsFilePath := filepath.Join(tmpDir, "cloudfox-output/aws/123456789012-unittesting/table/buckets.txt")
|
||||
resultsFilePath := filepath.Join(tmpDir, "cloudfox-output/aws/unittesting-123456789012/table/buckets.txt")
|
||||
resultsFile, err := afero.ReadFile(fs, resultsFilePath)
|
||||
if err != nil {
|
||||
t.Fatalf("Cannot read output file at %s: %s", resultsFilePath, err)
|
||||
|
||||
@@ -148,7 +148,7 @@ func (m *CloudformationModule) PrintCloudformationStacks(outputFormat string, ou
|
||||
Name: m.output.CallingModule,
|
||||
})
|
||||
o.PrefixIdentifier = m.AWSProfile
|
||||
o.Table.DirectoryName = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
o.Table.DirectoryName = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
o.WriteFullOutput(o.Table.TableFiles, nil)
|
||||
m.writeLoot(o.Table.DirectoryName, verbosity)
|
||||
fmt.Printf("[%s][%s] %s cloudformation stacks found.\n", cyan(m.output.CallingModule), cyan(m.AWSProfile), strconv.Itoa(len(m.output.Body)))
|
||||
|
||||
@@ -1,81 +1,15 @@
|
||||
package aws
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"log"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/BishopFox/cloudfox/aws/sdk"
|
||||
"github.com/BishopFox/cloudfox/internal"
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/cloudformation"
|
||||
"github.com/aws/aws-sdk-go-v2/service/cloudformation/types"
|
||||
"github.com/aws/aws-sdk-go-v2/service/sts"
|
||||
)
|
||||
|
||||
const DESCRIBE_STACKS_TEST_FILE = "./test-data/cloudformation-describestacks.json"
|
||||
const TEMPLATE_BODY_TEST_FILE = "./test-data/cloudformation-getTemplate.json"
|
||||
|
||||
type Stacks struct {
|
||||
Stacks []struct {
|
||||
StackID string `json:"StackId"`
|
||||
Description string `json:"Description"`
|
||||
Tags []interface{} `json:"Tags"`
|
||||
Outputs []types.Output `json:"Outputs"`
|
||||
Parameters []types.Parameter `json:"Parameters"`
|
||||
StackStatusReason interface{} `json:"StackStatusReason"`
|
||||
CreationTime time.Time `json:"CreationTime"`
|
||||
Capabilities []interface{} `json:"Capabilities"`
|
||||
StackName string `json:"StackName"`
|
||||
RoleArn string `json:"RoleArn"`
|
||||
StackStatus string `json:"StackStatus"`
|
||||
DisableRollback bool `json:"DisableRollback"`
|
||||
} `json:"Stacks"`
|
||||
}
|
||||
|
||||
type TemplateBody struct {
|
||||
TemplateBody string `json:"TemplateBody"`
|
||||
}
|
||||
|
||||
type MockedCloudformationClient struct {
|
||||
describeStacks Stacks
|
||||
getTemplateBody TemplateBody
|
||||
}
|
||||
|
||||
func (m *MockedCloudformationClient) DescribeStacks(ctx context.Context, params *cloudformation.DescribeStacksInput, optFns ...func(*cloudformation.Options)) (*cloudformation.DescribeStacksOutput, error) {
|
||||
|
||||
err := json.Unmarshal(readTestFile(DESCRIBE_STACKS_TEST_FILE), &m.describeStacks)
|
||||
if err != nil {
|
||||
log.Fatalf("can't unmarshall file %s", DESCRIBE_STACKS_TEST_FILE)
|
||||
}
|
||||
var stacks []types.Stack
|
||||
for _, stack := range m.describeStacks.Stacks {
|
||||
stacks = append(stacks, types.Stack{
|
||||
StackName: &stack.StackName,
|
||||
RoleARN: &stack.RoleArn,
|
||||
Outputs: stack.Outputs,
|
||||
Parameters: stack.Parameters,
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
return &cloudformation.DescribeStacksOutput{Stacks: stacks}, nil
|
||||
}
|
||||
|
||||
func (m *MockedCloudformationClient) GetTemplate(ctx context.Context, params *cloudformation.GetTemplateInput, optFns ...func(*cloudformation.Options)) (*cloudformation.GetTemplateOutput, error) {
|
||||
err := json.Unmarshal(readTestFile(DESCRIBE_STACKS_TEST_FILE), &m.getTemplateBody)
|
||||
if err != nil {
|
||||
log.Fatalf("can't unmarshall file %s", TEMPLATE_BODY_TEST_FILE)
|
||||
}
|
||||
|
||||
return &cloudformation.GetTemplateOutput{TemplateBody: &m.getTemplateBody.TemplateBody}, nil
|
||||
}
|
||||
|
||||
func (m *MockedCloudformationClient) ListStacks(ctx context.Context, params *cloudformation.ListStacksInput, optFns ...func(*cloudformation.Options)) (*cloudformation.ListStacksOutput, error) {
|
||||
return &cloudformation.ListStacksOutput{}, nil
|
||||
}
|
||||
|
||||
func TestCloudFormation(t *testing.T) {
|
||||
subtests := []struct {
|
||||
name string
|
||||
@@ -89,7 +23,7 @@ func TestCloudFormation(t *testing.T) {
|
||||
outputDirectory: ".",
|
||||
verbosity: 2,
|
||||
testModule: CloudformationModule{
|
||||
CloudFormationClient: &MockedCloudformationClient{},
|
||||
CloudFormationClient: &sdk.MockedCloudformationClient{},
|
||||
Caller: sts.GetCallerIdentityOutput{Arn: aws.String("test")},
|
||||
OutputFormat: "table",
|
||||
AWSProfile: "test",
|
||||
|
||||
+2
-2
@@ -161,7 +161,7 @@ func (m *CodeBuildModule) PrintCodeBuildProjects(outputFormat string, outputDire
|
||||
}
|
||||
|
||||
if len(m.output.Body) > 0 {
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
//m.output.OutputSelector(outputFormat)
|
||||
//utils.OutputSelector(verbosity, outputFormat, m.output.Headers, m.output.Body, m.output.FilePath, m.output.CallingModule, m.output.CallingModule)
|
||||
//internal.OutputSelector(verbosity, outputFormat, m.output.Headers, m.output.Body, m.output.FilePath, m.output.CallingModule, m.output.CallingModule, m.WrapTable, m.AWSProfile)
|
||||
@@ -180,7 +180,7 @@ func (m *CodeBuildModule) PrintCodeBuildProjects(outputFormat string, outputDire
|
||||
Name: m.output.CallingModule,
|
||||
})
|
||||
o.PrefixIdentifier = m.AWSProfile
|
||||
o.Table.DirectoryName = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
o.Table.DirectoryName = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
o.WriteFullOutput(o.Table.TableFiles, nil)
|
||||
//m.writeLoot(o.Table.DirectoryName, verbosity)
|
||||
fmt.Printf("[%s][%s] %d projects found.\n", cyan(m.output.CallingModule), cyan(m.AWSProfile), len(m.output.Body))
|
||||
|
||||
@@ -126,7 +126,7 @@ func TestCodeBuildProjects(t *testing.T) {
|
||||
// execute the module with verbosity set to 2
|
||||
m.PrintCodeBuildProjects("table", tmpDir, 2)
|
||||
|
||||
resultsFilePath := filepath.Join(tmpDir, "cloudfox-output/aws/123456789012-unittesting/table/codebuild.txt")
|
||||
resultsFilePath := filepath.Join(tmpDir, "cloudfox-output/aws/unittesting-123456789012/table/codebuild.txt")
|
||||
resultsFile, err := afero.ReadFile(fs, resultsFilePath)
|
||||
if err != nil {
|
||||
t.Fatalf("Cannot read output file at %s: %s", resultsFilePath, err)
|
||||
|
||||
+3
-3
@@ -19,7 +19,7 @@ import (
|
||||
|
||||
type DatabasesModule struct {
|
||||
RDSClient sdk.RDSClientInterface
|
||||
RedshiftClient sdk.RedShiftClientInterface
|
||||
RedshiftClient sdk.AWSRedShiftClientInterface
|
||||
DynamoDBClient sdk.DynamoDBClientInterface
|
||||
DocDBClient sdk.DocDBClientInterface
|
||||
|
||||
@@ -134,7 +134,7 @@ func (m *DatabasesModule) PrintDatabases(outputFormat string, outputDirectory st
|
||||
|
||||
}
|
||||
if len(m.output.Body) > 0 {
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
//m.output.OutputSelector(outputFormat)
|
||||
//utils.OutputSelector(verbosity, outputFormat, m.output.Headers, m.output.Body, m.output.FilePath, m.output.CallingModule, m.output.CallingModule)
|
||||
//internal.OutputSelector(verbosity, outputFormat, m.output.Headers, m.output.Body, m.output.FilePath, m.output.CallingModule, m.output.CallingModule, m.WrapTable, m.AWSProfile)
|
||||
@@ -152,7 +152,7 @@ func (m *DatabasesModule) PrintDatabases(outputFormat string, outputDirectory st
|
||||
Name: m.output.CallingModule,
|
||||
})
|
||||
o.PrefixIdentifier = m.AWSProfile
|
||||
o.Table.DirectoryName = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
o.Table.DirectoryName = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
o.WriteFullOutput(o.Table.TableFiles, nil)
|
||||
m.writeLoot(o.Table.DirectoryName, verbosity)
|
||||
fmt.Printf("[%s][%s] %s databases found.\n", cyan(m.output.CallingModule), cyan(m.AWSProfile), strconv.Itoa(len(m.output.Body)))
|
||||
|
||||
+2
-2
@@ -123,7 +123,7 @@ func (m *ECRModule) PrintECR(outputFormat string, outputDirectory string, verbos
|
||||
|
||||
}
|
||||
if len(m.output.Body) > 0 {
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
//m.output.OutputSelector(outputFormat)
|
||||
//utils.OutputSelector(verbosity, outputFormat, m.output.Headers, m.output.Body, m.output.FilePath, m.output.CallingModule, m.output.CallingModule)
|
||||
//internal.OutputSelector(verbosity, outputFormat, m.output.Headers, m.output.Body, m.output.FilePath, m.output.CallingModule, m.output.CallingModule, m.WrapTable, m.AWSProfile)
|
||||
@@ -141,7 +141,7 @@ func (m *ECRModule) PrintECR(outputFormat string, outputDirectory string, verbos
|
||||
Name: m.output.CallingModule,
|
||||
})
|
||||
o.PrefixIdentifier = m.AWSProfile
|
||||
o.Table.DirectoryName = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
o.Table.DirectoryName = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
o.WriteFullOutput(o.Table.TableFiles, nil)
|
||||
m.writeLoot(o.Table.DirectoryName, verbosity)
|
||||
fmt.Printf("[%s][%s] %s repositories found.\n", cyan(m.output.CallingModule), cyan(m.AWSProfile), strconv.Itoa(len(m.output.Body)))
|
||||
|
||||
+40
-100
@@ -13,7 +13,6 @@ import (
|
||||
"github.com/BishopFox/cloudfox/aws/sdk"
|
||||
"github.com/BishopFox/cloudfox/internal"
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/ec2"
|
||||
"github.com/aws/aws-sdk-go-v2/service/ecs"
|
||||
"github.com/aws/aws-sdk-go-v2/service/ecs/types"
|
||||
"github.com/aws/aws-sdk-go-v2/service/sts"
|
||||
@@ -21,16 +20,10 @@ import (
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type DescribeTasksDefinitionAPIClient interface {
|
||||
DescribeTaskDefinition(context.Context, *ecs.DescribeTaskDefinitionInput, ...func(*ecs.Options)) (*ecs.DescribeTaskDefinitionOutput, error)
|
||||
}
|
||||
type ECSTasksModule struct {
|
||||
DescribeTaskDefinitionClient DescribeTasksDefinitionAPIClient
|
||||
DescribeTasksClient ecs.DescribeTasksAPIClient
|
||||
ListTasksClient ecs.ListTasksAPIClient
|
||||
ListClustersClient ecs.ListClustersAPIClient
|
||||
DescribeNetworkInterfacesClient ec2.DescribeNetworkInterfacesAPIClient
|
||||
IAMClient sdk.AWSIAMClientInterface
|
||||
ECSClient sdk.AWSECSClientInterface
|
||||
EC2Client sdk.AWSEC2ClientInterface
|
||||
IAMClient sdk.AWSIAMClientInterface
|
||||
|
||||
Caller sts.GetCallerIdentityOutput
|
||||
AWSRegions []string
|
||||
@@ -207,7 +200,7 @@ func (m *ECSTasksModule) printECSTaskData(outputFormat string, outputDirectory s
|
||||
}
|
||||
|
||||
if len(m.output.Body) > 0 {
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
//utils.OutputSelector(m.output.Verbosity, outputFormat, m.output.Headers, m.output.Body, m.output.FilePath, m.output.CallingModule, m.output.CallingModule)
|
||||
//internal.OutputSelector(m.output.Verbosity, outputFormat, m.output.Headers, m.output.Body, m.output.FilePath, m.output.CallingModule, m.output.CallingModule, m.WrapTable, m.AWSProfile)
|
||||
//m.writeLoot(m.output.FilePath)
|
||||
@@ -224,7 +217,7 @@ func (m *ECSTasksModule) printECSTaskData(outputFormat string, outputDirectory s
|
||||
Name: m.output.CallingModule,
|
||||
})
|
||||
o.PrefixIdentifier = m.AWSProfile
|
||||
o.Table.DirectoryName = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
o.Table.DirectoryName = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
o.WriteFullOutput(o.Table.TableFiles, nil)
|
||||
m.writeLoot(o.Table.DirectoryName)
|
||||
fmt.Printf("[%s][%s] %s ECS tasks found.\n", cyan(m.output.CallingModule), cyan(m.AWSProfile), strconv.Itoa(len(m.output.Body)))
|
||||
@@ -313,75 +306,37 @@ func (m *ECSTasksModule) executeChecks(r string, wg *sync.WaitGroup, dataReceive
|
||||
|
||||
func (m *ECSTasksModule) getListClusters(region string, dataReceiver chan MappedECSTask) {
|
||||
|
||||
var PaginationControl *string
|
||||
for {
|
||||
ListClusters, err := m.ListClustersClient.ListClusters(
|
||||
context.TODO(),
|
||||
&(ecs.ListClustersInput{
|
||||
NextToken: PaginationControl,
|
||||
}),
|
||||
func(o *ecs.Options) {
|
||||
o.Region = region
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
m.modLog.Error(err.Error())
|
||||
m.CommandCounter.Error++
|
||||
break
|
||||
}
|
||||
|
||||
for _, clusterARN := range ListClusters.ClusterArns {
|
||||
m.getListTasks(clusterARN, region, dataReceiver)
|
||||
}
|
||||
|
||||
if ListClusters.NextToken != nil {
|
||||
PaginationControl = ListClusters.NextToken
|
||||
} else {
|
||||
PaginationControl = nil
|
||||
break
|
||||
}
|
||||
|
||||
ClusterArns, err := sdk.CachedECSListClusters(m.ECSClient, aws.ToString(m.Caller.Account), region)
|
||||
if err != nil {
|
||||
m.modLog.Error(err.Error())
|
||||
m.CommandCounter.Error++
|
||||
return
|
||||
}
|
||||
|
||||
for _, clusterARN := range ClusterArns {
|
||||
m.getListTasks(clusterARN, region, dataReceiver)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (m *ECSTasksModule) getListTasks(clusterARN string, region string, dataReceiver chan MappedECSTask) {
|
||||
var PaginationControl *string
|
||||
for {
|
||||
|
||||
ListTasks, err := m.ListTasksClient.ListTasks(
|
||||
context.TODO(),
|
||||
&(ecs.ListTasksInput{
|
||||
Cluster: aws.String(clusterARN),
|
||||
NextToken: PaginationControl,
|
||||
}),
|
||||
func(o *ecs.Options) {
|
||||
o.Region = region
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
m.modLog.Error(err.Error())
|
||||
m.CommandCounter.Error++
|
||||
break
|
||||
}
|
||||
|
||||
batchSize := 100 // maximum value: https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_DescribeTasks.html#API_DescribeTasks_RequestSyntax
|
||||
for i := 0; i < len(ListTasks.TaskArns); i += batchSize {
|
||||
j := i + batchSize
|
||||
if j > len(ListTasks.TaskArns) {
|
||||
j = len(ListTasks.TaskArns)
|
||||
}
|
||||
|
||||
m.loadTasksData(clusterARN, ListTasks.TaskArns[i:j], region, dataReceiver)
|
||||
}
|
||||
|
||||
if ListTasks.NextToken != nil {
|
||||
PaginationControl = ListTasks.NextToken
|
||||
} else {
|
||||
PaginationControl = nil
|
||||
break
|
||||
}
|
||||
|
||||
TaskArns, err := sdk.CachedECSListTasks(m.ECSClient, aws.ToString(m.Caller.Account), region, clusterARN)
|
||||
if err != nil {
|
||||
m.modLog.Error(err.Error())
|
||||
m.CommandCounter.Error++
|
||||
return
|
||||
}
|
||||
|
||||
batchSize := 100 // maximum value: https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_DescribeTasks.html#API_DescribeTasks_RequestSyntax
|
||||
for i := 0; i < len(TaskArns); i += batchSize {
|
||||
j := i + batchSize
|
||||
if j > len(TaskArns) {
|
||||
j = len(TaskArns)
|
||||
}
|
||||
|
||||
m.loadTasksData(clusterARN, TaskArns[i:j], region, dataReceiver)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (m *ECSTasksModule) loadTasksData(clusterARN string, taskARNs []string, region string, dataReceiver chan MappedECSTask) {
|
||||
@@ -390,16 +345,7 @@ func (m *ECSTasksModule) loadTasksData(clusterARN string, taskARNs []string, reg
|
||||
return
|
||||
}
|
||||
|
||||
DescribeTasks, err := m.DescribeTasksClient.DescribeTasks(
|
||||
context.TODO(),
|
||||
&(ecs.DescribeTasksInput{
|
||||
Cluster: aws.String(clusterARN),
|
||||
Tasks: taskARNs,
|
||||
}),
|
||||
func(o *ecs.Options) {
|
||||
o.Region = region
|
||||
},
|
||||
)
|
||||
Tasks, err := sdk.CachedECSDescribeTasks(m.ECSClient, aws.ToString(m.Caller.Account), region, clusterARN, taskARNs)
|
||||
if err != nil {
|
||||
m.modLog.Error(err.Error())
|
||||
m.CommandCounter.Error++
|
||||
@@ -407,7 +353,7 @@ func (m *ECSTasksModule) loadTasksData(clusterARN string, taskARNs []string, reg
|
||||
}
|
||||
|
||||
eniIDs := []string{}
|
||||
for _, task := range DescribeTasks.Tasks {
|
||||
for _, task := range Tasks {
|
||||
eniID := getElasticNetworkInterfaceIDOfECSTask(task)
|
||||
if eniID != "" {
|
||||
eniIDs = append(eniIDs, eniID)
|
||||
@@ -420,8 +366,9 @@ func (m *ECSTasksModule) loadTasksData(clusterARN string, taskARNs []string, reg
|
||||
return
|
||||
}
|
||||
|
||||
for _, task := range DescribeTasks.Tasks {
|
||||
taskDefinition, err := m.describeTaskDefinition(aws.ToString(task.TaskDefinitionArn), region)
|
||||
for _, task := range Tasks {
|
||||
//taskDefinition, err := m.describeTaskDefinition(aws.ToString(task.TaskDefinitionArn), region)
|
||||
taskDefinition, err := sdk.CachedECSDescribeTaskDefinition(m.ECSClient, aws.ToString(m.Caller.Account), region, aws.ToString(task.TaskDefinitionArn))
|
||||
if err != nil {
|
||||
m.modLog.Error(err.Error())
|
||||
m.CommandCounter.Error++
|
||||
@@ -461,7 +408,7 @@ func getTaskDefinitionContent(taskDefinition types.TaskDefinition) string {
|
||||
}
|
||||
|
||||
func (m *ECSTasksModule) describeTaskDefinition(taskDefinitionArn string, region string) (types.TaskDefinition, error) {
|
||||
DescribeTaskDefinition, err := m.DescribeTaskDefinitionClient.DescribeTaskDefinition(
|
||||
DescribeTaskDefinition, err := m.ECSClient.DescribeTaskDefinition(
|
||||
context.TODO(),
|
||||
&ecs.DescribeTaskDefinitionInput{
|
||||
TaskDefinition: &taskDefinitionArn,
|
||||
@@ -511,20 +458,13 @@ func (m *ECSTasksModule) loadPublicIPs(eniIDs []string, region string) (map[stri
|
||||
if len(eniIDs) == 0 {
|
||||
return eniPublicIPs, nil
|
||||
}
|
||||
DescribeNetworkInterfaces, err := m.DescribeNetworkInterfacesClient.DescribeNetworkInterfaces(
|
||||
context.TODO(),
|
||||
&(ec2.DescribeNetworkInterfacesInput{
|
||||
NetworkInterfaceIds: eniIDs,
|
||||
}),
|
||||
func(o *ec2.Options) {
|
||||
o.Region = region
|
||||
},
|
||||
)
|
||||
|
||||
NetworkInterfaces, err := sdk.CachedEC2DescribeNetworkInterfaces(m.EC2Client, aws.ToString(m.Caller.Account), region)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("getting elastic network interfaces: %s", err)
|
||||
}
|
||||
|
||||
for _, eni := range DescribeNetworkInterfaces.NetworkInterfaces {
|
||||
for _, eni := range NetworkInterfaces {
|
||||
eniPublicIPs[aws.ToString(eni.NetworkInterfaceId)] = getPublicIPOfElasticNetworkInterface(eni)
|
||||
}
|
||||
|
||||
|
||||
+8
-246
@@ -1,249 +1,15 @@
|
||||
package aws
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"log"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/BishopFox/cloudfox/aws/sdk"
|
||||
"github.com/BishopFox/cloudfox/internal"
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/ec2"
|
||||
ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types"
|
||||
"github.com/aws/aws-sdk-go-v2/service/ecs"
|
||||
ecsTypes "github.com/aws/aws-sdk-go-v2/service/ecs/types"
|
||||
"github.com/aws/aws-sdk-go-v2/service/sts"
|
||||
)
|
||||
|
||||
const DESCRIBE_TASKS_TEST_FILE = "./test-data/describe-tasks.json"
|
||||
const DESCRIBE_NETWORK_INTEFACES_TEST_FILE = "./test-data/describe-network-interfaces.json"
|
||||
|
||||
type ListTasks struct {
|
||||
TaskArns []string `json:"taskArns"`
|
||||
}
|
||||
|
||||
type DescribeTasks struct {
|
||||
Tasks []struct {
|
||||
Attachments []struct {
|
||||
ID string `json:"id"`
|
||||
Type string `json:"type"`
|
||||
Status string `json:"status"`
|
||||
Details []struct {
|
||||
Name string `json:"name"`
|
||||
Value string `json:"value"`
|
||||
} `json:"details"`
|
||||
} `json:"attachments"`
|
||||
Attributes []struct {
|
||||
Name string `json:"name"`
|
||||
Value string `json:"value"`
|
||||
} `json:"attributes"`
|
||||
AvailabilityZone string `json:"availabilityZone"`
|
||||
ClusterArn string `json:"clusterArn"`
|
||||
Connectivity string `json:"connectivity"`
|
||||
ConnectivityAt string `json:"connectivityAt"`
|
||||
Containers []struct {
|
||||
ContainerArn string `json:"containerArn"`
|
||||
TaskArn string `json:"taskArn"`
|
||||
Name string `json:"name"`
|
||||
Image string `json:"image"`
|
||||
RuntimeID string `json:"runtimeId"`
|
||||
LastStatus string `json:"lastStatus"`
|
||||
NetworkBindings []interface{} `json:"networkBindings"`
|
||||
NetworkInterfaces []struct {
|
||||
AttachmentID string `json:"attachmentId"`
|
||||
PrivateIpv4Address string `json:"privateIpv4Address"`
|
||||
} `json:"networkInterfaces"`
|
||||
HealthStatus string `json:"healthStatus"`
|
||||
CPU string `json:"cpu"`
|
||||
Memory string `json:"memory"`
|
||||
} `json:"containers"`
|
||||
CPU string `json:"cpu"`
|
||||
CreatedAt string `json:"createdAt"`
|
||||
DesiredStatus string `json:"desiredStatus"`
|
||||
EnableExecuteCommand bool `json:"enableExecuteCommand"`
|
||||
Group string `json:"group"`
|
||||
HealthStatus string `json:"healthStatus"`
|
||||
LastStatus string `json:"lastStatus"`
|
||||
LaunchType string `json:"launchType"`
|
||||
Memory string `json:"memory"`
|
||||
Overrides struct {
|
||||
ContainerOverrides []struct {
|
||||
Name string `json:"name"`
|
||||
} `json:"containerOverrides"`
|
||||
InferenceAcceleratorOverrides []interface{} `json:"inferenceAcceleratorOverrides"`
|
||||
} `json:"overrides"`
|
||||
PlatformVersion string `json:"platformVersion"`
|
||||
PlatformFamily string `json:"platformFamily"`
|
||||
PullStartedAt string `json:"pullStartedAt"`
|
||||
PullStoppedAt string `json:"pullStoppedAt"`
|
||||
StartedAt string `json:"startedAt"`
|
||||
StartedBy string `json:"startedBy"`
|
||||
Tags []interface{} `json:"tags"`
|
||||
TaskArn string `json:"taskArn"`
|
||||
TaskDefinitionArn string `json:"taskDefinitionArn"`
|
||||
Version int `json:"version"`
|
||||
EphemeralStorage struct {
|
||||
SizeInGiB int `json:"sizeInGiB"`
|
||||
} `json:"ephemeralStorage"`
|
||||
} `json:"tasks"`
|
||||
Failures []interface{} `json:"failures"`
|
||||
}
|
||||
|
||||
type DescribeNetworkInterfaces struct {
|
||||
NetworkInterfaces []struct {
|
||||
Status string `json:"Status"`
|
||||
MacAddress string `json:"MacAddress"`
|
||||
SourceDestCheck bool `json:"SourceDestCheck"`
|
||||
VpcID string `json:"VpcId"`
|
||||
Description string `json:"Description"`
|
||||
Association struct {
|
||||
PublicIP string `json:"PublicIp"`
|
||||
AssociationID string `json:"AssociationId"`
|
||||
PublicDNSName string `json:"PublicDnsName"`
|
||||
IPOwnerID string `json:"IpOwnerId"`
|
||||
} `json:"Association"`
|
||||
NetworkInterfaceID string `json:"NetworkInterfaceId"`
|
||||
PrivateIPAddresses []struct {
|
||||
PrivateDNSName string `json:"PrivateDnsName"`
|
||||
Association struct {
|
||||
PublicIP string `json:"PublicIp"`
|
||||
AssociationID string `json:"AssociationId"`
|
||||
PublicDNSName string `json:"PublicDnsName"`
|
||||
IPOwnerID string `json:"IpOwnerId"`
|
||||
} `json:"Association"`
|
||||
Primary bool `json:"Primary"`
|
||||
PrivateIPAddress string `json:"PrivateIpAddress"`
|
||||
} `json:"PrivateIpAddresses"`
|
||||
RequesterManaged bool `json:"RequesterManaged"`
|
||||
Ipv6Addresses []interface{} `json:"Ipv6Addresses"`
|
||||
PrivateDNSName string `json:"PrivateDnsName,omitempty"`
|
||||
AvailabilityZone string `json:"AvailabilityZone"`
|
||||
Attachment struct {
|
||||
Status string `json:"Status"`
|
||||
DeviceIndex int `json:"DeviceIndex"`
|
||||
AttachTime time.Time `json:"AttachTime"`
|
||||
InstanceID string `json:"InstanceId"`
|
||||
DeleteOnTermination bool `json:"DeleteOnTermination"`
|
||||
AttachmentID string `json:"AttachmentId"`
|
||||
InstanceOwnerID string `json:"InstanceOwnerId"`
|
||||
} `json:"Attachment"`
|
||||
Groups []struct {
|
||||
GroupName string `json:"GroupName"`
|
||||
GroupID string `json:"GroupId"`
|
||||
} `json:"Groups"`
|
||||
SubnetID string `json:"SubnetId"`
|
||||
OwnerID string `json:"OwnerId"`
|
||||
TagSet []interface{} `json:"TagSet"`
|
||||
PrivateIPAddress string `json:"PrivateIpAddress"`
|
||||
} `json:"NetworkInterfaces"`
|
||||
}
|
||||
|
||||
func readTestFile(testFile string) []byte {
|
||||
file, err := os.ReadFile(testFile)
|
||||
if err != nil {
|
||||
log.Fatalf("can't read file %s", testFile)
|
||||
}
|
||||
return file
|
||||
}
|
||||
|
||||
type mockedListclustersClient struct {
|
||||
}
|
||||
|
||||
func (c *mockedListclustersClient) ListClusters(context.Context, *ecs.ListClustersInput, ...func(*ecs.Options)) (*ecs.ListClustersOutput, error) {
|
||||
return &ecs.ListClustersOutput{ClusterArns: []string{
|
||||
"arn:aws:ecs:us-east-1:123456789012:cluster/MyCluster",
|
||||
"arn:aws:ecs:us-east-1:123456789012:cluster/MyCluster2",
|
||||
"arn:aws:ecs:us-east-1:123456789012:cluster/MyCluster3",
|
||||
}}, nil
|
||||
}
|
||||
|
||||
type mockedListTasksClient struct{}
|
||||
|
||||
func (c *mockedListTasksClient) ListTasks(ctx context.Context, input *ecs.ListTasksInput, f ...func(*ecs.Options)) (*ecs.ListTasksOutput, error) {
|
||||
return &ecs.ListTasksOutput{TaskArns: []string{
|
||||
"arn:aws:ecs:us-east-1:123456789012:task/MyCluster/74de0355a10a4f979ac495c14EXAMPLE",
|
||||
"arn:aws:ecs:us-east-1:123456789012:task/MyCluster/d789e94343414c25b9f6bd59eEXAMPLE",
|
||||
}}, nil
|
||||
}
|
||||
|
||||
type mockedDescribeTasksClient struct {
|
||||
describeTasks DescribeTasks
|
||||
}
|
||||
|
||||
func (c *mockedDescribeTasksClient) DescribeTasks(ctx context.Context, input *ecs.DescribeTasksInput, f ...func(*ecs.Options)) (*ecs.DescribeTasksOutput, error) {
|
||||
err := json.Unmarshal(readTestFile(DESCRIBE_TASKS_TEST_FILE), &c.describeTasks)
|
||||
if err != nil {
|
||||
log.Fatalf("can't unmarshall file %s", DESCRIBE_TASKS_TEST_FILE)
|
||||
}
|
||||
var tasks []ecsTypes.Task
|
||||
for _, mockedTask := range c.describeTasks.Tasks {
|
||||
if mockedTask.ClusterArn == aws.ToString(input.Cluster) {
|
||||
for _, inputTask := range input.Tasks {
|
||||
if mockedTask.TaskArn == inputTask {
|
||||
var attachments []ecsTypes.Attachment
|
||||
for _, a := range mockedTask.Attachments {
|
||||
var deets []ecsTypes.KeyValuePair
|
||||
for _, detail := range a.Details {
|
||||
deets = append(deets, ecsTypes.KeyValuePair{
|
||||
Name: aws.String(detail.Name),
|
||||
Value: aws.String(detail.Value)})
|
||||
}
|
||||
attachments = append(attachments, ecsTypes.Attachment{
|
||||
Type: aws.String(a.Type),
|
||||
Details: deets,
|
||||
Id: aws.String(a.ID),
|
||||
Status: aws.String(a.Status),
|
||||
})
|
||||
}
|
||||
tasks = append(tasks, ecsTypes.Task{
|
||||
ClusterArn: aws.String(mockedTask.ClusterArn),
|
||||
TaskDefinitionArn: aws.String(mockedTask.TaskDefinitionArn),
|
||||
LaunchType: ecsTypes.LaunchType(*aws.String(mockedTask.LaunchType)),
|
||||
TaskArn: aws.String(mockedTask.TaskArn),
|
||||
Attachments: attachments,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return &ecs.DescribeTasksOutput{Tasks: tasks}, nil
|
||||
}
|
||||
|
||||
type mockedDescribeNetworkInterfacesClient struct {
|
||||
describeNetworkInterfaces DescribeNetworkInterfaces
|
||||
}
|
||||
|
||||
func (c *mockedDescribeNetworkInterfacesClient) DescribeNetworkInterfaces(ctx context.Context, input *ec2.DescribeNetworkInterfacesInput, f ...func(o *ec2.Options)) (*ec2.DescribeNetworkInterfacesOutput, error) {
|
||||
var nics []ec2types.NetworkInterface
|
||||
err := json.Unmarshal(readTestFile(DESCRIBE_NETWORK_INTEFACES_TEST_FILE), &c.describeNetworkInterfaces)
|
||||
if err != nil {
|
||||
log.Fatalf("can't unmarshall file %s", DESCRIBE_NETWORK_INTEFACES_TEST_FILE)
|
||||
}
|
||||
for _, mockedNic := range c.describeNetworkInterfaces.NetworkInterfaces {
|
||||
for _, inputNicID := range input.NetworkInterfaceIds {
|
||||
if mockedNic.NetworkInterfaceID == inputNicID {
|
||||
nics = append(nics, ec2types.NetworkInterface{
|
||||
Association: &ec2types.NetworkInterfaceAssociation{
|
||||
PublicIp: aws.String(mockedNic.Association.PublicIP),
|
||||
},
|
||||
NetworkInterfaceId: aws.String(mockedNic.NetworkInterfaceID)})
|
||||
}
|
||||
}
|
||||
}
|
||||
return &ec2.DescribeNetworkInterfacesOutput{NetworkInterfaces: nics}, nil
|
||||
}
|
||||
|
||||
type mockedDescribeTaskDefinitionInterface struct {
|
||||
}
|
||||
|
||||
func (c *mockedDescribeTaskDefinitionInterface) DescribeTaskDefinition(ctx context.Context, input *ecs.DescribeTaskDefinitionInput, f ...func(o *ecs.Options)) (*ecs.DescribeTaskDefinitionOutput, error) {
|
||||
testTaskDefinition := ecsTypes.TaskDefinition{}
|
||||
testTaskDefinition.TaskRoleArn = aws.String("test123")
|
||||
return &ecs.DescribeTaskDefinitionOutput{TaskDefinition: &testTaskDefinition}, nil
|
||||
}
|
||||
|
||||
func TestECSTasks(t *testing.T) {
|
||||
subtests := []struct {
|
||||
name string
|
||||
@@ -258,17 +24,13 @@ func TestECSTasks(t *testing.T) {
|
||||
verbosity: 2,
|
||||
testModule: ECSTasksModule{
|
||||
|
||||
AWSProfile: "default",
|
||||
AWSRegions: []string{"us-east-1", "us-west-1"},
|
||||
Caller: sts.GetCallerIdentityOutput{Arn: aws.String("arn:aws:iam::123456789012:user/cloudfox_unit_tests")},
|
||||
SkipAdminCheck: true,
|
||||
Goroutines: 30,
|
||||
DescribeNetworkInterfacesClient: &mockedDescribeNetworkInterfacesClient{},
|
||||
DescribeTasksClient: &mockedDescribeTasksClient{},
|
||||
ListTasksClient: &mockedListTasksClient{},
|
||||
ListClustersClient: &mockedListclustersClient{},
|
||||
DescribeTaskDefinitionClient: &mockedDescribeTaskDefinitionInterface{},
|
||||
//IAMSimulatePrincipalPolicyClient: &mockedDescribeTaskDefinitionsClient{},
|
||||
AWSProfile: "default",
|
||||
AWSRegions: []string{"us-east-1", "us-west-1"},
|
||||
Caller: sts.GetCallerIdentityOutput{Arn: aws.String("arn:aws:iam::123456789012:user/cloudfox_unit_tests")},
|
||||
SkipAdminCheck: true,
|
||||
Goroutines: 30,
|
||||
EC2Client: &sdk.MockedEC2Client2{},
|
||||
ECSClient: &sdk.MockedECSClient{},
|
||||
},
|
||||
expectedResult: []MappedECSTask{{
|
||||
Cluster: "MyCluster",
|
||||
|
||||
+12
-5
@@ -198,7 +198,7 @@ func (m *EKSModule) EKS(outputFormat string, outputDirectory string, verbosity i
|
||||
}
|
||||
|
||||
if len(m.output.Body) > 0 {
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
//m.output.OutputSelector(outputFormat)
|
||||
//utils.OutputSelector(verbosity, outputFormat, m.output.Headers, m.output.Body, m.output.FilePath, m.output.CallingModule, m.output.CallingModule)
|
||||
//internal.OutputSelector(verbosity, outputFormat, m.output.Headers, m.output.Body, m.output.FilePath, m.output.CallingModule, m.output.CallingModule, m.WrapTable, m.AWSProfile)
|
||||
@@ -216,7 +216,7 @@ func (m *EKSModule) EKS(outputFormat string, outputDirectory string, verbosity i
|
||||
Name: m.output.CallingModule,
|
||||
})
|
||||
o.PrefixIdentifier = m.AWSProfile
|
||||
o.Table.DirectoryName = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
o.Table.DirectoryName = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
o.WriteFullOutput(o.Table.TableFiles, nil)
|
||||
m.writeLoot(o.Table.DirectoryName, verbosity)
|
||||
fmt.Printf("[%s][%s] %d clusters with a total of %d node groups found.\n", cyan(m.output.CallingModule), cyan(m.AWSProfile), len(seen), len(m.output.Body))
|
||||
@@ -314,7 +314,6 @@ func (m *EKSModule) getEKSRecordsPerRegion(r string, wg *sync.WaitGroup, semapho
|
||||
<-semaphore
|
||||
}()
|
||||
var clusters []string
|
||||
var role string
|
||||
|
||||
clusters, err := sdk.CachedEKSListClusters(m.EKSClient, aws.ToString(m.Caller.Account), r)
|
||||
if err != nil {
|
||||
@@ -324,6 +323,9 @@ func (m *EKSModule) getEKSRecordsPerRegion(r string, wg *sync.WaitGroup, semapho
|
||||
}
|
||||
|
||||
for _, clusterName := range clusters {
|
||||
var role string
|
||||
var oidc string = ""
|
||||
var publicEndpoint = ""
|
||||
clusterDetails, err := sdk.CachedEKSDescribeCluster(m.EKSClient, aws.ToString(m.Caller.Account), clusterName, r)
|
||||
if err != nil {
|
||||
m.modLog.Error(err.Error())
|
||||
@@ -332,8 +334,13 @@ func (m *EKSModule) getEKSRecordsPerRegion(r string, wg *sync.WaitGroup, semapho
|
||||
|
||||
//nodeGroups = append(nodeGroups, DescribeCluster.Cluster.)
|
||||
endpoint := aws.ToString(clusterDetails.Endpoint)
|
||||
oidc := aws.ToString(clusterDetails.Identity.Oidc.Issuer)
|
||||
publicEndpoint := strconv.FormatBool(clusterDetails.ResourcesVpcConfig.EndpointPublicAccess)
|
||||
if clusterDetails.Identity != nil && clusterDetails.Identity.Oidc != nil {
|
||||
oidc = aws.ToString(clusterDetails.Identity.Oidc.Issuer)
|
||||
|
||||
}
|
||||
if clusterDetails.ResourcesVpcConfig != nil {
|
||||
publicEndpoint = strconv.FormatBool(clusterDetails.ResourcesVpcConfig.EndpointPublicAccess)
|
||||
}
|
||||
// if DescribeCluster.Cluster.ResourcesVpcConfig.PublicAccessCidrs[0] == "0.0.0.0/0" {
|
||||
// publicCIDRs := "0.0.0.0/0"
|
||||
// } else {
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
package aws
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"sync"
|
||||
|
||||
"github.com/BishopFox/cloudfox/aws/sdk"
|
||||
"github.com/BishopFox/cloudfox/internal"
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/ec2"
|
||||
"github.com/aws/aws-sdk-go-v2/service/ec2/types"
|
||||
"github.com/aws/aws-sdk-go-v2/service/sts"
|
||||
"github.com/bishopfox/awsservicemap"
|
||||
@@ -18,8 +17,7 @@ import (
|
||||
)
|
||||
|
||||
type ElasticNetworkInterfacesModule struct {
|
||||
//EC2Client *ec2.Client
|
||||
DescribeNetworkInterfacesClient ec2.DescribeNetworkInterfacesAPIClient
|
||||
EC2Client sdk.AWSEC2ClientInterface
|
||||
|
||||
Caller sts.GetCallerIdentityOutput
|
||||
AWSRegions []string
|
||||
@@ -126,7 +124,7 @@ func (m *ElasticNetworkInterfacesModule) printENIsData(outputFormat string, outp
|
||||
)
|
||||
}
|
||||
if len(m.output.Body) > 0 {
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
//utils.OutputSelector(m.output.Verbosity, outputFormat, m.output.Headers, m.output.Body, m.output.FilePath, m.output.CallingModule, m.output.CallingModule)
|
||||
//internal.OutputSelector(m.output.Verbosity, outputFormat, m.output.Headers, m.output.Body, m.output.FilePath, m.output.CallingModule, m.output.CallingModule, m.WrapTable, m.AWSProfile)
|
||||
|
||||
@@ -144,7 +142,7 @@ func (m *ElasticNetworkInterfacesModule) printENIsData(outputFormat string, outp
|
||||
Name: m.output.CallingModule,
|
||||
})
|
||||
o.PrefixIdentifier = m.AWSProfile
|
||||
o.Table.DirectoryName = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
o.Table.DirectoryName = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
o.WriteFullOutput(o.Table.TableFiles, nil)
|
||||
m.writeLoot(o.Table.DirectoryName)
|
||||
fmt.Printf("[%s][%s] %s elastic network interfaces found.\n", cyan(m.output.CallingModule), cyan(m.AWSProfile), strconv.Itoa(len(m.output.Body)))
|
||||
@@ -213,50 +211,45 @@ func (m *ElasticNetworkInterfacesModule) executeChecks(r string, wg *sync.WaitGr
|
||||
}
|
||||
|
||||
func (m *ElasticNetworkInterfacesModule) getDescribeNetworkInterfaces(region string, dataReceiver chan MappedENI) {
|
||||
var PaginationControl *string
|
||||
for {
|
||||
DescribeNetworkInterfaces, err := m.DescribeNetworkInterfacesClient.DescribeNetworkInterfaces(
|
||||
context.TODO(),
|
||||
&(ec2.DescribeNetworkInterfacesInput{
|
||||
NextToken: PaginationControl,
|
||||
}),
|
||||
func(o *ec2.Options) {
|
||||
o.Region = region
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
m.modLog.Error(err.Error())
|
||||
m.CommandCounter.Error++
|
||||
break
|
||||
}
|
||||
|
||||
for _, eni := range DescribeNetworkInterfaces.NetworkInterfaces {
|
||||
status := string(eni.Status)
|
||||
if status == "available" {
|
||||
continue // unused ENI
|
||||
}
|
||||
|
||||
mappedENI := MappedENI{
|
||||
ID: aws.ToString(eni.NetworkInterfaceId),
|
||||
Type: string(eni.InterfaceType),
|
||||
ExternalIP: getPublicIPOfElasticNetworkInterface(eni),
|
||||
PrivateIP: aws.ToString(eni.PrivateIpAddress),
|
||||
VPCID: aws.ToString(eni.VpcId),
|
||||
AttachedInstance: getAttachmentInstanceOfElasticNetworkInterface(eni),
|
||||
Description: aws.ToString(eni.Description),
|
||||
}
|
||||
|
||||
dataReceiver <- mappedENI
|
||||
}
|
||||
|
||||
if DescribeNetworkInterfaces.NextToken != nil {
|
||||
PaginationControl = DescribeNetworkInterfaces.NextToken
|
||||
} else {
|
||||
PaginationControl = nil
|
||||
break
|
||||
}
|
||||
NetworkInterfaces, err := sdk.CachedEC2DescribeNetworkInterfaces(m.EC2Client, aws.ToString(m.Caller.Account), region)
|
||||
|
||||
// var PaginationControl *string
|
||||
// for {
|
||||
// DescribeNetworkInterfaces, err := m.DescribeNetworkInterfacesClient.DescribeNetworkInterfaces(
|
||||
// context.TODO(),
|
||||
// &(ec2.DescribeNetworkInterfacesInput{
|
||||
// NextToken: PaginationControl,
|
||||
// }),
|
||||
// func(o *ec2.Options) {
|
||||
// o.Region = region
|
||||
// },
|
||||
// )
|
||||
if err != nil {
|
||||
m.modLog.Error(err.Error())
|
||||
m.CommandCounter.Error++
|
||||
return
|
||||
}
|
||||
|
||||
for _, eni := range NetworkInterfaces {
|
||||
status := string(eni.Status)
|
||||
if status == "available" {
|
||||
continue // unused ENI
|
||||
}
|
||||
|
||||
mappedENI := MappedENI{
|
||||
ID: aws.ToString(eni.NetworkInterfaceId),
|
||||
Type: string(eni.InterfaceType),
|
||||
ExternalIP: getPublicIPOfElasticNetworkInterface(eni),
|
||||
PrivateIP: aws.ToString(eni.PrivateIpAddress),
|
||||
VPCID: aws.ToString(eni.VpcId),
|
||||
AttachedInstance: getAttachmentInstanceOfElasticNetworkInterface(eni),
|
||||
Description: aws.ToString(eni.Description),
|
||||
}
|
||||
|
||||
dataReceiver <- mappedENI
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func getPublicIPOfElasticNetworkInterface(elasticNetworkInterface types.NetworkInterface) string {
|
||||
|
||||
@@ -1,48 +1,59 @@
|
||||
package aws
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"log"
|
||||
"testing"
|
||||
|
||||
"github.com/BishopFox/cloudfox/aws/sdk"
|
||||
"github.com/BishopFox/cloudfox/internal"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/ec2"
|
||||
ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/service/sts"
|
||||
)
|
||||
|
||||
type mockedDescribeNetworkInterfacesClient2 struct {
|
||||
describeNetworkInterfaces DescribeNetworkInterfaces
|
||||
}
|
||||
func TestElasticNetworkInterfaces(t *testing.T) {
|
||||
|
||||
func (c *mockedDescribeNetworkInterfacesClient2) DescribeNetworkInterfaces(ctx context.Context, input *ec2.DescribeNetworkInterfacesInput, f ...func(o *ec2.Options)) (*ec2.DescribeNetworkInterfacesOutput, error) {
|
||||
var nics []ec2types.NetworkInterface
|
||||
err := json.Unmarshal(readTestFile(DESCRIBE_NETWORK_INTEFACES_TEST_FILE), &c.describeNetworkInterfaces)
|
||||
if err != nil {
|
||||
log.Fatalf("can't unmarshall file %s", DESCRIBE_NETWORK_INTEFACES_TEST_FILE)
|
||||
m := ElasticNetworkInterfacesModule{
|
||||
AWSProfile: "default",
|
||||
AWSRegions: []string{"us-east-1", "us-west-1"},
|
||||
Caller: sts.GetCallerIdentityOutput{Arn: aws.String("arn:aws:iam::123456789012:user/cloudfox_unit_tests")},
|
||||
EC2Client: &sdk.MockedEC2Client2{},
|
||||
}
|
||||
for _, mockednic := range c.describeNetworkInterfaces.NetworkInterfaces {
|
||||
nics = append(nics, ec2types.NetworkInterface{
|
||||
Association: &ec2types.NetworkInterfaceAssociation{
|
||||
PublicIp: aws.String(mockednic.Association.PublicIP),
|
||||
|
||||
//m.ElasticNetworkInterfaces("table", ".", 3)
|
||||
subtests := []struct {
|
||||
name string
|
||||
testModule ElasticNetworkInterfacesModule
|
||||
expectedResult []MappedENI
|
||||
}{
|
||||
{
|
||||
name: "Test ElasticNetworkInterfaces",
|
||||
testModule: m,
|
||||
expectedResult: []MappedENI{
|
||||
{
|
||||
PrivateIP: "10.0.1.17",
|
||||
ExternalIP: "203.0.113.12",
|
||||
},
|
||||
{
|
||||
PrivateIP: "10.0.1.149",
|
||||
ExternalIP: "198.51.100.0",
|
||||
},
|
||||
},
|
||||
NetworkInterfaceId: aws.String(mockednic.NetworkInterfaceID),
|
||||
PrivateIpAddress: aws.String(mockednic.PrivateIPAddress),
|
||||
VpcId: aws.String(mockednic.VpcID),
|
||||
Attachment: &ec2types.NetworkInterfaceAttachment{InstanceId: aws.String(mockednic.Attachment.InstanceID)},
|
||||
Description: aws.String(mockednic.Description),
|
||||
},
|
||||
}
|
||||
internal.MockFileSystem(true)
|
||||
for _, subtest := range subtests {
|
||||
t.Run(subtest.name, func(t *testing.T) {
|
||||
subtest.testModule.ElasticNetworkInterfaces("table", ".", 3)
|
||||
for index, expectedTask := range subtest.expectedResult {
|
||||
if expectedTask.ExternalIP != subtest.testModule.MappedENIs[index].ExternalIP {
|
||||
t.Errorf("expected %s, got %s", expectedTask.ExternalIP, subtest.testModule.MappedENIs[index].ExternalIP)
|
||||
}
|
||||
if expectedTask.PrivateIP != subtest.testModule.MappedENIs[index].PrivateIP {
|
||||
t.Errorf("expected %s, got %s", expectedTask.PrivateIP, subtest.testModule.MappedENIs[index].PrivateIP)
|
||||
}
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
return &ec2.DescribeNetworkInterfacesOutput{NetworkInterfaces: nics}, nil
|
||||
}
|
||||
|
||||
func TestElasticNetworkInterfaces(t *testing.T) {
|
||||
m := ElasticNetworkInterfacesModule{
|
||||
AWSProfile: "default",
|
||||
AWSRegions: []string{"us-east-1", "us-west-1"},
|
||||
Caller: sts.GetCallerIdentityOutput{Arn: aws.String("arn:aws:iam::123456789012:user/cloudfox_unit_tests")},
|
||||
DescribeNetworkInterfacesClient: &mockedDescribeNetworkInterfacesClient2{},
|
||||
}
|
||||
m.ElasticNetworkInterfaces("table", ".", 3)
|
||||
}
|
||||
+434
-101
@@ -15,7 +15,10 @@ import (
|
||||
"github.com/BishopFox/cloudfox/internal"
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/apigateway"
|
||||
apigatewayTypes "github.com/aws/aws-sdk-go-v2/service/apigateway/types"
|
||||
"github.com/aws/aws-sdk-go-v2/service/apigatewayv2"
|
||||
|
||||
apigatewayV2Types "github.com/aws/aws-sdk-go-v2/service/apigatewayv2/types"
|
||||
"github.com/aws/aws-sdk-go-v2/service/apprunner"
|
||||
apprunnerTypes "github.com/aws/aws-sdk-go-v2/service/apprunner/types"
|
||||
"github.com/aws/aws-sdk-go-v2/service/cloudfront"
|
||||
@@ -170,7 +173,7 @@ func (m *EndpointsModule) PrintEndpoints(outputFormat string, outputDirectory st
|
||||
|
||||
}
|
||||
if len(m.output.Body) > 0 {
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
//m.output.OutputSelector(outputFormat)
|
||||
//utils.OutputSelector(verbosity, outputFormat, m.output.Headers, m.output.Body, m.output.FilePath, m.output.CallingModule, m.output.CallingModule)
|
||||
//internal.OutputSelector(verbosity, outputFormat, m.output.Headers, m.output.Body, m.output.FilePath, m.output.CallingModule, m.output.CallingModule, m.WrapTable, m.AWSProfile)
|
||||
@@ -188,7 +191,7 @@ func (m *EndpointsModule) PrintEndpoints(outputFormat string, outputDirectory st
|
||||
Name: m.output.CallingModule,
|
||||
})
|
||||
o.PrefixIdentifier = m.AWSProfile
|
||||
o.Table.DirectoryName = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
o.Table.DirectoryName = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
o.WriteFullOutput(o.Table.TableFiles, nil)
|
||||
m.writeLoot(o.Table.DirectoryName, verbosity)
|
||||
fmt.Printf("[%s][%s] %s endpoints found.\n", cyan(m.output.CallingModule), cyan(m.AWSProfile), strconv.Itoa(len(m.output.Body)))
|
||||
@@ -297,9 +300,17 @@ func (m *EndpointsModule) executeChecks(r string, wg *sync.WaitGroup, semaphore
|
||||
wg.Add(1)
|
||||
go m.getAPIGatewayAPIsPerRegion(r, wg, semaphore, dataReceiver)
|
||||
|
||||
m.CommandCounter.Total++
|
||||
wg.Add(1)
|
||||
go m.getAPIGatewayVIPsPerRegion(r, wg, semaphore, dataReceiver)
|
||||
|
||||
m.CommandCounter.Total++
|
||||
wg.Add(1)
|
||||
go m.getAPIGatewayv2APIsPerRegion(r, wg, semaphore, dataReceiver)
|
||||
|
||||
m.CommandCounter.Total++
|
||||
wg.Add(1)
|
||||
go m.getAPIGatewayv2VIPsPerRegion(r, wg, semaphore, dataReceiver)
|
||||
}
|
||||
res, err = servicemap.IsServiceInRegion("rds", r)
|
||||
if err != nil {
|
||||
@@ -853,8 +864,39 @@ func (m *EndpointsModule) getAPIGatewayAPIsPerRegion(r string, wg *sync.WaitGrou
|
||||
m.CommandCounter.Executing++
|
||||
// "PaginationMarker" is a control variable used for output continuity, as AWS return the output in pages.
|
||||
|
||||
Items, err := sdk.CachedApiGatewayGetRestAPIs(m.APIGatewayClient, aws.ToString(m.Caller.Account), r)
|
||||
|
||||
if err != nil {
|
||||
m.modLog.Error(err.Error())
|
||||
m.CommandCounter.Error++
|
||||
return
|
||||
}
|
||||
|
||||
for _, api := range Items {
|
||||
for _, endpoint := range m.getEndpointsPerAPIGateway(r, api) {
|
||||
dataReceiver <- endpoint
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (m *EndpointsModule) getAPIGatewayVIPsPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Endpoint) {
|
||||
defer func() {
|
||||
m.CommandCounter.Executing--
|
||||
m.CommandCounter.Complete++
|
||||
wg.Done()
|
||||
|
||||
}()
|
||||
semaphore <- struct{}{}
|
||||
defer func() {
|
||||
<-semaphore
|
||||
}()
|
||||
// m.CommandCounter.Total++
|
||||
m.CommandCounter.Pending--
|
||||
m.CommandCounter.Executing++
|
||||
// "PaginationMarker" is a control variable used for output continuity, as AWS return the output in pages.
|
||||
|
||||
var PaginationControl2 *string
|
||||
awsService := "APIGateway"
|
||||
var PaginationControl3 *string
|
||||
|
||||
Items, err := sdk.CachedApiGatewayGetRestAPIs(m.APIGatewayClient, aws.ToString(m.Caller.Account), r)
|
||||
|
||||
@@ -864,77 +906,186 @@ func (m *EndpointsModule) getAPIGatewayAPIsPerRegion(r string, wg *sync.WaitGrou
|
||||
return
|
||||
}
|
||||
|
||||
var public string
|
||||
for _, api := range Items {
|
||||
for {
|
||||
GetDomainNames, err := m.APIGatewayClient.GetDomainNames(
|
||||
context.TODO(),
|
||||
&apigateway.GetDomainNamesInput{
|
||||
Position: PaginationControl2,
|
||||
},
|
||||
func(o *apigateway.Options) {
|
||||
o.Region = r
|
||||
},
|
||||
)
|
||||
|
||||
name := aws.ToString(api.Name)
|
||||
id := aws.ToString(api.Id)
|
||||
raw_endpoint := fmt.Sprintf("https://%s.execute-api.%s.amazonaws.com", id, r)
|
||||
var port int32 = 443
|
||||
protocol := "https"
|
||||
|
||||
endpointType := *api.EndpointConfiguration
|
||||
//fmt.Println(endpointType)
|
||||
if endpointType.Types[0] == "PRIVATE" {
|
||||
public = "False"
|
||||
} else {
|
||||
public = "True"
|
||||
if err != nil {
|
||||
if errors.As(err, &oe) {
|
||||
m.Errors = append(m.Errors, (fmt.Sprintf(" Error: Region: %s, Service: %s, Operation: %s", r, oe.Service(), oe.Operation())))
|
||||
}
|
||||
m.modLog.Error(err.Error())
|
||||
m.CommandCounter.Error++
|
||||
break
|
||||
}
|
||||
|
||||
for {
|
||||
GetResources, err := m.APIGatewayClient.GetResources(
|
||||
context.TODO(),
|
||||
&apigateway.GetResourcesInput{
|
||||
RestApiId: &id,
|
||||
Position: PaginationControl2,
|
||||
},
|
||||
func(o *apigateway.Options) {
|
||||
o.Region = r
|
||||
},
|
||||
)
|
||||
for _, item := range GetDomainNames.Items {
|
||||
|
||||
if err != nil {
|
||||
if errors.As(err, &oe) {
|
||||
m.Errors = append(m.Errors, (fmt.Sprintf(" Error: Region: %s, Service: %s, Operation: %s", r, oe.Service(), oe.Operation())))
|
||||
}
|
||||
m.modLog.Error(err.Error())
|
||||
m.CommandCounter.Error++
|
||||
break
|
||||
}
|
||||
domain := aws.ToString(item.DomainName)
|
||||
|
||||
for _, resource := range GetResources.Items {
|
||||
for {
|
||||
GetBasePathMappings, err := m.APIGatewayClient.GetBasePathMappings(
|
||||
context.TODO(),
|
||||
&apigateway.GetBasePathMappingsInput{
|
||||
DomainName: item.DomainName,
|
||||
Position: PaginationControl3,
|
||||
},
|
||||
func(o *apigateway.Options) {
|
||||
o.Region = r
|
||||
},
|
||||
)
|
||||
|
||||
path := resource.Path
|
||||
//pathPart := resource.PathPart
|
||||
//fmt.Printf(*path, *pathPart)
|
||||
//var path string
|
||||
|
||||
// if len(strings.Fields(*routeKey)) == 2 {
|
||||
// path = strings.Fields(*routeKey)[1]
|
||||
// }
|
||||
endpoint := fmt.Sprintf("%s%s", raw_endpoint, aws.ToString(path))
|
||||
|
||||
dataReceiver <- Endpoint{
|
||||
AWSService: awsService,
|
||||
Region: r,
|
||||
Name: name,
|
||||
Endpoint: endpoint,
|
||||
Port: port,
|
||||
Protocol: protocol,
|
||||
Public: public,
|
||||
if err != nil {
|
||||
if errors.As(err, &oe) {
|
||||
m.Errors = append(m.Errors, (fmt.Sprintf(" Error: Region: %s, Service: %s, Operation: %s", r, oe.Service(), oe.Operation())))
|
||||
}
|
||||
m.modLog.Error(err.Error())
|
||||
m.CommandCounter.Error++
|
||||
break
|
||||
}
|
||||
|
||||
}
|
||||
if GetResources.Position != nil {
|
||||
PaginationControl2 = GetResources.Position
|
||||
} else {
|
||||
PaginationControl2 = nil
|
||||
break
|
||||
}
|
||||
for _, mapping := range GetBasePathMappings.Items {
|
||||
stage := aws.ToString(mapping.Stage)
|
||||
basePath := aws.ToString(mapping.BasePath)
|
||||
if basePath == "(none)" {
|
||||
basePath = "" // Empty string since '/' is already prepended
|
||||
}
|
||||
|
||||
for _, api := range Items {
|
||||
if api.Id != nil && aws.ToString(api.Id) == aws.ToString(mapping.RestApiId) {
|
||||
endpoints := m.getEndpointsPerAPIGateway(r, api)
|
||||
for _, endpoint := range endpoints {
|
||||
old := fmt.Sprintf("https://%s.execute-api.%s.amazonaws.com/%s/", aws.ToString(mapping.RestApiId), r, stage)
|
||||
|
||||
if strings.HasPrefix(endpoint.Endpoint, old) {
|
||||
var new string
|
||||
if basePath == "" {
|
||||
new = fmt.Sprintf("https://%s/", domain)
|
||||
} else {
|
||||
new = fmt.Sprintf("https://%s/%s/", domain, basePath)
|
||||
}
|
||||
endpoint.Endpoint = strings.Replace(endpoint.Endpoint, old, new, 1)
|
||||
endpoint.Name = domain
|
||||
dataReceiver <- endpoint
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if GetBasePathMappings.Position != nil {
|
||||
PaginationControl3 = GetBasePathMappings.Position
|
||||
} else {
|
||||
PaginationControl3 = nil
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if GetDomainNames.Position != nil {
|
||||
PaginationControl2 = GetDomainNames.Position
|
||||
} else {
|
||||
PaginationControl2 = nil
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (m *EndpointsModule) getEndpointsPerAPIGateway(r string, api apigatewayTypes.RestApi) []Endpoint {
|
||||
var endpoints []Endpoint
|
||||
|
||||
var PaginationControl2 *string
|
||||
awsService := "APIGateway"
|
||||
var public string
|
||||
|
||||
name := aws.ToString(api.Name)
|
||||
id := aws.ToString(api.Id)
|
||||
raw_endpoint := fmt.Sprintf("https://%s.execute-api.%s.amazonaws.com", id, r)
|
||||
var port int32 = 443
|
||||
protocol := "https"
|
||||
|
||||
endpointType := *api.EndpointConfiguration
|
||||
//fmt.Println(endpointType)
|
||||
if endpointType.Types[0] == "PRIVATE" {
|
||||
public = "False"
|
||||
} else {
|
||||
public = "True"
|
||||
}
|
||||
|
||||
GetStages, err := m.APIGatewayClient.GetStages(
|
||||
context.TODO(),
|
||||
&apigateway.GetStagesInput{
|
||||
RestApiId: &id,
|
||||
},
|
||||
func(o *apigateway.Options) {
|
||||
o.Region = r
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
if errors.As(err, &oe) {
|
||||
m.Errors = append(m.Errors, (fmt.Sprintf(" Error: Region: %s, Service: %s, Operation: %s", r, oe.Service(), oe.Operation())))
|
||||
}
|
||||
m.modLog.Error(err.Error())
|
||||
m.CommandCounter.Error++
|
||||
}
|
||||
|
||||
for {
|
||||
GetResources, err := m.APIGatewayClient.GetResources(
|
||||
context.TODO(),
|
||||
&apigateway.GetResourcesInput{
|
||||
RestApiId: &id,
|
||||
Position: PaginationControl2,
|
||||
},
|
||||
func(o *apigateway.Options) {
|
||||
o.Region = r
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
if errors.As(err, &oe) {
|
||||
m.Errors = append(m.Errors, (fmt.Sprintf(" Error: Region: %s, Service: %s, Operation: %s", r, oe.Service(), oe.Operation())))
|
||||
}
|
||||
m.modLog.Error(err.Error())
|
||||
m.CommandCounter.Error++
|
||||
break
|
||||
}
|
||||
|
||||
for _, stage := range GetStages.Item {
|
||||
stageName := aws.ToString(stage.StageName)
|
||||
for _, resource := range GetResources.Items {
|
||||
if len(resource.ResourceMethods) != 0 {
|
||||
path := aws.ToString(resource.Path)
|
||||
|
||||
endpoint := fmt.Sprintf("%s/%s%s", raw_endpoint, stageName, path)
|
||||
|
||||
endpoints = append(endpoints, Endpoint{
|
||||
AWSService: awsService,
|
||||
Region: r,
|
||||
Name: name,
|
||||
Endpoint: endpoint,
|
||||
Port: port,
|
||||
Protocol: protocol,
|
||||
Public: public,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
if GetResources.Position != nil {
|
||||
PaginationControl2 = GetResources.Position
|
||||
} else {
|
||||
PaginationControl2 = nil
|
||||
break
|
||||
}
|
||||
}
|
||||
return endpoints
|
||||
}
|
||||
|
||||
func (m *EndpointsModule) getAPIGatewayv2APIsPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Endpoint) {
|
||||
@@ -952,8 +1103,6 @@ func (m *EndpointsModule) getAPIGatewayv2APIsPerRegion(r string, wg *sync.WaitGr
|
||||
m.CommandCounter.Pending--
|
||||
m.CommandCounter.Executing++
|
||||
// "PaginationMarker" is a control variable used for output continuity, as AWS return the output in pages.
|
||||
var PaginationControl2 *string
|
||||
awsService := "APIGatewayv2"
|
||||
|
||||
Items, err := sdk.CachedAPIGatewayv2GetAPIs(m.APIGatewayv2Client, aws.ToString(m.Caller.Account), r)
|
||||
|
||||
@@ -962,46 +1111,227 @@ func (m *EndpointsModule) getAPIGatewayv2APIsPerRegion(r string, wg *sync.WaitGr
|
||||
m.CommandCounter.Error++
|
||||
return
|
||||
}
|
||||
var public string
|
||||
for _, api := range Items {
|
||||
for _, endpoint := range m.getEndpointsPerAPIGatewayv2(r, api) {
|
||||
dataReceiver <- endpoint
|
||||
}
|
||||
}
|
||||
|
||||
name := aws.ToString(api.Name)
|
||||
raw_endpoint := aws.ToString(api.ApiEndpoint)
|
||||
id := aws.ToString(api.ApiId)
|
||||
var port int32 = 443
|
||||
protocol := "https"
|
||||
}
|
||||
|
||||
for {
|
||||
GetRoutes, err := m.APIGatewayv2Client.GetRoutes(
|
||||
context.TODO(),
|
||||
&apigatewayv2.GetRoutesInput{
|
||||
ApiId: &id,
|
||||
NextToken: PaginationControl2,
|
||||
},
|
||||
func(o *apigatewayv2.Options) {
|
||||
o.Region = r
|
||||
},
|
||||
)
|
||||
func (m *EndpointsModule) getAPIGatewayv2VIPsPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Endpoint) {
|
||||
defer func() {
|
||||
m.CommandCounter.Executing--
|
||||
m.CommandCounter.Complete++
|
||||
wg.Done()
|
||||
|
||||
if err != nil {
|
||||
if errors.As(err, &oe) {
|
||||
m.Errors = append(m.Errors, (fmt.Sprintf(" Error: Region: %s, Service: %s, Operation: %s", r, oe.Service(), oe.Operation())))
|
||||
}
|
||||
m.modLog.Error(err.Error())
|
||||
m.CommandCounter.Error++
|
||||
continue
|
||||
}()
|
||||
semaphore <- struct{}{}
|
||||
defer func() {
|
||||
<-semaphore
|
||||
}()
|
||||
// m.CommandCounter.Total++
|
||||
m.CommandCounter.Pending--
|
||||
m.CommandCounter.Executing++
|
||||
// "PaginationMarker" is a control variable used for output continuity, as AWS return the output in pages.
|
||||
|
||||
var PaginationControl2 *string
|
||||
var PaginationControl3 *string
|
||||
|
||||
Items, err := sdk.CachedAPIGatewayv2GetAPIs(m.APIGatewayv2Client, aws.ToString(m.Caller.Account), r)
|
||||
|
||||
if err != nil {
|
||||
m.modLog.Error(err.Error())
|
||||
m.CommandCounter.Error++
|
||||
return
|
||||
}
|
||||
|
||||
for {
|
||||
GetDomainNames, err := m.APIGatewayv2Client.GetDomainNames(
|
||||
context.TODO(),
|
||||
&apigatewayv2.GetDomainNamesInput{
|
||||
NextToken: PaginationControl2,
|
||||
},
|
||||
func(o *apigatewayv2.Options) {
|
||||
o.Region = r
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
if errors.As(err, &oe) {
|
||||
m.Errors = append(m.Errors, (fmt.Sprintf(" Error: Region: %s, Service: %s, Operation: %s", r, oe.Service(), oe.Operation())))
|
||||
}
|
||||
m.modLog.Error(err.Error())
|
||||
m.CommandCounter.Error++
|
||||
break
|
||||
}
|
||||
|
||||
for _, item := range GetDomainNames.Items {
|
||||
|
||||
domain := aws.ToString(item.DomainName)
|
||||
|
||||
for {
|
||||
GetApiMappings, err := m.APIGatewayv2Client.GetApiMappings(
|
||||
context.TODO(),
|
||||
&apigatewayv2.GetApiMappingsInput{
|
||||
DomainName: item.DomainName,
|
||||
NextToken: PaginationControl3,
|
||||
},
|
||||
func(o *apigatewayv2.Options) {
|
||||
o.Region = r
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
if errors.As(err, &oe) {
|
||||
m.Errors = append(m.Errors, (fmt.Sprintf(" Error: Region: %s, Service: %s, Operation: %s", r, oe.Service(), oe.Operation())))
|
||||
}
|
||||
m.modLog.Error(err.Error())
|
||||
m.CommandCounter.Error++
|
||||
break
|
||||
}
|
||||
|
||||
for _, mapping := range GetApiMappings.Items {
|
||||
stage := aws.ToString(mapping.Stage)
|
||||
if stage == "$default" {
|
||||
stage = ""
|
||||
}
|
||||
path := aws.ToString(mapping.ApiMappingKey)
|
||||
|
||||
for _, api := range Items {
|
||||
if api.ApiId != nil && aws.ToString(api.ApiId) == aws.ToString(mapping.ApiId) {
|
||||
endpoints := m.getEndpointsPerAPIGatewayv2(r, api)
|
||||
for _, endpoint := range endpoints {
|
||||
var old string
|
||||
if stage == "" {
|
||||
old = fmt.Sprintf("https://%s.execute-api.%s.amazonaws.com/", aws.ToString(mapping.ApiId), r)
|
||||
} else {
|
||||
old = fmt.Sprintf("https://%s.execute-api.%s.amazonaws.com/%s/", aws.ToString(mapping.ApiId), r, stage)
|
||||
}
|
||||
if strings.HasPrefix(endpoint.Endpoint, old) {
|
||||
var new string
|
||||
if path == "" {
|
||||
new = fmt.Sprintf("https://%s/", domain)
|
||||
} else {
|
||||
new = fmt.Sprintf("https://%s/%s/", domain, path)
|
||||
}
|
||||
endpoint.Endpoint = strings.Replace(endpoint.Endpoint, old, new, 1)
|
||||
endpoint.Name = domain
|
||||
dataReceiver <- endpoint
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if GetApiMappings.NextToken != nil {
|
||||
PaginationControl3 = GetApiMappings.NextToken
|
||||
} else {
|
||||
PaginationControl3 = nil
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if GetDomainNames.NextToken != nil {
|
||||
PaginationControl2 = GetDomainNames.NextToken
|
||||
} else {
|
||||
PaginationControl2 = nil
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (m *EndpointsModule) getEndpointsPerAPIGatewayv2(r string, api apigatewayV2Types.Api) []Endpoint {
|
||||
var endpoints []Endpoint
|
||||
|
||||
var PaginationControl2 *string
|
||||
var PaginationControl3 *string
|
||||
awsService := "APIGatewayv2"
|
||||
|
||||
var public string
|
||||
|
||||
name := aws.ToString(api.Name)
|
||||
raw_endpoint := aws.ToString(api.ApiEndpoint)
|
||||
id := aws.ToString(api.ApiId)
|
||||
var port int32 = 443
|
||||
protocol := "https"
|
||||
|
||||
var stages []string
|
||||
for {
|
||||
GetStages, err := m.APIGatewayv2Client.GetStages(
|
||||
context.TODO(),
|
||||
&apigatewayv2.GetStagesInput{
|
||||
ApiId: &id,
|
||||
NextToken: PaginationControl2,
|
||||
},
|
||||
func(o *apigatewayv2.Options) {
|
||||
o.Region = r
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
if errors.As(err, &oe) {
|
||||
m.Errors = append(m.Errors, (fmt.Sprintf(" Error: Region: %s, Service: %s, Operation: %s", r, oe.Service(), oe.Operation())))
|
||||
}
|
||||
m.modLog.Error(err.Error())
|
||||
m.CommandCounter.Error++
|
||||
break
|
||||
}
|
||||
|
||||
for _, stage := range GetStages.Items {
|
||||
s := aws.ToString(stage.StageName)
|
||||
if s == "$default" {
|
||||
s = ""
|
||||
}
|
||||
stages = append(stages, s)
|
||||
}
|
||||
|
||||
if GetStages.NextToken != nil {
|
||||
PaginationControl2 = GetStages.NextToken
|
||||
} else {
|
||||
PaginationControl2 = nil
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
for {
|
||||
GetRoutes, err := m.APIGatewayv2Client.GetRoutes(
|
||||
context.TODO(),
|
||||
&apigatewayv2.GetRoutesInput{
|
||||
ApiId: &id,
|
||||
NextToken: PaginationControl3,
|
||||
},
|
||||
func(o *apigatewayv2.Options) {
|
||||
o.Region = r
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
if errors.As(err, &oe) {
|
||||
m.Errors = append(m.Errors, (fmt.Sprintf(" Error: Region: %s, Service: %s, Operation: %s", r, oe.Service(), oe.Operation())))
|
||||
}
|
||||
m.modLog.Error(err.Error())
|
||||
m.CommandCounter.Error++
|
||||
continue
|
||||
}
|
||||
|
||||
for _, stage := range stages {
|
||||
for _, route := range GetRoutes.Items {
|
||||
routeKey := route.RouteKey
|
||||
var path string
|
||||
if len(strings.Fields(*routeKey)) == 2 {
|
||||
path = strings.Fields(*routeKey)[1]
|
||||
}
|
||||
endpoint := fmt.Sprintf("%s%s", raw_endpoint, path)
|
||||
var endpoint string
|
||||
if stage == "" {
|
||||
endpoint = fmt.Sprintf("%s%s", raw_endpoint, path)
|
||||
} else {
|
||||
endpoint = fmt.Sprintf("%s/%s%s", raw_endpoint, stage, path)
|
||||
}
|
||||
public = "True"
|
||||
|
||||
dataReceiver <- Endpoint{
|
||||
endpoints = append(endpoints, Endpoint{
|
||||
AWSService: awsService,
|
||||
Region: r,
|
||||
Name: name,
|
||||
@@ -1009,19 +1339,18 @@ func (m *EndpointsModule) getAPIGatewayv2APIsPerRegion(r string, wg *sync.WaitGr
|
||||
Port: port,
|
||||
Protocol: protocol,
|
||||
Public: public,
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
if GetRoutes.NextToken != nil {
|
||||
PaginationControl2 = GetRoutes.NextToken
|
||||
} else {
|
||||
PaginationControl2 = nil
|
||||
break
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if GetRoutes.NextToken != nil {
|
||||
PaginationControl3 = GetRoutes.NextToken
|
||||
} else {
|
||||
PaginationControl3 = nil
|
||||
break
|
||||
}
|
||||
|
||||
}
|
||||
return endpoints
|
||||
}
|
||||
|
||||
func (m *EndpointsModule) getRdsClustersPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Endpoint) {
|
||||
@@ -1293,7 +1622,11 @@ func (m *EndpointsModule) getCloudfrontEndpoints(wg *sync.WaitGroup, semaphore c
|
||||
//fmt.Println(origin.DomainName)
|
||||
public = "Unknown"
|
||||
var port int32 = 443
|
||||
endpoint := fmt.Sprintf("https://%s/%s", aws.ToString(origin.DomainName), aws.ToString(origin.OriginPath))
|
||||
path := aws.ToString(origin.OriginPath)
|
||||
if !strings.HasPrefix(path, "/") {
|
||||
path = "/" + path
|
||||
}
|
||||
endpoint := fmt.Sprintf("https://%s%s", aws.ToString(origin.DomainName), path)
|
||||
awsServiceOrigin := fmt.Sprintf("%s [origin]", awsService)
|
||||
dataReceiver <- Endpoint{
|
||||
AWSService: awsServiceOrigin,
|
||||
|
||||
+2
-2
@@ -140,7 +140,7 @@ func (m *EnvsModule) PrintEnvs(outputFormat string, outputDirectory string, verb
|
||||
}
|
||||
if len(m.output.Body) > 0 {
|
||||
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
//m.output.OutputSelector(outputFormat)
|
||||
//utils.OutputSelector(verbosity, outputFormat, m.output.Headers, m.output.Body, m.output.FilePath, m.output.CallingModule, m.output.CallingModule)
|
||||
//internal.OutputSelector(verbosity, outputFormat, m.output.Headers, m.output.Body, m.output.FilePath, m.output.CallingModule, m.output.CallingModule, m.WrapTable, m.AWSProfile)
|
||||
@@ -157,7 +157,7 @@ func (m *EnvsModule) PrintEnvs(outputFormat string, outputDirectory string, verb
|
||||
Name: m.output.CallingModule,
|
||||
})
|
||||
o.PrefixIdentifier = m.AWSProfile
|
||||
o.Table.DirectoryName = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
o.Table.DirectoryName = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
o.WriteFullOutput(o.Table.TableFiles, nil)
|
||||
fmt.Printf("[%s][%s] %s environment variables found.\n", cyan(m.output.CallingModule), cyan(m.AWSProfile), strconv.Itoa(len(m.output.Body)))
|
||||
|
||||
|
||||
+7
-5
@@ -136,7 +136,7 @@ func (m *FilesystemsModule) PrintFilesystems(outputFormat string, outputDirector
|
||||
}
|
||||
if len(m.output.Body) > 0 {
|
||||
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
//m.output.OutputSelector(outputFormat)
|
||||
//utils.OutputSelector(verbosity, outputFormat, m.output.Headers, m.output.Body, m.output.FilePath, m.output.CallingModule, m.output.CallingModule)
|
||||
//internal.OutputSelector(verbosity, outputFormat, m.output.Headers, m.output.Body, m.output.FilePath, m.output.CallingModule, m.output.CallingModule, m.WrapTable, m.AWSProfile)
|
||||
@@ -154,7 +154,7 @@ func (m *FilesystemsModule) PrintFilesystems(outputFormat string, outputDirector
|
||||
Name: m.output.CallingModule,
|
||||
})
|
||||
o.PrefixIdentifier = m.AWSProfile
|
||||
o.Table.DirectoryName = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
o.Table.DirectoryName = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
o.WriteFullOutput(o.Table.TableFiles, nil)
|
||||
m.writeLoot(o.Table.DirectoryName, verbosity)
|
||||
fmt.Printf("[%s][%s] %s filesystems found.\n", cyan(m.output.CallingModule), cyan(m.AWSProfile), strconv.Itoa(len(m.output.Body)))
|
||||
@@ -287,12 +287,13 @@ func (m *FilesystemsModule) getEFSSharesPerRegion(r string, wg *sync.WaitGroup,
|
||||
)
|
||||
if err != nil {
|
||||
policy = "Default (No IAM auth)"
|
||||
} else {
|
||||
policy = "IAM Authenticated"
|
||||
}
|
||||
|
||||
DescribeMountTargets, err := sdk.CachedDescribeMountTargets(m.EFSClient, aws.ToString(m.Caller.Account), r, id)
|
||||
if err != nil {
|
||||
sharedLogger.Error(err.Error())
|
||||
|
||||
m.CommandCounter.Error++
|
||||
break
|
||||
}
|
||||
@@ -486,10 +487,11 @@ func (m *FilesystemsModule) getEFSfilesystemPermissions(accessPoint types.Access
|
||||
var path string
|
||||
var permissions string
|
||||
|
||||
if accessPoint.AccessPointId != nil {
|
||||
if accessPoint.AccessPointId != nil && accessPoint.RootDirectory != nil && accessPoint.RootDirectory.CreationInfo != nil {
|
||||
path = aws.ToString(accessPoint.RootDirectory.Path)
|
||||
permissions = aws.ToString(accessPoint.RootDirectory.CreationInfo.Permissions)
|
||||
return path, permissions
|
||||
}
|
||||
return path, permissions
|
||||
return "", ""
|
||||
|
||||
}
|
||||
@@ -73,7 +73,7 @@ func (m *IamSimulatorModule) PrintIamSimulator(principal string, action string,
|
||||
m.modLog = internal.TxtLog.WithFields(logrus.Fields{
|
||||
"module": m.output.CallingModule,
|
||||
})
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
var actionList []string
|
||||
var pmapperCommands []string
|
||||
var pmapperOutFileName string
|
||||
@@ -171,7 +171,7 @@ func (m *IamSimulatorModule) PrintIamSimulator(principal string, action string,
|
||||
|
||||
}
|
||||
if len(m.output.Body) > 0 {
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
//utils.OutputSelector(verbosity, outputFormat, m.output.Headers, m.output.Body, m.output.FilePath, m.output.FullFilename, m.output.CallingModule)
|
||||
//internal.OutputSelector(verbosity, outputFormat, m.output.Headers, m.output.Body, m.output.FilePath, m.output.FullFilename, m.output.CallingModule, m.WrapTable, m.AWSProfile)
|
||||
o := internal.OutputClient{
|
||||
@@ -187,7 +187,7 @@ func (m *IamSimulatorModule) PrintIamSimulator(principal string, action string,
|
||||
Name: m.output.CallingModule,
|
||||
})
|
||||
o.PrefixIdentifier = m.AWSProfile
|
||||
o.Table.DirectoryName = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
o.Table.DirectoryName = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
o.WriteFullOutput(o.Table.TableFiles, nil)
|
||||
fmt.Printf("[%s][%s] We suggest running the pmapper commands in the loot file to get the same information but taking privesc paths into account.\n", cyan(m.output.CallingModule), cyan(m.AWSProfile))
|
||||
// fmt.Printf("[%s]\t\tpmapper --profile %s graph create\n", cyan(m.output.CallingModule), cyan(m.AWSProfile), m.AWSProfile)
|
||||
|
||||
+3
-3
@@ -173,7 +173,7 @@ func (m *InstancesModule) printInstancesUserDataAttributesOnly(outputFormat stri
|
||||
}()
|
||||
|
||||
m.output.CallingModule = "instance-userdata"
|
||||
path := filepath.Join(outputDirectory, "cloudfox-output", "aws", m.AWSProfile, "loot")
|
||||
path := filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)), "loot")
|
||||
err := os.MkdirAll(path, os.ModePerm)
|
||||
if err != nil {
|
||||
m.modLog.Error(err.Error())
|
||||
@@ -296,7 +296,7 @@ func (m *InstancesModule) printGeneralInstanceData(outputFormat string, outputDi
|
||||
}
|
||||
|
||||
if len(m.output.Body) > 0 {
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
////m.output.OutputSelector(outputFormat)
|
||||
//utils.OutputSelector(m.output.Verbosity, outputFormat, m.output.Headers, m.output.Body, m.output.FilePath, m.output.CallingModule, m.output.CallingModule)
|
||||
//internal.OutputSelector(m.output.Verbosity, outputFormat, m.output.Headers, m.output.Body, m.output.FilePath, m.output.CallingModule, m.output.CallingModule, m.WrapTable, m.AWSProfile)
|
||||
@@ -315,7 +315,7 @@ func (m *InstancesModule) printGeneralInstanceData(outputFormat string, outputDi
|
||||
Name: m.output.CallingModule,
|
||||
})
|
||||
o.PrefixIdentifier = m.AWSProfile
|
||||
o.Table.DirectoryName = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
o.Table.DirectoryName = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
o.WriteFullOutput(o.Table.TableFiles, nil)
|
||||
m.writeLoot(o.Table.DirectoryName, verbosity)
|
||||
fmt.Printf("[%s][%s] %s instances found.\n", cyan(m.output.CallingModule), cyan(m.AWSProfile), strconv.Itoa(len(m.output.Body)))
|
||||
|
||||
+1807
-603
File diff suppressed because it is too large.
Load diff
+2
-2
@@ -181,7 +181,7 @@ func (m *LambdasModule) PrintLambdas(outputFormat string, outputDirectory string
|
||||
|
||||
}
|
||||
if len(m.output.Body) > 0 {
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
//utils.OutputSelector(verbosity, outputFormat, m.output.Headers, m.output.Body, m.output.FilePath, m.output.CallingModule, m.output.CallingModule)
|
||||
//internal.OutputSelector(verbosity, outputFormat, m.output.Headers, m.output.Body, m.output.FilePath, m.output.CallingModule, m.output.CallingModule, m.WrapTable, m.AWSProfile)
|
||||
o := internal.OutputClient{
|
||||
@@ -197,7 +197,7 @@ func (m *LambdasModule) PrintLambdas(outputFormat string, outputDirectory string
|
||||
Name: m.output.CallingModule,
|
||||
})
|
||||
o.PrefixIdentifier = m.AWSProfile
|
||||
o.Table.DirectoryName = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
o.Table.DirectoryName = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
o.WriteFullOutput(o.Table.TableFiles, nil)
|
||||
m.writeLoot(o.Table.DirectoryName, verbosity)
|
||||
fmt.Printf("[%s][%s] %s lambdas found.\n", cyan(m.output.CallingModule), cyan(m.AWSProfile), strconv.Itoa(len(m.output.Body)))
|
||||
|
||||
@@ -210,7 +210,7 @@ func (m *NetworkPortsModule) PrintNetworkPorts(outputFormat string, outputDirect
|
||||
}
|
||||
|
||||
if len(m.IPv4_Private) > 0 || len(m.IPv4_Public) > 0 || len(m.IPv6) > 0 {
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
//m.output.OutputSelector(outputFormat)
|
||||
//internal.OutputSelector(m.Verbosity, outputFormat, m.output.Headers, m.output.Body, m.output.FilePath, m.output.CallingModule, m.output.CallingModule, m.WrapTable, m.AWSProfile)
|
||||
//m.writeLoot(m.output.FilePath)
|
||||
@@ -227,7 +227,7 @@ func (m *NetworkPortsModule) PrintNetworkPorts(outputFormat string, outputDirect
|
||||
Name: m.output.CallingModule,
|
||||
})
|
||||
o.PrefixIdentifier = m.AWSProfile
|
||||
o.Table.DirectoryName = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
o.Table.DirectoryName = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
o.WriteFullOutput(o.Table.TableFiles, nil)
|
||||
m.writeLoot(o.Table.DirectoryName)
|
||||
fmt.Printf("[%s][%s] %s network services found.\n", cyan(m.output.CallingModule), cyan(m.AWSProfile), strconv.Itoa(len(m.output.Body)))
|
||||
|
||||
+2
-2
@@ -108,7 +108,7 @@ func (m *OrgModule) PrintOrgAccounts(outputFormat string, outputDirectory string
|
||||
}
|
||||
|
||||
if len(m.output.Body) > 0 {
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
//internal.OutputSelector(verbosity, outputFormat, m.output.Headers, m.output.Body, m.output.FilePath, m.output.CallingModule, m.output.CallingModule, m.WrapTable, m.AWSProfile)
|
||||
//m.writeLoot(m.output.FilePath, verbosity)
|
||||
o := internal.OutputClient{
|
||||
@@ -124,7 +124,7 @@ func (m *OrgModule) PrintOrgAccounts(outputFormat string, outputDirectory string
|
||||
Name: m.output.CallingModule,
|
||||
})
|
||||
o.PrefixIdentifier = m.AWSProfile
|
||||
o.Table.DirectoryName = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
o.Table.DirectoryName = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
o.WriteFullOutput(o.Table.TableFiles, nil)
|
||||
//m.writeLoot(o.Table.DirectoryName, verbosity)
|
||||
fmt.Printf("[%s][%s] %d accounts found.\n", cyan(m.output.CallingModule), cyan(m.AWSProfile), len(m.output.Body))
|
||||
|
||||
@@ -190,7 +190,7 @@ func (m *OutboundAssumedRolesModule) PrintOutboundRoleTrusts(days int, outputFor
|
||||
}
|
||||
if len(m.output.Body) > 0 {
|
||||
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
//m.output.OutputSelector(outputFormat)
|
||||
//utils.OutputSelector(verbosity, outputFormat, m.output.Headers, m.output.Body, m.output.FilePath, m.output.CallingModule, m.output.CallingModule)
|
||||
//internal.OutputSelector(verbosity, outputFormat, m.output.Headers, m.output.Body, m.output.FilePath, m.output.CallingModule, m.output.CallingModule, m.WrapTable, m.AWSProfile)
|
||||
@@ -207,7 +207,7 @@ func (m *OutboundAssumedRolesModule) PrintOutboundRoleTrusts(days int, outputFor
|
||||
Name: m.output.CallingModule,
|
||||
})
|
||||
o.PrefixIdentifier = m.AWSProfile
|
||||
o.Table.DirectoryName = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
o.Table.DirectoryName = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
o.WriteFullOutput(o.Table.TableFiles, nil)
|
||||
//m.writeLoot(o.Table.DirectoryName, verbosity)
|
||||
fmt.Printf("[%s][%s] %s log entries found.\n", cyan(m.output.CallingModule), cyan(m.AWSProfile), strconv.Itoa(len(m.output.Body)))
|
||||
|
||||
+3
-3
@@ -94,7 +94,7 @@ func (m *IamPermissionsModule) PrintIamPermissions(outputFormat string, outputDi
|
||||
if m.AWSProfile == "" {
|
||||
m.AWSProfile = internal.BuildAWSPath(m.Caller)
|
||||
}
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
fmt.Printf("[%s][%s] Enumerating IAM permissions for account %s.\n", cyan(m.output.CallingModule), cyan(m.AWSProfile), aws.ToString(m.Caller.Account))
|
||||
|
||||
if principal != "" {
|
||||
@@ -138,7 +138,7 @@ func (m *IamPermissionsModule) PrintIamPermissions(outputFormat string, outputDi
|
||||
}
|
||||
|
||||
if len(m.output.Body) > 0 {
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
//m.output.OutputSelector3(outputFormat)
|
||||
//utils.OutputSelector(verbosity, outputFormat, m.output.Headers, m.output.Body, m.output.FilePath, m.output.FullFilename, m.output.CallingModule)
|
||||
//internal.OutputSelector(verbosity, outputFormat, m.output.Headers, m.output.Body, m.output.FilePath, m.output.FullFilename, m.output.CallingModule, m.WrapTable, m.AWSProfile)
|
||||
@@ -155,7 +155,7 @@ func (m *IamPermissionsModule) PrintIamPermissions(outputFormat string, outputDi
|
||||
Name: m.output.CallingModule,
|
||||
})
|
||||
o.PrefixIdentifier = m.AWSProfile
|
||||
o.Table.DirectoryName = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
o.Table.DirectoryName = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
o.WriteFullOutput(o.Table.TableFiles, nil)
|
||||
//m.writeLoot(o.Table.DirectoryName, verbosity)
|
||||
fmt.Printf("[%s][%s] %s unique permissions identified.\n", cyan(m.output.CallingModule), cyan(m.AWSProfile), strconv.Itoa(len(m.output.Body)))
|
||||
|
||||
+3
-3
@@ -148,7 +148,7 @@ func (m *PmapperModule) PrintPmapperData(outputFormat string, outputDirectory st
|
||||
if m.AWSProfile == "" {
|
||||
m.AWSProfile = internal.BuildAWSPath(m.Caller)
|
||||
}
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
fmt.Printf("[%s][%s] Looking for pmapper data for this account and building a PrivEsc graph in golang if it exists.\n", cyan(m.output.CallingModule), cyan(m.AWSProfile))
|
||||
pmapperError := m.initPmapperGraph()
|
||||
if pmapperError != nil {
|
||||
@@ -195,7 +195,7 @@ func (m *PmapperModule) PrintPmapperData(outputFormat string, outputDirectory st
|
||||
}
|
||||
|
||||
if len(m.output.Body) > 0 {
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
//utils.OutputSelector(verbosity, outputFormat, m.output.Headers, m.output.Body, m.output.FilePath, m.output.FullFilename, m.output.CallingModule)
|
||||
//internal.OutputSelector(verbosity, outputFormat, m.output.Headers, m.output.Body, m.output.FilePath, m.output.FullFilename, m.output.CallingModule, m.WrapTable, m.AWSProfile)
|
||||
o := internal.OutputClient{
|
||||
@@ -211,7 +211,7 @@ func (m *PmapperModule) PrintPmapperData(outputFormat string, outputDirectory st
|
||||
Name: m.output.CallingModule,
|
||||
})
|
||||
o.PrefixIdentifier = m.AWSProfile
|
||||
o.Table.DirectoryName = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
o.Table.DirectoryName = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
o.WriteFullOutput(o.Table.TableFiles, nil)
|
||||
//m.writeLoot(o.Table.DirectoryName, verbosity)
|
||||
|
||||
|
||||
+2
-2
@@ -134,7 +134,7 @@ func (m *IamPrincipalsModule) PrintIamPrincipals(outputFormat string, outputDire
|
||||
|
||||
}
|
||||
if len(m.output.Body) > 0 {
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
//m.output.OutputSelector(outputFormat)
|
||||
//utils.OutputSelector(verbosity, outputFormat, m.output.Headers, m.output.Body, m.output.FilePath, m.output.CallingModule, m.output.CallingModule)
|
||||
//internal.OutputSelector(verbosity, outputFormat, m.output.Headers, m.output.Body, m.output.FilePath, m.output.CallingModule, m.output.CallingModule, m.WrapTable, m.AWSProfile)
|
||||
@@ -151,7 +151,7 @@ func (m *IamPrincipalsModule) PrintIamPrincipals(outputFormat string, outputDire
|
||||
Name: m.output.CallingModule,
|
||||
})
|
||||
o.PrefixIdentifier = m.AWSProfile
|
||||
o.Table.DirectoryName = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
o.Table.DirectoryName = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
o.WriteFullOutput(o.Table.TableFiles, nil)
|
||||
//m.writeLoot(o.Table.DirectoryName, verbosity)
|
||||
fmt.Printf("[%s][%s] %s IAM principals found.\n", cyan(m.output.CallingModule), cyan(m.AWSProfile), strconv.Itoa(len(m.output.Body)))
|
||||
|
||||
+2
-2
@@ -115,7 +115,7 @@ func (m *RAMModule) PrintRAM(outputFormat string, outputDirectory string, verbos
|
||||
|
||||
}
|
||||
if len(m.output.Body) > 0 {
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
//m.output.OutputSelector(outputFormat)
|
||||
//utils.OutputSelector(verbosity, outputFormat, m.output.Headers, m.output.Body, m.output.FilePath, m.output.CallingModule, m.output.CallingModule)
|
||||
//internal.OutputSelector(verbosity, outputFormat, m.output.Headers, m.output.Body, m.output.FilePath, m.output.CallingModule, m.output.CallingModule, m.WrapTable, m.AWSProfile)
|
||||
@@ -132,7 +132,7 @@ func (m *RAMModule) PrintRAM(outputFormat string, outputDirectory string, verbos
|
||||
Name: m.output.CallingModule,
|
||||
})
|
||||
o.PrefixIdentifier = m.AWSProfile
|
||||
o.Table.DirectoryName = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
o.Table.DirectoryName = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
o.WriteFullOutput(o.Table.TableFiles, nil)
|
||||
//m.writeLoot(o.Table.DirectoryName, verbosity)
|
||||
fmt.Printf("[%s][%s] %s resources found.\n", cyan(m.output.CallingModule), cyan(m.AWSProfile), strconv.Itoa(len(m.output.Body)))
|
||||
|
||||
@@ -54,7 +54,7 @@ func (m *ResourceTrustsModule) PrintResources(outputFormat string, outputDirecto
|
||||
m.modLog = internal.TxtLog.WithFields(logrus.Fields{
|
||||
"module": m.output.CallingModule,
|
||||
})
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
if m.AWSProfile == "" {
|
||||
m.AWSProfile = internal.BuildAWSPath(m.Caller)
|
||||
}
|
||||
@@ -137,7 +137,7 @@ func (m *ResourceTrustsModule) PrintResources(outputFormat string, outputDirecto
|
||||
Name: m.output.CallingModule,
|
||||
})
|
||||
o.PrefixIdentifier = m.AWSProfile
|
||||
o.Table.DirectoryName = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
o.Table.DirectoryName = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
o.WriteFullOutput(o.Table.TableFiles, nil)
|
||||
//m.writeLoot(o.Table.DirectoryName, verbosity)
|
||||
fmt.Printf("[%s][%s] %s resource policies found.\n", cyan(m.output.CallingModule), cyan(m.AWSProfile), strconv.Itoa(len(m.output.Body)))
|
||||
|
||||
+7
-2
@@ -127,7 +127,7 @@ func (m *RoleTrustsModule) PrintRoleTrusts(outputFormat string, outputDirectory
|
||||
}
|
||||
|
||||
o.PrefixIdentifier = m.AWSProfile
|
||||
o.Table.DirectoryName = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
o.Table.DirectoryName = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
|
||||
principalsHeader, principalsBody := m.printPrincipalTrusts(outputFormat, outputDirectory)
|
||||
o.Table.TableFiles = append(o.Table.TableFiles, internal.TableFile{
|
||||
@@ -279,7 +279,12 @@ func (m *RoleTrustsModule) printServiceTrusts(outputFormat string, outputDirecto
|
||||
}
|
||||
}
|
||||
|
||||
m.sortTrustsTablePerTrustedPrincipal()
|
||||
// sort the rows based on column 2 (service)
|
||||
sort.SliceStable(body, func(i, j int) bool {
|
||||
return body[i][1] < body[j][1]
|
||||
})
|
||||
|
||||
//m.sortTrustsTablePerTrustedPrincipal()
|
||||
return header, body
|
||||
|
||||
// if len(m.output.Body) > 0 {
|
||||
|
||||
+38
-59
@@ -1,22 +1,21 @@
|
||||
package aws
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
|
||||
"github.com/BishopFox/cloudfox/aws/sdk"
|
||||
"github.com/BishopFox/cloudfox/internal"
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/route53"
|
||||
"github.com/aws/aws-sdk-go-v2/service/sts"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type Route53Module struct {
|
||||
// General configuration data
|
||||
Route53Client *route53.Client
|
||||
Route53Client sdk.AWSRoute53ClientInterface
|
||||
|
||||
Caller sts.GetCallerIdentityOutput
|
||||
AWSRegions []string
|
||||
@@ -83,7 +82,7 @@ func (m *Route53Module) PrintRoute53(outputFormat string, outputDirectory string
|
||||
}
|
||||
if len(m.output.Body) > 0 {
|
||||
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
m.output.FilePath = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
//m.output.OutputSelector(outputFormat)
|
||||
//utils.OutputSelector(verbosity, outputFormat, m.output.Headers, m.output.Body, m.output.FilePath, m.output.CallingModule, m.output.CallingModule)
|
||||
//internal.OutputSelector(verbosity, outputFormat, m.output.Headers, m.output.Body, m.output.FilePath, m.output.CallingModule, m.output.CallingModule, m.WrapTable, m.AWSProfile)
|
||||
@@ -101,7 +100,7 @@ func (m *Route53Module) PrintRoute53(outputFormat string, outputDirectory string
|
||||
Name: m.output.CallingModule,
|
||||
})
|
||||
o.PrefixIdentifier = m.AWSProfile
|
||||
o.Table.DirectoryName = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", aws.ToString(m.Caller.Account), m.AWSProfile))
|
||||
o.Table.DirectoryName = filepath.Join(outputDirectory, "cloudfox-output", "aws", fmt.Sprintf("%s-%s", m.AWSProfile, aws.ToString(m.Caller.Account)))
|
||||
o.WriteFullOutput(o.Table.TableFiles, nil)
|
||||
m.writeLoot(o.Table.DirectoryName, verbosity)
|
||||
fmt.Printf("[%s][%s] %s DNS records found.\n", cyan(m.output.CallingModule), cyan(m.AWSProfile), strconv.Itoa(len(m.output.Body)))
|
||||
@@ -127,7 +126,7 @@ func (m *Route53Module) writeLoot(outputDirectory string, verbosity int) {
|
||||
var route53APublicRecords string
|
||||
|
||||
for _, record := range m.Records {
|
||||
if record.Type == "A" || record.Type == "AAAA" {
|
||||
if record.Type == "A" || record.Type == "AAAA" || record.Type == "CNAME" {
|
||||
if record.PrivateZone == "True" {
|
||||
route53APrivateRecords = route53APrivateRecords + fmt.Sprintln(record.Name)
|
||||
} else {
|
||||
@@ -176,71 +175,51 @@ func (m *Route53Module) writeLoot(outputDirectory string, verbosity int) {
|
||||
|
||||
func (m *Route53Module) getRoute53Records() {
|
||||
// "PaginationMarker" is a control variable used for output continuity, as AWS return the output in pages.
|
||||
var PaginationControl *string
|
||||
var recordName string
|
||||
var recordType string
|
||||
|
||||
for {
|
||||
ListHostedZones, err := m.Route53Client.ListHostedZones(
|
||||
context.TODO(),
|
||||
&route53.ListHostedZonesInput{
|
||||
Marker: PaginationControl,
|
||||
},
|
||||
)
|
||||
HostedZones, err := sdk.CachedRoute53ListHostedZones(m.Route53Client, aws.ToString(m.Caller.Account))
|
||||
|
||||
if err != nil {
|
||||
m.modLog.Error(err.Error())
|
||||
m.CommandCounter.Error++
|
||||
return
|
||||
}
|
||||
|
||||
var privateZone string
|
||||
for _, zone := range HostedZones {
|
||||
if zone.Config.PrivateZone {
|
||||
privateZone = "True"
|
||||
} else {
|
||||
privateZone = "False"
|
||||
}
|
||||
|
||||
Records, err := sdk.CachedRoute53ListResourceRecordSets(m.Route53Client, aws.ToString(m.Caller.Account), aws.ToString(zone.Id))
|
||||
|
||||
if err != nil {
|
||||
m.modLog.Error(err.Error())
|
||||
m.CommandCounter.Error++
|
||||
break
|
||||
}
|
||||
for _, record := range Records {
|
||||
recordName = aws.ToString(record.Name)
|
||||
recordType = string(record.Type)
|
||||
|
||||
for _, resourceRecord := range record.ResourceRecords {
|
||||
recordValue := resourceRecord.Value
|
||||
m.Records = append(
|
||||
m.Records,
|
||||
Record{
|
||||
AWSService: "Route53",
|
||||
Name: recordName,
|
||||
Type: recordType,
|
||||
Value: aws.ToString(recordValue),
|
||||
PrivateZone: privateZone,
|
||||
})
|
||||
|
||||
var privateZone string
|
||||
for _, zone := range ListHostedZones.HostedZones {
|
||||
id := aws.ToString(zone.Id)
|
||||
if zone.Config.PrivateZone {
|
||||
privateZone = "True"
|
||||
} else {
|
||||
privateZone = "False"
|
||||
}
|
||||
|
||||
ListResourceRecordSets, err := m.Route53Client.ListResourceRecordSets(
|
||||
context.TODO(),
|
||||
&route53.ListResourceRecordSetsInput{
|
||||
HostedZoneId: &id,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
m.modLog.Error(err.Error())
|
||||
m.CommandCounter.Error++
|
||||
break
|
||||
}
|
||||
for _, record := range ListResourceRecordSets.ResourceRecordSets {
|
||||
recordName = aws.ToString(record.Name)
|
||||
recordType = string(record.Type)
|
||||
|
||||
for _, resourceRecord := range record.ResourceRecords {
|
||||
recordValue := resourceRecord.Value
|
||||
m.Records = append(
|
||||
m.Records,
|
||||
Record{
|
||||
AWSService: "Route53",
|
||||
Name: recordName,
|
||||
Type: recordType,
|
||||
Value: aws.ToString(recordValue),
|
||||
PrivateZone: privateZone,
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// The "NextToken" value is nil when there's no more data to return.
|
||||
if ListHostedZones.NextMarker != nil {
|
||||
PaginationControl = ListHostedZones.NextMarker
|
||||
} else {
|
||||
PaginationControl = nil
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,7 +14,7 @@ type APIGatewayClientInterface interface {
|
||||
GetRestApis(context.Context, *apigateway.GetRestApisInput, ...func(*apigateway.Options)) (*apigateway.GetRestApisOutput, error)
|
||||
}
|
||||
|
||||
func RegisterApiGatewayTypes() {
|
||||
func init() {
|
||||
gob.Register([]apiGatewayTypes.RestApi{})
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/apigateway"
|
||||
apiGatewayTypes "github.com/aws/aws-sdk-go-v2/service/apigateway/types"
|
||||
)
|
||||
|
||||
type MockedAWSAPIGatewayClient struct {
|
||||
}
|
||||
|
||||
func (m *MockedAWSAPIGatewayClient) GetRestApis(ctx context.Context, input *apigateway.GetRestApisInput, options ...func(*apigateway.Options)) (*apigateway.GetRestApisOutput, error) {
|
||||
return &apigateway.GetRestApisOutput{
|
||||
Items: []apiGatewayTypes.RestApi{
|
||||
{
|
||||
Id: aws.String("api1"),
|
||||
Name: aws.String("api1"),
|
||||
},
|
||||
{
|
||||
Id: aws.String("api2"),
|
||||
Name: aws.String("api2"),
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
@@ -16,7 +16,7 @@ type APIGatewayv2ClientInterface interface {
|
||||
GetApis(context.Context, *apigatewayv2.GetApisInput, ...func(*apigatewayv2.Options)) (*apigatewayv2.GetApisOutput, error)
|
||||
}
|
||||
|
||||
func RegisterApiGatewayV2Types() {
|
||||
func init() {
|
||||
gob.Register([]apiGatwayV2Types.Api{})
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/apigatewayv2"
|
||||
apiGatwayV2Types "github.com/aws/aws-sdk-go-v2/service/apigatewayv2/types"
|
||||
)
|
||||
|
||||
type MockedAWSAPIGatewayv2Client struct {
|
||||
}
|
||||
|
||||
func (m *MockedAWSAPIGatewayv2Client) GetApis(ctx context.Context, input *apigatewayv2.GetApisInput, options ...func(*apigatewayv2.Options)) (*apigatewayv2.GetApisOutput, error) {
|
||||
return &apigatewayv2.GetApisOutput{
|
||||
Items: []apiGatwayV2Types.Api{
|
||||
{
|
||||
ApiId: aws.String("api1"),
|
||||
Name: aws.String("api1"),
|
||||
},
|
||||
{
|
||||
ApiId: aws.String("api2"),
|
||||
Name: aws.String("api2"),
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
@@ -15,7 +15,7 @@ type AppRunnerClientInterface interface {
|
||||
ListServices(context.Context, *apprunner.ListServicesInput, ...func(*apprunner.Options)) (*apprunner.ListServicesOutput, error)
|
||||
}
|
||||
|
||||
func RegisterApprunnerTypes() {
|
||||
func init() {
|
||||
gob.Register([]apprunnerTypes.Service{})
|
||||
gob.Register([]apprunnerTypes.ServiceSummary{})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/apprunner"
|
||||
apprunnerTypes "github.com/aws/aws-sdk-go-v2/service/apprunner/types"
|
||||
)
|
||||
|
||||
type MockedAppRunnerClient struct {
|
||||
}
|
||||
|
||||
func (m *MockedAppRunnerClient) ListServices(ctx context.Context, input *apprunner.ListServicesInput, options ...func(*apprunner.Options)) (*apprunner.ListServicesOutput, error) {
|
||||
return &apprunner.ListServicesOutput{
|
||||
ServiceSummaryList: []apprunnerTypes.ServiceSummary{
|
||||
{
|
||||
ServiceName: aws.String("service1"),
|
||||
},
|
||||
{
|
||||
ServiceName: aws.String("service2"),
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/gob"
|
||||
"fmt"
|
||||
|
||||
"github.com/BishopFox/cloudfox/internal"
|
||||
"github.com/aws/aws-sdk-go-v2/service/athena"
|
||||
athenaTypes "github.com/aws/aws-sdk-go-v2/service/athena/types"
|
||||
"github.com/patrickmn/go-cache"
|
||||
)
|
||||
|
||||
type AWSAthenaClientInterface interface {
|
||||
ListDataCatalogs(context.Context, *athena.ListDataCatalogsInput, ...func(*athena.Options)) (*athena.ListDataCatalogsOutput, error)
|
||||
ListDatabases(context.Context, *athena.ListDatabasesInput, ...func(*athena.Options)) (*athena.ListDatabasesOutput, error)
|
||||
}
|
||||
|
||||
func init() {
|
||||
gob.Register([]athenaTypes.DataCatalogSummary{})
|
||||
}
|
||||
|
||||
func CachedAthenaListDataCatalogs(client AWSAthenaClientInterface, accountID string, region string) ([]athenaTypes.DataCatalogSummary, error) {
|
||||
var PaginationControl *string
|
||||
var dataCatalogs []athenaTypes.DataCatalogSummary
|
||||
cacheKey := fmt.Sprintf("%s-athena-ListDataCatalogs-%s", accountID, region)
|
||||
cached, found := internal.Cache.Get(cacheKey)
|
||||
if found {
|
||||
return cached.([]athenaTypes.DataCatalogSummary), nil
|
||||
}
|
||||
for {
|
||||
ListDataCatalogs, err := client.ListDataCatalogs(
|
||||
context.TODO(),
|
||||
&athena.ListDataCatalogsInput{
|
||||
NextToken: PaginationControl,
|
||||
},
|
||||
func(o *athena.Options) {
|
||||
o.Region = region
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return dataCatalogs, err
|
||||
}
|
||||
|
||||
dataCatalogs = append(dataCatalogs, ListDataCatalogs.DataCatalogsSummary...)
|
||||
|
||||
//pagination
|
||||
if ListDataCatalogs.NextToken == nil {
|
||||
break
|
||||
}
|
||||
PaginationControl = ListDataCatalogs.NextToken
|
||||
}
|
||||
|
||||
internal.Cache.Set(cacheKey, dataCatalogs, cache.DefaultExpiration)
|
||||
return dataCatalogs, nil
|
||||
}
|
||||
|
||||
func CachedAthenaListDatabases(client AWSAthenaClientInterface, accountID string, region string, catalogName string) ([]string, error) {
|
||||
var PaginationControl *string
|
||||
var databases []string
|
||||
cacheKey := fmt.Sprintf("%s-athena-ListDatabases-%s-%s", accountID, region, catalogName)
|
||||
cached, found := internal.Cache.Get(cacheKey)
|
||||
if found {
|
||||
return cached.([]string), nil
|
||||
}
|
||||
for {
|
||||
ListDatabases, err := client.ListDatabases(
|
||||
context.TODO(),
|
||||
&athena.ListDatabasesInput{
|
||||
CatalogName: &catalogName,
|
||||
NextToken: PaginationControl,
|
||||
},
|
||||
func(o *athena.Options) {
|
||||
o.Region = region
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return databases, err
|
||||
}
|
||||
|
||||
for _, database := range ListDatabases.DatabaseList {
|
||||
databases = append(databases, *database.Name)
|
||||
}
|
||||
|
||||
//pagination
|
||||
if ListDatabases.NextToken == nil {
|
||||
break
|
||||
}
|
||||
PaginationControl = ListDatabases.NextToken
|
||||
}
|
||||
|
||||
internal.Cache.Set(cacheKey, databases, cache.DefaultExpiration)
|
||||
return databases, nil
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/athena"
|
||||
athenaTypes "github.com/aws/aws-sdk-go-v2/service/athena/types"
|
||||
)
|
||||
|
||||
type MockedAWSAthenaClient struct {
|
||||
}
|
||||
|
||||
func (m *MockedAWSAthenaClient) ListDatabases(ctx context.Context, input *athena.ListDatabasesInput, options ...func(*athena.Options)) (*athena.ListDatabasesOutput, error) {
|
||||
return &athena.ListDatabasesOutput{
|
||||
DatabaseList: []athenaTypes.Database{
|
||||
{
|
||||
Name: aws.String("db1"),
|
||||
},
|
||||
{
|
||||
Name: aws.String("db2"),
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (m *MockedAWSAthenaClient) ListDataCatalogs(ctx context.Context, input *athena.ListDataCatalogsInput, options ...func(*athena.Options)) (*athena.ListDataCatalogsOutput, error) {
|
||||
return &athena.ListDataCatalogsOutput{
|
||||
DataCatalogsSummary: []athenaTypes.DataCatalogSummary{
|
||||
{
|
||||
CatalogName: aws.String("catalog1"),
|
||||
},
|
||||
{
|
||||
CatalogName: aws.String("catalog2"),
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
@@ -18,7 +18,7 @@ type CloudFormationClientInterface interface {
|
||||
ListStacks(context.Context, *cloudformation.ListStacksInput, ...func(*cloudformation.Options)) (*cloudformation.ListStacksOutput, error)
|
||||
}
|
||||
|
||||
func RegisterCloudFormationTypes() {
|
||||
func init() {
|
||||
gob.Register([]cloudFormationTypes.Stack{})
|
||||
gob.Register([]cloudFormationTypes.StackSummary{})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/service/cloudformation"
|
||||
"github.com/aws/aws-sdk-go-v2/service/cloudformation/types"
|
||||
)
|
||||
|
||||
const DESCRIBE_STACKS_TEST_FILE = "./test-data/cloudformation-describestacks.json"
|
||||
const TEMPLATE_BODY_TEST_FILE = "./test-data/cloudformation-getTemplate.json"
|
||||
|
||||
type Stacks struct {
|
||||
Stacks []struct {
|
||||
StackID string `json:"StackId"`
|
||||
Description string `json:"Description"`
|
||||
Tags []interface{} `json:"Tags"`
|
||||
Outputs []types.Output `json:"Outputs"`
|
||||
Parameters []types.Parameter `json:"Parameters"`
|
||||
StackStatusReason interface{} `json:"StackStatusReason"`
|
||||
CreationTime time.Time `json:"CreationTime"`
|
||||
Capabilities []interface{} `json:"Capabilities"`
|
||||
StackName string `json:"StackName"`
|
||||
RoleArn string `json:"RoleArn"`
|
||||
StackStatus string `json:"StackStatus"`
|
||||
DisableRollback bool `json:"DisableRollback"`
|
||||
} `json:"Stacks"`
|
||||
}
|
||||
|
||||
type TemplateBody struct {
|
||||
TemplateBody string `json:"TemplateBody"`
|
||||
}
|
||||
|
||||
type MockedCloudformationClient struct {
|
||||
describeStacks Stacks
|
||||
getTemplateBody TemplateBody
|
||||
}
|
||||
|
||||
func (m *MockedCloudformationClient) DescribeStacks(ctx context.Context, params *cloudformation.DescribeStacksInput, optFns ...func(*cloudformation.Options)) (*cloudformation.DescribeStacksOutput, error) {
|
||||
|
||||
err := json.Unmarshal(readTestFile(DESCRIBE_STACKS_TEST_FILE), &m.describeStacks)
|
||||
if err != nil {
|
||||
log.Fatalf("can't unmarshall file %s", DESCRIBE_STACKS_TEST_FILE)
|
||||
}
|
||||
var stacks []types.Stack
|
||||
for _, stack := range m.describeStacks.Stacks {
|
||||
stacks = append(stacks, types.Stack{
|
||||
StackName: &stack.StackName,
|
||||
RoleARN: &stack.RoleArn,
|
||||
Outputs: stack.Outputs,
|
||||
Parameters: stack.Parameters,
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
return &cloudformation.DescribeStacksOutput{Stacks: stacks}, nil
|
||||
}
|
||||
|
||||
func (m *MockedCloudformationClient) GetTemplate(ctx context.Context, params *cloudformation.GetTemplateInput, optFns ...func(*cloudformation.Options)) (*cloudformation.GetTemplateOutput, error) {
|
||||
err := json.Unmarshal(readTestFile(DESCRIBE_STACKS_TEST_FILE), &m.getTemplateBody)
|
||||
if err != nil {
|
||||
log.Fatalf("can't unmarshall file %s", TEMPLATE_BODY_TEST_FILE)
|
||||
}
|
||||
|
||||
return &cloudformation.GetTemplateOutput{TemplateBody: &m.getTemplateBody.TemplateBody}, nil
|
||||
}
|
||||
|
||||
func (m *MockedCloudformationClient) ListStacks(ctx context.Context, params *cloudformation.ListStacksInput, optFns ...func(*cloudformation.Options)) (*cloudformation.ListStacksOutput, error) {
|
||||
return &cloudformation.ListStacksOutput{}, nil
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/gob"
|
||||
|
||||
"github.com/BishopFox/cloudfox/internal"
|
||||
"github.com/aws/aws-sdk-go-v2/service/cloudfront"
|
||||
cloudfrontTypes "github.com/aws/aws-sdk-go-v2/service/cloudfront/types"
|
||||
"github.com/patrickmn/go-cache"
|
||||
)
|
||||
|
||||
type AWSCloudFrontClientInterface interface {
|
||||
ListDistributions(ctx context.Context, params *cloudfront.ListDistributionsInput, optFns ...func(*cloudfront.Options)) (*cloudfront.ListDistributionsOutput, error)
|
||||
}
|
||||
|
||||
func init() {
|
||||
gob.Register([]cloudfrontTypes.DistributionSummary{})
|
||||
gob.Register(cloudfrontTypes.DistributionSummary{})
|
||||
}
|
||||
|
||||
func CachedCloudFrontListDistributions(CloudFrontClient AWSCloudFrontClientInterface, accountID string) ([]cloudfrontTypes.DistributionSummary, error) {
|
||||
var PaginationControl *string
|
||||
var distributions []cloudfrontTypes.DistributionSummary
|
||||
cacheKey := "cloudfront-ListDistributions-" + accountID
|
||||
cached, found := internal.Cache.Get(cacheKey)
|
||||
if found {
|
||||
sharedLogger.Debug("Using cached CloudFront distributions data")
|
||||
return cached.([]cloudfrontTypes.DistributionSummary), nil
|
||||
}
|
||||
|
||||
for {
|
||||
ListDistributions, err := CloudFrontClient.ListDistributions(
|
||||
context.TODO(),
|
||||
&cloudfront.ListDistributionsInput{
|
||||
Marker: PaginationControl,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
sharedLogger.Error(err.Error())
|
||||
break
|
||||
}
|
||||
|
||||
distributions = append(distributions, ListDistributions.DistributionList.Items...)
|
||||
|
||||
// Pagination control.
|
||||
if ListDistributions.DistributionList.NextMarker != nil {
|
||||
PaginationControl = ListDistributions.DistributionList.NextMarker
|
||||
} else {
|
||||
PaginationControl = nil
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
internal.Cache.Set(cacheKey, distributions, cache.DefaultExpiration)
|
||||
return distributions, nil
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/cloudfront"
|
||||
cloudfrontTypes "github.com/aws/aws-sdk-go-v2/service/cloudfront/types"
|
||||
)
|
||||
|
||||
type MockedAWSCloudFrontClient struct {
|
||||
}
|
||||
|
||||
func (m *MockedAWSCloudFrontClient) ListDistributions(ctx context.Context, input *cloudfront.ListDistributionsInput, options ...func(*cloudfront.Options)) (*cloudfront.ListDistributionsOutput, error) {
|
||||
return &cloudfront.ListDistributionsOutput{
|
||||
DistributionList: &cloudfrontTypes.DistributionList{
|
||||
Items: []cloudfrontTypes.DistributionSummary{
|
||||
{
|
||||
Id: aws.String("distribution1"),
|
||||
},
|
||||
{
|
||||
Id: aws.String("distribution2"),
|
||||
},
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/gob"
|
||||
"fmt"
|
||||
|
||||
"github.com/BishopFox/cloudfox/internal"
|
||||
"github.com/aws/aws-sdk-go-v2/service/codeartifact"
|
||||
codeArtifactTypes "github.com/aws/aws-sdk-go-v2/service/codeartifact/types"
|
||||
"github.com/patrickmn/go-cache"
|
||||
)
|
||||
|
||||
type AWSCodeArtifactClientInterface interface {
|
||||
ListDomains(context.Context, *codeartifact.ListDomainsInput, ...func(*codeartifact.Options)) (*codeartifact.ListDomainsOutput, error)
|
||||
ListRepositories(context.Context, *codeartifact.ListRepositoriesInput, ...func(*codeartifact.Options)) (*codeartifact.ListRepositoriesOutput, error)
|
||||
}
|
||||
|
||||
func init() {
|
||||
gob.Register([]codeArtifactTypes.DomainSummary{})
|
||||
gob.Register([]codeArtifactTypes.RepositorySummary{})
|
||||
}
|
||||
|
||||
func CachedCodeArtifactListDomains(client AWSCodeArtifactClientInterface, accountID string, region string) ([]codeArtifactTypes.DomainSummary, error) {
|
||||
var PaginationControl *string
|
||||
var domains []codeArtifactTypes.DomainSummary
|
||||
cacheKey := fmt.Sprintf("%s-codeartifact-ListDomains-%s", accountID, region)
|
||||
cached, found := internal.Cache.Get(cacheKey)
|
||||
if found {
|
||||
return cached.([]codeArtifactTypes.DomainSummary), nil
|
||||
}
|
||||
for {
|
||||
ListDomains, err := client.ListDomains(
|
||||
context.TODO(),
|
||||
&codeartifact.ListDomainsInput{
|
||||
NextToken: PaginationControl,
|
||||
},
|
||||
func(o *codeartifact.Options) {
|
||||
o.Region = region
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return domains, err
|
||||
}
|
||||
|
||||
domains = append(domains, ListDomains.Domains...)
|
||||
|
||||
//pagination
|
||||
if ListDomains.NextToken == nil {
|
||||
break
|
||||
}
|
||||
PaginationControl = ListDomains.NextToken
|
||||
}
|
||||
|
||||
internal.Cache.Set(cacheKey, domains, cache.DefaultExpiration)
|
||||
return domains, nil
|
||||
}
|
||||
|
||||
func CachedCodeArtifactListRepositories(client AWSCodeArtifactClientInterface, accountID string, region string) ([]codeArtifactTypes.RepositorySummary, error) {
|
||||
var PaginationControl *string
|
||||
var repositories []codeArtifactTypes.RepositorySummary
|
||||
cacheKey := fmt.Sprintf("%s-codeartifact-ListRepositories-%s", accountID, region)
|
||||
cached, found := internal.Cache.Get(cacheKey)
|
||||
if found {
|
||||
return cached.([]codeArtifactTypes.RepositorySummary), nil
|
||||
}
|
||||
for {
|
||||
ListRepositories, err := client.ListRepositories(
|
||||
context.TODO(),
|
||||
&codeartifact.ListRepositoriesInput{
|
||||
NextToken: PaginationControl,
|
||||
},
|
||||
func(o *codeartifact.Options) {
|
||||
o.Region = region
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return repositories, err
|
||||
}
|
||||
|
||||
repositories = append(repositories, ListRepositories.Repositories...)
|
||||
|
||||
//pagination
|
||||
if ListRepositories.NextToken == nil {
|
||||
break
|
||||
}
|
||||
PaginationControl = ListRepositories.NextToken
|
||||
}
|
||||
|
||||
internal.Cache.Set(cacheKey, repositories, cache.DefaultExpiration)
|
||||
return repositories, nil
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/codeartifact"
|
||||
codeArtifactTypes "github.com/aws/aws-sdk-go-v2/service/codeartifact/types"
|
||||
)
|
||||
|
||||
type MockedAWSCodeArtifactClient struct {
|
||||
}
|
||||
|
||||
func (m *MockedAWSCodeArtifactClient) ListRepositories(ctx context.Context, input *codeartifact.ListRepositoriesInput, options ...func(*codeartifact.Options)) (*codeartifact.ListRepositoriesOutput, error) {
|
||||
return &codeartifact.ListRepositoriesOutput{
|
||||
NextToken: nil,
|
||||
Repositories: []codeArtifactTypes.RepositorySummary{
|
||||
{
|
||||
Name: aws.String("repo1"),
|
||||
Arn: aws.String("arn:aws:codeartifact:us-east-1:123456789012:repository/repo1"),
|
||||
DomainName: aws.String("domain1"),
|
||||
},
|
||||
{
|
||||
Name: aws.String("repo2"),
|
||||
Arn: aws.String("arn:aws:codeartifact:us-east-1:123456789012:repository/repo2"),
|
||||
DomainName: aws.String("domain1"),
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (m *MockedAWSCodeArtifactClient) ListDomains(ctx context.Context, input *codeartifact.ListDomainsInput, options ...func(*codeartifact.Options)) (*codeartifact.ListDomainsOutput, error) {
|
||||
return &codeartifact.ListDomainsOutput{
|
||||
NextToken: nil,
|
||||
Domains: []codeArtifactTypes.DomainSummary{
|
||||
{
|
||||
Name: aws.String("domain1"),
|
||||
Arn: aws.String("arn:aws:codeartifact:us-east-1:123456789012:domain/domain1"),
|
||||
},
|
||||
{
|
||||
Name: aws.String("domain2"),
|
||||
Arn: aws.String("arn:aws:codeartifact:us-east-1:123456789012:domain/domain2"),
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
@@ -18,7 +18,7 @@ type CodeBuildClientInterface interface {
|
||||
GetResourcePolicy(ctx context.Context, params *codebuild.GetResourcePolicyInput, optFns ...func(*codebuild.Options)) (*codebuild.GetResourcePolicyOutput, error)
|
||||
}
|
||||
|
||||
func RegisterCodeBuildTypes() {
|
||||
func init() {
|
||||
gob.Register(codeBuildTypes.Project{})
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/service/codebuild"
|
||||
)
|
||||
|
||||
type MockedCodeBuildClient struct {
|
||||
}
|
||||
|
||||
func (m *MockedCodeBuildClient) ListProjects(ctx context.Context, input *codebuild.ListProjectsInput, options ...func(*codebuild.Options)) (*codebuild.ListProjectsOutput, error) {
|
||||
return &codebuild.ListProjectsOutput{
|
||||
Projects: []string{
|
||||
"project1",
|
||||
"project2",
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/gob"
|
||||
"fmt"
|
||||
|
||||
"github.com/BishopFox/cloudfox/internal"
|
||||
"github.com/aws/aws-sdk-go-v2/service/codecommit"
|
||||
codeCommitTypes "github.com/aws/aws-sdk-go-v2/service/codecommit/types"
|
||||
"github.com/patrickmn/go-cache"
|
||||
)
|
||||
|
||||
type AWSCodeCommitClientInterface interface {
|
||||
ListRepositories(context.Context, *codecommit.ListRepositoriesInput, ...func(*codecommit.Options)) (*codecommit.ListRepositoriesOutput, error)
|
||||
}
|
||||
|
||||
func init() {
|
||||
gob.Register([]codeCommitTypes.RepositoryNameIdPair{})
|
||||
}
|
||||
|
||||
func CachedCodeCommitListRepositories(client AWSCodeCommitClientInterface, accountID string, region string) ([]codeCommitTypes.RepositoryNameIdPair, error) {
|
||||
var PaginationControl *string
|
||||
var repositories []codeCommitTypes.RepositoryNameIdPair
|
||||
cacheKey := fmt.Sprintf("%s-codecommit-ListRepositories-%s", accountID, region)
|
||||
cached, found := internal.Cache.Get(cacheKey)
|
||||
if found {
|
||||
return cached.([]codeCommitTypes.RepositoryNameIdPair), nil
|
||||
}
|
||||
for {
|
||||
ListRepositories, err := client.ListRepositories(
|
||||
context.TODO(),
|
||||
&codecommit.ListRepositoriesInput{
|
||||
NextToken: PaginationControl,
|
||||
},
|
||||
func(o *codecommit.Options) {
|
||||
o.Region = region
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return repositories, err
|
||||
}
|
||||
|
||||
repositories = append(repositories, ListRepositories.Repositories...)
|
||||
|
||||
//pagination
|
||||
if ListRepositories.NextToken == nil {
|
||||
break
|
||||
}
|
||||
PaginationControl = ListRepositories.NextToken
|
||||
}
|
||||
|
||||
internal.Cache.Set(cacheKey, repositories, cache.DefaultExpiration)
|
||||
return repositories, nil
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/codecommit"
|
||||
codeCommitTypes "github.com/aws/aws-sdk-go-v2/service/codecommit/types"
|
||||
)
|
||||
|
||||
// create mocks for codecommit ListRepositories
|
||||
|
||||
type MockedAWSCodeCommitClient struct {
|
||||
}
|
||||
|
||||
func (m *MockedAWSCodeCommitClient) ListRepositories(ctx context.Context, input *codecommit.ListRepositoriesInput, options ...func(*codecommit.Options)) (*codecommit.ListRepositoriesOutput, error) {
|
||||
return &codecommit.ListRepositoriesOutput{
|
||||
NextToken: nil,
|
||||
Repositories: []codeCommitTypes.RepositoryNameIdPair{
|
||||
{
|
||||
RepositoryId: aws.String("repo1"),
|
||||
RepositoryName: aws.String("repo1"),
|
||||
},
|
||||
{
|
||||
RepositoryId: aws.String("repo2"),
|
||||
RepositoryName: aws.String("repo2"),
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,212 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/gob"
|
||||
"fmt"
|
||||
|
||||
"github.com/BishopFox/cloudfox/internal"
|
||||
"github.com/aws/aws-sdk-go-v2/service/codedeploy"
|
||||
codeDeployTypes "github.com/aws/aws-sdk-go-v2/service/codedeploy/types"
|
||||
"github.com/patrickmn/go-cache"
|
||||
)
|
||||
|
||||
type AWSCodeDeployClientInterface interface {
|
||||
ListApplications(context.Context, *codedeploy.ListApplicationsInput, ...func(*codedeploy.Options)) (*codedeploy.ListApplicationsOutput, error)
|
||||
GetApplication(context.Context, *codedeploy.GetApplicationInput, ...func(*codedeploy.Options)) (*codedeploy.GetApplicationOutput, error)
|
||||
ListDeployments(context.Context, *codedeploy.ListDeploymentsInput, ...func(*codedeploy.Options)) (*codedeploy.ListDeploymentsOutput, error)
|
||||
GetDeployment(context.Context, *codedeploy.GetDeploymentInput, ...func(*codedeploy.Options)) (*codedeploy.GetDeploymentOutput, error)
|
||||
ListDeploymentConfigs(context.Context, *codedeploy.ListDeploymentConfigsInput, ...func(*codedeploy.Options)) (*codedeploy.ListDeploymentConfigsOutput, error)
|
||||
GetDeploymentConfig(context.Context, *codedeploy.GetDeploymentConfigInput, ...func(*codedeploy.Options)) (*codedeploy.GetDeploymentConfigOutput, error)
|
||||
}
|
||||
|
||||
func init() {
|
||||
gob.Register([]string{})
|
||||
gob.Register([]codeDeployTypes.ApplicationInfo{})
|
||||
gob.Register([]codeDeployTypes.DeploymentConfigInfo{})
|
||||
gob.Register([]codeDeployTypes.DeploymentInfo{})
|
||||
|
||||
}
|
||||
|
||||
func CachedCodeDeployListApplications(client AWSCodeDeployClientInterface, accountID string, region string) ([]string, error) {
|
||||
var PaginationControl *string
|
||||
var applications []string
|
||||
cacheKey := fmt.Sprintf("%s-codedeploy-ListApplications-%s", accountID, region)
|
||||
cached, found := internal.Cache.Get(cacheKey)
|
||||
if found {
|
||||
return cached.([]string), nil
|
||||
}
|
||||
for {
|
||||
ListApplications, err := client.ListApplications(
|
||||
context.TODO(),
|
||||
&codedeploy.ListApplicationsInput{
|
||||
NextToken: PaginationControl,
|
||||
},
|
||||
func(o *codedeploy.Options) {
|
||||
o.Region = region
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return applications, err
|
||||
}
|
||||
|
||||
applications = append(applications, ListApplications.Applications...)
|
||||
|
||||
//pagination
|
||||
if ListApplications.NextToken == nil {
|
||||
break
|
||||
}
|
||||
PaginationControl = ListApplications.NextToken
|
||||
}
|
||||
|
||||
internal.Cache.Set(cacheKey, applications, cache.DefaultExpiration)
|
||||
return applications, nil
|
||||
}
|
||||
|
||||
func CachedCodeDeployListDeploymentConfigs(client AWSCodeDeployClientInterface, accountID string, region string) ([]string, error) {
|
||||
var PaginationControl *string
|
||||
var deploymentConfigs []string
|
||||
cacheKey := fmt.Sprintf("%s-codedeploy-ListDeploymentConfigs-%s", accountID, region)
|
||||
cached, found := internal.Cache.Get(cacheKey)
|
||||
if found {
|
||||
return cached.([]string), nil
|
||||
}
|
||||
for {
|
||||
ListDeploymentConfigs, err := client.ListDeploymentConfigs(
|
||||
context.TODO(),
|
||||
&codedeploy.ListDeploymentConfigsInput{
|
||||
NextToken: PaginationControl,
|
||||
},
|
||||
func(o *codedeploy.Options) {
|
||||
o.Region = region
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return deploymentConfigs, err
|
||||
}
|
||||
|
||||
deploymentConfigs = append(deploymentConfigs, ListDeploymentConfigs.DeploymentConfigsList...)
|
||||
|
||||
//pagination
|
||||
if ListDeploymentConfigs.NextToken == nil {
|
||||
break
|
||||
}
|
||||
PaginationControl = ListDeploymentConfigs.NextToken
|
||||
}
|
||||
|
||||
internal.Cache.Set(cacheKey, deploymentConfigs, cache.DefaultExpiration)
|
||||
return deploymentConfigs, nil
|
||||
}
|
||||
|
||||
func CachedCodeDeployListDeployments(client AWSCodeDeployClientInterface, accountID string, region string) ([]string, error) {
|
||||
var PaginationControl *string
|
||||
var deployments []string
|
||||
cacheKey := fmt.Sprintf("%s-codedeploy-ListDeployments-%s", accountID, region)
|
||||
cached, found := internal.Cache.Get(cacheKey)
|
||||
if found {
|
||||
return cached.([]string), nil
|
||||
}
|
||||
for {
|
||||
ListDeployments, err := client.ListDeployments(
|
||||
context.TODO(),
|
||||
&codedeploy.ListDeploymentsInput{
|
||||
NextToken: PaginationControl,
|
||||
},
|
||||
func(o *codedeploy.Options) {
|
||||
o.Region = region
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return deployments, err
|
||||
}
|
||||
|
||||
deployments = append(deployments, ListDeployments.Deployments...)
|
||||
|
||||
//pagination
|
||||
if ListDeployments.NextToken == nil {
|
||||
break
|
||||
}
|
||||
PaginationControl = ListDeployments.NextToken
|
||||
}
|
||||
|
||||
internal.Cache.Set(cacheKey, deployments, cache.DefaultExpiration)
|
||||
return deployments, nil
|
||||
}
|
||||
|
||||
func CachedCodeDeployGetApplication(client AWSCodeDeployClientInterface, accountID string, region string, applicationName string) (codeDeployTypes.ApplicationInfo, error) {
|
||||
cacheKey := fmt.Sprintf("%s-codedeploy-GetApplication-%s-%s", accountID, region, applicationName)
|
||||
cached, found := internal.Cache.Get(cacheKey)
|
||||
if found {
|
||||
return cached.(codeDeployTypes.ApplicationInfo), nil
|
||||
}
|
||||
GetApplication, err := client.GetApplication(
|
||||
context.TODO(),
|
||||
&codedeploy.GetApplicationInput{
|
||||
ApplicationName: &applicationName,
|
||||
},
|
||||
func(o *codedeploy.Options) {
|
||||
o.Region = region
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return *GetApplication.Application, err
|
||||
}
|
||||
|
||||
internal.Cache.Set(cacheKey, *GetApplication.Application, cache.DefaultExpiration)
|
||||
|
||||
return *GetApplication.Application, nil
|
||||
}
|
||||
|
||||
func CachedCodeDeployGetDeploymentConfig(client AWSCodeDeployClientInterface, accountID string, region string, deploymentConfigName string) (codeDeployTypes.DeploymentConfigInfo, error) {
|
||||
cacheKey := fmt.Sprintf("%s-codedeploy-GetDeploymentConfig-%s-%s", accountID, region, deploymentConfigName)
|
||||
cached, found := internal.Cache.Get(cacheKey)
|
||||
if found {
|
||||
return cached.(codeDeployTypes.DeploymentConfigInfo), nil
|
||||
}
|
||||
GetDeploymentConfig, err := client.GetDeploymentConfig(
|
||||
context.TODO(),
|
||||
&codedeploy.GetDeploymentConfigInput{
|
||||
DeploymentConfigName: &deploymentConfigName,
|
||||
},
|
||||
func(o *codedeploy.Options) {
|
||||
o.Region = region
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return *GetDeploymentConfig.DeploymentConfigInfo, err
|
||||
}
|
||||
|
||||
internal.Cache.Set(cacheKey, *GetDeploymentConfig.DeploymentConfigInfo, cache.DefaultExpiration)
|
||||
|
||||
return *GetDeploymentConfig.DeploymentConfigInfo, nil
|
||||
}
|
||||
|
||||
func CachedCodeDeployGetDeployment(client AWSCodeDeployClientInterface, accountID string, region string, deploymentID string) (codeDeployTypes.DeploymentInfo, error) {
|
||||
cacheKey := fmt.Sprintf("%s-codedeploy-GetDeployment-%s-%s", accountID, region, deploymentID)
|
||||
cached, found := internal.Cache.Get(cacheKey)
|
||||
if found {
|
||||
return cached.(codeDeployTypes.DeploymentInfo), nil
|
||||
}
|
||||
GetDeployment, err := client.GetDeployment(
|
||||
context.TODO(),
|
||||
&codedeploy.GetDeploymentInput{
|
||||
DeploymentId: &deploymentID,
|
||||
},
|
||||
func(o *codedeploy.Options) {
|
||||
o.Region = region
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return *GetDeployment.DeploymentInfo, err
|
||||
}
|
||||
|
||||
internal.Cache.Set(cacheKey, *GetDeployment.DeploymentInfo, cache.DefaultExpiration)
|
||||
|
||||
return *GetDeployment.DeploymentInfo, nil
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/codedeploy"
|
||||
codedeployTypes "github.com/aws/aws-sdk-go-v2/service/codedeploy/types"
|
||||
)
|
||||
|
||||
type MockedCodedeployClient struct {
|
||||
}
|
||||
|
||||
func (m *MockedCodedeployClient) ListApplications(ctx context.Context, input *codedeploy.ListApplicationsInput, options ...func(*codedeploy.Options)) (*codedeploy.ListApplicationsOutput, error) {
|
||||
return &codedeploy.ListApplicationsOutput{
|
||||
Applications: []string{
|
||||
"app1",
|
||||
"app2",
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (m *MockedCodedeployClient) ListDeployments(ctx context.Context, input *codedeploy.ListDeploymentsInput, options ...func(*codedeploy.Options)) (*codedeploy.ListDeploymentsOutput, error) {
|
||||
return &codedeploy.ListDeploymentsOutput{
|
||||
Deployments: []string{
|
||||
"deployment1",
|
||||
"deployment2",
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (m *MockedCodedeployClient) ListDeploymentConfigs(ctx context.Context, input *codedeploy.ListDeploymentConfigsInput, options ...func(*codedeploy.Options)) (*codedeploy.ListDeploymentConfigsOutput, error) {
|
||||
return &codedeploy.ListDeploymentConfigsOutput{
|
||||
DeploymentConfigsList: []string{
|
||||
"deploymentConfig1",
|
||||
"deploymentConfig2",
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (m *MockedCodedeployClient) GetApplication(ctx context.Context, input *codedeploy.GetApplicationInput, options ...func(*codedeploy.Options)) (*codedeploy.GetApplicationOutput, error) {
|
||||
return &codedeploy.GetApplicationOutput{
|
||||
Application: &codedeployTypes.ApplicationInfo{
|
||||
ApplicationName: aws.String("application1"),
|
||||
ApplicationId: aws.String("application1"),
|
||||
CreateTime: aws.Time(time.Now()),
|
||||
GitHubAccountName: aws.String("github"),
|
||||
LinkedToGitHub: true,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (m *MockedCodedeployClient) GetDeployment(ctx context.Context, input *codedeploy.GetDeploymentInput, options ...func(*codedeploy.Options)) (*codedeploy.GetDeploymentOutput, error) {
|
||||
return &codedeploy.GetDeploymentOutput{
|
||||
DeploymentInfo: &codedeployTypes.DeploymentInfo{
|
||||
ApplicationName: aws.String("application1"),
|
||||
CreateTime: aws.Time(time.Now()),
|
||||
DeploymentId: aws.String("deployment1"),
|
||||
DeploymentOverview: &codedeployTypes.DeploymentOverview{
|
||||
Failed: 0,
|
||||
InProgress: 0,
|
||||
Pending: 0,
|
||||
Ready: 0,
|
||||
Skipped: 0,
|
||||
Succeeded: 0,
|
||||
},
|
||||
DeploymentConfigName: aws.String("deploymentConfig1"),
|
||||
Status: codedeployTypes.DeploymentStatusSucceeded,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (m *MockedCodedeployClient) GetDeploymentConfig(ctx context.Context, input *codedeploy.GetDeploymentConfigInput, options ...func(*codedeploy.Options)) (*codedeploy.GetDeploymentConfigOutput, error) {
|
||||
return &codedeploy.GetDeploymentConfigOutput{
|
||||
DeploymentConfigInfo: &codedeployTypes.DeploymentConfigInfo{
|
||||
DeploymentConfigName: aws.String("deploymentConfig1"),
|
||||
ComputePlatform: codedeployTypes.ComputePlatformServer,
|
||||
MinimumHealthyHosts: &codedeployTypes.MinimumHealthyHosts{
|
||||
Type: codedeployTypes.MinimumHealthyHostsTypeFleetPercent,
|
||||
Value: 100,
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/gob"
|
||||
"fmt"
|
||||
|
||||
"github.com/BishopFox/cloudfox/internal"
|
||||
"github.com/aws/aws-sdk-go-v2/service/datapipeline"
|
||||
dataPipelineTypes "github.com/aws/aws-sdk-go-v2/service/datapipeline/types"
|
||||
"github.com/patrickmn/go-cache"
|
||||
)
|
||||
|
||||
type AWSDataPipelineClientInterface interface {
|
||||
ListPipelines(ctx context.Context, input *datapipeline.ListPipelinesInput, opts ...func(*datapipeline.Options)) (*datapipeline.ListPipelinesOutput, error)
|
||||
}
|
||||
|
||||
func init() {
|
||||
gob.Register([]dataPipelineTypes.PipelineIdName{})
|
||||
}
|
||||
|
||||
func CachedDataPipelineListPipelines(client AWSDataPipelineClientInterface, accountID string, region string) ([]dataPipelineTypes.PipelineIdName, error) {
|
||||
var PaginationControl *string
|
||||
var pipelines []dataPipelineTypes.PipelineIdName
|
||||
cacheKey := fmt.Sprintf("%s-datapipeline-ListPipelines-%s", accountID, region)
|
||||
cached, found := internal.Cache.Get(cacheKey)
|
||||
if found {
|
||||
return cached.([]dataPipelineTypes.PipelineIdName), nil
|
||||
}
|
||||
for {
|
||||
ListPipelines, err := client.ListPipelines(
|
||||
context.TODO(),
|
||||
&datapipeline.ListPipelinesInput{
|
||||
Marker: PaginationControl,
|
||||
},
|
||||
func(o *datapipeline.Options) {
|
||||
o.Region = region
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return pipelines, err
|
||||
}
|
||||
|
||||
pipelines = append(pipelines, ListPipelines.PipelineIdList...)
|
||||
|
||||
//pagination
|
||||
if ListPipelines.Marker == nil {
|
||||
break
|
||||
}
|
||||
PaginationControl = ListPipelines.Marker
|
||||
}
|
||||
|
||||
internal.Cache.Set(cacheKey, pipelines, cache.DefaultExpiration)
|
||||
return pipelines, nil
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/datapipeline"
|
||||
dataPipelineTypes "github.com/aws/aws-sdk-go-v2/service/datapipeline/types"
|
||||
)
|
||||
|
||||
type MockedDataPipelineClient struct {
|
||||
}
|
||||
|
||||
func (m *MockedDataPipelineClient) ListPipelines(ctx context.Context, input *datapipeline.ListPipelinesInput, options ...func(*datapipeline.Options)) (*datapipeline.ListPipelinesOutput, error) {
|
||||
return &datapipeline.ListPipelinesOutput{
|
||||
PipelineIdList: []dataPipelineTypes.PipelineIdName{
|
||||
{
|
||||
Id: aws.String("pipeline1"),
|
||||
Name: aws.String("pipeline1"),
|
||||
},
|
||||
{
|
||||
Id: aws.String("pipeline2"),
|
||||
Name: aws.String("pipeline2"),
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
+1
-1
@@ -19,7 +19,7 @@ type DocDBClientInterface interface {
|
||||
DescribeDBInstances(context.Context, *docdb.DescribeDBInstancesInput, ...func(*docdb.Options)) (*docdb.DescribeDBInstancesOutput, error)
|
||||
}
|
||||
|
||||
func RegisterDocDBTypes() {
|
||||
func init() {
|
||||
gob.Register([]docdbTypes.GlobalCluster{})
|
||||
gob.Register([]docdbTypes.DBCluster{})
|
||||
//gob.Register([]docdbTypes.DBInstance{})
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/docdb"
|
||||
docdbTypes "github.com/aws/aws-sdk-go-v2/service/docdb/types"
|
||||
)
|
||||
|
||||
type MockedAWSDocsDBClient struct {
|
||||
}
|
||||
|
||||
func (m *MockedAWSDocsDBClient) DescribeDBClusters(ctx context.Context, input *docdb.DescribeDBClustersInput, options ...func(*docdb.Options)) (*docdb.DescribeDBClustersOutput, error) {
|
||||
return &docdb.DescribeDBClustersOutput{
|
||||
DBClusters: []docdbTypes.DBCluster{
|
||||
{
|
||||
DBClusterIdentifier: aws.String("cluster1"),
|
||||
},
|
||||
{
|
||||
DBClusterIdentifier: aws.String("cluster2"),
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
+1
-1
@@ -16,7 +16,7 @@ type DynamoDBClientInterface interface {
|
||||
DescribeTable(context.Context, *dynamodb.DescribeTableInput, ...func(*dynamodb.Options)) (*dynamodb.DescribeTableOutput, error)
|
||||
}
|
||||
|
||||
func RegisterDynamoDBTypes() {
|
||||
func init() {
|
||||
gob.Register([]string{})
|
||||
gob.Register(dynamoDBTypes.TableDescription{})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
|
||||
dynamodbTypes "github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
|
||||
)
|
||||
|
||||
type MockedAWSDynamoDBClient struct {
|
||||
}
|
||||
|
||||
func (m *MockedAWSDynamoDBClient) ListTables() ([]string, error) {
|
||||
return []string{"table1", "table2"}, nil
|
||||
}
|
||||
|
||||
func (m *MockedAWSDynamoDBClient) DescribeTable(ctx context.Context, input *dynamodb.DescribeTableInput, options ...func(*dynamodb.Options)) (*dynamodb.DescribeTableOutput, error) {
|
||||
return &dynamodb.DescribeTableOutput{
|
||||
Table: &dynamodbTypes.TableDescription{
|
||||
TableName: input.TableName,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
+151
-3
@@ -11,15 +11,24 @@ import (
|
||||
"github.com/patrickmn/go-cache"
|
||||
)
|
||||
|
||||
type EC2ClientInterface interface {
|
||||
type AWSEC2ClientInterface interface {
|
||||
DescribeInstances(context.Context, *ec2.DescribeInstancesInput, ...func(*ec2.Options)) (*ec2.DescribeInstancesOutput, error)
|
||||
DescribeNetworkInterfaces(context.Context, *ec2.DescribeNetworkInterfacesInput, ...func(*ec2.Options)) (*ec2.DescribeNetworkInterfacesOutput, error)
|
||||
DescribeSnapshots(context.Context, *ec2.DescribeSnapshotsInput, ...func(*ec2.Options)) (*ec2.DescribeSnapshotsOutput, error)
|
||||
DescribeVolumes(context.Context, *ec2.DescribeVolumesInput, ...func(*ec2.Options)) (*ec2.DescribeVolumesOutput, error)
|
||||
DescribeImages(context.Context, *ec2.DescribeImagesInput, ...func(*ec2.Options)) (*ec2.DescribeImagesOutput, error)
|
||||
}
|
||||
|
||||
func RegisterEC2Types() {
|
||||
func init() {
|
||||
gob.Register([]ec2Types.Instance{})
|
||||
gob.Register([]ec2Types.NetworkInterface{})
|
||||
gob.Register([]ec2Types.Snapshot{})
|
||||
gob.Register([]ec2Types.Volume{})
|
||||
gob.Register([]ec2Types.Image{})
|
||||
|
||||
}
|
||||
|
||||
func CachedEC2DescribeInstances(client EC2ClientInterface, accountID string, region string) ([]ec2Types.Instance, error) {
|
||||
func CachedEC2DescribeInstances(client AWSEC2ClientInterface, accountID string, region string) ([]ec2Types.Instance, error) {
|
||||
var PaginationControl *string
|
||||
var instances []ec2Types.Instance
|
||||
cacheKey := fmt.Sprintf("%s-ec2-DescribeInstances-%s", accountID, region)
|
||||
@@ -56,3 +65,142 @@ func CachedEC2DescribeInstances(client EC2ClientInterface, accountID string, reg
|
||||
internal.Cache.Set(cacheKey, instances, cache.DefaultExpiration)
|
||||
return instances, nil
|
||||
}
|
||||
|
||||
func CachedEC2DescribeNetworkInterfaces(client AWSEC2ClientInterface, accountID string, region string) ([]ec2Types.NetworkInterface, error) {
|
||||
var PaginationControl *string
|
||||
var NetworkInterfaces []ec2Types.NetworkInterface
|
||||
cacheKey := fmt.Sprintf("%s-ec2-DescribeNetworkInterfaces-%s", accountID, region)
|
||||
cached, found := internal.Cache.Get(cacheKey)
|
||||
if found {
|
||||
return cached.([]ec2Types.NetworkInterface), nil
|
||||
}
|
||||
for {
|
||||
DescribeNetworkInterfaces, err := client.DescribeNetworkInterfaces(
|
||||
context.TODO(),
|
||||
&(ec2.DescribeNetworkInterfacesInput{
|
||||
NextToken: PaginationControl,
|
||||
}),
|
||||
func(o *ec2.Options) {
|
||||
o.Region = region
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return NetworkInterfaces, err
|
||||
}
|
||||
for _, networkInterface := range DescribeNetworkInterfaces.NetworkInterfaces {
|
||||
NetworkInterfaces = append(NetworkInterfaces, networkInterface)
|
||||
}
|
||||
if DescribeNetworkInterfaces.NextToken == nil {
|
||||
break
|
||||
}
|
||||
PaginationControl = DescribeNetworkInterfaces.NextToken
|
||||
}
|
||||
|
||||
internal.Cache.Set(cacheKey, NetworkInterfaces, cache.DefaultExpiration)
|
||||
return NetworkInterfaces, nil
|
||||
}
|
||||
|
||||
func CachedEC2DescribeSnapshots(client AWSEC2ClientInterface, accountID string, region string) ([]ec2Types.Snapshot, error) {
|
||||
var PaginationControl *string
|
||||
var Snapshots []ec2Types.Snapshot
|
||||
cacheKey := fmt.Sprintf("%s-ec2-DescribeSnapshots-%s", accountID, region)
|
||||
cached, found := internal.Cache.Get(cacheKey)
|
||||
if found {
|
||||
return cached.([]ec2Types.Snapshot), nil
|
||||
}
|
||||
for {
|
||||
DescribeSnapshots, err := client.DescribeSnapshots(
|
||||
context.TODO(),
|
||||
&(ec2.DescribeSnapshotsInput{
|
||||
NextToken: PaginationControl,
|
||||
OwnerIds: []string{accountID},
|
||||
}),
|
||||
func(o *ec2.Options) {
|
||||
o.Region = region
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return Snapshots, err
|
||||
}
|
||||
for _, snapshot := range DescribeSnapshots.Snapshots {
|
||||
Snapshots = append(Snapshots, snapshot)
|
||||
}
|
||||
if DescribeSnapshots.NextToken == nil {
|
||||
break
|
||||
}
|
||||
PaginationControl = DescribeSnapshots.NextToken
|
||||
}
|
||||
|
||||
internal.Cache.Set(cacheKey, Snapshots, cache.DefaultExpiration)
|
||||
return Snapshots, nil
|
||||
}
|
||||
|
||||
func CachedEC2DescribeVolumes(client AWSEC2ClientInterface, accountID string, region string) ([]ec2Types.Volume, error) {
|
||||
var PaginationControl *string
|
||||
var Volumes []ec2Types.Volume
|
||||
cacheKey := fmt.Sprintf("%s-ec2-DescribeVolumes-%s", accountID, region)
|
||||
cached, found := internal.Cache.Get(cacheKey)
|
||||
if found {
|
||||
return cached.([]ec2Types.Volume), nil
|
||||
}
|
||||
for {
|
||||
DescribeVolumes, err := client.DescribeVolumes(
|
||||
context.TODO(),
|
||||
&(ec2.DescribeVolumesInput{
|
||||
NextToken: PaginationControl,
|
||||
}),
|
||||
func(o *ec2.Options) {
|
||||
o.Region = region
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return Volumes, err
|
||||
}
|
||||
for _, volume := range DescribeVolumes.Volumes {
|
||||
Volumes = append(Volumes, volume)
|
||||
}
|
||||
if DescribeVolumes.NextToken == nil {
|
||||
break
|
||||
}
|
||||
PaginationControl = DescribeVolumes.NextToken
|
||||
}
|
||||
|
||||
internal.Cache.Set(cacheKey, Volumes, cache.DefaultExpiration)
|
||||
return Volumes, nil
|
||||
}
|
||||
|
||||
func CachedEC2DescribeImages(client AWSEC2ClientInterface, accountID string, region string) ([]ec2Types.Image, error) {
|
||||
var PaginationControl *string
|
||||
var Images []ec2Types.Image
|
||||
cacheKey := fmt.Sprintf("%s-ec2-DescribeImages-%s", accountID, region)
|
||||
cached, found := internal.Cache.Get(cacheKey)
|
||||
if found {
|
||||
return cached.([]ec2Types.Image), nil
|
||||
}
|
||||
for {
|
||||
DescribeImages, err := client.DescribeImages(
|
||||
context.TODO(),
|
||||
&(ec2.DescribeImagesInput{
|
||||
Owners: []string{accountID},
|
||||
NextToken: PaginationControl,
|
||||
}),
|
||||
func(o *ec2.Options) {
|
||||
o.Region = region
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return Images, err
|
||||
}
|
||||
for _, image := range DescribeImages.Images {
|
||||
Images = append(Images, image)
|
||||
}
|
||||
if DescribeImages.NextToken == nil {
|
||||
break
|
||||
}
|
||||
PaginationControl = DescribeImages.NextToken
|
||||
}
|
||||
|
||||
internal.Cache.Set(cacheKey, Images, cache.DefaultExpiration)
|
||||
return Images, nil
|
||||
|
||||
}
|
||||
@@ -0,0 +1,374 @@
|
||||
package sdk
|
||||
|
||||
// create test for the Cached EC2 functions. Create a mocked client and mocked functions for each of the methods used in the ec2.go file
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/ec2"
|
||||
ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types"
|
||||
)
|
||||
|
||||
const DESCRIBE_NETWORK_INTEFACES_TEST_FILE = "./test-data/describe-network-interfaces.json"
|
||||
const DESCRIBE_INSTANCES_TEST_FILE = "./test-data/ec2-describeInstances.json"
|
||||
const DESCRIBE_SNAPSHOTS_TEST_FILE = "./test-data/ec2-describeSnapshots.json"
|
||||
const DESCRIBE_VOLUMES_TEST_FILE = "./test-data/ec2-describeVolumes.json"
|
||||
const DESCRIBE_IMAGES_TEST_FILE = "./test-data/ec2-describeImages.json"
|
||||
|
||||
type MockedEC2Client2 struct {
|
||||
describeNetworkInterfaces DescribeNetworkInterfaces
|
||||
describeInstances DescribeInstances
|
||||
describeSnapshots DescribeSnapshots
|
||||
describeVolumes DescribeVolumes
|
||||
describeImages DescribeImages
|
||||
}
|
||||
|
||||
type DescribeNetworkInterfaces struct {
|
||||
NetworkInterfaces []struct {
|
||||
Status string `json:"Status"`
|
||||
MacAddress string `json:"MacAddress"`
|
||||
SourceDestCheck bool `json:"SourceDestCheck"`
|
||||
VpcID string `json:"VpcId"`
|
||||
Description string `json:"Description"`
|
||||
Association struct {
|
||||
PublicIP string `json:"PublicIp"`
|
||||
AssociationID string `json:"AssociationId"`
|
||||
PublicDNSName string `json:"PublicDnsName"`
|
||||
IPOwnerID string `json:"IpOwnerId"`
|
||||
} `json:"Association"`
|
||||
NetworkInterfaceID string `json:"NetworkInterfaceId"`
|
||||
PrivateIPAddresses []struct {
|
||||
PrivateDNSName string `json:"PrivateDnsName"`
|
||||
Association struct {
|
||||
PublicIP string `json:"PublicIp"`
|
||||
AssociationID string `json:"AssociationId"`
|
||||
PublicDNSName string `json:"PublicDnsName"`
|
||||
IPOwnerID string `json:"IpOwnerId"`
|
||||
} `json:"Association"`
|
||||
Primary bool `json:"Primary"`
|
||||
PrivateIPAddress string `json:"PrivateIpAddress"`
|
||||
} `json:"PrivateIpAddresses"`
|
||||
RequesterManaged bool `json:"RequesterManaged"`
|
||||
Ipv6Addresses []interface{} `json:"Ipv6Addresses"`
|
||||
PrivateDNSName string `json:"PrivateDnsName,omitempty"`
|
||||
AvailabilityZone string `json:"AvailabilityZone"`
|
||||
Attachment struct {
|
||||
Status string `json:"Status"`
|
||||
DeviceIndex int `json:"DeviceIndex"`
|
||||
AttachTime time.Time `json:"AttachTime"`
|
||||
InstanceID string `json:"InstanceId"`
|
||||
DeleteOnTermination bool `json:"DeleteOnTermination"`
|
||||
AttachmentID string `json:"AttachmentId"`
|
||||
InstanceOwnerID string `json:"InstanceOwnerId"`
|
||||
} `json:"Attachment"`
|
||||
Groups []struct {
|
||||
GroupName string `json:"GroupName"`
|
||||
GroupID string `json:"GroupId"`
|
||||
} `json:"Groups"`
|
||||
SubnetID string `json:"SubnetId"`
|
||||
OwnerID string `json:"OwnerId"`
|
||||
TagSet []interface{} `json:"TagSet"`
|
||||
PrivateIPAddress string `json:"PrivateIpAddress"`
|
||||
} `json:"NetworkInterfaces"`
|
||||
}
|
||||
|
||||
type DescribeInstances struct {
|
||||
Reservations []struct {
|
||||
Instances []struct {
|
||||
AmiLaunchIndex int `json:"AmiLaunchIndex"`
|
||||
ImageID string `json:"ImageId"`
|
||||
InstanceID string `json:"InstanceId"`
|
||||
InstanceType string `json:"InstanceType"`
|
||||
KernelID string `json:"KernelId"`
|
||||
KeyName string `json:"KeyName"`
|
||||
LaunchTime string `json:"LaunchTime"`
|
||||
Monitoring struct {
|
||||
State string `json:"State"`
|
||||
} `json:"Monitoring"`
|
||||
Placement struct {
|
||||
AvailabilityZone string `json:"AvailabilityZone"`
|
||||
GroupName string `json:"GroupName"`
|
||||
Tenancy string `json:"Tenancy"`
|
||||
} `json:"Placement"`
|
||||
Platform string `json:"Platform"`
|
||||
PrivateDNS string `json:"PrivateDnsName"`
|
||||
PrivateIP string `json:"PrivateIpAddress"`
|
||||
PublicDNS string `json:"PublicDnsName"`
|
||||
PublicIP string `json:"PublicIpAddress"`
|
||||
State string `json:"State"`
|
||||
SubnetID string `json:"SubnetId"`
|
||||
VpcID string `json:"VpcId"`
|
||||
Architecture string `json:"Architecture"`
|
||||
BlockDeviceMappings []struct {
|
||||
DeviceName string `json:"DeviceName"`
|
||||
Ebs struct {
|
||||
AttachTime time.Time `json:"AttachTime"`
|
||||
DeleteOnTermination bool `json:"DeleteOnTermination"`
|
||||
Status string `json:"Status"`
|
||||
VolumeID string `json:"VolumeId"`
|
||||
} `json:"Ebs"`
|
||||
} `json:"BlockDeviceMappings"`
|
||||
ClientToken string `json:"ClientToken"`
|
||||
EbsOptimized bool `json:"EbsOptimized"`
|
||||
Hypervisor string `json:"Hypervisor"`
|
||||
IamInstanceProfile struct {
|
||||
Arn string `json:"Arn"`
|
||||
ID string `json:"Id"`
|
||||
} `json:"IamInstanceProfile"`
|
||||
NetworkInterfaces []struct {
|
||||
Attachment struct {
|
||||
AttachTime time.Time `json:"AttachTime"`
|
||||
AttachmentID string `json:"AttachmentId"`
|
||||
DeleteOnTermination bool `json:"DeleteOnTermination"`
|
||||
DeviceIndex int `json:"DeviceIndex"`
|
||||
Status string `json:"Status"`
|
||||
} `json:"Attachment"`
|
||||
Description string `json:"Description"`
|
||||
Groups []struct {
|
||||
GroupName string `json:"GroupName"`
|
||||
GroupID string `json:"GroupId"`
|
||||
} `json:"Groups"`
|
||||
MacAddress string `json:"MacAddress"`
|
||||
NetworkInterfaceID string `json:"NetworkInterfaceId"`
|
||||
OwnerID string `json:"OwnerId"`
|
||||
PrivateDNSName string `json:"PrivateDnsName"`
|
||||
PrivateIPAddress string `json:"PrivateIpAddress"`
|
||||
PrivateIPAddresses []struct {
|
||||
Association struct {
|
||||
IPOwnerID string `json:"IpOwnerId"`
|
||||
PublicDNSName string `json:"PublicDnsName"`
|
||||
PublicIP string `json:"PublicIp"`
|
||||
} `json:"Association"`
|
||||
Primary bool `json:"Primary"`
|
||||
PrivateDNSName string `json:"PrivateDnsName"`
|
||||
PrivateIPAddress string `json:"PrivateIpAddress"`
|
||||
} `json:"PrivateIpAddresses"`
|
||||
SourceDestCheck bool `json:"SourceDestCheck"`
|
||||
Status string `json:"Status"`
|
||||
SubnetID string `json:"SubnetId"`
|
||||
VpcID string `json:"VpcId"`
|
||||
} `json:"NetworkInterfaces"`
|
||||
RootDeviceName string `json:"RootDeviceName"`
|
||||
RootDeviceType string `json:"RootDeviceType"`
|
||||
SecurityGroups []struct {
|
||||
GroupName string `json:"GroupName"`
|
||||
GroupID string `json:"GroupId"`
|
||||
} `json:"SecurityGroups"`
|
||||
SourceDestCheck bool `json:"SourceDestCheck"`
|
||||
StateReason struct {
|
||||
Code string `json:"Code"`
|
||||
Message string `json:"Message"`
|
||||
} `json:"StateReason"`
|
||||
Tags []struct {
|
||||
Key string `json:"Key"`
|
||||
Value string `json:"Value"`
|
||||
} `json:"Tags"`
|
||||
VirtualizationType string `json:"VirtualizationType"`
|
||||
} `json:"Instances"`
|
||||
OwnerID string `json:"OwnerId"`
|
||||
RequesterID string `json:"RequesterId"`
|
||||
ReservationID string `json:"ReservationId"`
|
||||
} `json:"Reservations"`
|
||||
}
|
||||
|
||||
type DescribeImages struct {
|
||||
Images []struct {
|
||||
Architecture string `json:"Architecture"`
|
||||
BlockDeviceMappings []struct {
|
||||
DeviceName string `json:"DeviceName"`
|
||||
Ebs struct {
|
||||
DeleteOnTermination bool `json:"DeleteOnTermination"`
|
||||
SnapshotID string `json:"SnapshotId"`
|
||||
VolumeSize int `json:"VolumeSize"`
|
||||
VolumeType string `json:"VolumeType"`
|
||||
} `json:"Ebs"`
|
||||
} `json:"BlockDeviceMappings"`
|
||||
CreationDate string `json:"CreationDate"`
|
||||
Description string `json:"Description"`
|
||||
EnaSupport bool `json:"EnaSupport"`
|
||||
Hypervisor string `json:"Hypervisor"`
|
||||
ImageID string `json:"ImageId"`
|
||||
ImageLocation string `json:"ImageLocation"`
|
||||
ImageType string `json:"ImageType"`
|
||||
KernelID string `json:"KernelId"`
|
||||
Name string `json:"Name"`
|
||||
OwnerAlias string `json:"OwnerAlias"`
|
||||
OwnerID string `json:"OwnerId"`
|
||||
Platform string `json:"Platform"`
|
||||
ProductCodes []struct {
|
||||
ProductCodeID string `json:"ProductCodeId"`
|
||||
ProductCodeType string `json:"ProductCodeType"`
|
||||
} `json:"ProductCodes"`
|
||||
Public bool `json:"Public"`
|
||||
RamdiskID string `json:"RamdiskId"`
|
||||
RootDeviceName string `json:"RootDeviceName"`
|
||||
RootDeviceType string `json:"RootDeviceType"`
|
||||
SriovNetSupport string `json:"SriovNetSupport"`
|
||||
State string `json:"State"`
|
||||
StateReason struct {
|
||||
Code string `json:"Code"`
|
||||
Message string `json:"Message"`
|
||||
} `json:"StateReason"`
|
||||
Tags []struct {
|
||||
Key string `json:"Key"`
|
||||
Value string `json:"Value"`
|
||||
} `json:"Tags"`
|
||||
VirtualizationType string `json:"VirtualizationType"`
|
||||
} `json:"Images"`
|
||||
NextToken string `json:"NextToken"`
|
||||
}
|
||||
|
||||
type DescribeSnapshots struct {
|
||||
Snapshots []struct {
|
||||
DataEncryptionKeyID string `json:"DataEncryptionKeyId"`
|
||||
Description string `json:"Description"`
|
||||
Encrypted bool `json:"Encrypted"`
|
||||
KMSKeyID string `json:"KmsKeyId"`
|
||||
OwnerAlias string `json:"OwnerAlias"`
|
||||
OwnerID string `json:"OwnerId"`
|
||||
Progress string `json:"Progress"`
|
||||
SnapshotID string `json:"SnapshotId"`
|
||||
StartTime time.Time `json:"StartTime"`
|
||||
State string `json:"State"`
|
||||
StateMessage string `json:"StateMessage"`
|
||||
TagSet []struct {
|
||||
Key string `json:"Key"`
|
||||
Value string `json:"Value"`
|
||||
} `json:"Tags"`
|
||||
VolumeID string `json:"VolumeId"`
|
||||
VolumeSize int `json:"VolumeSize"`
|
||||
} `json:"Snapshots"`
|
||||
}
|
||||
|
||||
type DescribeVolumes struct {
|
||||
Volumes []struct {
|
||||
Attachments []struct {
|
||||
AttachTime time.Time `json:"AttachTime"`
|
||||
DeleteOnTermination bool `json:"DeleteOnTermination"`
|
||||
Device string `json:"Device"`
|
||||
InstanceID string `json:"InstanceId"`
|
||||
State string `json:"State"`
|
||||
VolumeID string `json:"VolumeId"`
|
||||
} `json:"Attachments"`
|
||||
AvailabilityZone string `json:"AvailabilityZone"`
|
||||
CreateTime string `json:"CreateTime"`
|
||||
Encrypted bool `json:"Encrypted"`
|
||||
KMSKeyID string `json:"KmsKeyId"`
|
||||
Size int `json:"Size"`
|
||||
SnapshotID string `json:"SnapshotId"`
|
||||
State string `json:"State"`
|
||||
VolumeID string `json:"VolumeId"`
|
||||
} `json:"Volumes"`
|
||||
}
|
||||
|
||||
func (c *MockedEC2Client2) DescribeNetworkInterfaces(ctx context.Context, input *ec2.DescribeNetworkInterfacesInput, f ...func(o *ec2.Options)) (*ec2.DescribeNetworkInterfacesOutput, error) {
|
||||
var nics []ec2types.NetworkInterface
|
||||
err := json.Unmarshal(readTestFile(DESCRIBE_NETWORK_INTEFACES_TEST_FILE), &c.describeNetworkInterfaces)
|
||||
if err != nil {
|
||||
log.Fatalf("can't unmarshall file %s", DESCRIBE_NETWORK_INTEFACES_TEST_FILE)
|
||||
}
|
||||
for _, mockednic := range c.describeNetworkInterfaces.NetworkInterfaces {
|
||||
nics = append(nics, ec2types.NetworkInterface{
|
||||
Association: &ec2types.NetworkInterfaceAssociation{
|
||||
PublicIp: aws.String(mockednic.Association.PublicIP),
|
||||
},
|
||||
NetworkInterfaceId: aws.String(mockednic.NetworkInterfaceID),
|
||||
PrivateIpAddress: aws.String(mockednic.PrivateIPAddress),
|
||||
VpcId: aws.String(mockednic.VpcID),
|
||||
Attachment: &ec2types.NetworkInterfaceAttachment{InstanceId: aws.String(mockednic.Attachment.InstanceID)},
|
||||
Description: aws.String(mockednic.Description),
|
||||
})
|
||||
}
|
||||
return &ec2.DescribeNetworkInterfacesOutput{NetworkInterfaces: nics}, nil
|
||||
}
|
||||
|
||||
func (c *MockedEC2Client2) DescribeInstances(ctx context.Context, input *ec2.DescribeInstancesInput, f ...func(o *ec2.Options)) (*ec2.DescribeInstancesOutput, error) {
|
||||
var instances []ec2types.Instance
|
||||
err := json.Unmarshal(readTestFile(DESCRIBE_INSTANCES_TEST_FILE), &c.describeInstances)
|
||||
if err != nil {
|
||||
log.Fatalf("can't unmarshall file %s", DESCRIBE_INSTANCES_TEST_FILE)
|
||||
}
|
||||
for _, mockedReservation := range c.describeInstances.Reservations {
|
||||
for _, mockedInstance := range mockedReservation.Instances {
|
||||
for _, inputInstanceID := range input.InstanceIds {
|
||||
if mockedInstance.InstanceID == inputInstanceID {
|
||||
instances = append(instances, ec2types.Instance{
|
||||
InstanceId: aws.String(mockedInstance.InstanceID),
|
||||
InstanceType: ec2types.InstanceType(mockedInstance.InstanceType),
|
||||
ImageId: aws.String(mockedInstance.ImageID),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return &ec2.DescribeInstancesOutput{Reservations: []ec2types.Reservation{
|
||||
{Instances: instances},
|
||||
}}, nil
|
||||
}
|
||||
|
||||
func (c *MockedEC2Client2) DescribeVolumes(ctx context.Context, input *ec2.DescribeVolumesInput, f ...func(o *ec2.Options)) (*ec2.DescribeVolumesOutput, error) {
|
||||
var volumes []ec2types.Volume
|
||||
err := json.Unmarshal(readTestFile(DESCRIBE_VOLUMES_TEST_FILE), &c.describeVolumes)
|
||||
if err != nil {
|
||||
log.Fatalf("can't unmarshall file %s", DESCRIBE_VOLUMES_TEST_FILE)
|
||||
}
|
||||
for _, mockedVolume := range c.describeVolumes.Volumes {
|
||||
for _, inputVolumeID := range input.VolumeIds {
|
||||
if mockedVolume.VolumeID == inputVolumeID {
|
||||
volumes = append(volumes, ec2types.Volume{
|
||||
VolumeId: aws.String(mockedVolume.VolumeID),
|
||||
Size: aws.Int32(int32(mockedVolume.Size)),
|
||||
Attachments: []ec2types.VolumeAttachment{
|
||||
{
|
||||
InstanceId: aws.String(mockedVolume.Attachments[0].InstanceID),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
return &ec2.DescribeVolumesOutput{Volumes: volumes}, nil
|
||||
}
|
||||
|
||||
func (c *MockedEC2Client2) DescribeSnapshots(ctx context.Context, input *ec2.DescribeSnapshotsInput, f ...func(o *ec2.Options)) (*ec2.DescribeSnapshotsOutput, error) {
|
||||
var snapshots []ec2types.Snapshot
|
||||
err := json.Unmarshal(readTestFile(DESCRIBE_SNAPSHOTS_TEST_FILE), &c.describeSnapshots)
|
||||
if err != nil {
|
||||
log.Fatalf("can't unmarshall file %s", DESCRIBE_SNAPSHOTS_TEST_FILE)
|
||||
}
|
||||
for _, mockedSnapshot := range c.describeSnapshots.Snapshots {
|
||||
for _, inputSnapshotID := range input.SnapshotIds {
|
||||
if mockedSnapshot.SnapshotID == inputSnapshotID {
|
||||
snapshots = append(snapshots, ec2types.Snapshot{
|
||||
SnapshotId: aws.String(mockedSnapshot.SnapshotID),
|
||||
VolumeId: aws.String(mockedSnapshot.VolumeID),
|
||||
State: ec2types.SnapshotState(mockedSnapshot.State),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
return &ec2.DescribeSnapshotsOutput{Snapshots: snapshots}, nil
|
||||
}
|
||||
|
||||
func (c *MockedEC2Client2) DescribeImages(ctx context.Context, input *ec2.DescribeImagesInput, f ...func(o *ec2.Options)) (*ec2.DescribeImagesOutput, error) {
|
||||
var images []ec2types.Image
|
||||
err := json.Unmarshal(readTestFile(DESCRIBE_IMAGES_TEST_FILE), &c.describeImages)
|
||||
if err != nil {
|
||||
log.Fatalf("can't unmarshall file %s", DESCRIBE_IMAGES_TEST_FILE)
|
||||
}
|
||||
for _, mockedImage := range c.describeImages.Images {
|
||||
for _, inputImageID := range input.ImageIds {
|
||||
if mockedImage.ImageID == inputImageID {
|
||||
images = append(images, ec2types.Image{
|
||||
ImageId: aws.String(mockedImage.ImageID),
|
||||
Name: aws.String(mockedImage.Name),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
return &ec2.DescribeImagesOutput{Images: images}, nil
|
||||
}
|
||||
+2
-1
@@ -19,9 +19,10 @@ type AWSECRClientInterface interface {
|
||||
GetRepositoryPolicy(ctx context.Context, params *ecr.GetRepositoryPolicyInput, optFns ...func(*ecr.Options)) (*ecr.GetRepositoryPolicyOutput, error)
|
||||
}
|
||||
|
||||
func RegisterECRTypes() {
|
||||
func init() {
|
||||
gob.Register([]ecrTypes.Repository{})
|
||||
gob.Register([]ecrTypes.ImageDetail{})
|
||||
gob.Register(ecrTypes.Repository{})
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/ecr"
|
||||
ecrTypes "github.com/aws/aws-sdk-go-v2/service/ecr/types"
|
||||
)
|
||||
|
||||
type MockedECRClient struct {
|
||||
}
|
||||
|
||||
func (m *MockedECRClient) DescribeRepositories(ctx context.Context, input *ecr.DescribeRepositoriesInput, options ...func(*ecr.Options)) (*ecr.DescribeRepositoriesOutput, error) {
|
||||
return &ecr.DescribeRepositoriesOutput{
|
||||
Repositories: []ecrTypes.Repository{
|
||||
{
|
||||
RepositoryName: aws.String("repo1"),
|
||||
},
|
||||
{
|
||||
RepositoryName: aws.String("repo2"),
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (m *MockedECRClient) DescribeImages(ctx context.Context, input *ecr.DescribeImagesInput, options ...func(*ecr.Options)) (*ecr.DescribeImagesOutput, error) {
|
||||
return &ecr.DescribeImagesOutput{
|
||||
ImageDetails: []ecrTypes.ImageDetail{
|
||||
{
|
||||
ImageTags: []string{
|
||||
"tag1",
|
||||
"tag2",
|
||||
},
|
||||
},
|
||||
{
|
||||
ImageTags: []string{
|
||||
"tag3", "tag4", "tag5", "tag6"},
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (m *MockedECRClient) GetRepositoryPolicy(ctx context.Context, input *ecr.GetRepositoryPolicyInput, options ...func(*ecr.Options)) (*ecr.GetRepositoryPolicyOutput, error) {
|
||||
return &ecr.GetRepositoryPolicyOutput{
|
||||
PolicyText: aws.String(`{
|
||||
"Version": "2008-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Sid": "AllowPushPull",
|
||||
"Effect": "Allow",
|
||||
"Principal": {
|
||||
"AWS": [
|
||||
"arn:aws:iam::123456789012:root",
|
||||
"arn:aws:iam::123456789012:user/MyUser"
|
||||
]
|
||||
},
|
||||
"Action": [
|
||||
|
||||
"ecr:GetDownloadUrlForLayer",
|
||||
"ecr:BatchGetImage",
|
||||
"ecr:BatchCheckLayerAvailability",
|
||||
"ecr:PutImage",
|
||||
"ecr:InitiateLayerUpload",
|
||||
"ecr:UploadLayerPart",
|
||||
"ecr:CompleteLayerUpload"
|
||||
]
|
||||
|
||||
}
|
||||
]
|
||||
}`),
|
||||
}, nil
|
||||
}
|
||||
+215
@@ -0,0 +1,215 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/gob"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/BishopFox/cloudfox/internal"
|
||||
"github.com/aws/aws-sdk-go-v2/service/ecs"
|
||||
ecsTypes "github.com/aws/aws-sdk-go-v2/service/ecs/types"
|
||||
"github.com/patrickmn/go-cache"
|
||||
)
|
||||
|
||||
type AWSECSClientInterface interface {
|
||||
ListClusters(ctx context.Context, params *ecs.ListClustersInput, optFns ...func(*ecs.Options)) (*ecs.ListClustersOutput, error)
|
||||
ListTasks(ctx context.Context, params *ecs.ListTasksInput, optFns ...func(*ecs.Options)) (*ecs.ListTasksOutput, error)
|
||||
ListServices(ctx context.Context, params *ecs.ListServicesInput, optFns ...func(*ecs.Options)) (*ecs.ListServicesOutput, error)
|
||||
DescribeTasks(ctx context.Context, params *ecs.DescribeTasksInput, optFns ...func(*ecs.Options)) (*ecs.DescribeTasksOutput, error)
|
||||
DescribeTaskDefinition(ctx context.Context, params *ecs.DescribeTaskDefinitionInput, optFns ...func(*ecs.Options)) (*ecs.DescribeTaskDefinitionOutput, error)
|
||||
}
|
||||
|
||||
func init() {
|
||||
gob.Register([]string{})
|
||||
gob.Register(ecsTypes.Task{})
|
||||
gob.Register(ecsTypes.TaskDefinition{})
|
||||
|
||||
}
|
||||
|
||||
func CachedECSListClusters(ECSClient AWSECSClientInterface, accountID string, region string) ([]string, error) {
|
||||
var PaginationControl *string
|
||||
var clusters []string
|
||||
cacheKey := fmt.Sprintf("%s-ecs-ListClusters-%s", accountID, region)
|
||||
cached, found := internal.Cache.Get(cacheKey)
|
||||
if found {
|
||||
sharedLogger.Debug("Using cached ECS clusters data")
|
||||
return cached.([]string), nil
|
||||
}
|
||||
|
||||
for {
|
||||
ListClusters, err := ECSClient.ListClusters(
|
||||
context.TODO(),
|
||||
&ecs.ListClustersInput{
|
||||
NextToken: PaginationControl,
|
||||
},
|
||||
func(o *ecs.Options) {
|
||||
o.Region = region
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
sharedLogger.Error(err.Error())
|
||||
break
|
||||
}
|
||||
|
||||
clusters = append(clusters, ListClusters.ClusterArns...)
|
||||
|
||||
// Pagination control.
|
||||
if ListClusters.NextToken != nil {
|
||||
PaginationControl = ListClusters.NextToken
|
||||
} else {
|
||||
PaginationControl = nil
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
internal.Cache.Set(cacheKey, clusters, cache.DefaultExpiration)
|
||||
return clusters, nil
|
||||
}
|
||||
|
||||
func CachedECSListTasks(ECSClient AWSECSClientInterface, accountID string, region string, cluster string) ([]string, error) {
|
||||
var PaginationControl *string
|
||||
var tasks []string
|
||||
//grab cluster name from AWS ARN
|
||||
clusterName := cluster[strings.LastIndex(cluster, "/")+1:]
|
||||
|
||||
cacheKey := fmt.Sprintf("%s-ecs-ListTasks-%s-%s", accountID, region, clusterName)
|
||||
cached, found := internal.Cache.Get(cacheKey)
|
||||
if found {
|
||||
sharedLogger.Debug("Using cached ECS tasks data")
|
||||
return cached.([]string), nil
|
||||
}
|
||||
|
||||
for {
|
||||
ListTasks, err := ECSClient.ListTasks(
|
||||
context.TODO(),
|
||||
&ecs.ListTasksInput{
|
||||
Cluster: &cluster,
|
||||
NextToken: PaginationControl,
|
||||
},
|
||||
func(o *ecs.Options) {
|
||||
o.Region = region
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
sharedLogger.Error(err.Error())
|
||||
break
|
||||
}
|
||||
|
||||
tasks = append(tasks, ListTasks.TaskArns...)
|
||||
|
||||
// Pagination control.
|
||||
if ListTasks.NextToken != nil {
|
||||
PaginationControl = ListTasks.NextToken
|
||||
} else {
|
||||
PaginationControl = nil
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
internal.Cache.Set(cacheKey, tasks, cache.DefaultExpiration)
|
||||
return tasks, nil
|
||||
}
|
||||
|
||||
func CachedECSDescribeTasks(ECSClient AWSECSClientInterface, accountID string, region string, cluster string, tasks []string) ([]ecsTypes.Task, error) {
|
||||
var taskDetails []ecsTypes.Task
|
||||
cacheKey := fmt.Sprintf("%s-ecs-DescribeTasks-%s-%s", accountID, region, cluster)
|
||||
cached, found := internal.Cache.Get(cacheKey)
|
||||
if found {
|
||||
sharedLogger.Debug("Using cached ECS task details data")
|
||||
return cached.([]ecsTypes.Task), nil
|
||||
}
|
||||
|
||||
DescribeTasks, err := ECSClient.DescribeTasks(
|
||||
context.TODO(),
|
||||
&ecs.DescribeTasksInput{
|
||||
Cluster: &cluster,
|
||||
Tasks: tasks,
|
||||
},
|
||||
func(o *ecs.Options) {
|
||||
o.Region = region
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
sharedLogger.Error(err.Error())
|
||||
return []ecsTypes.Task{}, err
|
||||
}
|
||||
|
||||
taskDetails = append(taskDetails, DescribeTasks.Tasks...)
|
||||
|
||||
internal.Cache.Set(cacheKey, taskDetails, cache.DefaultExpiration)
|
||||
return taskDetails, nil
|
||||
}
|
||||
|
||||
func CachedECSDescribeTaskDefinition(ECSClient AWSECSClientInterface, accountID string, region string, taskDefinition string) (ecsTypes.TaskDefinition, error) {
|
||||
var taskDefinitionDetails ecsTypes.TaskDefinition
|
||||
cacheKey := fmt.Sprintf("%s-ecs-DescribeTaskDefinition-%s-%s", accountID, region, taskDefinition)
|
||||
cached, found := internal.Cache.Get(cacheKey)
|
||||
if found {
|
||||
sharedLogger.Debug("Using cached ECS task definition details data")
|
||||
return cached.(ecsTypes.TaskDefinition), nil
|
||||
}
|
||||
|
||||
DescribeTaskDefinition, err := ECSClient.DescribeTaskDefinition(
|
||||
context.TODO(),
|
||||
&ecs.DescribeTaskDefinitionInput{
|
||||
TaskDefinition: &taskDefinition,
|
||||
},
|
||||
func(o *ecs.Options) {
|
||||
o.Region = region
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
sharedLogger.Error(err.Error())
|
||||
return ecsTypes.TaskDefinition{}, err
|
||||
}
|
||||
|
||||
taskDefinitionDetails = *DescribeTaskDefinition.TaskDefinition
|
||||
|
||||
internal.Cache.Set(cacheKey, taskDefinitionDetails, cache.DefaultExpiration)
|
||||
return taskDefinitionDetails, nil
|
||||
}
|
||||
|
||||
func CachedECSListServices(ECSClient AWSECSClientInterface, accountID string, region string, cluster string) ([]string, error) {
|
||||
var PaginationControl *string
|
||||
var services []string
|
||||
//grab cluster name from AWS ARN
|
||||
clusterName := cluster[strings.LastIndex(cluster, "/")+1:]
|
||||
|
||||
cacheKey := fmt.Sprintf("%s-ecs-ListServices-%s-%s", accountID, region, clusterName)
|
||||
cached, found := internal.Cache.Get(cacheKey)
|
||||
if found {
|
||||
sharedLogger.Debug("Using cached ECS services data")
|
||||
return cached.([]string), nil
|
||||
}
|
||||
|
||||
for {
|
||||
ListServices, err := ECSClient.ListServices(
|
||||
context.TODO(),
|
||||
&ecs.ListServicesInput{
|
||||
Cluster: &cluster,
|
||||
NextToken: PaginationControl,
|
||||
},
|
||||
func(o *ecs.Options) {
|
||||
o.Region = region
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
sharedLogger.Error(err.Error())
|
||||
break
|
||||
}
|
||||
|
||||
services = append(services, ListServices.ServiceArns...)
|
||||
|
||||
// Pagination control.
|
||||
if ListServices.NextToken != nil {
|
||||
PaginationControl = ListServices.NextToken
|
||||
} else {
|
||||
PaginationControl = nil
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
internal.Cache.Set(cacheKey, services, cache.DefaultExpiration)
|
||||
return services, nil
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"log"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/ecs"
|
||||
ecsTypes "github.com/aws/aws-sdk-go-v2/service/ecs/types"
|
||||
)
|
||||
|
||||
const DESCRIBE_TASKS_TEST_FILE = "./test-data/describe-tasks.json"
|
||||
|
||||
type MockedECSClient struct {
|
||||
describeTasks DescribeTasks
|
||||
}
|
||||
|
||||
type ListTasks struct {
|
||||
TaskArns []string `json:"taskArns"`
|
||||
}
|
||||
|
||||
type DescribeTasks struct {
|
||||
Tasks []struct {
|
||||
Attachments []struct {
|
||||
ID string `json:"id"`
|
||||
Type string `json:"type"`
|
||||
Status string `json:"status"`
|
||||
Details []struct {
|
||||
Name string `json:"name"`
|
||||
Value string `json:"value"`
|
||||
} `json:"details"`
|
||||
} `json:"attachments"`
|
||||
Attributes []struct {
|
||||
Name string `json:"name"`
|
||||
Value string `json:"value"`
|
||||
} `json:"attributes"`
|
||||
AvailabilityZone string `json:"availabilityZone"`
|
||||
ClusterArn string `json:"clusterArn"`
|
||||
Connectivity string `json:"connectivity"`
|
||||
ConnectivityAt string `json:"connectivityAt"`
|
||||
Containers []struct {
|
||||
ContainerArn string `json:"containerArn"`
|
||||
TaskArn string `json:"taskArn"`
|
||||
Name string `json:"name"`
|
||||
Image string `json:"image"`
|
||||
RuntimeID string `json:"runtimeId"`
|
||||
LastStatus string `json:"lastStatus"`
|
||||
NetworkBindings []interface{} `json:"networkBindings"`
|
||||
NetworkInterfaces []struct {
|
||||
AttachmentID string `json:"attachmentId"`
|
||||
PrivateIpv4Address string `json:"privateIpv4Address"`
|
||||
} `json:"networkInterfaces"`
|
||||
HealthStatus string `json:"healthStatus"`
|
||||
CPU string `json:"cpu"`
|
||||
Memory string `json:"memory"`
|
||||
} `json:"containers"`
|
||||
CPU string `json:"cpu"`
|
||||
CreatedAt string `json:"createdAt"`
|
||||
DesiredStatus string `json:"desiredStatus"`
|
||||
EnableExecuteCommand bool `json:"enableExecuteCommand"`
|
||||
Group string `json:"group"`
|
||||
HealthStatus string `json:"healthStatus"`
|
||||
LastStatus string `json:"lastStatus"`
|
||||
LaunchType string `json:"launchType"`
|
||||
Memory string `json:"memory"`
|
||||
Overrides struct {
|
||||
ContainerOverrides []struct {
|
||||
Name string `json:"name"`
|
||||
} `json:"containerOverrides"`
|
||||
InferenceAcceleratorOverrides []interface{} `json:"inferenceAcceleratorOverrides"`
|
||||
} `json:"overrides"`
|
||||
PlatformVersion string `json:"platformVersion"`
|
||||
PlatformFamily string `json:"platformFamily"`
|
||||
PullStartedAt string `json:"pullStartedAt"`
|
||||
PullStoppedAt string `json:"pullStoppedAt"`
|
||||
StartedAt string `json:"startedAt"`
|
||||
StartedBy string `json:"startedBy"`
|
||||
Tags []interface{} `json:"tags"`
|
||||
TaskArn string `json:"taskArn"`
|
||||
TaskDefinitionArn string `json:"taskDefinitionArn"`
|
||||
Version int `json:"version"`
|
||||
EphemeralStorage struct {
|
||||
SizeInGiB int `json:"sizeInGiB"`
|
||||
} `json:"ephemeralStorage"`
|
||||
} `json:"tasks"`
|
||||
Failures []interface{} `json:"failures"`
|
||||
}
|
||||
|
||||
func (c *MockedECSClient) ListClusters(context.Context, *ecs.ListClustersInput, ...func(*ecs.Options)) (*ecs.ListClustersOutput, error) {
|
||||
return &ecs.ListClustersOutput{ClusterArns: []string{
|
||||
"arn:aws:ecs:us-east-1:123456789012:cluster/MyCluster",
|
||||
"arn:aws:ecs:us-east-1:123456789012:cluster/MyCluster2",
|
||||
"arn:aws:ecs:us-east-1:123456789012:cluster/MyCluster3",
|
||||
}}, nil
|
||||
}
|
||||
|
||||
func (c *MockedECSClient) ListTasks(ctx context.Context, input *ecs.ListTasksInput, f ...func(*ecs.Options)) (*ecs.ListTasksOutput, error) {
|
||||
return &ecs.ListTasksOutput{TaskArns: []string{
|
||||
"arn:aws:ecs:us-east-1:123456789012:task/MyCluster/74de0355a10a4f979ac495c14EXAMPLE",
|
||||
"arn:aws:ecs:us-east-1:123456789012:task/MyCluster/d789e94343414c25b9f6bd59eEXAMPLE",
|
||||
}}, nil
|
||||
}
|
||||
|
||||
func (c *MockedECSClient) ListServices(ctx context.Context, input *ecs.ListServicesInput, f ...func(*ecs.Options)) (*ecs.ListServicesOutput, error) {
|
||||
return &ecs.ListServicesOutput{ServiceArns: []string{
|
||||
"arn:aws:ecs:us-east-1:123456789012:service/MyService",
|
||||
"arn:aws:ecs:us-east-1:123456789012:service/MyService2",
|
||||
"arn:aws:ecs:us-east-1:123456789012:service/MyService3",
|
||||
}}, nil
|
||||
}
|
||||
|
||||
func (c *MockedECSClient) DescribeTasks(ctx context.Context, input *ecs.DescribeTasksInput, f ...func(*ecs.Options)) (*ecs.DescribeTasksOutput, error) {
|
||||
err := json.Unmarshal(readTestFile(DESCRIBE_TASKS_TEST_FILE), &c.describeTasks)
|
||||
if err != nil {
|
||||
log.Fatalf("can't unmarshall file %s", DESCRIBE_TASKS_TEST_FILE)
|
||||
}
|
||||
var tasks []ecsTypes.Task
|
||||
for _, mockedTask := range c.describeTasks.Tasks {
|
||||
if mockedTask.ClusterArn == aws.ToString(input.Cluster) {
|
||||
for _, inputTask := range input.Tasks {
|
||||
if mockedTask.TaskArn == inputTask {
|
||||
var attachments []ecsTypes.Attachment
|
||||
for _, a := range mockedTask.Attachments {
|
||||
var deets []ecsTypes.KeyValuePair
|
||||
for _, detail := range a.Details {
|
||||
deets = append(deets, ecsTypes.KeyValuePair{
|
||||
Name: aws.String(detail.Name),
|
||||
Value: aws.String(detail.Value)})
|
||||
}
|
||||
attachments = append(attachments, ecsTypes.Attachment{
|
||||
Type: aws.String(a.Type),
|
||||
Details: deets,
|
||||
Id: aws.String(a.ID),
|
||||
Status: aws.String(a.Status),
|
||||
})
|
||||
}
|
||||
tasks = append(tasks, ecsTypes.Task{
|
||||
ClusterArn: aws.String(mockedTask.ClusterArn),
|
||||
TaskDefinitionArn: aws.String(mockedTask.TaskDefinitionArn),
|
||||
LaunchType: ecsTypes.LaunchType(*aws.String(mockedTask.LaunchType)),
|
||||
TaskArn: aws.String(mockedTask.TaskArn),
|
||||
Attachments: attachments,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return &ecs.DescribeTasksOutput{Tasks: tasks}, nil
|
||||
}
|
||||
|
||||
func (c *MockedECSClient) DescribeTaskDefinition(ctx context.Context, input *ecs.DescribeTaskDefinitionInput, f ...func(o *ecs.Options)) (*ecs.DescribeTaskDefinitionOutput, error) {
|
||||
testTaskDefinition := ecsTypes.TaskDefinition{}
|
||||
testTaskDefinition.TaskRoleArn = aws.String("test123")
|
||||
return &ecs.DescribeTaskDefinitionOutput{TaskDefinition: &testTaskDefinition}, nil
|
||||
}
|
||||
+1
-1
@@ -20,7 +20,7 @@ type AWSEFSClientInterface interface {
|
||||
DescribeFileSystemPolicy(ctx context.Context, params *efs.DescribeFileSystemPolicyInput, optFns ...func(*efs.Options)) (*efs.DescribeFileSystemPolicyOutput, error)
|
||||
}
|
||||
|
||||
func RegisterEFSTypes() {
|
||||
func init() {
|
||||
gob.Register([]efsTypes.FileSystemDescription{})
|
||||
gob.Register([]efsTypes.MountTargetDescription{})
|
||||
gob.Register([]efsTypes.AccessPointDescription{})
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/efs"
|
||||
efsTypes "github.com/aws/aws-sdk-go-v2/service/efs/types"
|
||||
)
|
||||
|
||||
type MockedEfsClient struct {
|
||||
}
|
||||
|
||||
func (m *MockedEfsClient) DescribeFileSystems(ctx context.Context, input *efs.DescribeFileSystemsInput, options ...func(*efs.Options)) (*efs.DescribeFileSystemsOutput, error) {
|
||||
return &efs.DescribeFileSystemsOutput{
|
||||
FileSystems: []efsTypes.FileSystemDescription{
|
||||
{
|
||||
FileSystemId: aws.String("fs-12345678"),
|
||||
},
|
||||
{
|
||||
FileSystemId: aws.String("fs-87654321"),
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (m *MockedEfsClient) DescribeMountTargets(ctx context.Context, input *efs.DescribeMountTargetsInput, options ...func(*efs.Options)) (*efs.DescribeMountTargetsOutput, error) {
|
||||
return &efs.DescribeMountTargetsOutput{
|
||||
MountTargets: []efsTypes.MountTargetDescription{
|
||||
{
|
||||
MountTargetId: aws.String("fsmt-12345678"),
|
||||
FileSystemId: aws.String("fs-12345678"),
|
||||
IpAddress: aws.String("10.1.1.1"),
|
||||
},
|
||||
{
|
||||
MountTargetId: aws.String("fsmt-87654321"),
|
||||
FileSystemId: aws.String("fs-87654321"),
|
||||
IpAddress: aws.String("10.2.2.2.2"),
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (m *MockedEfsClient) DescribeAccessPoints(ctx context.Context, input *efs.DescribeAccessPointsInput, options ...func(*efs.Options)) (*efs.DescribeAccessPointsOutput, error) {
|
||||
return &efs.DescribeAccessPointsOutput{
|
||||
AccessPoints: []efsTypes.AccessPointDescription{
|
||||
{
|
||||
AccessPointId: aws.String("fsap-12345678"),
|
||||
FileSystemId: aws.String("fs-12345678"),
|
||||
Name: aws.String("fsap-12345678"),
|
||||
PosixUser: &efsTypes.PosixUser{
|
||||
Gid: aws.Int64(1000),
|
||||
Uid: aws.Int64(1000),
|
||||
},
|
||||
},
|
||||
{
|
||||
AccessPointId: aws.String("fsap-87654321"),
|
||||
FileSystemId: aws.String("fs-87654321"),
|
||||
Name: aws.String("fsap-12345679"),
|
||||
PosixUser: &efsTypes.PosixUser{
|
||||
Gid: aws.Int64(1000),
|
||||
Uid: aws.Int64(1000),
|
||||
},
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
+2
-2
@@ -18,14 +18,14 @@ type EKSClientInterface interface {
|
||||
ListNodegroups(context.Context, *eks.ListNodegroupsInput, ...func(*eks.Options)) (*eks.ListNodegroupsOutput, error)
|
||||
}
|
||||
|
||||
func RegisterEKSTypes() {
|
||||
func init() {
|
||||
gob.Register([]string{})
|
||||
gob.Register(eksTypes.Cluster{})
|
||||
gob.Register(eksTypes.Nodegroup{})
|
||||
|
||||
}
|
||||
|
||||
func CachedEKSDescribeCluster(client EKSClientInterface, accountID string, region string, clusterName string) (eksTypes.Cluster, error) {
|
||||
func CachedEKSDescribeCluster(client EKSClientInterface, accountID string, clusterName string, region string) (eksTypes.Cluster, error) {
|
||||
var cluster eksTypes.Cluster
|
||||
cacheKey := fmt.Sprintf("%s-eks-DescribeCluster-%s-%s", accountID, region, clusterName)
|
||||
cached, found := internal.Cache.Get(cacheKey)
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/eks"
|
||||
eksTypes "github.com/aws/aws-sdk-go-v2/service/eks/types"
|
||||
)
|
||||
|
||||
type MockedAWSEksClient struct {
|
||||
}
|
||||
|
||||
func (m *MockedAWSEksClient) ListClusters(ctx context.Context, input *eks.ListClustersInput, options ...func(*eks.Options)) (*eks.ListClustersOutput, error) {
|
||||
return &eks.ListClustersOutput{
|
||||
Clusters: []string{
|
||||
"cluster1",
|
||||
"cluster2",
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (m *MockedAWSEksClient) DescribeCluster(ctx context.Context, input *eks.DescribeClusterInput, options ...func(*eks.Options)) (*eks.DescribeClusterOutput, error) {
|
||||
return &eks.DescribeClusterOutput{
|
||||
Cluster: &eksTypes.Cluster{
|
||||
Arn: aws.String("arn:aws:eks:us-east-1:123456789012:cluster/cluster1"),
|
||||
Endpoint: aws.String("https://cluster1.us-east-1.eks.amazonaws.com"),
|
||||
Name: aws.String("cluster1"),
|
||||
PlatformVersion: aws.String("eks.1"),
|
||||
Version: aws.String("1.18"),
|
||||
RoleArn: aws.String("arn:aws:iam::123456789012:role/eks-role"),
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (m *MockedAWSEksClient) ListNodegroups(ctx context.Context, input *eks.ListNodegroupsInput, options ...func(*eks.Options)) (*eks.ListNodegroupsOutput, error) {
|
||||
return &eks.ListNodegroupsOutput{
|
||||
Nodegroups: []string{
|
||||
"nodegroup1",
|
||||
"nodegroup2",
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (m *MockedAWSEksClient) DescribeNodegroup(ctx context.Context, input *eks.DescribeNodegroupInput, options ...func(*eks.Options)) (*eks.DescribeNodegroupOutput, error) {
|
||||
return &eks.DescribeNodegroupOutput{
|
||||
Nodegroup: &eksTypes.Nodegroup{
|
||||
ClusterName: aws.String("cluster1"),
|
||||
NodeRole: aws.String("arn:aws:iam::123456789012:role/eks-role"),
|
||||
NodegroupName: aws.String("nodegroup1"),
|
||||
NodegroupArn: aws.String("arn:aws:eks:us-east-1:123456789012:nodegroup/cluster1/nodegroup1"),
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/gob"
|
||||
"fmt"
|
||||
|
||||
"github.com/BishopFox/cloudfox/internal"
|
||||
"github.com/aws/aws-sdk-go-v2/service/elasticache"
|
||||
elasticacheTypes "github.com/aws/aws-sdk-go-v2/service/elasticache/types"
|
||||
"github.com/patrickmn/go-cache"
|
||||
)
|
||||
|
||||
type AWSElastiCacheClientInterface interface {
|
||||
DescribeCacheClusters(context.Context, *elasticache.DescribeCacheClustersInput, ...func(*elasticache.Options)) (*elasticache.DescribeCacheClustersOutput, error)
|
||||
}
|
||||
|
||||
func init() {
|
||||
gob.Register([]elasticacheTypes.CacheCluster{})
|
||||
|
||||
}
|
||||
|
||||
func CachedElastiCacheDescribeCacheClusters(client AWSElastiCacheClientInterface, accountID string, region string) ([]elasticacheTypes.CacheCluster, error) {
|
||||
var PaginationControl *string
|
||||
var clusters []elasticacheTypes.CacheCluster
|
||||
cacheKey := fmt.Sprintf("%s-elasticache-DescribeCacheClusters-%s", accountID, region)
|
||||
cached, found := internal.Cache.Get(cacheKey)
|
||||
if found {
|
||||
return cached.([]elasticacheTypes.CacheCluster), nil
|
||||
}
|
||||
for {
|
||||
DescribeCacheClusters, err := client.DescribeCacheClusters(
|
||||
context.TODO(),
|
||||
&elasticache.DescribeCacheClustersInput{
|
||||
Marker: PaginationControl,
|
||||
},
|
||||
func(o *elasticache.Options) {
|
||||
o.Region = region
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return clusters, err
|
||||
}
|
||||
|
||||
clusters = append(clusters, DescribeCacheClusters.CacheClusters...)
|
||||
|
||||
//pagination
|
||||
if DescribeCacheClusters.Marker == nil {
|
||||
break
|
||||
}
|
||||
PaginationControl = DescribeCacheClusters.Marker
|
||||
}
|
||||
|
||||
internal.Cache.Set(cacheKey, clusters, cache.DefaultExpiration)
|
||||
return clusters, nil
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/elasticache"
|
||||
elasticacheTypes "github.com/aws/aws-sdk-go-v2/service/elasticache/types"
|
||||
)
|
||||
|
||||
type MockedElasticacheClient struct {
|
||||
}
|
||||
|
||||
func (m *MockedElasticacheClient) DescribeCacheClusters(ctx context.Context, input *elasticache.DescribeCacheClustersInput, options ...func(*elasticache.Options)) (*elasticache.DescribeCacheClustersOutput, error) {
|
||||
return &elasticache.DescribeCacheClustersOutput{
|
||||
CacheClusters: []elasticacheTypes.CacheCluster{
|
||||
{
|
||||
CacheClusterId: aws.String("test"),
|
||||
ARN: aws.String("arn:aws:elasticache:us-east-1:123456789012:cluster:myCluster"),
|
||||
Engine: aws.String("redis"),
|
||||
EngineVersion: aws.String("6.x"),
|
||||
CacheNodeType: aws.String("cache.t3.micro"),
|
||||
NumCacheNodes: aws.Int32(1),
|
||||
CacheClusterStatus: aws.String("available"),
|
||||
PreferredAvailabilityZone: aws.String("us-east-1a"),
|
||||
CacheSubnetGroupName: aws.String("default"),
|
||||
ReplicationGroupId: aws.String("test"),
|
||||
SecurityGroups: []elasticacheTypes.SecurityGroupMembership{
|
||||
{
|
||||
SecurityGroupId: aws.String("test"),
|
||||
Status: aws.String("active"),
|
||||
},
|
||||
},
|
||||
|
||||
AutoMinorVersionUpgrade: true,
|
||||
PreferredMaintenanceWindow: aws.String("sun:05:00-sun:06:00"),
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/gob"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/service/elasticbeanstalk"
|
||||
elasticbeanstalkTypes "github.com/aws/aws-sdk-go-v2/service/elasticbeanstalk/types"
|
||||
)
|
||||
|
||||
type AWSElasticBeanstalkClientInterface interface {
|
||||
DescribeApplications(context.Context, *elasticbeanstalk.DescribeApplicationsInput, ...func(*elasticbeanstalk.Options)) (*elasticbeanstalk.DescribeApplicationsOutput, error)
|
||||
}
|
||||
|
||||
func init() {
|
||||
gob.Register([]elasticbeanstalkTypes.ApplicationDescription{})
|
||||
}
|
||||
|
||||
func CachedElasticBeanstalkDescribeApplications(client AWSElasticBeanstalkClientInterface, accountID string, region string) ([]elasticbeanstalkTypes.ApplicationDescription, error) {
|
||||
var applications []elasticbeanstalkTypes.ApplicationDescription
|
||||
DescribeApplications, err := client.DescribeApplications(
|
||||
context.TODO(),
|
||||
&elasticbeanstalk.DescribeApplicationsInput{},
|
||||
func(o *elasticbeanstalk.Options) {
|
||||
o.Region = region
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return applications, err
|
||||
}
|
||||
|
||||
applications = append(applications, DescribeApplications.Applications...)
|
||||
return applications, nil
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/elasticbeanstalk"
|
||||
elasticbeanstalkTypes "github.com/aws/aws-sdk-go-v2/service/elasticbeanstalk/types"
|
||||
)
|
||||
|
||||
type MockedElasticBeanstalkClient struct {
|
||||
}
|
||||
|
||||
func (m *MockedElasticBeanstalkClient) DescribeApplications(ctx context.Context, input *elasticbeanstalk.DescribeApplicationsInput, options ...func(*elasticbeanstalk.Options)) (*elasticbeanstalk.DescribeApplicationsOutput, error) {
|
||||
return &elasticbeanstalk.DescribeApplicationsOutput{
|
||||
Applications: []elasticbeanstalkTypes.ApplicationDescription{
|
||||
{
|
||||
ApplicationName: aws.String("app1"),
|
||||
ApplicationArn: aws.String("arn:aws:elasticbeanstalk:us-east-1:123456789012:application/app1"),
|
||||
ConfigurationTemplates: []string{
|
||||
"template1",
|
||||
},
|
||||
},
|
||||
{
|
||||
ApplicationName: aws.String("app2"),
|
||||
ApplicationArn: aws.String("arn:aws:elasticbeanstalk:us-east-1:123456789012:application/app2"),
|
||||
ConfigurationTemplates: []string{
|
||||
"template2",
|
||||
},
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
+1
-1
@@ -15,7 +15,7 @@ type ELBClientInterface interface {
|
||||
DescribeLoadBalancers(context.Context, *elasticloadbalancing.DescribeLoadBalancersInput, ...func(*elasticloadbalancing.Options)) (*elasticloadbalancing.DescribeLoadBalancersOutput, error)
|
||||
}
|
||||
|
||||
func RegisterELBTypes() {
|
||||
func init() {
|
||||
gob.Register([]elbTypes.LoadBalancerDescription{})
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing"
|
||||
elbTypes "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing/types"
|
||||
)
|
||||
|
||||
type MockedElbClient struct {
|
||||
}
|
||||
|
||||
func (m *MockedElbClient) DescribeLoadBalancers(ctx context.Context, input *elasticloadbalancing.DescribeLoadBalancersInput, options ...func(*elasticloadbalancing.Options)) (*elasticloadbalancing.DescribeLoadBalancersOutput, error) {
|
||||
return &elasticloadbalancing.DescribeLoadBalancersOutput{
|
||||
LoadBalancerDescriptions: []elbTypes.LoadBalancerDescription{
|
||||
{
|
||||
LoadBalancerName: aws.String("elb1"),
|
||||
DNSName: aws.String("elb1"),
|
||||
Instances: []elbTypes.Instance{
|
||||
{
|
||||
InstanceId: aws.String("i-1234567890abcdef0"),
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
LoadBalancerName: aws.String("elb2"),
|
||||
DNSName: aws.String("elb2"),
|
||||
Instances: []elbTypes.Instance{
|
||||
{
|
||||
InstanceId: aws.String("i-1234567890abcdef1"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
+1
-1
@@ -15,7 +15,7 @@ type ELBv2ClientInterface interface {
|
||||
DescribeLoadBalancers(context.Context, *elasticloadbalancingv2.DescribeLoadBalancersInput, ...func(*elasticloadbalancingv2.Options)) (*elasticloadbalancingv2.DescribeLoadBalancersOutput, error)
|
||||
}
|
||||
|
||||
func RegisterELBv2Types() {
|
||||
func init() {
|
||||
gob.Register([]elbV2Types.LoadBalancer{})
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2"
|
||||
elbv2Types "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2/types"
|
||||
)
|
||||
|
||||
type MockedElbv2Client struct {
|
||||
}
|
||||
|
||||
func (m *MockedElbv2Client) DescribeLoadBalancers(ctx context.Context, input *elasticloadbalancingv2.DescribeLoadBalancersInput, options ...func(*elasticloadbalancingv2.Options)) (*elasticloadbalancingv2.DescribeLoadBalancersOutput, error) {
|
||||
return &elasticloadbalancingv2.DescribeLoadBalancersOutput{
|
||||
LoadBalancers: []elbv2Types.LoadBalancer{
|
||||
{
|
||||
LoadBalancerArn: aws.String("arn:aws:elasticloadbalancing:us-east-1:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188"),
|
||||
DNSName: aws.String("my-load-balancer-424835706.us-east-1.elb.amazonaws.com"),
|
||||
CanonicalHostedZoneId: aws.String("Z2P70J7EXAMPLE"),
|
||||
CreatedTime: aws.Time(time.Now()),
|
||||
LoadBalancerName: aws.String("my-load-balancer"),
|
||||
Scheme: elbv2Types.LoadBalancerSchemeEnumInternetFacing,
|
||||
VpcId: aws.String("vpc-3ac0fb5f"),
|
||||
State: &elbv2Types.LoadBalancerState{
|
||||
Code: elbv2Types.LoadBalancerStateEnumActive,
|
||||
Reason: aws.String(""),
|
||||
},
|
||||
Type: elbv2Types.LoadBalancerTypeEnumApplication,
|
||||
AvailabilityZones: []elbv2Types.AvailabilityZone{
|
||||
{
|
||||
ZoneName: aws.String("us-east-1a"),
|
||||
SubnetId: aws.String("subnet-8360a9e7"),
|
||||
LoadBalancerAddresses: []elbv2Types.LoadBalancerAddress{
|
||||
{
|
||||
IpAddress: aws.String("1.2.3.4"),
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
ZoneName: aws.String("us-east-1b"),
|
||||
SubnetId: aws.String("subnet-b7d581c0"),
|
||||
LoadBalancerAddresses: []elbv2Types.LoadBalancerAddress{
|
||||
{
|
||||
IpAddress: aws.String("2.3.4.5"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
SecurityGroups: []string{
|
||||
"sg-5943793c",
|
||||
},
|
||||
IpAddressType: elbv2Types.IpAddressTypeDualstack,
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/gob"
|
||||
"fmt"
|
||||
|
||||
"github.com/BishopFox/cloudfox/internal"
|
||||
"github.com/aws/aws-sdk-go-v2/service/emr"
|
||||
emrTypes "github.com/aws/aws-sdk-go-v2/service/emr/types"
|
||||
"github.com/patrickmn/go-cache"
|
||||
)
|
||||
|
||||
type AWSEMRClientInterface interface {
|
||||
ListClusters(context.Context, *emr.ListClustersInput, ...func(*emr.Options)) (*emr.ListClustersOutput, error)
|
||||
ListInstances(context.Context, *emr.ListInstancesInput, ...func(*emr.Options)) (*emr.ListInstancesOutput, error)
|
||||
}
|
||||
|
||||
func init() {
|
||||
gob.Register([]emrTypes.ClusterSummary{})
|
||||
|
||||
//need to do this to avoid conflicts with the Instance type in the ec2 package
|
||||
type EMRInstance emrTypes.Instance
|
||||
gob.Register([]EMRInstance{})
|
||||
}
|
||||
|
||||
func CachedEMRListClusters(client AWSEMRClientInterface, accountID string, region string) ([]emrTypes.ClusterSummary, error) {
|
||||
var PaginationControl *string
|
||||
var clusters []emrTypes.ClusterSummary
|
||||
cacheKey := fmt.Sprintf("%s-emr-ListClusters-%s", accountID, region)
|
||||
cached, found := internal.Cache.Get(cacheKey)
|
||||
if found {
|
||||
return cached.([]emrTypes.ClusterSummary), nil
|
||||
}
|
||||
for {
|
||||
ListClusters, err := client.ListClusters(
|
||||
context.TODO(),
|
||||
&emr.ListClustersInput{
|
||||
Marker: PaginationControl,
|
||||
},
|
||||
func(o *emr.Options) {
|
||||
o.Region = region
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return clusters, err
|
||||
}
|
||||
|
||||
clusters = append(clusters, ListClusters.Clusters...)
|
||||
|
||||
//pagination
|
||||
if ListClusters.Marker == nil {
|
||||
break
|
||||
}
|
||||
PaginationControl = ListClusters.Marker
|
||||
}
|
||||
|
||||
internal.Cache.Set(cacheKey, clusters, cache.DefaultExpiration)
|
||||
return clusters, nil
|
||||
}
|
||||
|
||||
func CachedEMRListInstances(client AWSEMRClientInterface, accountID string, region string, clusterID string) ([]emrTypes.Instance, error) {
|
||||
var PaginationControl *string
|
||||
var instances []emrTypes.Instance
|
||||
cacheKey := fmt.Sprintf("%s-emr-ListInstances-%s-%s", accountID, region, clusterID)
|
||||
cached, found := internal.Cache.Get(cacheKey)
|
||||
if found {
|
||||
return cached.([]emrTypes.Instance), nil
|
||||
}
|
||||
for {
|
||||
ListInstances, err := client.ListInstances(
|
||||
context.TODO(),
|
||||
&emr.ListInstancesInput{
|
||||
ClusterId: &clusterID,
|
||||
Marker: PaginationControl,
|
||||
},
|
||||
func(o *emr.Options) {
|
||||
o.Region = region
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return instances, err
|
||||
}
|
||||
|
||||
instances = append(instances, ListInstances.Instances...)
|
||||
|
||||
//pagination
|
||||
if ListInstances.Marker == nil {
|
||||
break
|
||||
}
|
||||
PaginationControl = ListInstances.Marker
|
||||
}
|
||||
|
||||
internal.Cache.Set(cacheKey, instances, cache.DefaultExpiration)
|
||||
return instances, nil
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/emr"
|
||||
emrTypes "github.com/aws/aws-sdk-go-v2/service/emr/types"
|
||||
)
|
||||
|
||||
type MockedEMRClient struct {
|
||||
}
|
||||
|
||||
func (m *MockedEMRClient) ListClusters(ctx context.Context, input *emr.ListClustersInput, options ...func(*emr.Options)) (*emr.ListClustersOutput, error) {
|
||||
return &emr.ListClustersOutput{
|
||||
Clusters: []emrTypes.ClusterSummary{
|
||||
{
|
||||
Id: aws.String("cluster1"),
|
||||
},
|
||||
{
|
||||
Id: aws.String("cluster2"),
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (m *MockedEMRClient) ListInstances(ctx context.Context, input *emr.ListInstancesInput, options ...func(*emr.Options)) (*emr.ListInstancesOutput, error) {
|
||||
return &emr.ListInstancesOutput{
|
||||
Instances: []emrTypes.Instance{
|
||||
{
|
||||
Id: aws.String("instance1"),
|
||||
InstanceType: aws.String("m5.xlarge"),
|
||||
Ec2InstanceId: aws.String("i-1234567890"),
|
||||
PrivateDnsName: aws.String("ip-10-0-0-1.ec2.internal"),
|
||||
PublicDnsName: aws.String("ec2-1-2-3-4.compute-1.amazonaws.com"),
|
||||
PrivateIpAddress: aws.String("10.0.0.1"),
|
||||
PublicIpAddress: aws.String("1.2.3.4"),
|
||||
},
|
||||
{
|
||||
Id: aws.String("instance2"),
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
+192
@@ -0,0 +1,192 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/gob"
|
||||
|
||||
"github.com/BishopFox/cloudfox/internal"
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/glue"
|
||||
glueTypes "github.com/aws/aws-sdk-go-v2/service/glue/types"
|
||||
"github.com/patrickmn/go-cache"
|
||||
)
|
||||
|
||||
type AWSGlueClientInterface interface {
|
||||
ListDevEndpoints(ctx context.Context, params *glue.ListDevEndpointsInput, optFns ...func(*glue.Options)) (*glue.ListDevEndpointsOutput, error)
|
||||
ListJobs(ctx context.Context, params *glue.ListJobsInput, optFns ...func(*glue.Options)) (*glue.ListJobsOutput, error)
|
||||
GetTables(ctx context.Context, params *glue.GetTablesInput, optFns ...func(*glue.Options)) (*glue.GetTablesOutput, error)
|
||||
GetDatabases(ctx context.Context, params *glue.GetDatabasesInput, optFns ...func(*glue.Options)) (*glue.GetDatabasesOutput, error)
|
||||
}
|
||||
|
||||
func init() {
|
||||
gob.Register([]string{})
|
||||
gob.Register(glueTypes.DevEndpoint{})
|
||||
gob.Register(glueTypes.Job{})
|
||||
gob.Register([]glueTypes.Table{})
|
||||
gob.Register([]glueTypes.Database{})
|
||||
}
|
||||
|
||||
func CachedGlueListDevEndpoints(GlueClient AWSGlueClientInterface, accountID string, region string) ([]string, error) {
|
||||
var PaginationControl *string
|
||||
var devEndpoints []string
|
||||
cacheKey := "glue-ListDevEndpoints-" + accountID + "-" + region
|
||||
cached, found := internal.Cache.Get(cacheKey)
|
||||
if found {
|
||||
sharedLogger.Debug("Using cached Glue dev endpoints data")
|
||||
return cached.([]string), nil
|
||||
}
|
||||
|
||||
for {
|
||||
ListDevEndpoints, err := GlueClient.ListDevEndpoints(
|
||||
context.TODO(),
|
||||
&glue.ListDevEndpointsInput{
|
||||
NextToken: PaginationControl,
|
||||
},
|
||||
func(o *glue.Options) {
|
||||
o.Region = region
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
sharedLogger.Error(err.Error())
|
||||
break
|
||||
}
|
||||
|
||||
devEndpoints = append(devEndpoints, ListDevEndpoints.DevEndpointNames...)
|
||||
|
||||
// Pagination control.
|
||||
if aws.ToString(ListDevEndpoints.NextToken) != "" {
|
||||
PaginationControl = ListDevEndpoints.NextToken
|
||||
} else {
|
||||
PaginationControl = nil
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
internal.Cache.Set(cacheKey, devEndpoints, cache.DefaultExpiration)
|
||||
|
||||
return devEndpoints, nil
|
||||
}
|
||||
|
||||
func CachedGlueListJobs(GlueClient AWSGlueClientInterface, accountID string, region string) ([]string, error) {
|
||||
var PaginationControl *string
|
||||
var jobs []string
|
||||
cacheKey := "glue-ListJobs-" + accountID + "-" + region
|
||||
cached, found := internal.Cache.Get(cacheKey)
|
||||
if found {
|
||||
sharedLogger.Debug("Using cached Glue jobs data")
|
||||
return cached.([]string), nil
|
||||
}
|
||||
|
||||
for {
|
||||
ListJobs, err := GlueClient.ListJobs(
|
||||
context.TODO(),
|
||||
&glue.ListJobsInput{
|
||||
NextToken: PaginationControl,
|
||||
},
|
||||
func(o *glue.Options) {
|
||||
o.Region = region
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
sharedLogger.Error(err.Error())
|
||||
break
|
||||
}
|
||||
|
||||
jobs = append(jobs, ListJobs.JobNames...)
|
||||
|
||||
// Pagination control.
|
||||
if ListJobs.NextToken != nil {
|
||||
PaginationControl = ListJobs.NextToken
|
||||
} else {
|
||||
PaginationControl = nil
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
internal.Cache.Set(cacheKey, jobs, cache.DefaultExpiration)
|
||||
|
||||
return jobs, nil
|
||||
}
|
||||
|
||||
func CachedGlueGetTables(GlueClient AWSGlueClientInterface, accountID string, region string, dbName string) ([]glueTypes.Table, error) {
|
||||
var PaginationControl *string
|
||||
var tables []glueTypes.Table
|
||||
cacheKey := "glue-GetTables-" + accountID + "-" + region
|
||||
cached, found := internal.Cache.Get(cacheKey)
|
||||
if found {
|
||||
sharedLogger.Debug("Using cached Glue tables data")
|
||||
return cached.([]glueTypes.Table), nil
|
||||
}
|
||||
|
||||
for {
|
||||
GetTables, err := GlueClient.GetTables(
|
||||
context.TODO(),
|
||||
&glue.GetTablesInput{
|
||||
DatabaseName: &dbName,
|
||||
NextToken: PaginationControl,
|
||||
},
|
||||
func(o *glue.Options) {
|
||||
o.Region = region
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
sharedLogger.Error(err.Error())
|
||||
break
|
||||
}
|
||||
|
||||
tables = append(tables, GetTables.TableList...)
|
||||
|
||||
// Pagination control.
|
||||
if GetTables.NextToken != nil {
|
||||
PaginationControl = GetTables.NextToken
|
||||
} else {
|
||||
PaginationControl = nil
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
internal.Cache.Set(cacheKey, tables, cache.DefaultExpiration)
|
||||
|
||||
return tables, nil
|
||||
}
|
||||
|
||||
func CachedGlueGetDatabases(GlueClient AWSGlueClientInterface, accountID string, region string) ([]glueTypes.Database, error) {
|
||||
var PaginationControl *string
|
||||
var databases []glueTypes.Database
|
||||
cacheKey := "glue-GetDatabases-" + accountID + "-" + region
|
||||
cached, found := internal.Cache.Get(cacheKey)
|
||||
if found {
|
||||
sharedLogger.Debug("Using cached Glue databases data")
|
||||
return cached.([]glueTypes.Database), nil
|
||||
}
|
||||
|
||||
for {
|
||||
GetDatabases, err := GlueClient.GetDatabases(
|
||||
context.TODO(),
|
||||
&glue.GetDatabasesInput{
|
||||
NextToken: PaginationControl,
|
||||
},
|
||||
func(o *glue.Options) {
|
||||
o.Region = region
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
sharedLogger.Error(err.Error())
|
||||
break
|
||||
}
|
||||
|
||||
databases = append(databases, GetDatabases.DatabaseList...)
|
||||
|
||||
// Pagination control.
|
||||
if GetDatabases.NextToken != nil {
|
||||
PaginationControl = GetDatabases.NextToken
|
||||
} else {
|
||||
PaginationControl = nil
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
internal.Cache.Set(cacheKey, databases, cache.DefaultExpiration)
|
||||
|
||||
return databases, nil
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/glue"
|
||||
glueTypes "github.com/aws/aws-sdk-go-v2/service/glue/types"
|
||||
)
|
||||
|
||||
type MockedGlueClient struct {
|
||||
}
|
||||
|
||||
func (m *MockedGlueClient) ListDevEndpoints(ctx context.Context, input *glue.ListDevEndpointsInput, options ...func(*glue.Options)) (*glue.ListDevEndpointsOutput, error) {
|
||||
return &glue.ListDevEndpointsOutput{
|
||||
DevEndpointNames: []string{
|
||||
"devendpoint1",
|
||||
"devendpoint2",
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (m *MockedGlueClient) ListJobs(ctx context.Context, input *glue.ListJobsInput, options ...func(*glue.Options)) (*glue.ListJobsOutput, error) {
|
||||
return &glue.ListJobsOutput{
|
||||
JobNames: []string{
|
||||
"job1",
|
||||
"job2",
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (m *MockedGlueClient) GetTables(ctx context.Context, input *glue.GetTablesInput, options ...func(*glue.Options)) (*glue.GetTablesOutput, error) {
|
||||
return &glue.GetTablesOutput{
|
||||
TableList: []glueTypes.Table{
|
||||
{
|
||||
Name: aws.String("table1"),
|
||||
DatabaseName: aws.String("database1"),
|
||||
Description: aws.String("description1"),
|
||||
Parameters: map[string]string{
|
||||
"param1": "value1",
|
||||
"param2": "value2",
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: aws.String("table2"),
|
||||
DatabaseName: aws.String("database2"),
|
||||
Description: aws.String("description2"),
|
||||
Parameters: map[string]string{
|
||||
"param1": "value1",
|
||||
"param2": "value2",
|
||||
},
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (m *MockedGlueClient) GetDatabases(ctx context.Context, input *glue.GetDatabasesInput, options ...func(*glue.Options)) (*glue.GetDatabasesOutput, error) {
|
||||
return &glue.GetDatabasesOutput{
|
||||
DatabaseList: []glueTypes.Database{
|
||||
{
|
||||
Name: aws.String("database1"),
|
||||
Description: aws.String("description1"),
|
||||
LocationUri: aws.String("s3://bucket1"),
|
||||
Parameters: map[string]string{
|
||||
"param1": "value1",
|
||||
"param2": "value2",
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: aws.String("database2"),
|
||||
Description: aws.String("description2"),
|
||||
LocationUri: aws.String("s3://bucket2"),
|
||||
Parameters: map[string]string{
|
||||
"param1": "value1",
|
||||
"param2": "value2",
|
||||
},
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
+1
-1
@@ -15,7 +15,7 @@ type GrafanaClientInterface interface {
|
||||
ListWorkspaces(context.Context, *grafana.ListWorkspacesInput, ...func(*grafana.Options)) (*grafana.ListWorkspacesOutput, error)
|
||||
}
|
||||
|
||||
func RegisterGrafanaTypes() {
|
||||
func init() {
|
||||
gob.Register([]grafanaTypes.WorkspaceSummary{})
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/grafana"
|
||||
grafanaTypes "github.com/aws/aws-sdk-go-v2/service/grafana/types"
|
||||
)
|
||||
|
||||
type MockedGrafanaClient struct {
|
||||
}
|
||||
|
||||
func (m *MockedGrafanaClient) ListWorkspaces(ctx context.Context, input *grafana.ListWorkspacesInput, options ...func(*grafana.Options)) (*grafana.ListWorkspacesOutput, error) {
|
||||
return &grafana.ListWorkspacesOutput{
|
||||
Workspaces: []grafanaTypes.WorkspaceSummary{
|
||||
{
|
||||
Authentication: &grafanaTypes.AuthenticationSummary{
|
||||
Providers: []grafanaTypes.AuthenticationProviderTypes{
|
||||
grafanaTypes.AuthenticationProviderTypesAwsSso,
|
||||
},
|
||||
},
|
||||
Created: aws.Time(time.Now()),
|
||||
Id: aws.String("workspace1"),
|
||||
Name: aws.String("workspace1"),
|
||||
Status: grafanaTypes.WorkspaceStatusActive,
|
||||
},
|
||||
{
|
||||
Authentication: &grafanaTypes.AuthenticationSummary{
|
||||
Providers: []grafanaTypes.AuthenticationProviderTypes{
|
||||
grafanaTypes.AuthenticationProviderTypesAwsSso,
|
||||
},
|
||||
},
|
||||
Created: aws.Time(time.Now()),
|
||||
Id: aws.String("workspace2"),
|
||||
Name: aws.String("workspace2"),
|
||||
Status: grafanaTypes.WorkspaceStatusActive,
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
+39
-1
@@ -22,12 +22,14 @@ type AWSIAMClientInterface interface {
|
||||
GetAccountAuthorizationDetails(ctx context.Context, params *iam.GetAccountAuthorizationDetailsInput, optFns ...func(*iam.Options)) (*iam.GetAccountAuthorizationDetailsOutput, error)
|
||||
SimulatePrincipalPolicy(ctx context.Context, params *iam.SimulatePrincipalPolicyInput, optFns ...func(*iam.Options)) (*iam.SimulatePrincipalPolicyOutput, error)
|
||||
ListInstanceProfiles(ctx context.Context, params *iam.ListInstanceProfilesInput, optFns ...func(*iam.Options)) (*iam.ListInstanceProfilesOutput, error)
|
||||
ListGroups(ctx context.Context, params *iam.ListGroupsInput, optFns ...func(*iam.Options)) (*iam.ListGroupsOutput, error)
|
||||
}
|
||||
|
||||
func RegisterIamTypes() {
|
||||
func init() {
|
||||
gob.Register([]iamTypes.User{})
|
||||
gob.Register([]iamTypes.AccessKeyMetadata{})
|
||||
gob.Register([]iamTypes.Role{})
|
||||
gob.Register([]iamTypes.Group{})
|
||||
gob.Register([]iamTypes.PolicyDetail{})
|
||||
gob.Register([]iamTypes.InstanceProfile{})
|
||||
gob.Register([]iamTypes.EvaluationResult{})
|
||||
@@ -250,3 +252,39 @@ func CachedIamSimulatePrincipalPolicy(IAMClient AWSIAMClientInterface, accountID
|
||||
internal.Cache.Set(cacheKey, EvaluationResults, cache.DefaultExpiration)
|
||||
return EvaluationResults, nil
|
||||
}
|
||||
|
||||
func CachedIamListGroups(IAMClient AWSIAMClientInterface, accountID string) ([]iamTypes.Group, error) {
|
||||
var PaginationControl *string
|
||||
var Groups []iamTypes.Group
|
||||
cacheKey := fmt.Sprintf("%s-iam-ListGroups", accountID)
|
||||
cached, found := internal.Cache.Get(cacheKey)
|
||||
if found {
|
||||
return cached.([]iamTypes.Group), nil
|
||||
}
|
||||
|
||||
for {
|
||||
ListGroups, err := IAMClient.ListGroups(
|
||||
context.TODO(),
|
||||
&iam.ListGroupsInput{
|
||||
Marker: PaginationControl,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return Groups, err
|
||||
}
|
||||
|
||||
Groups = append(Groups, ListGroups.Groups...)
|
||||
|
||||
// Pagination control.
|
||||
if ListGroups.Marker != nil {
|
||||
PaginationControl = ListGroups.Marker
|
||||
} else {
|
||||
PaginationControl = nil
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
internal.Cache.Set(cacheKey, Groups, cache.DefaultExpiration)
|
||||
return Groups, nil
|
||||
|
||||
}
|
||||
@@ -0,0 +1,222 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/iam"
|
||||
iamTypes "github.com/aws/aws-sdk-go-v2/service/iam/types"
|
||||
)
|
||||
|
||||
type MockedIAMClient struct {
|
||||
}
|
||||
|
||||
func (m *MockedIAMClient) ListUsers(ctx context.Context, input *iam.ListUsersInput, options ...func(*iam.Options)) (*iam.ListUsersOutput, error) {
|
||||
return &iam.ListUsersOutput{
|
||||
Users: []iamTypes.User{
|
||||
{
|
||||
Arn: aws.String("arn:aws:iam::123456789012:user/user1"),
|
||||
CreateDate: aws.Time(time.Now()),
|
||||
Path: aws.String("/"),
|
||||
UserId: aws.String("123456789012"),
|
||||
UserName: aws.String("user1"),
|
||||
},
|
||||
{
|
||||
Arn: aws.String("arn:aws:iam::123456789012:user/user2"),
|
||||
CreateDate: aws.Time(time.Now()),
|
||||
Path: aws.String("/"),
|
||||
UserId: aws.String("123456789012"),
|
||||
UserName: aws.String("user2"),
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (m *MockedIAMClient) ListAccessKeys(ctx context.Context, input *iam.ListAccessKeysInput, options ...func(*iam.Options)) (*iam.ListAccessKeysOutput, error) {
|
||||
return &iam.ListAccessKeysOutput{
|
||||
AccessKeyMetadata: []iamTypes.AccessKeyMetadata{
|
||||
{
|
||||
AccessKeyId: aws.String("accesskey1"),
|
||||
CreateDate: aws.Time(time.Now()),
|
||||
Status: iamTypes.StatusTypeActive,
|
||||
UserName: aws.String("user1"),
|
||||
},
|
||||
{
|
||||
AccessKeyId: aws.String("accesskey2"),
|
||||
CreateDate: aws.Time(time.Now()),
|
||||
Status: iamTypes.StatusTypeActive,
|
||||
UserName: aws.String("user2"),
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
||||
func (m *MockedIAMClient) ListGroups(ctx context.Context, input *iam.ListGroupsInput, options ...func(*iam.Options)) (*iam.ListGroupsOutput, error) {
|
||||
return &iam.ListGroupsOutput{
|
||||
Groups: []iamTypes.Group{
|
||||
{
|
||||
Arn: aws.String("arn:aws:iam::123456789012:group/group1"),
|
||||
CreateDate: aws.Time(time.Now()),
|
||||
GroupId: aws.String("123456789012"),
|
||||
GroupName: aws.String("group1"),
|
||||
Path: aws.String("/"),
|
||||
},
|
||||
{
|
||||
Arn: aws.String("arn:aws:iam::123456789012:group/group2"),
|
||||
CreateDate: aws.Time(time.Now()),
|
||||
GroupId: aws.String("123456789012"),
|
||||
GroupName: aws.String("group2"),
|
||||
Path: aws.String("/"),
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
||||
func (m *MockedIAMClient) ListRoles(ctx context.Context, input *iam.ListRolesInput, options ...func(*iam.Options)) (*iam.ListRolesOutput, error) {
|
||||
return &iam.ListRolesOutput{
|
||||
Roles: []iamTypes.Role{
|
||||
{
|
||||
Arn: aws.String("arn:aws:iam::123456789012:role/role1"),
|
||||
AssumeRolePolicyDocument: aws.String("{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"Service\":\"ec2.amazonaws.com\"},\"Action\":\"sts:AssumeRole\"}]}"),
|
||||
CreateDate: aws.Time(time.Now()),
|
||||
RoleId: aws.String("123456789012"),
|
||||
RoleName: aws.String("role1"),
|
||||
Path: aws.String("/"),
|
||||
},
|
||||
{
|
||||
Arn: aws.String("arn:aws:iam::123456789012:role/role2"),
|
||||
AssumeRolePolicyDocument: aws.String("{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"Service\":\"ec2.amazonaws.com\"},\"Action\":\"sts:AssumeRole\"}]}"),
|
||||
CreateDate: aws.Time(time.Now()),
|
||||
RoleId: aws.String("123456789012"),
|
||||
RoleName: aws.String("role2"),
|
||||
Path: aws.String("/"),
|
||||
},
|
||||
{
|
||||
Arn: aws.String("arn:aws:iam::123456789012:role/role3"),
|
||||
AssumeRolePolicyDocument: aws.String("{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"AWS\":\"arn:aws:iam::123456789012:root\"},\"Action\":\"sts:AssumeRole\"}]}"),
|
||||
CreateDate: aws.Time(time.Now()),
|
||||
RoleId: aws.String("123456789012"),
|
||||
RoleName: aws.String("role3"),
|
||||
Path: aws.String("/"),
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
||||
func (m *MockedIAMClient) GetAccountAuthorizationDetails(ctx context.Context, params *iam.GetAccountAuthorizationDetailsInput, optFns ...func(*iam.Options)) (*iam.GetAccountAuthorizationDetailsOutput, error) {
|
||||
return &iam.GetAccountAuthorizationDetailsOutput{
|
||||
GroupDetailList: []iamTypes.GroupDetail{
|
||||
{
|
||||
Arn: aws.String("arn:aws:iam::123456789012:group/group1"),
|
||||
CreateDate: aws.Time(time.Now()),
|
||||
GroupId: aws.String("123456789012"),
|
||||
GroupName: aws.String("group1"),
|
||||
Path: aws.String("/"),
|
||||
},
|
||||
{
|
||||
Arn: aws.String("arn:aws:iam::123456789012:group/group2"),
|
||||
CreateDate: aws.Time(time.Now()),
|
||||
GroupId: aws.String("123456789012"),
|
||||
GroupName: aws.String("group2"),
|
||||
Path: aws.String("/"),
|
||||
},
|
||||
},
|
||||
RoleDetailList: []iamTypes.RoleDetail{
|
||||
{
|
||||
Arn: aws.String("arn:aws:iam::123456789012:role/role1"),
|
||||
AssumeRolePolicyDocument: aws.String("{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"Service\":\"ec2.amazonaws.com\"},\"Action\":\"sts:AssumeRole\"}]}"),
|
||||
CreateDate: aws.Time(time.Now()),
|
||||
RoleId: aws.String("123456789012"),
|
||||
RoleName: aws.String("role1"),
|
||||
Path: aws.String("/"),
|
||||
},
|
||||
{
|
||||
Arn: aws.String("arn:aws:iam::123456789012:role/role2"),
|
||||
AssumeRolePolicyDocument: aws.String("{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"Service\":\"ec2.amazonaws.com\"},\"Action\":\"sts:AssumeRole\"}]}"),
|
||||
CreateDate: aws.Time(time.Now()),
|
||||
RoleId: aws.String("123456789012"),
|
||||
RoleName: aws.String("role2"),
|
||||
Path: aws.String("/"),
|
||||
},
|
||||
{
|
||||
Arn: aws.String("arn:aws:iam::123456789012:role/role3"),
|
||||
AssumeRolePolicyDocument: aws.String("{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"AWS\":\"arn:aws:iam::123456789012:root\"},\"Action\":\"sts:AssumeRole\"}]}"),
|
||||
CreateDate: aws.Time(time.Now()),
|
||||
RoleId: aws.String("123456789012"),
|
||||
|
||||
RoleName: aws.String("role3"),
|
||||
Path: aws.String("/"),
|
||||
},
|
||||
},
|
||||
UserDetailList: []iamTypes.UserDetail{
|
||||
{
|
||||
Arn: aws.String("arn:aws:iam::123456789012:user/user1"),
|
||||
CreateDate: aws.Time(time.Now()),
|
||||
|
||||
UserId: aws.String("123456789012"),
|
||||
UserName: aws.String("user1"),
|
||||
Path: aws.String("/"),
|
||||
},
|
||||
{
|
||||
Arn: aws.String("arn:aws:iam::123456789012:user/user2"),
|
||||
CreateDate: aws.Time(time.Now()),
|
||||
|
||||
UserId: aws.String("123456789012"),
|
||||
UserName: aws.String("user2"),
|
||||
Path: aws.String("/"),
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (m *MockedIAMClient) SimulatePrincipalPolicy(ctx context.Context, params *iam.SimulatePrincipalPolicyInput, optFns ...func(*iam.Options)) (*iam.SimulatePrincipalPolicyOutput, error) {
|
||||
return &iam.SimulatePrincipalPolicyOutput{
|
||||
EvaluationResults: []iamTypes.EvaluationResult{
|
||||
{
|
||||
EvalActionName: aws.String("sts:AssumeRole"),
|
||||
EvalDecision: iamTypes.PolicyEvaluationDecisionTypeAllowed,
|
||||
EvalResourceName: aws.String("arn:aws:iam::123456789012:role/role1"),
|
||||
MatchedStatements: []iamTypes.Statement{
|
||||
{
|
||||
SourcePolicyId: aws.String("PolicyForRole1"),
|
||||
SourcePolicyType: iamTypes.PolicySourceTypeUser,
|
||||
StartPosition: &iamTypes.Position{
|
||||
Column: 0,
|
||||
Line: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
||||
func (m *MockedIAMClient) ListInstanceProfiles(ctx context.Context, params *iam.ListInstanceProfilesInput, optFns ...func(*iam.Options)) (*iam.ListInstanceProfilesOutput, error) {
|
||||
return &iam.ListInstanceProfilesOutput{
|
||||
InstanceProfiles: []iamTypes.InstanceProfile{
|
||||
{
|
||||
Arn: aws.String("arn:aws:iam::123456789012:instance-profile/instance-profile1"),
|
||||
CreateDate: aws.Time(time.Now()),
|
||||
InstanceProfileId: aws.String("123456789012"),
|
||||
InstanceProfileName: aws.String("instance-profile1"),
|
||||
Path: aws.String("/"),
|
||||
Roles: []iamTypes.Role{
|
||||
{
|
||||
Arn: aws.String("arn:aws:iam::123456789012:role/role1"),
|
||||
AssumeRolePolicyDocument: aws.String("{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"Service\":\"ec2.amazonaws.com\"},\"Action\":\"sts:AssumeRole\"}]}"),
|
||||
CreateDate: aws.Time(time.Now()),
|
||||
RoleId: aws.String("123456789012"),
|
||||
RoleName: aws.String("role1"),
|
||||
Path: aws.String("/"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/gob"
|
||||
"fmt"
|
||||
|
||||
"github.com/BishopFox/cloudfox/internal"
|
||||
"github.com/aws/aws-sdk-go-v2/service/kinesis"
|
||||
"github.com/patrickmn/go-cache"
|
||||
)
|
||||
|
||||
type AWSKinesisClientInterface interface {
|
||||
ListStreams(context.Context, *kinesis.ListStreamsInput, ...func(*kinesis.Options)) (*kinesis.ListStreamsOutput, error)
|
||||
}
|
||||
|
||||
func init() {
|
||||
gob.Register([]string{})
|
||||
}
|
||||
|
||||
func CachedKinesisListStreams(client AWSKinesisClientInterface, accountID string, region string) ([]string, error) {
|
||||
var PaginationControl *string
|
||||
var streams []string
|
||||
cacheKey := fmt.Sprintf("%s-kinesis-ListStreams-%s", accountID, region)
|
||||
cached, found := internal.Cache.Get(cacheKey)
|
||||
if found {
|
||||
return cached.([]string), nil
|
||||
}
|
||||
for {
|
||||
ListStreams, err := client.ListStreams(
|
||||
context.TODO(),
|
||||
&kinesis.ListStreamsInput{
|
||||
NextToken: PaginationControl,
|
||||
},
|
||||
func(o *kinesis.Options) {
|
||||
o.Region = region
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return streams, err
|
||||
}
|
||||
|
||||
streams = append(streams, ListStreams.StreamNames...)
|
||||
|
||||
//pagination
|
||||
if ListStreams.NextToken == nil {
|
||||
break
|
||||
}
|
||||
PaginationControl = ListStreams.NextToken
|
||||
}
|
||||
|
||||
internal.Cache.Set(cacheKey, streams, cache.DefaultExpiration)
|
||||
return streams, nil
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/kinesis"
|
||||
)
|
||||
|
||||
type MockedKinesisClient struct {
|
||||
}
|
||||
|
||||
func (m *MockedKinesisClient) ListStreams(ctx context.Context, input *kinesis.ListStreamsInput, options ...func(*kinesis.Options)) (*kinesis.ListStreamsOutput, error) {
|
||||
return &kinesis.ListStreamsOutput{
|
||||
HasMoreStreams: aws.Bool(false),
|
||||
StreamNames: []string{
|
||||
"stream1",
|
||||
"stream2",
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
+1
-1
@@ -17,7 +17,7 @@ type LambdaClientInterface interface {
|
||||
GetFunctionUrlConfig(context.Context, *lambda.GetFunctionUrlConfigInput, ...func(*lambda.Options)) (*lambda.GetFunctionUrlConfigOutput, error)
|
||||
}
|
||||
|
||||
func RegisterLambdaTypes() {
|
||||
func init() {
|
||||
gob.Register([]lambdaTypes.FunctionConfiguration{})
|
||||
gob.Register(customGetFuntionURLOutput{})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/lambda"
|
||||
lambdaTypes "github.com/aws/aws-sdk-go-v2/service/lambda/types"
|
||||
)
|
||||
|
||||
type MockedLambdaClient struct {
|
||||
}
|
||||
|
||||
func (m *MockedLambdaClient) ListFunctions(ctx context.Context, input *lambda.ListFunctionsInput, options ...func(*lambda.Options)) (*lambda.ListFunctionsOutput, error) {
|
||||
return &lambda.ListFunctionsOutput{
|
||||
Functions: []lambdaTypes.FunctionConfiguration{
|
||||
{
|
||||
FunctionArn: aws.String("arn:aws:lambda:us-east-1:123456789012:function:my-function"),
|
||||
FunctionName: aws.String("my-function"),
|
||||
Handler: aws.String("index.handler"),
|
||||
Runtime: lambdaTypes.RuntimeNodejs18x,
|
||||
Environment: &lambdaTypes.EnvironmentResponse{
|
||||
Variables: map[string]string{
|
||||
"key1": "value1",
|
||||
"key2": "value2",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
FunctionArn: aws.String("arn:aws:lambda:us-east-1:123456789012:function:my-function2"),
|
||||
FunctionName: aws.String("my-function2"),
|
||||
Handler: aws.String("index.handler"),
|
||||
Runtime: lambdaTypes.RuntimeNodejs18x,
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (m *MockedLambdaClient) GetFunction(ctx context.Context, input *lambda.GetFunctionInput, options ...func(*lambda.Options)) (*lambda.GetFunctionOutput, error) {
|
||||
return &lambda.GetFunctionOutput{
|
||||
Configuration: &lambdaTypes.FunctionConfiguration{
|
||||
FunctionArn: aws.String("arn:aws:lambda:us-east-1:123456789012:function:my-function"),
|
||||
FunctionName: aws.String("my-function"),
|
||||
Handler: aws.String("index.handler"),
|
||||
Runtime: lambdaTypes.RuntimeNodejs18x,
|
||||
Environment: &lambdaTypes.EnvironmentResponse{
|
||||
Variables: map[string]string{
|
||||
"key1": "value1",
|
||||
"key2": "value2",
|
||||
},
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (m *MockedLambdaClient) GetFunctionUrlConfig(ctx context.Context, input *lambda.GetFunctionInput, options ...func(*lambda.Options)) (*lambda.GetFunctionUrlConfigOutput, error) {
|
||||
return &lambda.GetFunctionUrlConfigOutput{
|
||||
FunctionUrl: aws.String("https://my-function.us-east-1.amazonaws.com/Prod/"),
|
||||
FunctionArn: aws.String("arn:aws:lambda:us-east-1:123456789012:function:my-function"),
|
||||
AuthType: lambdaTypes.FunctionUrlAuthTypeNone,
|
||||
}, nil
|
||||
}
|
||||
@@ -16,8 +16,12 @@ type lightsailClientInterface interface {
|
||||
GetContainerServices(context.Context, *lightsail.GetContainerServicesInput, ...func(*lightsail.Options)) (*lightsail.GetContainerServicesOutput, error)
|
||||
}
|
||||
|
||||
func RegisterLightsailTypes() {
|
||||
//gob.Register([]lightsailTypes.Instance{})
|
||||
func init() {
|
||||
|
||||
//need to do this to avoid conflicts with the Instance type in the ec2 package
|
||||
type lightsailInstance lightsailTypes.Instance
|
||||
gob.Register([]lightsailInstance{})
|
||||
|
||||
gob.Register([]lightsailTypes.ContainerService{})
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/lightsail"
|
||||
lightsailTypes "github.com/aws/aws-sdk-go-v2/service/lightsail/types"
|
||||
)
|
||||
|
||||
type MockedLightsailClient struct {
|
||||
}
|
||||
|
||||
func (m *MockedLightsailClient) GetInstances(ctx context.Context, input *lightsail.GetInstancesInput, options ...func(*lightsail.Options)) (*lightsail.GetInstancesOutput, error) {
|
||||
return &lightsail.GetInstancesOutput{
|
||||
Instances: []lightsailTypes.Instance{
|
||||
{
|
||||
BlueprintId: aws.String("blueprint1"),
|
||||
BundleId: aws.String("bundle1"),
|
||||
CreatedAt: aws.Time(time.Now()),
|
||||
Location: &lightsailTypes.ResourceLocation{
|
||||
AvailabilityZone: aws.String("us-east-1a"),
|
||||
RegionName: lightsailTypes.RegionNameUsEast1,
|
||||
},
|
||||
Name: aws.String("instance1"),
|
||||
Networking: &lightsailTypes.InstanceNetworking{
|
||||
MonthlyTransfer: &lightsailTypes.MonthlyTransfer{
|
||||
GbPerMonthAllocated: aws.Int32(1),
|
||||
},
|
||||
},
|
||||
PrivateIpAddress: aws.String("10.1.1.1"),
|
||||
PublicIpAddress: aws.String("1.2.3.4"),
|
||||
},
|
||||
{
|
||||
BlueprintId: aws.String("blueprint2"),
|
||||
BundleId: aws.String("bundle2"),
|
||||
CreatedAt: aws.Time(time.Now()),
|
||||
Location: &lightsailTypes.ResourceLocation{
|
||||
AvailabilityZone: aws.String("us-east-1b"),
|
||||
RegionName: lightsailTypes.RegionNameUsEast1,
|
||||
},
|
||||
Name: aws.String("instance2"),
|
||||
Networking: &lightsailTypes.InstanceNetworking{
|
||||
MonthlyTransfer: &lightsailTypes.MonthlyTransfer{
|
||||
GbPerMonthAllocated: aws.Int32(2),
|
||||
},
|
||||
},
|
||||
PrivateIpAddress: aws.String("10.2.2.2"),
|
||||
PublicIpAddress: aws.String("2.3.4.4"),
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
||||
func (m *MockedLightsailClient) GetContainerServices(ctx context.Context, input *lightsail.GetContainerServicesInput, options ...func(*lightsail.Options)) (*lightsail.GetContainerServicesOutput, error) {
|
||||
return &lightsail.GetContainerServicesOutput{
|
||||
ContainerServices: []lightsailTypes.ContainerService{
|
||||
{
|
||||
Arn: aws.String("arn1"),
|
||||
Location: &lightsailTypes.ResourceLocation{
|
||||
AvailabilityZone: aws.String("us-east-1a"),
|
||||
RegionName: lightsailTypes.RegionNameUsEast1,
|
||||
},
|
||||
Url: aws.String("https://container1"),
|
||||
PrivateDomainName: aws.String("container1"),
|
||||
},
|
||||
{
|
||||
Arn: aws.String("arn2"),
|
||||
Location: &lightsailTypes.ResourceLocation{
|
||||
AvailabilityZone: aws.String("us-east-1a"),
|
||||
RegionName: lightsailTypes.RegionNameUsEast1,
|
||||
},
|
||||
Url: aws.String("https://container2"),
|
||||
PrivateDomainName: aws.String("container2"),
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
+1
-1
@@ -15,7 +15,7 @@ type MQClientInterface interface {
|
||||
ListBrokers(context.Context, *mq.ListBrokersInput, ...func(*mq.Options)) (*mq.ListBrokersOutput, error)
|
||||
}
|
||||
|
||||
func RegisterMQTypes() {
|
||||
func init() {
|
||||
gob.Register([]mqTypes.BrokerSummary{})
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/mq"
|
||||
mqTypes "github.com/aws/aws-sdk-go-v2/service/mq/types"
|
||||
)
|
||||
|
||||
type MockedMQClient struct {
|
||||
}
|
||||
|
||||
func (m *MockedMQClient) ListBrokers(ctx context.Context, input *mq.ListBrokersInput, options ...func(*mq.Options)) (*mq.ListBrokersOutput, error) {
|
||||
return &mq.ListBrokersOutput{
|
||||
BrokerSummaries: []mqTypes.BrokerSummary{
|
||||
{
|
||||
BrokerArn: aws.String("broker1"),
|
||||
BrokerId: aws.String("broker1"),
|
||||
BrokerName: aws.String("broker1"),
|
||||
BrokerState: mqTypes.BrokerStateRunning,
|
||||
Created: aws.Time(time.Now()),
|
||||
DeploymentMode: mqTypes.DeploymentModeSingleInstance,
|
||||
EngineType: mqTypes.EngineTypeRabbitmq,
|
||||
HostInstanceType: aws.String("host1"),
|
||||
},
|
||||
{
|
||||
BrokerArn: aws.String("broker2"),
|
||||
BrokerId: aws.String("broker2"),
|
||||
BrokerName: aws.String("broker2"),
|
||||
BrokerState: mqTypes.BrokerStateRunning,
|
||||
Created: aws.Time(time.Now()),
|
||||
DeploymentMode: mqTypes.DeploymentModeSingleInstance,
|
||||
EngineType: mqTypes.EngineTypeActivemq,
|
||||
HostInstanceType: aws.String("host2"),
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
+31
-1
@@ -14,11 +14,13 @@ import (
|
||||
type OpenSearchClientInterface interface {
|
||||
ListDomainNames(context.Context, *opensearch.ListDomainNamesInput, ...func(*opensearch.Options)) (*opensearch.ListDomainNamesOutput, error)
|
||||
DescribeDomainConfig(context.Context, *opensearch.DescribeDomainConfigInput, ...func(*opensearch.Options)) (*opensearch.DescribeDomainConfigOutput, error)
|
||||
DescribeDomain(context.Context, *opensearch.DescribeDomainInput, ...func(*opensearch.Options)) (*opensearch.DescribeDomainOutput, error)
|
||||
}
|
||||
|
||||
func RegisterOpenSearchTypes() {
|
||||
func init() {
|
||||
gob.Register([]openSearchTypes.DomainInfo{})
|
||||
gob.Register(openSearchTypes.DomainConfig{})
|
||||
gob.Register(openSearchTypes.DomainStatus{})
|
||||
}
|
||||
|
||||
// create CachedOpenSearchListDomainNames function that uses go-cache and pagination
|
||||
@@ -75,3 +77,31 @@ func CachedOpenSearchDescribeDomainConfig(client OpenSearchClientInterface, acco
|
||||
internal.Cache.Set(cacheKey, DomainConfig, cache.DefaultExpiration)
|
||||
return DomainConfig, nil
|
||||
}
|
||||
|
||||
// create CachedOpenSearchDescribeDomain function that uses go-cache and pagination and supports region option
|
||||
func CachedOpenSearchDescribeDomain(client OpenSearchClientInterface, accountID string, region string, domainName string) (openSearchTypes.DomainStatus, error) {
|
||||
var DomainStatus openSearchTypes.DomainStatus
|
||||
cacheKey := fmt.Sprintf("%s-opensearch-DescribeDomain-%s-%s", accountID, region, domainName)
|
||||
cached, found := internal.Cache.Get(cacheKey)
|
||||
if found {
|
||||
return cached.(openSearchTypes.DomainStatus), nil
|
||||
}
|
||||
DescribeDomain, err := client.DescribeDomain(
|
||||
context.TODO(),
|
||||
&opensearch.DescribeDomainInput{
|
||||
DomainName: &domainName,
|
||||
},
|
||||
func(o *opensearch.Options) {
|
||||
o.Region = region
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return DomainStatus, err
|
||||
}
|
||||
|
||||
DomainStatus = *DescribeDomain.DomainStatus
|
||||
|
||||
internal.Cache.Set(cacheKey, DomainStatus, cache.DefaultExpiration)
|
||||
return DomainStatus, nil
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/opensearch"
|
||||
openSearchTypes "github.com/aws/aws-sdk-go-v2/service/opensearch/types"
|
||||
)
|
||||
|
||||
type MockedOpenSearchClient struct {
|
||||
}
|
||||
|
||||
func (m *MockedOpenSearchClient) ListDomainNames(ctx context.Context, input *opensearch.ListDomainNamesInput, options ...func(*opensearch.Options)) (*opensearch.ListDomainNamesOutput, error) {
|
||||
return &opensearch.ListDomainNamesOutput{
|
||||
DomainNames: []openSearchTypes.DomainInfo{
|
||||
{
|
||||
DomainName: aws.String("domain1"),
|
||||
EngineType: openSearchTypes.EngineTypeOpenSearch,
|
||||
},
|
||||
{
|
||||
DomainName: aws.String("domain2"),
|
||||
EngineType: openSearchTypes.EngineTypeElasticsearch,
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (m *MockedOpenSearchClient) DescribeDomainConfig(ctx context.Context, input *opensearch.DescribeDomainConfigInput, options ...func(*opensearch.Options)) (*opensearch.DescribeDomainConfigOutput, error) {
|
||||
return &opensearch.DescribeDomainConfigOutput{
|
||||
DomainConfig: &openSearchTypes.DomainConfig{
|
||||
EngineVersion: &openSearchTypes.VersionStatus{
|
||||
Options: aws.String("OpenSearch-1.1"),
|
||||
Status: &openSearchTypes.OptionStatus{
|
||||
PendingDeletion: aws.Bool(false),
|
||||
},
|
||||
},
|
||||
ClusterConfig: &openSearchTypes.ClusterConfigStatus{
|
||||
Options: &openSearchTypes.ClusterConfig{
|
||||
DedicatedMasterCount: aws.Int32(3),
|
||||
DedicatedMasterEnabled: aws.Bool(true),
|
||||
InstanceCount: aws.Int32(3),
|
||||
WarmCount: aws.Int32(3),
|
||||
WarmEnabled: aws.Bool(true),
|
||||
},
|
||||
},
|
||||
DomainEndpointOptions: &openSearchTypes.DomainEndpointOptionsStatus{
|
||||
Options: &openSearchTypes.DomainEndpointOptions{
|
||||
EnforceHTTPS: aws.Bool(true),
|
||||
},
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (m *MockedOpenSearchClient) DescribeDomain(ctx context.Context, input *opensearch.DescribeDomainInput, options ...func(*opensearch.Options)) (*opensearch.DescribeDomainOutput, error) {
|
||||
return &opensearch.DescribeDomainOutput{
|
||||
DomainStatus: &openSearchTypes.DomainStatus{
|
||||
DomainName: aws.String("domain1"),
|
||||
Endpoint: aws.String("https://domain1.us-east-1.es.amazonaws.com"),
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
+1
-1
@@ -16,7 +16,7 @@ type OrganizationsClientInterface interface {
|
||||
DescribeOrganization(ctx context.Context, params *organizations.DescribeOrganizationInput, optFns ...func(*organizations.Options)) (*organizations.DescribeOrganizationOutput, error)
|
||||
}
|
||||
|
||||
func RegisterOrganizationsTypes() {
|
||||
func init() {
|
||||
gob.Register([]orgTypes.Account{})
|
||||
//gob.Register(orgTypes.Organization{})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/organizations"
|
||||
organizationsTypes "github.com/aws/aws-sdk-go-v2/service/organizations/types"
|
||||
)
|
||||
|
||||
type MockedOrgClient struct {
|
||||
}
|
||||
|
||||
func (m *MockedOrgClient) ListAccounts(ctx context.Context, input *organizations.ListAccountsInput, options ...func(*organizations.Options)) (*organizations.ListAccountsOutput, error) {
|
||||
return &organizations.ListAccountsOutput{
|
||||
Accounts: []organizationsTypes.Account{
|
||||
{
|
||||
Arn: aws.String("arn:aws:organizations::123456789012:account/o-exampleorgid/111111111111"),
|
||||
Email: aws.String("[email protected]"),
|
||||
Id: aws.String("111111111111"),
|
||||
JoinedMethod: organizationsTypes.AccountJoinedMethodInvited,
|
||||
JoinedTimestamp: aws.Time(time.Now()),
|
||||
Name: aws.String("account1"),
|
||||
Status: organizationsTypes.AccountStatusActive,
|
||||
},
|
||||
{
|
||||
Arn: aws.String("arn:aws:organizations::123456789012:account/o-exampleorgid/222222222222"),
|
||||
Email: aws.String("[email protected]"),
|
||||
Id: aws.String("222222222222"),
|
||||
JoinedMethod: organizationsTypes.AccountJoinedMethodCreated,
|
||||
JoinedTimestamp: aws.Time(time.Now()),
|
||||
Name: aws.String("account2"),
|
||||
Status: organizationsTypes.AccountStatusActive,
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
||||
func (m *MockedOrgClient) DescribeOrganization(ctx context.Context, input *organizations.DescribeOrganizationInput, options ...func(*organizations.Options)) (*organizations.DescribeOrganizationOutput, error) {
|
||||
return &organizations.DescribeOrganizationOutput{
|
||||
Organization: &organizationsTypes.Organization{
|
||||
Arn: aws.String("arn:aws:organizations::123456789012:organization/o-exampleorgid"),
|
||||
FeatureSet: organizationsTypes.OrganizationFeatureSetAll,
|
||||
Id: aws.String("o-exampleorgid"),
|
||||
MasterAccountArn: aws.String("arn:aws:organizations::123456789012:account/o-exampleorgid/111111111111"),
|
||||
MasterAccountEmail: aws.String("[email protected]"),
|
||||
MasterAccountId: aws.String("111111111111"),
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
+1
-1
@@ -16,7 +16,7 @@ type RDSClientInterface interface {
|
||||
DescribeDBInstances(context.Context, *rds.DescribeDBInstancesInput, ...func(*rds.Options)) (*rds.DescribeDBInstancesOutput, error)
|
||||
}
|
||||
|
||||
func RegisterRDSTypes() {
|
||||
func init() {
|
||||
gob.Register([]rdsTypes.DBInstance{})
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/rds"
|
||||
rdsTypes "github.com/aws/aws-sdk-go-v2/service/rds/types"
|
||||
)
|
||||
|
||||
type MOckedRDSClient struct {
|
||||
}
|
||||
|
||||
func (m *MOckedRDSClient) DescribeDBInstances(ctx context.Context, input *rds.DescribeDBInstancesInput, options ...func(*rds.Options)) (*rds.DescribeDBInstancesOutput, error) {
|
||||
return &rds.DescribeDBInstancesOutput{
|
||||
DBInstances: []rdsTypes.DBInstance{
|
||||
{
|
||||
DBInstanceIdentifier: aws.String("db1"),
|
||||
Engine: aws.String("postgres"),
|
||||
EngineVersion: aws.String("13.3"),
|
||||
InstanceCreateTime: aws.Time(time.Now()),
|
||||
MasterUsername: aws.String("postgres"),
|
||||
},
|
||||
{
|
||||
DBInstanceIdentifier: aws.String("db2"),
|
||||
Engine: aws.String("postgres"),
|
||||
EngineVersion: aws.String("13.3"),
|
||||
InstanceCreateTime: aws.Time(time.Now()),
|
||||
MasterUsername: aws.String("postgres"),
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
+4
-3
@@ -11,15 +11,16 @@ import (
|
||||
"github.com/patrickmn/go-cache"
|
||||
)
|
||||
|
||||
type RedShiftClientInterface interface {
|
||||
type AWSRedShiftClientInterface interface {
|
||||
DescribeClusters(context.Context, *redshift.DescribeClustersInput, ...func(*redshift.Options)) (*redshift.DescribeClustersOutput, error)
|
||||
}
|
||||
|
||||
func RegisterRedShiftTypes() {
|
||||
func init() {
|
||||
gob.Register([]redshiftTypes.Cluster{})
|
||||
|
||||
}
|
||||
|
||||
func CachedRedShiftDescribeClusters(client RedShiftClientInterface, accountID string, region string) ([]redshiftTypes.Cluster, error) {
|
||||
func CachedRedShiftDescribeClusters(client AWSRedShiftClientInterface, accountID string, region string) ([]redshiftTypes.Cluster, error) {
|
||||
var PaginationControl *string
|
||||
var clusters []redshiftTypes.Cluster
|
||||
cacheKey := fmt.Sprintf("%s-redshift-DescribeClusters-%s", accountID, region)
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/redshift"
|
||||
redshiftTypes "github.com/aws/aws-sdk-go-v2/service/redshift/types"
|
||||
)
|
||||
|
||||
type MockedRedshiftClient struct {
|
||||
}
|
||||
|
||||
func (m *MockedRedshiftClient) DescribeClusters(ctx context.Context, input *redshift.DescribeClustersInput, options ...func(*redshift.Options)) (*redshift.DescribeClustersOutput, error) {
|
||||
return &redshift.DescribeClustersOutput{
|
||||
Clusters: []redshiftTypes.Cluster{
|
||||
{
|
||||
ClusterIdentifier: aws.String("cluster1"),
|
||||
ClusterNamespaceArn: aws.String("arn:aws:redshift:us-east-1:123456789012:cluster:cluster1"),
|
||||
DBName: aws.String("db1"),
|
||||
Endpoint: &redshiftTypes.Endpoint{
|
||||
Address: aws.String("cluster1.us-east-1.redshift.amazonaws.com"),
|
||||
Port: 5439,
|
||||
},
|
||||
},
|
||||
{
|
||||
ClusterIdentifier: aws.String("cluster2"),
|
||||
ClusterNamespaceArn: aws.String("arn:aws:redshift:us-east-1:123456789012:cluster:cluster2"),
|
||||
DBName: aws.String("db2"),
|
||||
Endpoint: &redshiftTypes.Endpoint{
|
||||
Address: aws.String("cluster2.us-east-1.redshift.amazonaws.com"),
|
||||
Port: 5439,
|
||||
},
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
Loaded 100 of 141 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user