Skip to content
Open
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
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/aws-enumerator.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/shabarkin/aws-enumerator
go 1.15

require (
github.com/aws/aws-sdk-go-v2 v1.3.2 // indirect
github.com/aws/aws-sdk-go-v2/config v1.1.5
github.com/aws/aws-sdk-go-v2/service/acm v1.2.2
github.com/aws/aws-sdk-go-v2/service/amplify v1.1.5
Expand Down
22 changes: 13 additions & 9 deletions helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package helper
import (
"flag"
"fmt"

"github.com/shabarkin/aws-enumerator/servicemaster"
"github.com/shabarkin/aws-enumerator/servicestructs"

"github.com/shabarkin/aws-enumerator/utils"
)

Expand All @@ -20,18 +20,20 @@ func changeSpeedForTime(speed string) (time int) {
return time
}

func SetEnumerationPipeline(services, speed *string) {
func SetEnumerationPipeline(services, speed *string, profile *string) {
// Load Global Variables from file
utils.LoadEnv()

if servicemaster.CheckAWSCredentials() {
if *profile == "" {
fmt.Println(utils.Green("Message: "), utils.Yellow("No AWS profile specified, attempting to load from .env file"))
utils.LoadEnv()
}

fmt.Println(utils.Green("Message: "), utils.Yellow("profile name: "), utils.Cyan(*profile))
if servicemaster.CheckAWSCredentials(profile) {
servicemaster.ServiceCall(
servicestructs.GetServices(),
servicestructs.GetServices(profile),
utils.ProcessServiceArgument(*services),
changeSpeedForTime(*speed),
)

}
}

Expand Down Expand Up @@ -80,10 +82,11 @@ aws-enumerator enum [command]
Flags:
-services Enumerate permissions specifying services divided by comma or 'all' for total enumeration
-speed Speed parameter has three defitions : fast or normal or slow (default is normal)
-profile Specify AWS profile to use for authentication

Example:
./aws-enumerator enum -services iam,sts,s3,ec2 -speed normal
./aws-enumerator enum -services all
./aws-enumerator enum -services iam,sts,s3,ec2 -speed normal -profile pwnedlabs
./aws-enumerator enum -services all -profile pwnedlabs
`

var Cloudrider_dump_help string = `Usage:
Expand Down Expand Up @@ -120,6 +123,7 @@ var AWS_session_token *string = Cred.String("aws_session_token", "", "")
var Enum *flag.FlagSet = flag.NewFlagSet("enum", flag.ExitOnError)
var Services_enum *string = Enum.String("services", "all", "")
var Speed *string = Enum.String("speed", "normal", "")
var Profile *string = Enum.String("profile", "", "")

var Dump *flag.FlagSet = flag.NewFlagSet("dump", flag.ExitOnError)
var Services_dump *string = Dump.String("services", "all", "")
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ func main() {
fmt.Println(utils.Green("Message: "), utils.Yellow("File"), utils.Red(".env"), utils.Yellow("with AWS credentials were created in current folder"))
case "enum":
helper.Enum.Parse(os.Args[2:])
helper.SetEnumerationPipeline(helper.Services_enum, helper.Speed)
fmt.Println(utils.Green("Message: "), utils.Yellow("Enumeration finished"))
helper.SetEnumerationPipeline(helper.Services_enum, helper.Speed, helper.Profile)
fmt.Println(utils.Green("Message:"), utils.Yellow("Enumeration Finished"))

case "dump":
helper.Dump.Parse(os.Args[2:])
Expand Down
59 changes: 39 additions & 20 deletions servicemaster/servicemaster.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package servicemaster
import (
"context"
"fmt"
"github.com/aws/aws-sdk-go-v2/aws"
"io/ioutil"
"log"
"os"
Expand All @@ -16,6 +17,8 @@ import (
"github.com/shabarkin/aws-enumerator/utils"
)

var PositiveResults []string

type ServiceMaster struct {
Svc interface{}
SvcName string
Expand Down Expand Up @@ -74,6 +77,10 @@ func (svc *ServiceMaster) control_node() {
defer close(svc.api_call_result_channel)
defer close(svc.api_call_error_channel)
fmt.Println(utils.Green("Message: "), utils.Yellow("Successful"), utils.Yellow(strings.ToUpper(svc.SvcName))+utils.Yellow(":"), utils.Green(svc.result_counter-svc.error_counter), utils.Yellow("/"), utils.Red(svc.result_counter))
if svc.result_counter-svc.error_counter > 0 {
message := utils.Green("Message: ") + utils.Yellow("Successful ") + utils.Yellow(strings.ToUpper(svc.SvcName)) + utils.Yellow(": ") + utils.Green(svc.result_counter-svc.error_counter) + utils.Yellow("/") + utils.Red(svc.result_counter)
PositiveResults = append(PositiveResults, message)
}
break
}

Expand Down Expand Up @@ -138,28 +145,35 @@ func (svc *ServiceMaster) save_result_to_file() {
ioutil.WriteFile(utils.ERROR_FILEPATH+svc.SvcName+"_errors.json", []byte(file_errors), 0644)
}

func CheckAWSCredentials() bool {
if utils.CheckEnvFileExistance() {
cfg, err := config.LoadDefaultConfig(context.TODO())
if err != nil {
fmt.Println(utils.Red("Error:"), utils.Yellow("Unable to load SDK config,"))
fmt.Println(utils.Green("Fix:"), utils.Yellow("The problem should be on our side, contact support please"))
fmt.Println(utils.Red("Trace:"), utils.Yellow(err))
os.Exit(1)
}
func CheckAWSCredentials(profile *string) bool {
var (
cfg aws.Config
err error
)

sts_svc := sts.NewFromConfig(cfg)
_, aws_err := sts_svc.GetCallerIdentity(context.TODO(), &sts.GetCallerIdentityInput{})
if aws_err != nil {
fmt.Println(utils.Red("Error:"), utils.Yellow("AWS Credentials are not valid"))
fmt.Println(utils.Green("Fix:"), utils.Yellow("Provide AWS Credentials, use `./aws-enumerator cred -h` command"))
fmt.Println(utils.Red("Trace:"), utils.Yellow(aws_err))
os.Exit(1)
}
return true
} else {
return false
if *profile == "" {
cfg, err = config.LoadDefaultConfig(context.TODO())
}

cfg, err = config.LoadDefaultConfig(context.TODO(), config.WithSharedConfigProfile(*profile))
if err != nil {
fmt.Println(utils.Red("Error:"), utils.Yellow("Unable to load SDK config,"))
fmt.Println(utils.Green("Fix:"), utils.Yellow("The problem should be on our side, contact support please"))
fmt.Println(utils.Red("Trace:"), utils.Yellow(err))
os.Exit(1)
}

sts_svc := sts.NewFromConfig(cfg)
output, aws_err := sts_svc.GetCallerIdentity(context.TODO(), &sts.GetCallerIdentityInput{})
if aws_err != nil {
fmt.Println(utils.Red("Error:"), utils.Yellow("AWS Credentials are not valid"))
fmt.Println(utils.Green("Fix:"), utils.Yellow("Provide AWS Credentials, use `./aws-enumerator cred -h` command"))
fmt.Println(utils.Red("Trace:"), utils.Yellow(aws_err))
os.Exit(1)
}
fmt.Println(utils.Green("Message: "), utils.Yellow("AWS Credentials are valid: "), utils.Cyan(*output.Arn))
return true

}

func sleep_delay(i, speed int) {
Expand Down Expand Up @@ -195,7 +209,12 @@ func ServiceCall(AllAWSServices []ServiceMaster, wanted_services []string, speed
}
wg.Wait()
}

t := time.Now()
elapsed := t.Sub(start)
fmt.Println(utils.Green("Time:"), elapsed)
fmt.Println(utils.Green("Positive Results:"))
for i := 0; i < len(PositiveResults); i++ {
fmt.Println(PositiveResults[i])
}
}
13 changes: 11 additions & 2 deletions servicestructs/servicestructs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package servicestructs

import (
"context"
"github.com/aws/aws-sdk-go-v2/aws"
"log"

"github.com/aws/aws-sdk-go-v2/config"
Expand Down Expand Up @@ -114,10 +115,18 @@ import (
"github.com/shabarkin/aws-enumerator/utils"
)

func GetServices() []servicemaster.ServiceMaster {
func GetServices(profile *string) []servicemaster.ServiceMaster {

cfg, err := config.LoadDefaultConfig(context.TODO())
var (
cfg aws.Config
err error
)

if *profile == "" {
cfg, err = config.LoadDefaultConfig(context.TODO())
}

cfg, err = config.LoadDefaultConfig(context.TODO(), config.WithSharedConfigProfile(*profile))
if err != nil {
log.Fatalln(utils.Red("Error:"), utils.Yellow("Unable to load SDK config,"))
}
Expand Down
27 changes: 21 additions & 6 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io/ioutil"
"os"
"reflect"
"runtime"
"strings"

"github.com/fatih/color"
Expand Down Expand Up @@ -44,15 +45,29 @@ func countPartWidth(terminal_width, service int) (n int) {

func PrintDividedLine(service string) {

terminal_width, _ := terminal.Width()
n := countPartWidth(int(terminal_width), len(service))
if runtime.GOOS == "windows" {
n := 20

fmt.Println()
if service == "" {
fmt.Println(White(strings.Repeat("-", 20)))
} else {
fmt.Println(White(strings.Repeat("-", n)), Magenta(strings.ToUpper(service)), White(strings.Repeat("-", n)))
}

fmt.Println()
if service == "" {
fmt.Println(White(strings.Repeat("-", int(terminal_width))))
} else {
fmt.Println(White(strings.Repeat("-", n)), Magenta(strings.ToUpper(service)), White(strings.Repeat("-", n)))

terminal_width, _ := terminal.Width()
n := countPartWidth(int(terminal_width), len(service))

fmt.Println()
if service == "" {
fmt.Println(White(strings.Repeat("-", int(terminal_width))))
} else {
fmt.Println(White(strings.Repeat("-", n)), Magenta(strings.ToUpper(service)), White(strings.Repeat("-", n)))
}
}

}

func ProcessServiceArgument(str string) []string {
Expand Down