-
Notifications
You must be signed in to change notification settings - Fork 2
/
epm.go
177 lines (143 loc) · 4.09 KB
/
epm.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
//go:build exclude
// epm.go script dumps all interfaces registered on the remote server and also
// maps particular endpoints using Map method.
package main
import (
"context"
"encoding/binary"
"flag"
"fmt"
"log"
"os"
"runtime/pprof"
"strings"
"github.com/oiweiwei/go-msrpc/dcerpc"
"github.com/oiweiwei/go-msrpc/midl/uuid"
"github.com/oiweiwei/go-msrpc/msrpc/dcetypes"
"github.com/oiweiwei/go-msrpc/msrpc/dnsp/dnsserver/v5"
"github.com/oiweiwei/go-msrpc/msrpc/epm/epm/v3"
"github.com/oiweiwei/go-msrpc/msrpc/even/eventlog/v0"
"github.com/oiweiwei/go-msrpc/msrpc/even6/ieventservice/v1"
"github.com/oiweiwei/go-msrpc/msrpc/nrpc/logon/v1"
"github.com/oiweiwei/go-msrpc/msrpc/well_known"
"github.com/rs/zerolog"
"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/erref/win32"
)
var short bool
var cpu string
func init() {
flag.BoolVar(&short, "s", false, "short form")
flag.StringVar(&cpu, "cpupprof", "/tmp/cpprof.pprof", "cpu profile")
flag.Parse()
}
func init() {
// add credentials.
gssapi.AddCredential(credential.NewFromNTHash(os.Getenv("USERNAME"), os.Getenv("PASSWORD_MD4")))
// add mechanism.
gssapi.AddMechanism(ssp.SPNEGO)
gssapi.AddMechanism(ssp.NTLM)
}
func main() {
if cpu != "" {
f, err := os.Create(cpu)
if err != nil {
log.Fatal(err)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
}
ctx := gssapi.NewSecurityContext(context.Background())
cc, err := dcerpc.Dial(ctx, os.Getenv("SERVER"), well_known.EndpointMapper())
if err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
defer cc.Close(ctx)
cli, err := epm.NewEpmClient(ctx, cc, dcerpc.WithSeal(), dcerpc.WithTargetName(os.Getenv("TARGET")), dcerpc.WithVerifyBitMask(true), dcerpc.WithVerifyPresenetation(true), dcerpc.WithVerifyHeader2(true), dcerpc.WithLogger(zerolog.New(os.Stdout)))
if err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
resp, err := cli.Lookup(ctx, &epm.LookupRequest{MaxEntries: 500})
if err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
uConv := func(u *uuid.UUID) string {
if n := strings.ToLower((*well_known.UUID)(u).Name()); n != "" {
return n
}
return u.String()
}
_ = uConv
if short {
for i, entries := range resp.Entries {
fmt.Printf("[%d] %s (%s)\n", i, entries.Tower.Binding().URL(uConv), entries.Tower.Binding().StringBinding)
}
} else {
for i, entries := range resp.Entries {
fmt.Println(i, " --- ", entries.Annotation, entries.Object)
for i, floor := range entries.Tower.Floors() {
if i == 0 {
fmt.Println(i, floor, "//", (*well_known.UUID)(floor.UUID).Describe())
} else {
fmt.Println(i, floor)
}
}
}
}
fmt.Println("logon")
MapSyntax(ctx, cli, logon.LogonSyntaxV1_0)
fmt.Println("dnsserver")
MapSyntax(ctx, cli, dnsserver.DNSServerSyntaxV5_0)
fmt.Println("epm")
MapSyntax(ctx, cli, epm.EpmSyntaxV3_0)
fmt.Println("ievent6")
MapSyntax(ctx, cli, ieventservice.EventServiceSyntaxV1_0)
fmt.Println("ievent")
MapSyntax(ctx, cli, eventlog.EventlogSyntaxV0_0)
}
func MapSyntax(ctx context.Context, cli epm.EpmClient, syntax *dcerpc.SyntaxID) {
resp, err := cli.Map(ctx, &epm.MapRequest{
MapTower: dcetypes.FloorsToTower([]*dcetypes.Floor{
{
Protocol: uint8(dcetypes.ProtocolUUID),
UUID: syntax.IfUUID,
VersionMajor: syntax.IfVersionMajor,
Data: []byte{0, 0},
},
{
Protocol: uint8(dcetypes.ProtocolUUID),
UUID: dcerpc.TransferNDR,
VersionMajor: syntax.IfVersionMajor,
Data: binary.LittleEndian.AppendUint16(nil, syntax.IfVersionMinor),
},
{
Protocol: uint8(dcetypes.ProtocolRPC_CO),
Data: []byte{0, 0},
},
{
Protocol: uint8(dcetypes.ProtocolTCP),
Data: []byte{0, 0},
},
{
Protocol: uint8(dcetypes.ProtocolIP),
Data: []byte{0, 0, 0, 0},
},
}),
MaxTowers: 100,
})
if err != nil {
fmt.Println("error", err)
return
}
for i, tower := range resp.Towers {
fmt.Println(i, " --- ", "*")
for i, floor := range tower.Floors() {
fmt.Println(i, floor)
}
}
}