This commit is contained in:
crusader 2018-09-17 23:18:49 +09:00
parent 10be32e2b4
commit b3e58106a9
17 changed files with 78 additions and 50 deletions

View File

@ -52,7 +52,7 @@ func Scan(discoverySession session.DiscoverySession) error {
} }
delay.Store(true) delay.Store(true)
if h := handlePacketARP(zone, targetHosts, hosts, packet); nil != h { if h := handlePacketARP(zone, targetHosts, hosts, packet); nil != h {
go discoverySession.AddHost("ARP", h, nil) go discoverySession.AddHost(omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumARP), h, nil)
} }
case <-ticker.C: case <-ticker.C:
if false == delay.Load().(bool) { if false == delay.Load().(bool) {

View File

@ -65,7 +65,7 @@ func scanV4(discoverySession session.DiscoverySession) error {
} }
delay.Store(true) delay.Store(true)
if h := handlePacketICMP4(zone, targetHosts, hosts, packet); nil != h { if h := handlePacketICMP4(zone, targetHosts, hosts, packet); nil != h {
go discoverySession.AddHost("ICMP", h, nil) go discoverySession.AddHost(omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumICMP), h, nil)
} }
case <-ticker.C: case <-ticker.C:
if false == delay.Load().(bool) { if false == delay.Load().(bool) {

View File

@ -54,7 +54,7 @@ func scanV6(discoverySession session.DiscoverySession) error {
} }
delay.Store(true) delay.Store(true)
if h := handlePacketICMP6(zone, targetHosts, hosts, packet); nil != h { if h := handlePacketICMP6(zone, targetHosts, hosts, packet); nil != h {
go discoverySession.AddHost("ICMP", h, nil) go discoverySession.AddHost(omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumICMP), h, nil)
} }
case <-ticker.C: case <-ticker.C:
if false == delay.Load().(bool) { if false == delay.Load().(bool) {

View File

@ -73,7 +73,7 @@ SERVICE_LOOP:
h.DiscoveredDate = omu.NowPtr() h.DiscoveredDate = omu.NowPtr()
h = discoverySession.AddHost( h = discoverySession.AddHost(
"mDNS", omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumMDNS),
h, h,
meta, meta,
) )
@ -90,7 +90,7 @@ SERVICE_LOOP:
p.DiscoveredDate = omu.NowPtr() p.DiscoveredDate = omu.NowPtr()
p = discoverySession.AddPort( p = discoverySession.AddPort(
"mDNS", omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumMDNS),
p, p,
meta, meta,
) )
@ -104,7 +104,7 @@ SERVICE_LOOP:
s.DiscoveredDate = omu.NowPtr() s.DiscoveredDate = omu.NowPtr()
discoverySession.AddService( discoverySession.AddService(
"mDNS", omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumMDNS),
s, s,
meta, meta,
) )
@ -121,7 +121,7 @@ SERVICE_LOOP:
h.DiscoveredDate = omu.NowPtr() h.DiscoveredDate = omu.NowPtr()
h = discoverySession.AddHost( h = discoverySession.AddHost(
"mDNS", omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumMDNS),
h, h,
meta, meta,
) )
@ -138,7 +138,7 @@ SERVICE_LOOP:
p.DiscoveredDate = omu.NowPtr() p.DiscoveredDate = omu.NowPtr()
p = discoverySession.AddPort( p = discoverySession.AddPort(
"mDNS", omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumMDNS),
p, p,
meta, meta,
) )
@ -152,7 +152,7 @@ SERVICE_LOOP:
s.DiscoveredDate = omu.NowPtr() s.DiscoveredDate = omu.NowPtr()
discoverySession.AddService( discoverySession.AddService(
"mDNS", omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumMDNS),
s, s,
meta, meta,
) )

View File

@ -151,7 +151,7 @@ func scanV2(target net.IP, discoverySession session.DiscoverySession, credential
h.DiscoveredDate = omu.NowPtr() h.DiscoveredDate = omu.NowPtr()
h = discoverySession.AddHost( h = discoverySession.AddHost(
"SNMP V2c", omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumSNMP),
h, h,
meta, meta,
) )
@ -164,7 +164,7 @@ func scanV2(target net.IP, discoverySession session.DiscoverySession, credential
p.DiscoveredDate = omu.NowPtr() p.DiscoveredDate = omu.NowPtr()
p = discoverySession.AddPort( p = discoverySession.AddPort(
"SNMP V2c", omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumSNMP),
p, p,
meta, meta,
) )
@ -180,7 +180,7 @@ func scanV2(target net.IP, discoverySession session.DiscoverySession, credential
s.DiscoveredDate = omu.NowPtr() s.DiscoveredDate = omu.NowPtr()
discoverySession.AddService( discoverySession.AddService(
"SNMP V2c", omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumSNMP),
s, s,
meta, meta,
) )

