probe/discovery/target/service/service-udp.go
crusader b3e58106a9 ing
2018-09-17 23:18:49 +09:00

58 lines
1.5 KiB
Go

package service
import (
"fmt"
omd "git.loafle.net/overflow/model/discovery"
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"
"git.loafle.net/overflow_scanner/probe/discovery/session"
"git.loafle.net/overflow_scanner/probe/internal/matcher"
)
func scanUDP(discoverySession session.DiscoverySession, targetPort *omd.Port) error {
portNumber, err := ouej.NumberToInt(targetPort.PortNumber)
if err != nil {
return fmt.Errorf("Service scan port[%s] error %v ", targetPort.PortNumber, err)
}
matchers := matcher.GetUDPMatchers()
matchCtx := osm.NewMatchCtx(targetPort.Host.Address, portNumber)
for _, _matcher := range matchers {
p := osm.NewPacket(targetPort.UDPLayer.LayerPayload(), len(targetPort.UDPLayer.LayerPayload()))
if err := _matcher.Match(matchCtx, 0, p); err == nil {
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(
omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumUDPMatcher),
s,
matchCtx.GetAttributes(),
)
return nil
}
select {
case <-discoverySession.StopChan():
return nil
default:
}
}
return nil
}