/
smbnt.go
46 lines (37 loc) · 815 Bytes
/
smbnt.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
package brute
import (
"fmt"
"net"
"time"
"github.com/hirochachacha/go-smb2"
)
func BruteSMB(host string, port int, user, password string, timeout time.Duration) (bool, bool) {
conn, err := net.DialTimeout("tcp", fmt.Sprintf("%s:%d", host, port), timeout)
if err != nil {
return false, false
}
defer conn.Close()
if err := conn.SetDeadline(time.Now().Add(timeout)); err != nil {
fmt.Println("Error setting deadline:", err)
}
d := &smb2.Dialer{
Initiator: &smb2.NTLMInitiator{
User: user,
Password: password,
},
}
s, err := d.Dial(conn)
if err != nil {
return false, true
}
defer func() {
if err := s.Logoff(); err != nil {
fmt.Printf("Failed to logoff: %v\n", err)
}
}()
_, err = s.ListSharenames()
if err != nil {
return false, true
}
return true, true
}