View File

@ -101,7 +101,7 @@ func tryConnect(discoverySession session.DiscoverySession, ports map[int]*omd.Po
ports[port] = p ports[port] = p
go discoverySession.AddPort("TCP Connection", p, nil) go discoverySession.AddPort(omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumTCPConnection), p, nil)
} }
func Ulimit() int64 { func Ulimit() int64 {

View File

@ -54,7 +54,7 @@ func scanV4(discoverySession session.DiscoverySession, targetHost *omd.Host) err
} }
delay.Store(true) delay.Store(true)
if p := handlePacketTCP4(discoverySession, targetHost, ports, packet); nil != p { if p := handlePacketTCP4(discoverySession, targetHost, ports, packet); nil != p {
go discoverySession.AddPort("TCP SYN", p, nil) go discoverySession.AddPort(omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumTCPSyn), p, nil)
} }
case <-ticker.C: case <-ticker.C:
if false == delay.Load().(bool) { if false == delay.Load().(bool) {

View File

@ -101,7 +101,7 @@ func tryConnect(discoverySession session.DiscoverySession, ports map[int]*omd.Po
ports[port] = p ports[port] = p
go discoverySession.AddPort("UDP Connection", p, nil) go discoverySession.AddPort(omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumUDPConnection), p, nil)
} }
func Ulimit() int64 { func Ulimit() int64 {

View File

@ -45,7 +45,7 @@ func scanV4(discoverySession session.DiscoverySession, targetHost *omd.Host) err
} }
delay.Store(true) delay.Store(true)
if p := handlePacketUDP4(discoverySession, targetHost, ports, packet); nil != p { if p := handlePacketUDP4(discoverySession, targetHost, ports, packet); nil != p {
go discoverySession.AddPort("UDP Matcher", p, nil) go discoverySession.AddPort(omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumUDPMatcher), p, nil)
} }
case <-ticker.C: case <-ticker.C:
if false == delay.Load().(bool) { if false == delay.Load().(bool) {

View File

@ -75,7 +75,7 @@ LOOP:
h.DiscoveredDate = omu.NowPtr() h.DiscoveredDate = omu.NowPtr()
discoverySession.AddHost( discoverySession.AddHost(
"UPnP", omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumUPnP),
h, h,
meta, meta,
) )
@ -93,7 +93,7 @@ LOOP:
p.DiscoveredDate = omu.NowPtr() p.DiscoveredDate = omu.NowPtr()
p = discoverySession.AddPort( p = discoverySession.AddPort(
"UPnP", omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumUPnP),
p, p,
meta, meta,
) )
@ -123,7 +123,7 @@ LOOP:
s.DiscoveredDate = omu.NowPtr() s.DiscoveredDate = omu.NowPtr()
discoverySession.AddService( discoverySession.AddService(
"UPnP", omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumUPnP),
s, s,
meta, meta,
) )

View File

