Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/auxiliary/scanner/msmail/exchange_enum.go
Views: 11784
//usr/bin/env go run "$0" "$@"; exit "$?"12package main34import (5"crypto/tls"6"fmt"7"metasploit/module"8"msmail"9"net/http"10"strconv"11"strings"12"sync"13)1415func main() {16metadata := &module.Metadata{17Name: "Exchange email enumeration",18Description: "Error-based user enumeration for Office 365 integrated email addresses",19Authors: []string{"poptart", "jlarose", "Vincent Yiu", "grimhacker", "Nate Power", "Nick Powers", "clee-r7"},20Date: "2018-11-06",21Type: "single_scanner",22Privileged: false,23References: []module.Reference{},24Options: map[string]module.Option{25"RHOSTS": {Type: "string", Description: "Target endpoint", Required: true, Default: "outlook.office365.com"},26"EMAIL": {Type: "string", Description: "Single email address to do identity test against", Required: false, Default: ""},27"EMAIL_FILE": {Type: "string", Description: "Path to file containing list of email addresses", Required: false, Default: ""},28}}2930module.Init(metadata, run_exchange_enum)31}3233func run_exchange_enum(params map[string]interface{}) {34email := params["EMAIL"].(string)35emailFile := params["EMAIL_FILE"].(string)36threads, e := strconv.Atoi(params["THREADS"].(string))37ip := params["rhost"].(string)3839if e != nil {40module.LogError("Unable to parse 'Threads' value using default (5)")41threads = 542}4344if threads > 100 {45module.LogInfo("Threads value too large, setting max(100)")46threads = 10047}4849if email == "" && emailFile == "" {50module.LogError("Expected 'EMAIL' or 'EMAIL_FILE' field to be populated")51return52}5354var validUsers []string55if email != "" {56validUsers = o365enum(ip, []string{email}, threads)57}5859if emailFile != "" {60validUsers = o365enum(ip, msmail.ImportUserList(emailFile), threads)61}6263msmail.ReportValidUsers(ip, validUsers)64}6566func o365enum(ip string, emaillist []string, threads int) []string {67limit := threads68var wg sync.WaitGroup69queue := make(chan string)70//limit := 1007172/*Keep in mind you, nothing has been added to handle successful auths73so the password for auth attempts has been hardcoded to something74that is not likely to be correct.75*/76pass := "Summer2018876"77URI := "https://" + ip + "/Microsoft-Server-ActiveSync"78var validemails []string7980tr := &http.Transport{81TLSClientConfig: &tls.Config{InsecureSkipVerify: true},82}8384for i := 0; i < limit; i++ {85wg.Add(1)86go func(i int) {87defer wg.Done()88for email := range queue {89responseCode := msmail.WebRequestBasicAuth(URI, email, pass, tr)90if strings.Contains(email, "@") && responseCode == 401 {91module.LogGood(email + " - 401")92validemails = append(validemails, email)93} else if strings.Contains(email, "@") && responseCode == 404 {94module.LogError(fmt.Sprintf("%s - %d", email, responseCode))95} else {96module.LogError(fmt.Sprintf("Unusual Response: %s - %d", email, responseCode))97}98}99}(i)100}101102for i := 0; i < len(emaillist); i++ {103queue <- emaillist[i]104}105106close(queue)107wg.Wait()108return validemails109}110111112