Skip to content

Commit

Permalink
Added AWS S3 provider (#316)
Browse files Browse the repository at this point in the history
  • Loading branch information
sl1nki authored Apr 10, 2023
1 parent 8a25f89 commit dbbc118
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ cloudlist -silent | httpx -silent | nuclei -t cves/
- AWS (Amazon web services)
- EC2
- Route53
- S3
- GCP (Google Cloud Platform)
- Cloud DNS
- DO (DigitalOcean)
Expand Down
11 changes: 10 additions & 1 deletion pkg/providers/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/route53"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/pkg/errors"
"github.com/projectdiscovery/cloudlist/pkg/schema"
)
Expand All @@ -17,6 +18,7 @@ type Provider struct {
id string
ec2Client *ec2.EC2
route53Client *route53.Route53
s3Client *s3.S3
regions *ec2.DescribeRegionsOutput
session *session.Session
}
Expand Down Expand Up @@ -45,12 +47,13 @@ func New(options schema.OptionBlock) (*Provider, error) {

ec2Client := ec2.New(session)
route53Client := route53.New(session)
s3Client := s3.New(session)

regions, err := ec2Client.DescribeRegions(&ec2.DescribeRegionsInput{})
if err != nil {
return nil, errors.Wrap(err, "could not get list of regions")
}
return &Provider{ec2Client: ec2Client, id: id, regions: regions, route53Client: route53Client, session: session}, nil
return &Provider{ec2Client: ec2Client, id: id, regions: regions, route53Client: route53Client, s3Client: s3Client, session: session}, nil
}

const apiAccessKey = "aws_access_key"
Expand Down Expand Up @@ -80,8 +83,14 @@ func (p *Provider) Resources(ctx context.Context) (*schema.Resources, error) {
if err != nil {
return nil, err
}
s3Provider := &s3Provider{s3: p.s3Client, id: p.id, session: p.session}
buckets, err := s3Provider.GetResource(ctx)
if err != nil {
return nil, err
}
finalList := schema.NewResources()
finalList.Merge(list)
finalList.Merge(zones)
finalList.Merge(buckets)
return finalList, nil
}
45 changes: 45 additions & 0 deletions pkg/providers/aws/s3.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package aws

import (
"context"
"strings"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/pkg/errors"
"github.com/projectdiscovery/cloudlist/pkg/schema"
)

// s3Provider is a provider for aws S3 API
type s3Provider struct {
id string
s3 *s3.S3
session *session.Session
}

// GetResource returns all the resources in the store for a provider.
func (d *s3Provider) GetResource(ctx context.Context) (*schema.Resources, error) {
list := schema.NewResources()

req := &s3.ListBucketsInput{}

listBucketsOutput, err := d.s3.ListBuckets(req)
if err != nil {
return nil, errors.Wrap(err, "could not list s3 buckets")
}
for _, bucket := range listBucketsOutput.Buckets {
endpointBuilder := &strings.Builder{}
endpointBuilder.WriteString(aws.StringValue(bucket.Name))
endpointBuilder.WriteString(".s3.amazonaws.com")

list.Append(&schema.Resource{
ID: d.id,
Public: true,
DNSName: endpointBuilder.String(),
Provider: providerName,
})
}

return list, nil
}

0 comments on commit dbbc118

Please sign in to comment.