4
4
"bytes"
5
5
"crypto/tls"
6
6
"fmt"
7
- "io/ioutil "
7
+ "io"
8
8
"net"
9
9
"net/http"
10
10
"net/url"
@@ -13,21 +13,20 @@ import (
13
13
"strings"
14
14
"text/template"
15
15
16
- "github.com/sensepost/ruler/http-ntlm"
17
16
httpntlm "github.com/sensepost/ruler/http-ntlm"
18
17
"github.com/sensepost/ruler/utils"
19
18
)
20
19
21
20
//globals
22
21
23
- //SessionConfig holds the configuration for this autodiscover session
22
+ // SessionConfig holds the configuration for this autodiscover session
24
23
var SessionConfig * utils.Session
25
24
var autodiscoverStep int
26
25
var secondaryEmail string //a secondary email to use, edge case seen in office365
27
26
var Transport http.Transport
28
27
var basicAuth = false
29
28
30
- //the xml for the autodiscover service
29
+ // the xml for the autodiscover service
31
30
const autodiscoverXML = `<?xml version="1.0" encoding="utf-8"?><Autodiscover xmlns="http://schemas.microsoft.com/exchange/autodiscover/outlook/requestschema/2006">
32
31
<Request><EMailAddress>{{.Email}}</EMailAddress>
33
32
<AcceptableResponseSchema>http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a</AcceptableResponseSchema>
@@ -44,10 +43,10 @@ func parseTemplate(tmpl string) (string, error) {
44
43
return buff .String (), nil
45
44
}
46
45
47
- //createAutodiscover generates a domain name of the format autodiscover.domain.com
48
- //and checks if a DNS entry exists for it. If it doesn't it tries DNS for just the domain name.
49
- //returns an empty string if no valid domain was found.
50
- //returns the full (expected) autodiscover URL
46
+ // createAutodiscover generates a domain name of the format autodiscover.domain.com
47
+ // and checks if a DNS entry exists for it. If it doesn't it tries DNS for just the domain name.
48
+ // returns an empty string if no valid domain was found.
49
+ // returns the full (expected) autodiscover URL
51
50
func createAutodiscover (domain string , https bool ) string {
52
51
_ , err := net .LookupHost (domain )
53
52
if err != nil {
@@ -59,7 +58,7 @@ func createAutodiscover(domain string, https bool) string {
59
58
return fmt .Sprintf ("http://%s/autodiscover/autodiscover.xml" , domain )
60
59
}
61
60
62
- //GetMapiHTTP gets the details for MAPI/HTTP
61
+ // GetMapiHTTP gets the details for MAPI/HTTP
63
62
func GetMapiHTTP (email , autoURLPtr string , resp * utils.AutodiscoverResp ) (* utils.AutodiscoverResp , string , error ) {
64
63
//var resp *utils.AutodiscoverResp
65
64
var err error
@@ -88,7 +87,7 @@ func GetMapiHTTP(email, autoURLPtr string, resp *utils.AutodiscoverResp) (*utils
88
87
return resp , rawAutodiscover , nil
89
88
}
90
89
91
- //GetRPCHTTP exports the RPC details for RPC/HTTP
90
+ // GetRPCHTTP exports the RPC details for RPC/HTTP
92
91
func GetRPCHTTP (email , autoURLPtr string , resp * utils.AutodiscoverResp ) (* utils.AutodiscoverResp , string , string , string , bool , error ) {
93
92
//var resp *utils.AutodiscoverResp
94
93
var err error
@@ -191,7 +190,7 @@ func GetRPCHTTP(email, autoURLPtr string, resp *utils.AutodiscoverResp) (*utils.
191
190
return resp , rawAutodiscover , RPCURL , user , ntlmAuth , nil
192
191
}
193
192
194
- //CheckCache checks to see if there is a stored copy of the autodiscover record
193
+ // CheckCache checks to see if there is a stored copy of the autodiscover record
195
194
func CheckCache (email string ) * utils.AutodiscoverResp {
196
195
//check the cache folder for a stored autodiscover record
197
196
email = strings .Replace (email , "@" , "_" , - 1 )
@@ -206,7 +205,7 @@ func CheckCache(email string) *utils.AutodiscoverResp {
206
205
return nil
207
206
}
208
207
utils .Info .Println ("Found cached Autodiscover record. Using this (use --nocache to force new lookup)" )
209
- data , err := ioutil .ReadFile (path )
208
+ data , err := os .ReadFile (path )
210
209
if err != nil {
211
210
utils .Error .Println ("Error reading stored record " , err )
212
211
return nil
@@ -216,7 +215,7 @@ func CheckCache(email string) *utils.AutodiscoverResp {
216
215
return & autodiscoverResp
217
216
}
218
217
219
- //CreateCache function stores the raw autodiscover record to file
218
+ // CreateCache function stores the raw autodiscover record to file
220
219
func CreateCache (email , autodiscover string ) {
221
220
222
221
if autodiscover == "" { //no autodiscover record passed in, don't try write
@@ -241,7 +240,7 @@ func CreateCache(email, autodiscover string) {
241
240
}
242
241
}
243
242
244
- //Autodiscover function to retrieve mailbox details using the autodiscover mechanism from MS Exchange
243
+ // Autodiscover function to retrieve mailbox details using the autodiscover mechanism from MS Exchange
245
244
func Autodiscover (domain string ) (* utils.AutodiscoverResp , string , error ) {
246
245
if SessionConfig .Proxy == "" {
247
246
Transport = http.Transport {
@@ -259,8 +258,8 @@ func Autodiscover(domain string) (*utils.AutodiscoverResp, string, error) {
259
258
return autodiscover (domain , false )
260
259
}
261
260
262
- //MAPIDiscover function to do the autodiscover request but specify the MAPI header
263
- //indicating that the MAPI end-points should be returned
261
+ // MAPIDiscover function to do the autodiscover request but specify the MAPI header
262
+ // indicating that the MAPI end-points should be returned
264
263
func MAPIDiscover (domain string ) (* utils.AutodiscoverResp , string , error ) {
265
264
//set transport
266
265
if SessionConfig .Proxy == "" {
@@ -345,7 +344,7 @@ func autodiscover(domain string, mapi bool) (*utils.AutodiscoverResp, string, er
345
344
346
345
if SessionConfig .Basic == true {
347
346
if SessionConfig .Domain != "" {
348
- req .SetBasicAuth (SessionConfig .Domain + "\\ " + SessionConfig .User , SessionConfig .Pass )
347
+ req .SetBasicAuth (SessionConfig .Domain + "\\ " + SessionConfig .User , SessionConfig .Pass )
349
348
} else {
350
349
req .SetBasicAuth (SessionConfig .Email , SessionConfig .Pass )
351
350
}
@@ -375,7 +374,7 @@ func autodiscover(domain string, mapi bool) (*utils.AutodiscoverResp, string, er
375
374
376
375
defer resp .Body .Close ()
377
376
378
- body , err := ioutil .ReadAll (resp .Body )
377
+ body , err := io .ReadAll (resp .Body )
379
378
if err != nil {
380
379
return nil , "" , err
381
380
}
@@ -492,17 +491,17 @@ func redirectAutodiscover(redirdom string) (string, error) {
492
491
return resp .Header .Get ("Location" ), nil
493
492
}
494
493
495
- //InsecureRedirectsO365 allows forwarding the Authorization header even when we shouldn't
494
+ // InsecureRedirectsO365 allows forwarding the Authorization header even when we shouldn't
496
495
type InsecureRedirectsO365 struct {
497
496
Transport http.RoundTripper
498
497
User string
499
498
Pass string
500
499
Insecure bool
501
500
}
502
501
503
- //RoundTrip custom redirector that allows us to forward the auth header, even when the domain changes.
504
- //This is needed as some office365 domains will redirect from autodiscover.domain.com to autodiscover.outlook.com
505
- //and Go does not forward Sensitive headers such as Authorization (https://golang.org/src/net/http/client.go#41)
502
+ // RoundTrip custom redirector that allows us to forward the auth header, even when the domain changes.
503
+ // This is needed as some office365 domains will redirect from autodiscover.domain.com to autodiscover.outlook.com
504
+ // and Go does not forward Sensitive headers such as Authorization (https://golang.org/src/net/http/client.go#41)
506
505
func (l InsecureRedirectsO365 ) RoundTrip (req * http.Request ) (resp * http.Response , err error ) {
507
506
t := l .Transport
508
507
0 commit comments