-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmxmap.go
328 lines (313 loc) · 7.24 KB
/
mxmap.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
//
//
//
package main
//
//
//
import (
"encoding/base64"
"flag"
"fmt"
"github.com/fatih/color"
"net"
"net/smtp"
"os"
"strings"
)
//
//
//
func banner() {
fmt.Print("\033[H\033[2J")
fmt.Println("----------------------------------------------------------------------")
fmt.Println("[- MXMAP by ncaio -]")
fmt.Println(">> caiogore _|_ gmail _|_ com")
fmt.Println("----------------------------------------------------------------------")
fmt.Println("")
}
//
//
//
func openr(h string, u string, he string) {
fmt.Print("\nCheking for open relay: ")
c, treta := smtp.Dial(h + ":25")
if treta != nil {
fmt.Println(" OMG - Connection refused.")
}
c.Hello(he)
c.Mail(u)
or := c.Rcpt(u)
if or != nil {
color.Green(" [- Access denied -]")
c.Close()
} else {
color.Red(" [- Access allowed -]")
c.Close()
}
}
//
//
//
func vrfy(h string, u string, he string) {
fmt.Print("Testing VRFY " + u + " : ")
c, treta := smtp.Dial(h + ":25")
if treta != nil {
fmt.Println(" OMG - Connection refused.")
}
c.Hello(he)
v := c.Verify(u)
if v != nil {
color.Green(" [- VRFY disallowed -]")
c.Close()
} else {
color.Red(" [- VRFY allowed -]")
c.Close()
}
}
//
//
//
func rcpt(h string, u string, he string, s string) {
fmt.Print("Testing RCPT ENUM " + u + ": ")
c, treta := smtp.Dial(h + ":25")
if treta != nil {
fmt.Println(" OMG - Connection refused.")
}
c.Hello(h)
c.Mail(u)
r := c.Rcpt(u)
if r != nil {
color.Green(" [- RCPT enum disallowed -]")
} else {
color.Red(" [- RCPT enum allowed -]")
if strings.Contains(s, "on") {
fmt.Print("Spoofing: sending mail from " + u + " to " + u)
spd, err := c.Data()
if err != nil {
color.Red(" [- Data error: (SPD) c.Data() -]")
c.Close()
}
_, err = fmt.Fprintf(spd, "[- MXMAP SPOOFING TEST -]")
if err != nil {
color.Red(" [- Data error: (SPD) body -]")
c.Close()
}
color.Green(" [- Email Sended -]")
c.Close()
}
}
}
//
//
//
func bann(h string, f string) {
if strings.Contains(f, "on") {
fmt.Println("\nBanner:")
conn, err := net.Dial("tcp", h+":25")
if err != nil {
fmt.Println(" OMG - Connection refused.")
}
defer conn.Close()
var readbuf [512]byte
n, _ := conn.Read(readbuf[0:])
os.Stdout.Write(readbuf[0:n])
if strings.Contains(string(readbuf[0:n]), "Exim") {
fmt.Println("\nExim Vulnerability Statistics - https://www.cvedetails.com/product/19563/Exim-Exim.html?vendor_id=10919")
}
if strings.Contains(string(readbuf[0:n]), "Postfix") {
fmt.Println("\nPostfix Vulnerability Statistics - https://www.cvedetails.com/product/14794/Postfix-Postfix.html?vendor_id=8450")
}
if strings.Contains(string(readbuf[0:n]), "Haraka") {
fmt.Println("\nHaraka - CVE 2016-1000282 - Command injection Haraka node.js mailserver < 2.8.9")
}
if strings.Contains(string(readbuf[0:n]), "Sendmail") {
fmt.Println("\nSendmail Vulnerability Statistics - https://www.cvedetails.com/vulnerability-list/vendor_id-31/Sendmail.html")
}
if strings.Contains(string(readbuf[0:n]), "EG5") {
fmt.Println("\nMcAfee Email and Web Security or McAfee Email Gateway - Vulnerability Statistics - https://www.cvedetails.com/vulnerability-list/vendor_id-345/product_id-17309/Mcafee-Email-Gateway.html")
}
}
}
//
//
//
func txtf(r []string) {
fmt.Print("SPF test: ")
for _, flag := range r {
if strings.Contains(flag, "v=spf1") {
color.Green("[- SPF Flag Found -]")
}
if strings.Contains(flag, "-all") {
color.Green("* [- Sender-ID Result: FAIL -]")
}
if strings.Contains(flag, "~all") {
color.Green("* [- Sender-ID Result: SOFTFAIL -]")
}
if strings.Contains(flag, "?all") {
color.Green("* [- Sender-ID Result: NEUTRAL -]")
}
if strings.Contains(flag, "+all") {
color.Red("* [- Sender-ID Result: PASS -]")
}
}
}
//
//
//
func dmarc(r string) {
fmt.Print("DMARC test: ")
txt, treta := net.LookupTXT("_dmarc." + r)
if treta != nil {
color.Red("[- Dmarc TXT not found -]")
} else {
color.Green("[- Dmarc TXT found -]")
fmt.Print("Dns txt records: ")
fmt.Println(txt)
for _, flag := range txt {
if strings.Contains(flag, "p=none") {
color.Red("* [- DMARC 'p' flag is none -]")
}
if strings.Contains(flag, "sp=none") {
color.Red("* [- DMARC 'sp' flag is none -]")
}
}
}
}
//
//
//
func dkim(in string, sele string) {
fmt.Print(sele + " DKIM Selector test: ")
txt, treta := net.LookupTXT("google._domainkey." + in)
if treta != nil {
color.Red("[- DKIM TXT not found -]")
} else {
color.Green("[- DKIM TXT found -]")
for _, f := range txt {
if strings.Contains(f, "; p=") {
s := strings.Split(f, ";")
rsa(strings.Trim(s[2], " p="))
}
}
}
}
//
//
//
func rsa(r string) {
p := r
_, err := base64.StdEncoding.DecodeString(p)
if err != nil {
color.Red("* [- Not valid DKIM key record -]")
}
color.Green("* [- Valid DKIM key record -]")
fmt.Print("* Key: ")
fmt.Println(p)
}
//
//
//
func main() {
//
// HELLO
//
banner()
//
// Flag domain. --domain=domain.tld or -domain=domain.tld
//
wp := flag.String("domain", "localhost", "domain address. Ex: domain.tld")
un := flag.String("user", "postmaster", "user address. Ex: postmaster")
sf := flag.String("spoof", "off", "spoofing attack flag")
he := flag.String("helo", "me", "helo string")
ud := flag.String("odomain", "evildomain.com", "a domain diferent of default")
ba := flag.String("banner", "off", "show smtp banner")
se := flag.String("selector", "google", "Selector arbitrary name")
flag.Parse()
//
// DOMAIN <- ARG
// USER <-ARG
//
domain := *wp
user := *un
spoof := *sf
helo := *he
opend := *ud
ban := *ba
sel := *se
//
// FINDING MX RECORDS
//
fmt.Println("Searching for MX records...")
mx, treta := net.LookupMX(domain)
if treta != nil {
color.Red("OMG - MX address not found.")
os.Exit(1)
}
//
// ACTION
//
fmt.Println("Mx found:", len(mx))
fmt.Print("Dns txt records: ")
txt, treta := net.LookupTXT(domain)
if treta != nil {
color.Red("TXT not found")
} else {
fmt.Println(txt)
fmt.Println("")
fmt.Println("----------------------------------------------------------------------")
fmt.Println("")
txtf(txt)
fmt.Println("")
fmt.Println("----------------------------------------------------------------------")
fmt.Println("")
dmarc(domain)
fmt.Println("")
fmt.Println("----------------------------------------------------------------------")
fmt.Println("")
dkim(domain, sel)
fmt.Println("")
}
fmt.Println("----------------------------------------------------------------------")
for p := range mx {
//
//
//
ip, _ := net.LookupIP(mx[p].Host)
fmt.Print("\nTesting: ", mx[p].Host)
fmt.Print(" -> ", ip[0])
c, treta := smtp.Dial(mx[p].Host + ":25")
if treta != nil {
fmt.Println(" OMG - Connection refused.")
c.Quit()
} else {
color.Green(" [- UP -]")
}
//
//
//
bann(mx[p].Host, ban)
//
// OPEN RELAY TEST
//
openr(mx[p].Host, user+"@"+opend, helo)
//
// VRFY WITHOUT DOMAIN
//
vrfy(mx[p].Host, user, helo)
//
// VRFY WITH DOMAIN
//
vrfy(mx[p].Host, user+"@"+domain, helo)
//
// RCPT ENUM WITHOUT DOMAIN
//
rcpt(mx[p].Host, user, helo, spoof)
//
// RCPT ENUM WITH DOMAIN
//
rcpt(mx[p].Host, user+"@"+domain, helo, spoof)
fmt.Println("")
fmt.Println("----------------------------------------------------------------------")
}
}