45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
package ipv4
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
cuej "git.loafle.net/commons/util-go/encoding/json"
|
|
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"
|
|
"git.loafle.net/overflow_scanner/probe/matcher"
|
|
)
|
|
|
|
func scanServiceUDP(port *omd.Port, ds *omd.DiscoverService, resultChan chan interface{}, errChan chan error, stopChan chan struct{}) bool {
|
|
portNumber, err := cuej.NumberToInt(port.PortNumber)
|
|
if err != nil {
|
|
errChan <- fmt.Errorf("Discovery: Service scan port[%s] error %v ", port.PortNumber, err)
|
|
return false
|
|
}
|
|
|
|
ms := matcher.GetUDPMatchers()
|
|
mi := osm.NewMatchInfo(port.Host.Address, portNumber)
|
|
|
|
for i := 0; i < len(ms); i++ {
|
|
m := ms[i]
|
|
p := osm.NewPacket(port.UDPLayer.LayerPayload(), len(port.UDPLayer.LayerPayload()))
|
|
|
|
if err := m.Match(mi, 0, p); err == nil {
|
|
s := &omd.Service{
|
|
Key: m.Key(),
|
|
Port: port,
|
|
MetaCryptoType: omm.ToMetaCryptoType(omm.MetaCryptoTypeEnumNONE),
|
|
DiscoveredDate: omu.NowPtr(),
|
|
Metadata: m.Meta(),
|
|
Name: m.Name(),
|
|
}
|
|
|
|
resultChan <- s
|
|
return true
|
|
}
|
|
}
|
|
|
|
return false
|
|
}
|