-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
177 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package enum | ||
|
||
import ( | ||
"GoMapEnum/src/logger" | ||
"GoMapEnum/src/modules/smtp" | ||
"GoMapEnum/src/orchestrator" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var smtpOptions smtp.Options | ||
|
||
// smtpCmd represents the smtp command | ||
var smtpCmd = &cobra.Command{ | ||
Use: "smtp", | ||
Short: "Enumerate email address by connection to the smtp port of the target.", | ||
Long: ` | ||
Credits: https://github.com/cytopia/smtp-user-enum`, | ||
Example: `go run main.go userenum smtp -u users -t mail.contoso.com -o validUsers`, | ||
Run: func(cmdCli *cobra.Command, args []string) { | ||
log := logger.New("Enumeration", "SMTP", smtpOptions.Target) | ||
log.SetLevel(level) | ||
log.Info("Starting the module SMTP") | ||
smtpOptions.Log = log | ||
smtpOptions.Proxy = proxy | ||
|
||
orchestratorOptions := orchestrator.Orchestrator{} | ||
orchestratorOptions.PreActionUserEnum = smtp.PrepareSMTPConnections | ||
orchestratorOptions.UserEnumFunc = smtp.UserEnum | ||
orchestratorOptions.PostActionUserEnum = smtp.CloseSMTPConnections | ||
validUsers = orchestratorOptions.UserEnum(&smtpOptions) | ||
|
||
}, | ||
} | ||
|
||
func init() { | ||
|
||
smtpCmd.Flags().StringVarP(&smtpOptions.Domain, "domain", "d", "", "Targeted domain ") | ||
smtpCmd.Flags().StringVarP(&smtpOptions.Mode, "mode", "m", "", "RCPT, VRFY, EXPN (default: RCPT)") | ||
smtpCmd.Flags().StringVarP(&smtpOptions.Users, "user", "u", "", "Username or file containing the usernames") | ||
smtpCmd.Flags().StringVarP(&smtpOptions.Target, "target", "t", "", "Host pointing to the OWA service") | ||
smtpCmd.Flags().IntVar(&smtpOptions.Thread, "thread", 2, "Number of threads") | ||
smtpCmd.MarkFlagRequired("user") | ||
smtpCmd.MarkFlagRequired("target") | ||
smtpCmd.MarkFlagRequired("domain") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package smtp | ||
|
||
import ( | ||
"GoMapEnum/src/utils" | ||
|
||
smtp "github.com/nodauf/net-smtp" | ||
) | ||
|
||
// Options for o365 module | ||
type Options struct { | ||
Target string | ||
Domain string | ||
Mode string | ||
utils.BaseOptions | ||
|
||
connectionsPool chan *smtp.Client | ||
} | ||
|
||
func (options *Options) GetBaseOptions() *utils.BaseOptions { | ||
return &options.BaseOptions | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package smtp | ||
|
||
import ( | ||
"GoMapEnum/src/utils" | ||
"fmt" | ||
"strconv" | ||
"strings" | ||
"time" | ||
|
||
smtp "github.com/nodauf/net-smtp" | ||
) | ||
|
||
func PrepareSMTPConnections(optionsInterface *interface{}) { | ||
options := (*optionsInterface).(*Options) | ||
options.connectionsPool = make(chan *smtp.Client, options.Thread) | ||
var nbConnectionsRequired int | ||
nbConnectionsRequired = options.Thread | ||
if len(options.UsernameList) < options.Thread { | ||
nbConnectionsRequired = len(options.UsernameList) | ||
} | ||
options.Log.Debug("Preparing a pool of " + strconv.Itoa(nbConnectionsRequired) + " connections") | ||
for i := 1; i <= nbConnectionsRequired; i++ { | ||
client, err := smtp.Dial(options.Target + ":25") | ||
if err != nil { | ||
options.Log.Error("Failed to establish a connection " + err.Error()) | ||
continue | ||
} | ||
err = client.Hello(utils.RandomString(6)) | ||
if err != nil { | ||
fmt.Println("hello" + err.Error()) | ||
} | ||
err = client.Mail(utils.RandomString(6) + "@" + options.Domain) | ||
if err != nil { | ||
fmt.Println("mail" + err.Error()) | ||
} | ||
options.connectionsPool <- client | ||
} | ||
} | ||
|
||
func UserEnum(optionsInterface *interface{}, username string) bool { | ||
options := (*optionsInterface).(*Options) | ||
valid := false | ||
smtpConnection := <-options.connectionsPool | ||
switch strings.ToLower(options.Mode) { | ||
case "rcpt", "": | ||
err := smtpConnection.Rcpt(username) | ||
if err == nil { | ||
options.Log.Success(username) | ||
valid = true | ||
} else { | ||
options.Log.Debug(username + " => " + err.Error()) | ||
options.Log.Fail(username) | ||
} | ||
case "vrfy": | ||
err := smtpConnection.Verify(username) | ||
if err == nil { | ||
options.Log.Success(username) | ||
valid = true | ||
} else { | ||
options.Log.Debug(username + " => " + err.Error()) | ||
options.Log.Fail(username) | ||
} | ||
case "expn": | ||
err := smtpConnection.Expand(username) | ||
if err == nil { | ||
options.Log.Success(username) | ||
valid = true | ||
} else { | ||
code := strings.Split(err.Error(), " ")[0] | ||
options.Log.Debug(username + " => " + err.Error()) | ||
options.Log.Fail(username) | ||
// If the command is not implemented no need to pursue | ||
if code == "502" { | ||
CloseSMTPConnections(optionsInterface) | ||
options.Log.Fatal("The command is not implemented. No need to pursue using this method.") | ||
} | ||
fmt.Println(code) | ||
} | ||
default: | ||
CloseSMTPConnections(optionsInterface) | ||
options.Log.Fatal("Unrecognised mode: " + options.Mode + ". Only RCPT, VRFY and EXPN are supported.") | ||
} | ||
|
||
options.connectionsPool <- smtpConnection | ||
return valid | ||
} | ||
|
||
func CloseSMTPConnections(optionsInterface *interface{}) { | ||
options := (*optionsInterface).(*Options) | ||
options.Log.Debug("Closing the pool of connections") | ||
for i := 1; i <= options.Thread; i++ { | ||
select { | ||
case smtpConnection := <-options.connectionsPool: | ||
smtpConnection.Close() | ||
case <-time.After(1 * time.Second): | ||
options.Log.Debug("Something went wrong0 A connection seems already closed") | ||
} | ||
|
||
} | ||
close(options.connectionsPool) | ||
} |