1
1
package smtp
2
2
3
3
import (
4
- "GoMapEnum/src/utils"
5
- "fmt"
6
4
"net"
7
5
"reflect"
8
6
"strconv"
@@ -32,27 +30,27 @@ func PrepareSMTPConnections(optionsInterface *interface{}) {
32
30
}
33
31
options .Log .Debug ("Preparing a pool of " + strconv .Itoa (nbConnectionsRequired ) + " connections" )
34
32
for i := 1 ; i <= nbConnectionsRequired ; i ++ {
35
- client , err := smtp .Dial (options .Target + ":25" )
36
- if err != nil {
37
- options .Log .Error ("Failed to establish a connection " + err .Error ())
38
- continue
39
- }
40
- err = client .Hello (utils .RandomString (6 ))
41
- if err != nil {
42
- fmt .Println ("hello" + err .Error ())
43
- }
44
- err = client .Mail (utils .RandomString (6 ) + "@" + options .Domain )
45
- if err != nil {
46
- fmt .Println ("mail" + err .Error ())
33
+ client := options .createNewConnection ()
34
+ if client != nil {
35
+ options .connectionsPool <- client
47
36
}
48
- options .connectionsPool <- client
49
37
}
50
38
}
51
39
52
40
func UserEnum (optionsInterface * interface {}, username string ) bool {
53
41
options := (* optionsInterface ).(* Options )
54
42
valid := false
55
43
smtpConnection := <- options .connectionsPool
44
+ smtpConnection .Reset ()
45
+ err := options .prepareOneConnection (smtpConnection )
46
+ if err != nil && strings .Contains (err .Error (), "connection reset by peer" ) {
47
+ options .Log .Debug ("Connection reset. Generating new one" )
48
+ smtpConnection = options .createNewConnection ()
49
+ err = options .prepareOneConnection (smtpConnection )
50
+ }
51
+ if err != nil {
52
+ options .Log .Fatal ("Failed to prepare a connection. " + err .Error ())
53
+ }
56
54
switch strings .ToLower (options .Mode ) {
57
55
case "rcpt" :
58
56
err := smtpConnection .Rcpt (username )
@@ -61,6 +59,11 @@ func UserEnum(optionsInterface *interface{}, username string) bool {
61
59
valid = true
62
60
} else {
63
61
options .Log .Debug (username + " => " + err .Error ())
62
+ if strings .Contains (err .Error (), "connection reset by peer" ) {
63
+ smtpConnection .Close ()
64
+ options .createNewConnection ()
65
+ return UserEnum (optionsInterface , username )
66
+ }
64
67
options .Log .Fail (username )
65
68
}
66
69
case "vrfy" :
@@ -70,6 +73,11 @@ func UserEnum(optionsInterface *interface{}, username string) bool {
70
73
valid = true
71
74
} else {
72
75
options .Log .Debug (username + " => " + err .Error ())
76
+ if strings .Contains (err .Error (), "connection reset by peer" ) {
77
+ smtpConnection .Close ()
78
+ options .createNewConnection ()
79
+ return UserEnum (optionsInterface , username )
80
+ }
73
81
options .Log .Fail (username )
74
82
}
75
83
case "expn" :
@@ -80,12 +88,20 @@ func UserEnum(optionsInterface *interface{}, username string) bool {
80
88
} else {
81
89
code := strings .Split (err .Error (), " " )[0 ]
82
90
options .Log .Debug (username + " => " + err .Error ())
91
+ if strings .Contains (err .Error (), "connection reset by peer" ) {
92
+ smtpConnection .Close ()
93
+ options .createNewConnection ()
94
+ return UserEnum (optionsInterface , username )
95
+ }
83
96
options .Log .Fail (username )
84
97
// If the command is not implemented no need to pursue
85
98
if code == "502" && ! options .all {
86
99
CloseSMTPConnections (optionsInterface )
87
100
options .Log .Fatal ("The command EXPN is not implemented. No need to pursue using this method." )
88
101
}
102
+ if code == "502" && options .all {
103
+ options .expnNotRecognized = true
104
+ }
89
105
}
90
106
case "" , "all" :
91
107
@@ -111,15 +127,16 @@ func UserEnum(optionsInterface *interface{}, username string) bool {
111
127
return true
112
128
}
113
129
// EXPN
114
- options .Log .Debug ("Enumerate with EXPN" )
115
- optionsCopy .Mode = "expn"
116
- newOptionsInterface = reflect .ValueOf (& optionsCopy ).Interface ()
117
- valid = UserEnum (& newOptionsInterface , username )
130
+ if ! options .expnNotRecognized {
131
+ options .Log .Debug ("Enumerate with EXPN" )
132
+ optionsCopy .Mode = "expn"
133
+ newOptionsInterface = reflect .ValueOf (& optionsCopy ).Interface ()
134
+ valid = UserEnum (& newOptionsInterface , username )
135
+ }
118
136
return valid
119
137
default :
120
138
options .Log .Fatal ("Unrecognised mode: " + options .Mode + ". Only RCPT, VRFY and EXPN are supported." )
121
139
}
122
-
123
140
options .connectionsPool <- smtpConnection
124
141
return valid
125
142
}
0 commit comments