Skip to content

Commit

Permalink
Fix a bug when the tenant was not valid.
Browse files Browse the repository at this point in the history
   Lower the number of request by remembering which domain are valid or note
  • Loading branch information
nodauf committed Jan 4, 2022
1 parent b689510 commit 040113a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/o365/userEnum.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ func (options *Options) UserEnum() []string {
emailList := strings.Split(options.Users, "\n")
var wg sync.WaitGroup
var validusers []string
domainValidated := make(map[string]bool)
queue := make(chan string)

for i := 0; i < options.Thread; i++ {
Expand All @@ -22,11 +23,26 @@ func (options *Options) UserEnum() []string {
defer wg.Done()
for email := range queue {
domain := strings.Split(email, "@")[1]
if !options.validTenant(domain) {
options.Log.Error("Tenant " + domain + " is not valid")
return
// If we didn't already checked the domain
mux.Lock()
if domainValid, ok := domainValidated[domain]; !ok {
if !options.validTenant(domain) {
options.Log.Error("Tenant " + domain + " is not valid")
domainValidated[domain] = false
mux.Unlock()
continue
}
options.Log.Info("Tenant " + domain + " is valid")
domainValidated[domain] = true
} else {
// If the domain was not valid, skip the email
if !domainValid {
options.Log.Debug("Tenant " + domain + " already checked and was not valid")
mux.Unlock()
continue
}
}
options.Log.Verbose("Tenant " + domain + " is valid")
mux.Unlock()

switch options.Mode {
case "office":
Expand Down
9 changes: 9 additions & 0 deletions src/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,12 @@ func GetKeysMap(m map[string]string) []string {
}
return keys
}

func StringInSlice(item string, slice []string) bool {
for _, elementOfSlice := range slice {
if item == elementOfSlice {
return true
}
}
return false
}

0 comments on commit 040113a

Please sign in to comment.