From a0c0fefa8df50ad5c688d4aa47b0aba6c2e07289 Mon Sep 17 00:00:00 2001 From: crusader Date: Mon, 4 Dec 2017 15:30:56 +0900 Subject: [PATCH] ing --- modules/discovery/model/DiscoveryHost.go | 10 +++++++ modules/discovery/model/DiscoveryPort.go | 28 +++++++++++++++++++ modules/discovery/model/DiscoveryService.go | 6 ++++ modules/discovery/model/DiscoveryZone.go | 7 +++++ modules/discovery/model/Host.go | 18 ++++++++++++ modules/discovery/model/Port.go | 21 ++++++++++++++ modules/discovery/model/Service.go | 17 +++++++++++ modules/discovery/model/Zone.go | 20 +++++++++++++ .../service/discovery/DiscoveryService.go | 13 +++++++++ .../service/probe/DiscoveryService.go | 19 +++++++++++++ 10 files changed, 159 insertions(+) create mode 100644 modules/discovery/model/DiscoveryHost.go create mode 100644 modules/discovery/model/DiscoveryPort.go create mode 100644 modules/discovery/model/DiscoveryService.go create mode 100644 modules/discovery/model/DiscoveryZone.go create mode 100644 modules/discovery/model/Host.go create mode 100644 modules/discovery/model/Port.go create mode 100644 modules/discovery/model/Service.go create mode 100644 modules/discovery/model/Zone.go create mode 100644 modules/discovery/service/discovery/DiscoveryService.go create mode 100644 modules/discovery/service/probe/DiscoveryService.go diff --git a/modules/discovery/model/DiscoveryHost.go b/modules/discovery/model/DiscoveryHost.go new file mode 100644 index 0000000..691b419 --- /dev/null +++ b/modules/discovery/model/DiscoveryHost.go @@ -0,0 +1,10 @@ +package model + +type DiscoveryHost struct { + FirstScanRange string `json:"firstScanRange,omitempty"` + LastScanRange string `json:"lastScanRange,omitempty"` + ExcludeHosts []string `json:"excludeHosts,omitempty"` + IncludeHosts []string `json:"includeHosts,omitempty"` + + DiscoveryPort *DiscoveryPort `json:"discoveryPort,omitempty"` +} diff --git a/modules/discovery/model/DiscoveryPort.go b/modules/discovery/model/DiscoveryPort.go new file mode 100644 index 0000000..1368116 --- /dev/null +++ b/modules/discovery/model/DiscoveryPort.go @@ -0,0 +1,28 @@ +package model + +type DiscoveryPort struct { + FirstScanRange int `json:"firstScanRange,omitempty"` + LastScanRange int `json:"lastScanRange,omitempty"` + ExcludePorts []int `json:"excludePorts,omitempty"` + + IncludeTCP bool `json:"includeTCP,omitempty"` + IncludeUDP bool `json:"includeUDP,omitempty"` + + DiscoveryService *DiscoveryService `json:"discoveryService,omitempty"` +} + +func (dp *DiscoveryPort) Contains(port int) bool { + if dp.FirstScanRange > port { + return false + } + if dp.LastScanRange < port { + return false + } + for _, p := range dp.ExcludePorts { + if p == port { + return false + } + } + + return true +} diff --git a/modules/discovery/model/DiscoveryService.go b/modules/discovery/model/DiscoveryService.go new file mode 100644 index 0000000..4181550 --- /dev/null +++ b/modules/discovery/model/DiscoveryService.go @@ -0,0 +1,6 @@ +package model + + +type DiscoveryService struct { + IncludeServices []string `json:"includeServices,omitempty"` +} diff --git a/modules/discovery/model/DiscoveryZone.go b/modules/discovery/model/DiscoveryZone.go new file mode 100644 index 0000000..90b8bac --- /dev/null +++ b/modules/discovery/model/DiscoveryZone.go @@ -0,0 +1,7 @@ +package model + +type DiscoveryZone struct { + ExcludePatterns []string `json:"excludePatterns,omitempty"` + + DiscoveryHost *DiscoveryHost `json:"discoveryHost,omitempty"` +} diff --git a/modules/discovery/model/Host.go b/modules/discovery/model/Host.go new file mode 100644 index 0000000..41af745 --- /dev/null +++ b/modules/discovery/model/Host.go @@ -0,0 +1,18 @@ +package model + +import ( + "encoding/json" + + "git.loafle.net/overflow/overflow_commons_go/util" +) + +type Host struct { + Zone *Zone `json:"zone"` + + ID json.Number `json:"id,Number,omitempty"` + IP string `json:"ip,omitempty"` + Mac string `json:"mac,omitempty"` + OS string `json:"os,omitempty"` + + DiscoveredDate util.Timestamp `json:"discoveredDate,omitempty"` +} diff --git a/modules/discovery/model/Port.go b/modules/discovery/model/Port.go new file mode 100644 index 0000000..0ec5b85 --- /dev/null +++ b/modules/discovery/model/Port.go @@ -0,0 +1,21 @@ +package model + +import ( + "encoding/json" + + "github.com/google/gopacket" + + util "git.loafle.net/overflow/overflow_commons_go/util" +) + +type Port struct { + Host *Host `json:"host,omitempty"` + + ID json.Number `json:"id,Number,omitempty"` + PortType string `json:"portType,omitempty"` + PortNumber json.Number `json:"portNumber,omitempty"` + + DiscoveredDate util.Timestamp `json:"discoveredDate,omitempty"` + + UDPLayer gopacket.Layer `json:"-"` +} diff --git a/modules/discovery/model/Service.go b/modules/discovery/model/Service.go new file mode 100644 index 0000000..5f67d86 --- /dev/null +++ b/modules/discovery/model/Service.go @@ -0,0 +1,17 @@ +package model + +import ( + "encoding/json" + + util "git.loafle.net/overflow/overflow_commons_go/util" +) + +type Service struct { + Port *Port `json:"port,omitempty"` + + ID json.Number `json:"id,Number,omitempty"` + CryptoType string `json:"cryptoType,omitempty"` + ServiceName string `json:"serviceName,omitempty"` + + DiscoveredDate util.Timestamp `json:"discoveredDate,omitempty"` +} diff --git a/modules/discovery/model/Zone.go b/modules/discovery/model/Zone.go new file mode 100644 index 0000000..0049cda --- /dev/null +++ b/modules/discovery/model/Zone.go @@ -0,0 +1,20 @@ +package model + +import ( + "encoding/json" + "sync" + + "git.loafle.net/overflow/overflow_commons_go/util" +) + +type Zone struct { + ID json.Number `json:"id,Number,omitempty"` + Network string `json:"network,omitempty"` + IP string `json:"ip,omitempty"` + Iface string `json:"iface,omitempty"` + Mac string `json:"mac,omitempty"` + + DiscoveredDate util.Timestamp `json:"discoveredDate,omitempty"` + + mtx sync.RWMutex `json:"-"` +} diff --git a/modules/discovery/service/discovery/DiscoveryService.go b/modules/discovery/service/discovery/DiscoveryService.go new file mode 100644 index 0000000..183ae2c --- /dev/null +++ b/modules/discovery/service/discovery/DiscoveryService.go @@ -0,0 +1,13 @@ +package discovery + +import ( + discoveryM "git.loafle.net/overflow/overflow_commons_go/modules/discovery/model" +) + +type DiscoveryService interface { + // use by probe + DiscoverZone(dz *discoveryM.DiscoveryZone) error + DiscoverHost(zone *discoveryM.Zone, dz *discoveryM.DiscoveryHost) error + DiscoverPort(host *discoveryM.Host, dz *discoveryM.DiscoveryPort) error + DiscoverService(port *discoveryM.Port, dz *discoveryM.DiscoveryService) error +} diff --git a/modules/discovery/service/probe/DiscoveryService.go b/modules/discovery/service/probe/DiscoveryService.go new file mode 100644 index 0000000..1f5ccc0 --- /dev/null +++ b/modules/discovery/service/probe/DiscoveryService.go @@ -0,0 +1,19 @@ +package probe + +import ( + discoveryM "git.loafle.net/overflow/overflow_commons_go/modules/discovery/model" +) + +type DiscoveryService interface { + // use by central + DiscoverZone(dz *discoveryM.DiscoveryZone) error + DiscoverHost(zone *discoveryM.Zone, dz *discoveryM.DiscoveryHost) error + DiscoverPort(host *discoveryM.Host, dz *discoveryM.DiscoveryPort) error + DiscoverService(port *discoveryM.Port, dz *discoveryM.DiscoveryService) error + + // use by discovery + DiscoveredZone(zone *discoveryM.Zone) + DiscoveredHost(host *discoveryM.Host) + DiscoveredPort(port *discoveryM.Port) + DiscoveredService(service *discoveryM.Service) +}