-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsrvsvc_enum_shares.go
86 lines (68 loc) · 1.86 KB
/
srvsvc_enum_shares.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
//go:build exclude
package main
import (
"context"
"encoding/json"
"fmt"
"os"
"github.com/rs/zerolog"
"github.com/oiweiwei/go-msrpc/dcerpc"
"github.com/oiweiwei/go-msrpc/smb2"
"github.com/oiweiwei/go-msrpc/ssp"
"github.com/oiweiwei/go-msrpc/ssp/credential"
"github.com/oiweiwei/go-msrpc/ssp/gssapi"
"github.com/oiweiwei/go-msrpc/msrpc/epm/epm/v3"
"github.com/oiweiwei/go-msrpc/msrpc/srvs/srvsvc/v3"
_ "github.com/oiweiwei/go-msrpc/msrpc/erref/ntstatus"
_ "github.com/oiweiwei/go-msrpc/msrpc/erref/win32"
)
func init() {
// add credentials.
gssapi.AddCredential(credential.NewFromPassword(os.Getenv("USERNAME"), os.Getenv("PASSWORD")))
// add mechanism.
gssapi.AddMechanism(ssp.SPNEGO)
gssapi.AddMechanism(ssp.KRB5)
gssapi.AddMechanism(ssp.NTLM)
}
func j(v any) string {
b, _ := json.MarshalIndent(v, "", " ")
return string(b)
}
func main() {
ctx := gssapi.NewSecurityContext(context.Background())
log := zerolog.New(os.Stderr)
dialer := smb2.NewDialer(
smb2.WithDialect(smb2.SMB311),
// smb2.WithSeal(),
smb2.WithSecurity(gssapi.WithTargetName(os.Getenv("TARGET"))))
opts := []dcerpc.Option{
dcerpc.WithLogger(log),
epm.EndpointMapper(ctx, os.Getenv("SERVER"), dcerpc.WithLogger(log)),
dcerpc.WithSMBDialer(dialer),
}
cc, err := dcerpc.Dial(ctx, os.Getenv("SERVER"), opts...)
if err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
cli, err := srvsvc.NewSrvsvcClient(ctx, cc, dcerpc.WithInsecure())
if err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
enums, err := cli.ShareEnum(ctx, &srvsvc.ShareEnumRequest{
ServerName: "",
Info: &srvsvc.ShareEnum{
Level: 503,
ShareInfo: &srvsvc.ShareEnumUnion{
Value: &srvsvc.ShareEnumUnion_Level503{Level503: &srvsvc.ShareInfo503Container{}},
},
},
PreferredMaximumLength: 0xffffffff,
})
if err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
fmt.Println(j(enums))
}