Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added AWS S3 provider #316

Merged
merged 1 commit into from
Apr 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}