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)
|
|
|
|
}
|
|
|
|
|
|
|
|
ms := matcher.GetUDPMatchers()
|
|
|
|
mi := osm.NewMatchInfo(targetPort.Host.Address, portNumber)
|
|
|
|
|
|
|
|
for i := 0; i < len(ms); i++ {
|
|
|
|
m := ms[i]
|
|
|
|
p := osm.NewPacket(targetPort.UDPLayer.LayerPayload(), len(targetPort.UDPLayer.LayerPayload()))
|
|
|
|
|
|
|
|
if err := m.Match(mi, 0, p); err == nil {
|
|
|
|
s := &omd.Service{
|
|
|
|
Key: m.Key(),
|
|
|
|
Port: targetPort,
|
|
|
|
MetaCryptoType: omm.ToMetaCryptoType(omm.MetaCryptoTypeEnumNONE),
|
|
|
|
DiscoveredDate: omu.NowPtr(),
|
|
|
|
Metadata: m.Meta(),
|
|
|
|
Name: m.Name(),
|
|
|
|
}
|
|
|
|
|
|
|
|
discoverySession.AddService(s)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
2018-08-31 10:53:33 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|