-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
110 lines (87 loc) · 2.34 KB
/
main.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
package main
import (
"flag"
"os"
"sync"
log "github.com/sirupsen/logrus"
"github.com/vpereira/brucutu/internal/connect"
"github.com/vpereira/brucutu/internal/util"
)
func main() {
cli := util.NewCliArgument()
err := cli.ReadParameters()
if err != nil {
log.Fatal(err.Error())
flag.PrintDefaults()
os.Exit(1)
}
myURL, err := cli.ParseURL()
if err != nil {
log.Fatal(*cli.URL, " can't be parsed")
os.Exit(1)
}
if !util.ProtocolSupported(myURL.Scheme) {
log.Fatal("Protocol ", myURL.Scheme, " not supported")
os.Exit(1)
}
users, err := util.GenerateUserList(cli)
if err != nil {
log.Fatal("Can't read user list, exiting.")
os.Exit(1)
}
passwords, err := util.GeneratePasswordList(cli)
if err != nil {
log.Fatal("Can't read password list, exiting:", err.Error())
os.Exit(1)
}
throttler := make(chan int, *cli.Concurrency)
outputChannel := make(chan string)
host := util.SetHostName(cli, myURL)
// test connection
if err := util.DialHost(*host); err != nil {
log.Fatal("util.DialHost", err.Error())
os.Exit(1)
}
var outputFile *os.File
if *cli.OutputFile != "" {
outputFile, err := os.Create(*cli.OutputFile)
if err != nil {
log.Fatal("Output file", err.Error())
os.Exit(1)
}
defer outputFile.Close()
}
// invert the logins, i.e foobar, become rabfoo and use it as password
if *cli.TryLoginReverse {
var reverseValues = make([]string, len(users))
for _, user := range users {
reverseValues = append(reverseValues, util.Reverse(user))
}
passwords = append(passwords, reverseValues...)
}
go util.WriteLog(outputChannel, outputFile, *cli.QuitFirstFound)
var wg sync.WaitGroup
for _, user := range users {
for _, password := range passwords {
throttler <- 0
wg.Add(1)
ca := connect.Arguments{StartTLS: *cli.StartTLS, UseTLS: *cli.UseTLS, Host: *host, User: user, Password: password}
switch myURL.Scheme {
case "ftp":
go connect.FTP(&wg, throttler, outputChannel, ca)
case "http", "https":
go connect.HTTPBasicAuth(&wg, throttler, outputChannel, ca)
case "pop3", "pop3s":
go connect.POP3(&wg, throttler, outputChannel, ca)
case "ssh":
go connect.SSH(&wg, throttler, outputChannel, ca)
case "imap", "imaps":
go connect.IMAP(&wg, throttler, outputChannel, ca)
default:
log.Fatal("not implemented")
}
}
}
wg.Wait()
close(outputChannel)
}