@ -43,10 +43,10 @@ type DiscoverySession interface {
SetDiscoveryDelegator(chan<- interface{}) SetDiscoveryDelegator(chan<- interface{})
AddHost(discoveredBy string, host *omd.Host, meta map[string]string) *omd.Host AddHost(discoveredBy *omm.MetaDiscovererType, host *omd.Host, meta map[string]string) *omd.Host
AddPort(discoveredBy string, port *omd.Port, meta map[string]string) *omd.Port AddPort(discoveredBy *omm.MetaDiscovererType, port *omd.Port, meta map[string]string) *omd.Port
AddService(discoveredBy string, service *omd.Service, meta map[string]string) *omd.Service AddService(discoveredBy *omm.MetaDiscovererType, service *omd.Service, meta map[string]string) *omd.Service
AddServiceUnknown(discoveredBy string, port *omd.Port) *omd.Service AddServiceUnknown(discoveredBy *omm.MetaDiscovererType, port *omd.Port) *omd.Service
DiscoveredHost(address string) *omd.Host DiscoveredHost(address string) *omd.Host
DiscoveredAllHosts(includeMac bool) map[string]*omd.Host DiscoveredAllHosts(includeMac bool) map[string]*omd.Host
@ -296,7 +296,7 @@ func (ds *ofDiscoverySession) IsTargetService(service *omd.Service) bool {
return true return true
} }
func (ds *ofDiscoverySession) AddHost(discoveredBy string, host *omd.Host, meta map[string]string) *omd.Host { func (ds *ofDiscoverySession) AddHost(discoveredBy *omm.MetaDiscovererType, host *omd.Host, meta map[string]string) *omd.Host {
ds.discoveredMtx.Lock() ds.discoveredMtx.Lock()
defer ds.discoveredMtx.Unlock() defer ds.discoveredMtx.Unlock()
@ -351,7 +351,7 @@ func (ds *ofDiscoverySession) AddHost(discoveredBy string, host *omd.Host, meta
return h return h
} }
func (ds *ofDiscoverySession) AddPort(discoveredBy string, port *omd.Port, meta map[string]string) *omd.Port { func (ds *ofDiscoverySession) AddPort(discoveredBy *omm.MetaDiscovererType, port *omd.Port, meta map[string]string) *omd.Port {
ds.discoveredMtx.Lock() ds.discoveredMtx.Lock()
defer ds.discoveredMtx.Unlock() defer ds.discoveredMtx.Unlock()
@ -376,7 +376,7 @@ func (ds *ofDiscoverySession) AddPort(discoveredBy string, port *omd.Port, meta
return p return p
} }
func (ds *ofDiscoverySession) AddService(discoveredBy string, service *omd.Service, meta map[string]string) *omd.Service { func (ds *ofDiscoverySession) AddService(discoveredBy *omm.MetaDiscovererType, service *omd.Service, meta map[string]string) *omd.Service {
ds.discoveredMtx.Lock() ds.discoveredMtx.Lock()
defer ds.discoveredMtx.Unlock() defer ds.discoveredMtx.Unlock()
@ -421,7 +421,7 @@ func (ds *ofDiscoverySession) AddService(discoveredBy string, service *omd.Servi
return s return s
} }
func (ds *ofDiscoverySession) AddServiceUnknown(discoveredBy string, port *omd.Port) *omd.Service { func (ds *ofDiscoverySession) AddServiceUnknown(discoveredBy *omm.MetaDiscovererType, port *omd.Port) *omd.Service {
if nil == ds.DiscoveredServices(port) { if nil == ds.DiscoveredServices(port) {
s := omd.NewService( s := omd.NewService(
port, port,
@ -651,7 +651,7 @@ func (ds *ofDiscoverySession) findService(service *omd.Service) (s *omd.Service,
return return
} }
func (ds *ofDiscoverySession) addtionalHost(discoveredBy string, host *omd.Host) (h *omd.Host, modified bool) { func (ds *ofDiscoverySession) addtionalHost(discoveredBy *omm.MetaDiscovererType, host *omd.Host) (h *omd.Host, modified bool) {
h = host h = host
modified = false modified = false
@ -659,13 +659,13 @@ func (ds *ofDiscoverySession) addtionalHost(discoveredBy string, host *omd.Host)
return return
} }
meta, ok := host.Meta[discoveredBy] meta, ok := host.Meta[discoveredBy.Key]
if !ok || nil == meta || 0 == len(meta) { if !ok || nil == meta || 0 == len(meta) {
return return
} }
switch discoveredBy { switch omm.ToMetaDiscovererTypeEnum(discoveredBy) {
case "mDNS": case omm.MetaDiscovererTypeEnumMDNS:
_h, _modified := ds.addtionalHostMDNS(h, meta) _h, _modified := ds.addtionalHostMDNS(h, meta)
if _modified { if _modified {
h = _h h = _h
@ -698,7 +698,7 @@ func (ds *ofDiscoverySession) addtionalHostMDNS(host *omd.Host, meta map[string]
return return
} }
func (ds *ofDiscoverySession) addtionalService(discoveredBy string, service *omd.Service) (s *omd.Service, modified bool) { func (ds *ofDiscoverySession) addtionalService(discoveredBy *omm.MetaDiscovererType, service *omd.Service) (s *omd.Service, modified bool) {
s = service s = service
modified = false modified = false
@ -706,13 +706,13 @@ func (ds *ofDiscoverySession) addtionalService(discoveredBy string, service *omd
return return
} }
meta, ok := service.Meta[discoveredBy] meta, ok := service.Meta[discoveredBy.Key]
if !ok || nil == meta || 0 == len(meta) { if !ok || nil == meta || 0 == len(meta) {
return return
} }
switch discoveredBy { switch omm.ToMetaDiscovererTypeEnum(discoveredBy) {
case "mDNS": case omm.MetaDiscovererTypeEnumMDNS:
_s, _modified := ds.addtionalServiceMDNS(s, meta) _s, _modified := ds.addtionalServiceMDNS(s, meta)
if _modified { if _modified {
s = _s s = _s
@ -753,16 +753,16 @@ func (ds *ofDiscoverySession) addtionalServiceMDNS(service *omd.Service, meta ma
return return
} }
func (ds *ofDiscoverySession) appendDiscoveredBy(discoveredBy string, oriDiscoveredBy []string) (resultDiscoveredBy []string, modified bool) { func (ds *ofDiscoverySession) appendDiscoveredBy(discoveredBy *omm.MetaDiscovererType, oriDiscoveredBy []*omm.MetaDiscovererType) (resultDiscoveredBy []*omm.MetaDiscovererType, modified bool) {
modified = false modified = false
if "" == discoveredBy { if "" == discoveredBy.Key {
resultDiscoveredBy = oriDiscoveredBy resultDiscoveredBy = oriDiscoveredBy
return return
} }
if nil == oriDiscoveredBy { if nil == oriDiscoveredBy {
resultDiscoveredBy = []string{ resultDiscoveredBy = []*omm.MetaDiscovererType{
discoveredBy, discoveredBy,
} }
modified = true modified = true
@ -783,7 +783,7 @@ func (ds *ofDiscoverySession) appendDiscoveredBy(discoveredBy string, oriDiscove
return return
} }
func (ds *ofDiscoverySession) appendMeta(discoveredBy string, oriMetas map[string]map[string]string, newMeta map[string]string) (resultMetas map[string]map[string]string, modified bool) { func (ds *ofDiscoverySession) appendMeta(discoveredBy *omm.MetaDiscovererType, oriMetas map[string]map[string]string, newMeta map[string]string) (resultMetas map[string]map[string]string, modified bool) {
modified = false modified = false
if nil == newMeta || 0 == len(newMeta) { if nil == newMeta || 0 == len(newMeta) {
resultMetas = oriMetas resultMetas = oriMetas
@ -792,15 +792,15 @@ func (ds *ofDiscoverySession) appendMeta(discoveredBy string, oriMetas map[strin
if nil == oriMetas { if nil == oriMetas {
resultMetas = map[string]map[string]string{ resultMetas = map[string]map[string]string{
discoveredBy: newMeta, discoveredBy.Key: newMeta,
} }
modified = true modified = true
return return
} }
oriMeta, ok := oriMetas[discoveredBy] oriMeta, ok := oriMetas[discoveredBy.Key]
if !ok { if !ok {
oriMetas[discoveredBy] = newMeta oriMetas[discoveredBy.Key] = newMeta
resultMetas = oriMetas resultMetas = oriMetas
return return
} }

View File

@ -5,6 +5,7 @@ import (
"log" "log"
omd "git.loafle.net/overflow/model/discovery" omd "git.loafle.net/overflow/model/discovery"
omm "git.loafle.net/overflow/model/meta"
"git.loafle.net/overflow_scanner/probe/discovery/types" "git.loafle.net/overflow_scanner/probe/discovery/types"
) )
@ -24,19 +25,19 @@ type mockDiscoverySession struct {
ofDiscoverySession ofDiscoverySession
} }
func (ds *mockDiscoverySession) AddHost(discoveredBy string, host *omd.Host, meta map[string]string) *omd.Host { func (ds *mockDiscoverySession) AddHost(discoveredBy *omm.MetaDiscovererType, host *omd.Host, meta map[string]string) *omd.Host {
b, _ := json.Marshal(host) b, _ := json.Marshal(host)
log.Print("Host: ", string(b)) log.Print("Host: ", string(b))
return ds.ofDiscoverySession.AddHost(discoveredBy, host, meta) return ds.ofDiscoverySession.AddHost(discoveredBy, host, meta)
} }
func (ds *mockDiscoverySession) AddPort(discoveredBy string, port *omd.Port, meta map[string]string) *omd.Port { func (ds *mockDiscoverySession) AddPort(discoveredBy *omm.MetaDiscovererType, port *omd.Port, meta map[string]string) *omd.Port {
b, _ := json.Marshal(port) b, _ := json.Marshal(port)
log.Print("Port: ", string(b)) log.Print("Port: ", string(b))
return ds.ofDiscoverySession.AddPort(discoveredBy, port, meta) return ds.ofDiscoverySession.AddPort(discoveredBy, port, meta)
} }
func (ds *mockDiscoverySession) AddService(discoveredBy string, service *omd.Service, meta map[string]string) *omd.Service { func (ds *mockDiscoverySession) AddService(discoveredBy *omm.MetaDiscovererType, service *omd.Service, meta map[string]string) *omd.Service {
b, _ := json.Marshal(service) b, _ := json.Marshal(service)
log.Print("Service: ", string(b)) log.Print("Service: ", string(b))
return ds.ofDiscoverySession.AddService(discoveredBy, service, meta) return ds.ofDiscoverySession.AddService(discoveredBy, service, meta)

View File

@ -6,6 +6,7 @@ import (
"time" "time"
omd "git.loafle.net/overflow/model/discovery" omd "git.loafle.net/overflow/model/discovery"
omm "git.loafle.net/overflow/model/meta"
omu "git.loafle.net/overflow/model/util" omu "git.loafle.net/overflow/model/util"
osm "git.loafle.net/overflow/service_matcher-go" osm "git.loafle.net/overflow/service_matcher-go"
ouej "git.loafle.net/overflow/util-go/encoding/json" ouej "git.loafle.net/overflow/util-go/encoding/json"
@ -89,13 +90,13 @@ LOOP:
s.DiscoveredDate = omu.NowPtr() s.DiscoveredDate = omu.NowPtr()
discoverySession.AddService( discoverySession.AddService(
"Service Matcher", omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumTCPMatcher),
s, s,
matchCtx.GetAttributes(), matchCtx.GetAttributes(),
) )
} else { } else {
discoverySession.AddServiceUnknown( discoverySession.AddServiceUnknown(
"Service Matcher", omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumTCPMatcher),
targetPort, targetPort,
) )
} }

View File

@ -37,7 +37,7 @@ func scanUDP(discoverySession session.DiscoverySession, targetPort *omd.Port) er
s.DiscoveredDate = omu.NowPtr() s.DiscoveredDate = omu.NowPtr()
discoverySession.AddService( discoverySession.AddService(
"Service Matcher", omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumUDPMatcher),
s, s,
matchCtx.GetAttributes(), matchCtx.GetAttributes(),
) )

12
ping/host/host.go Normal file
View File

@ -0,0 +1,12 @@
package host
import (
omcp "git.loafle.net/overflow/model/config/ping"
omd "git.loafle.net/overflow/model/discovery"
ounp "git.loafle.net/overflow/util-go/net/ping"
)
func Ping(host *omd.Host, pingOption omcp.Option) (omcp.Result, error) {
return ounp.Ping(host.Address, pingOption)
}

11
ping/service/service.go Normal file
View File

@ -0,0 +1,11 @@
package service
import (
omcp "git.loafle.net/overflow/model/config/ping"
omd "git.loafle.net/overflow/model/discovery"
)
func Ping(service *omd.Service, pingOption *omcp.PingOption) (*omcp.PingResult, error) {
return nil, nil
}

View File

@ -5,6 +5,8 @@ import (
oa "git.loafle.net/overflow/annotation-go" oa "git.loafle.net/overflow/annotation-go"
od "git.loafle.net/overflow/di-go" od "git.loafle.net/overflow/di-go"
omcp "git.loafle.net/overflow/model/config/ping"
omd "git.loafle.net/overflow/model/discovery"
) )
func init() { func init() {
@ -27,11 +29,12 @@ func (s *PingService) InitService() {
func (s *PingService) DestroyService() { func (s *PingService) DestroyService() {
} }
func (s *PingService) PingHost() error {
func (s *PingService) PingHost(host *omd.Host, pingOption *omcp.PingOption) error {
return nil return nil
} }
func (s *PingService) PingService() error { func (s *PingService) PingService(host *omd.Service, pingOption *omcp.PingOption) error {
return nil return nil
} }