probe/discovery/target/service/service-udp.go

58 lines
1.5 KiB
Go
Raw Normal View History

2018-08-31 10:53:33 +00:00
package service
import (
2018-09-03 04:44:54 +00:00
"fmt"
2018-08-31 10:53:33 +00:00
omd "git.loafle.net/overflow/model/discovery"
2018-09-03 04:44:54 +00:00
omm "git.loafle.net/overflow/model/meta"
omu "git.loafle.net/overflow/model/util"
osm "git.loafle.net/overflow/service_matcher-go"
ouej "git.loafle.net/overflow/util-go/encoding/json"
2018-08-31 10:53:33 +00:00
"git.loafle.net/overflow_scanner/probe/discovery/session"
2018-09-03 04:44:54 +00:00
"git.loafle.net/overflow_scanner/probe/internal/matcher"
2018-08-31 10:53:33 +00:00
)
func scanUDP(discoverySession session.DiscoverySession, targetPort *omd.Port) error {
2018-09-03 04:44:54 +00:00
portNumber, err := ouej.NumberToInt(targetPort.PortNumber)
if err != nil {
return fmt.Errorf("Service scan port[%s] error %v ", targetPort.PortNumber, err)
}
2018-09-03 10:33:20 +00:00
matchers := matcher.GetUDPMatchers()
2018-09-03 14:01:54 +00:00
matchCtx := osm.NewMatchCtx(targetPort.Host.Address, portNumber)
2018-09-03 04:44:54 +00:00
2018-09-03 10:33:20 +00:00
for _, _matcher := range matchers {
2018-09-03 04:44:54 +00:00
p := osm.NewPacket(targetPort.UDPLayer.LayerPayload(), len(targetPort.UDPLayer.LayerPayload()))
2018-09-03 14:01:54 +00:00
if err := _matcher.Match(matchCtx, 0, p); err == nil {
2018-09-12 04:55:51 +00:00
s := omd.NewService(
targetPort,
omm.ToMetaCryptoType(omm.MetaCryptoTypeEnumNONE),
_matcher.Key(),
)
s.Name = _matcher.Name(matchCtx)
s.ServiceType = _matcher.Type()
s.ServiceVendor = _matcher.Vendor(matchCtx)
s.ServiceVersion = _matcher.Version(matchCtx)
s.DiscoveredDate = omu.NowPtr()
discoverySession.AddService(
2018-09-17 14:18:49 +00:00
omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumUDPMatcher),
2018-09-12 04:55:51 +00:00
s,
matchCtx.GetAttributes(),
)
2018-09-03 04:44:54 +00:00
return nil
}
2018-09-03 10:33:20 +00:00
select {
case <-discoverySession.StopChan():
return nil
default:
}
2018-09-03 04:44:54 +00:00
}
2018-08-31 10:53:33 +00:00
return nil
}