-
Notifications
You must be signed in to change notification settings - Fork 37
/
types.go
510 lines (414 loc) · 12.3 KB
/
types.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
// Copyright 2022 Praetorian Security, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package plugins
import (
"encoding/json"
"net"
"net/http"
"net/netip"
"strings"
"time"
)
// type SupportedIPVersion uint64
type Protocol uint64
const (
IP Protocol = iota + 1
UDP
TCP
TCPTLS
)
const TypeService string = "service"
const (
ProtoDNS = "dns"
ProtoDHCP = "dhcp"
ProtoEcho = "echo"
ProtoFTP = "ftp"
ProtoHTTP = "http"
ProtoHTTPS = "https"
ProtoHTTP2 = "http2"
ProtoIMAP = "imap"
ProtoIMAPS = "imaps"
ProtoIPMI = "ipmi"
ProtoIPSEC = "ipsec"
ProtoJDWP = "jdwp"
ProtoKafka = "kafka"
ProtoLDAP = "ldap"
ProtoLDAPS = "ldaps"
ProtoModbus = "modbus"
ProtoMQTT = "mqtt"
ProtoMSSQL = "mssql"
ProtoMySQL = "mysql"
ProtoNetbios = "netbios"
ProtoNTP = "ntp"
ProtoOracle = "oracle"
ProtoOpenVPN = "openvpn"
ProtoPOP3 = "pop3"
ProtoPOP3S = "pop3s"
ProtoPostgreSQL = "postgresql"
ProtoRDP = "rdp"
ProtoRPC = "rpc"
ProtoRedis = "redis"
ProtoRedisTLS = "redis"
ProtoRsync = "rsync"
ProtoRtsp = "rtsp"
ProtoSMB = "smb"
ProtoSMTP = "smtp"
ProtoSMTPS = "smtps"
ProtoSNMP = "snmp"
ProtoSSH = "ssh"
ProtoStun = "stun"
ProtoTelnet = "telnet"
ProtoVNC = "vnc"
ProtoUnknown = "unknown"
)
// Used as a key for maps to plugins.
// i.e.: map[Service] Plugin
type PluginID struct {
name string
protocol Protocol
}
type Metadata interface {
Type() string
}
func (e Service) Type() string { return TypeService }
func (e Service) Metadata() Metadata {
switch e.Protocol {
case ProtoFTP:
var p ServiceFTP
_ = json.Unmarshal(e.Raw, &p)
return p
case ProtoPostgreSQL:
var p ServicePostgreSQL
_ = json.Unmarshal(e.Raw, &p)
return p
case ProtoVNC:
var p ServiceVNC
_ = json.Unmarshal(e.Raw, &p)
return p
case ProtoTelnet:
var p ServiceTelnet
_ = json.Unmarshal(e.Raw, &p)
return p
case ProtoRedis:
var p ServiceRedis
_ = json.Unmarshal(e.Raw, &p)
return p
case ProtoHTTP:
var p ServiceHTTP
_ = json.Unmarshal(e.Raw, &p)
return p
case ProtoHTTPS:
var p ServiceHTTPS
_ = json.Unmarshal(e.Raw, &p)
return p
case ProtoHTTP2:
var p ServiceHTTP
_ = json.Unmarshal(e.Raw, &p)
return p
case ProtoSMB:
var p ServiceSMB
_ = json.Unmarshal(e.Raw, &p)
return p
case ProtoRDP:
var p ServiceRDP
_ = json.Unmarshal(e.Raw, &p)
return p
case ProtoRPC:
var p ServiceRPC
_ = json.Unmarshal(e.Raw, &p)
return p
case ProtoMSSQL:
var p ServiceMSSQL
_ = json.Unmarshal(e.Raw, &p)
return p
case ProtoNetbios:
var p ServiceNetbios
_ = json.Unmarshal(e.Raw, &p)
return p
case ProtoKafka:
var p ServiceKafka
_ = json.Unmarshal(e.Raw, &p)
return p
case ProtoOracle:
var p ServiceOracle
_ = json.Unmarshal(e.Raw, &p)
return p
case ProtoMySQL:
var p ServiceMySQL
_ = json.Unmarshal(e.Raw, &p)
return p
case ProtoSMTP:
var p ServiceSMTP
_ = json.Unmarshal(e.Raw, &p)
return p
case ProtoSMTPS:
var p ServiceSMTPS
_ = json.Unmarshal(e.Raw, &p)
return p
case ProtoLDAP:
var p ServiceLDAP
_ = json.Unmarshal(e.Raw, &p)
return p
case ProtoModbus:
var p ServiceModbus
_ = json.Unmarshal(e.Raw, &p)
return p
case ProtoLDAPS:
var p ServiceLDAPS
_ = json.Unmarshal(e.Raw, &p)
return p
case ProtoSSH:
var p ServiceSSH
_ = json.Unmarshal(e.Raw, &p)
return p
case ProtoIMAP:
var p ServiceIMAP
_ = json.Unmarshal(e.Raw, &p)
return p
case ProtoRsync:
var p ServiceRsync
_ = json.Unmarshal(e.Raw, &p)
return p
case ProtoRtsp:
var p ServiceRtsp
_ = json.Unmarshal(e.Raw, &p)
return p
case ProtoIMAPS:
var p ServiceIMAPS
_ = json.Unmarshal(e.Raw, &p)
return p
case ProtoMQTT:
var p ServiceMQTT
_ = json.Unmarshal(e.Raw, &p)
return p
case ProtoPOP3:
var p ServicePOP3
_ = json.Unmarshal(e.Raw, &p)
return p
case ProtoPOP3S:
var p ServicePOP3S
_ = json.Unmarshal(e.Raw, &p)
return p
default:
var p ServiceUnknown
_ = json.Unmarshal(e.Raw, &p)
return p
}
}
type ServiceUnknown map[string]any
func (e ServiceUnknown) Type() string { return ProtoUnknown }
func (e ServiceUnknown) Map() map[string]any { return e }
func CreateServiceFrom(target Target, m Metadata, tls bool, version string, transport Protocol) *Service {
service := Service{}
b, _ := json.Marshal(m)
service.Host = target.Host
service.IP = target.Address.Addr().String()
service.Port = int(target.Address.Port())
service.Protocol = m.Type()
service.Transport = strings.ToLower(transport.String())
service.Raw = json.RawMessage(b)
if version != "" {
service.Version = version
}
service.TLS = tls
return &service
}
type Target struct {
Address netip.AddrPort
Host string
}
type Plugin interface {
Run(net.Conn, time.Duration, Target) (*Service, error)
PortPriority(uint16) bool
Name() string
Type() Protocol
Priority() int
}
type Service struct {
Host string `json:"host,omitempty"`
IP string `json:"ip"`
Port int `json:"port"`
Protocol string `json:"protocol"`
TLS bool `json:"tls"`
Transport string `json:"transport"`
Version string `json:"version,omitempty"`
Raw json.RawMessage `json:"metadata"`
}
type ServiceHTTP struct {
Status string `json:"status"` // e.g. "200 OK"
StatusCode int `json:"statusCode"` // e.g. 200
ResponseHeaders http.Header `json:"responseHeaders"`
Technologies []string `json:"technologies,omitempty"`
}
func (e ServiceHTTP) Type() string { return ProtoHTTP }
type ServiceHTTPS struct {
Status string `json:"status"` // e.g. "200 OK"
StatusCode int `json:"statusCode"` // e.g. 200
ResponseHeaders http.Header `json:"responseHeaders"`
Technologies []string `json:"technologies,omitempty"`
}
func (e ServiceHTTPS) Type() string { return ProtoHTTPS }
type ServiceRDP struct {
OSFingerprint string `json:"fingerprint,omitempty"` // e.g. Windows Server 2016 or 2019
OSVersion string `json:"osVersion,omitempty"`
TargetName string `json:"targetName,omitempty"`
NetBIOSComputerName string `json:"netBIOSComputerName,omitempty"`
NetBIOSDomainName string `json:"netBIOSDomainName,omitempty"`
DNSComputerName string `json:"dnsComputerName,omitempty"`
DNSDomainName string `json:"dnsDomainName,omitempty"`
ForestName string `json:"forestName,omitempty"`
}
func (e ServiceRDP) Type() string { return ProtoRDP }
type ServiceRPC struct {
Entries []RPCB `json:"entries"`
}
type RPCB struct {
Program int `json:"program"`
Version int `json:"version"`
Protocol string `json:"protocol"`
Address string `json:"address"`
Owner string `json:"owner"`
}
func (e ServiceRPC) Type() string { return ProtoRPC }
type ServiceSMB struct {
SigningEnabled bool `json:"signingEnabled"` // e.g. Is SMB Signing Enabled?
SigningRequired bool `json:"signingRequired"` // e.g. Is SMB Signing Required?
OSVersion string `json:"osVersion"`
NetBIOSComputerName string `json:"netBIOSComputerName,omitempty"`
NetBIOSDomainName string `json:"netBIOSDomainName,omitempty"`
DNSComputerName string `json:"dnsComputerName,omitempty"`
DNSDomainName string `json:"dnsDomainName,omitempty"`
ForestName string `json:"forestName,omitempty"`
}
func (e ServiceSMB) Type() string { return ProtoSMB }
type ServiceMySQL struct {
PacketType string `json:"packetType"` // the type of packet returned by the server (i.e. handshake or error)
ErrorMessage string `json:"errorMsg"` // error message if the server returns an error packet
ErrorCode int `json:"errorCode"` // error code returned if the server returns an error packet
}
func (e ServiceMySQL) Type() string { return ProtoMySQL }
func (e ServicePostgreSQL) Type() string { return ProtoPostgreSQL }
type ServicePostgreSQL struct {
AuthRequired bool `json:"authRequired"`
}
type ServicePOP3 struct {
Banner string `json:"banner"`
}
func (e ServicePOP3) Type() string { return ProtoPOP3 }
type ServicePOP3S struct {
Banner string `json:"banner"`
}
func (e ServicePOP3S) Type() string { return ProtoPOP3S }
type ServiceSNMP struct{}
func (e ServiceSNMP) Type() string { return ProtoSNMP }
type ServiceNTP struct{}
func (e ServiceNTP) Type() string { return ProtoNTP }
type ServiceNetbios struct {
NetBIOSName string `json:"netBIOSName"`
}
func (e ServiceNetbios) Type() string { return ProtoNetbios }
type ServiceIMAP struct {
Banner string `json:"banner"`
}
func (e ServiceIMAP) Type() string { return ProtoIMAP }
type ServiceIMAPS struct {
Banner string `json:"banner"`
}
func (e ServiceIMAPS) Type() string { return ProtoIMAPS }
type ServiceIPSEC struct {
ResponderISP string `json:"responderISP"`
MessageID string `json:"messageID"`
}
func (e ServiceIPSEC) Type() string { return ProtoIPSEC }
type ServiceMSSQL struct {
}
func (e ServiceMSSQL) Type() string { return ProtoMSSQL }
type ServiceVNC struct{}
func (e ServiceVNC) Type() string { return ProtoVNC }
type ServiceTelnet struct {
ServerData string `json:"serverData"`
}
func (e ServiceTelnet) Type() string { return ProtoTelnet }
type ServiceRedis struct {
AuthRequired bool `json:"authRequired:"`
}
func (e ServiceRedis) Type() string { return ProtoRedis }
type ServiceFTP struct {
Banner string `json:"banner"`
AnonymousLogin bool `json:"anonymousLogin"`
}
func (e ServiceFTP) Type() string { return ProtoFTP }
type ServiceSMTP struct {
Banner string `json:"banner"`
AuthMethods []string `json:"auth_methods"`
}
func (e ServiceSMTP) Type() string { return ProtoSMTP }
type ServiceSMTPS struct {
Banner string `json:"banner"`
AuthMethods []string `json:"auth_methods"`
}
func (e ServiceSMTPS) Type() string { return ProtoSMTPS }
type ServiceStun struct {
Info string `json:"info"`
}
func (e ServiceStun) Type() string { return ProtoStun }
type ServiceSSH struct {
Banner string `json:"banner"`
PasswordAuthEnabled bool `json:"passwordAuthEnabled"`
Algo string `json:"algo"`
HostKey string `json:"hostKey,omitempty"`
HostKeyType string `json:"hostKeyType,omitempty"`
HostKeyFingerprint string `json:"hostKeyFingerprint,omitempty"`
}
func (e ServiceSSH) Type() string { return ProtoSSH }
type ServiceLDAP struct{}
func (e ServiceLDAP) Type() string { return ProtoLDAP }
type ServiceLDAPS struct{}
func (e ServiceLDAPS) Type() string { return ProtoLDAPS }
type ServiceKafka struct{}
func (e ServiceKafka) Type() string { return ProtoKafka }
type ServiceOracle struct {
Info string `json:"info"`
}
func (e ServiceOracle) Type() string { return ProtoOracle }
type ServiceOpenVPN struct{}
func (e ServiceOpenVPN) Type() string { return ProtoOpenVPN }
type ServiceMQTT struct{}
func (e ServiceMQTT) Type() string { return ProtoMQTT }
type ServiceModbus struct{}
func (e ServiceModbus) Type() string { return ProtoModbus }
type ServiceRtsp struct {
ServerInfo string `json:"serverInfo"`
}
func (e ServiceRtsp) Type() string { return ProtoRtsp }
type ServiceDNS struct{}
func (e ServiceDNS) Type() string { return ProtoDNS }
type ServiceDHCP struct {
Option string `json:"option"`
}
func (e ServiceDHCP) Type() string { return ProtoDHCP }
type ServiceEcho struct{}
func (e ServiceEcho) Type() string { return ProtoEcho }
type ServiceIPMI struct{}
func (e ServiceIPMI) Type() string { return ProtoIPMI }
type ServiceRsync struct{}
func (e ServiceRsync) Type() string { return ProtoRsync }
type ServiceJDWP struct {
Description string `json:"description"`
JdwpMajor int32 `json:"jdwpMajor"`
JdwpMinor int32 `json:"jdwpMinor"`
VMVersion string `json:"VMVersion"`
VMName string `json:"VMName"`
}
func (e ServiceJDWP) Type() string { return ProtoJDWP }